Sort script dropdown, minor fixes

This commit is contained in:
GriffinR 2024-01-05 12:45:16 -05:00
parent db1aabe3c2
commit 1212d7dfd8
5 changed files with 27 additions and 71 deletions

View file

@ -199,8 +199,6 @@ public:
static QString getScriptFileExtension(bool usePoryScript);
QString getScriptDefaultString(bool usePoryScript, QString mapName) const;
QStringList getEventScriptsFilePaths() const;
QCompleter *getEventScriptLabelCompleter(QStringList additionalScriptLabels);
QStringList getGlobalScriptLabels();
QString getDefaultPrimaryTilesetLabel();
QString getDefaultSecondaryTilesetLabel();
@ -251,9 +249,6 @@ private:
static int default_map_size;
static int max_object_events;
QStringListModel eventScriptLabelModel;
QCompleter eventScriptLabelCompleter;
signals:
void reloadProject();
void uncheckMonitorFilesAction();

View file

@ -31,6 +31,8 @@ public:
void invalidateUi();
void invalidateValues();
void populateScriptDropdown(NoScrollComboBox * combo, Project * project);
virtual void setActive(bool active);
public:
@ -87,8 +89,6 @@ public:
private:
ObjectEvent *object;
QCompleter *scriptCompleter = nullptr;
};
@ -158,8 +158,6 @@ public:
private:
TriggerEvent *trigger;
QCompleter *scriptCompleter = nullptr;
};
@ -203,8 +201,6 @@ public:
private:
SignEvent *sign;
QCompleter *scriptCompleter = nullptr;
};

View file

@ -483,6 +483,7 @@ QStringList Map::getScriptLabels(Event::Group group) const {
// Add scripts from map's scripts file, and empty names.
scriptLabels.append(scriptsFileLabels);
scriptLabels.sort(Qt::CaseInsensitive);
scriptLabels.prepend("0x0");
scriptLabels.prepend("NULL");

View file

@ -35,9 +35,7 @@ int Project::default_map_size = 20;
int Project::max_object_events = 64;
Project::Project(QWidget *parent) :
QObject(parent),
eventScriptLabelModel(this),
eventScriptLabelCompleter(this)
QObject(parent)
{
initSignals();
}
@ -2406,18 +2404,13 @@ bool Project::readMiscellaneousConstants() {
return true;
}
QStringList Project::getGlobalScriptLabels() {
return this->eventScriptLabelModel.stringList();
}
bool Project::readEventScriptLabels() {
globalScriptLabels.clear();
for (const auto &filePath : getEventScriptsFilePaths())
globalScriptLabels << ParseUtil::getGlobalScriptLabels(filePath);
eventScriptLabelModel.setStringList(globalScriptLabels);
eventScriptLabelCompleter.setModel(&eventScriptLabelModel);
eventScriptLabelCompleter.setCaseSensitivity(Qt::CaseInsensitive);
eventScriptLabelCompleter.setFilterMode(Qt::MatchContains);
globalScriptLabels.sort(Qt::CaseInsensitive);
globalScriptLabels.removeDuplicates();
return true;
}
@ -2478,13 +2471,6 @@ QStringList Project::getEventScriptsFilePaths() const {
return filePaths;
}
QCompleter *Project::getEventScriptLabelCompleter(QStringList additionalScriptLabels) {
additionalScriptLabels << globalScriptLabels;
additionalScriptLabels.removeDuplicates();
eventScriptLabelModel.setStringList(additionalScriptLabels);
return &eventScriptLabelCompleter;
}
void Project::setEventPixmap(Event *event, bool forceLoad) {
if (event && (event->getPixmap().isNull() || forceLoad))
event->loadPixmap(this);

View file

@ -168,6 +168,23 @@ void EventFrame::setActive(bool active) {
this->blockSignals(!active);
}
void EventFrame::populateScriptDropdown(NoScrollComboBox * combo, Project * project) {
// The script dropdown is populated with scripts used by the map's events and from its scripts file.
if (this->event->getMap())
combo->addItems(this->event->getMap()->getScriptLabels());
// The dropdown's autocomplete has all script labels across the full project.
auto completer = new QCompleter(project->globalScriptLabels, combo);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
completer->setFilterMode(Qt::MatchContains);
// Improve display speed for the autocomplete popup
auto popup = (QListView *)completer->popup();
if (popup) popup->setUniformItemSizes(true);
combo->setCompleter(completer);
}
void ObjectFrame::setup() {
@ -367,20 +384,7 @@ void ObjectFrame::populate(Project *project) {
this->combo_flag->addItems(project->flagNames);
this->combo_trainer_type->addItems(project->trainerTypes);
// The script dropdown is populated with scripts used by the map's events and from its scripts file.
QStringList scriptLabels;
if (this->object->getMap()) {
scriptLabels.append(this->object->getMap()->getScriptLabels());
this->combo_script->addItems(scriptLabels);
}
// The dropdown's autocomplete has all script labels across the full project.
scriptLabels.append(project->getGlobalScriptLabels());
scriptLabels.removeDuplicates();
this->scriptCompleter = new QCompleter(scriptLabels, this);
this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);
this->scriptCompleter->setFilterMode(Qt::MatchContains);
this->combo_script->setCompleter(this->scriptCompleter);
this->populateScriptDropdown(this->combo_script, project);
}
@ -637,20 +641,7 @@ void TriggerFrame::populate(Project *project) {
// var combo
this->combo_var->addItems(project->varNames);
// The script dropdown is populated with scripts used by the map's events and from its scripts file.
QStringList scriptLabels;
if (this->trigger->getMap()) {
scriptLabels.append(this->trigger->getMap()->getScriptLabels());
this->combo_script->addItems(scriptLabels);
}
// The dropdown's autocomplete has all script labels across the full project.
scriptLabels.append(project->getGlobalScriptLabels());
scriptLabels.removeDuplicates();
this->scriptCompleter = new QCompleter(scriptLabels, this);
this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);
this->scriptCompleter->setFilterMode(Qt::MatchContains);
this->combo_script->setCompleter(this->scriptCompleter);
this->populateScriptDropdown(this->combo_script, project);
}
@ -772,20 +763,7 @@ void SignFrame::populate(Project *project) {
// facing dir
this->combo_facing_dir->addItems(project->bgEventFacingDirections);
// The script dropdown is populated with scripts used by the map's events and from its scripts file.
QStringList scriptLabels;
if (this->sign->getMap()) {
scriptLabels.append(this->sign->getMap()->getScriptLabels());
this->combo_script->addItems(scriptLabels);
}
// The dropdown's autocomplete has all script labels across the full project.
scriptLabels.append(project->getGlobalScriptLabels());
scriptLabels.removeDuplicates();
this->scriptCompleter = new QCompleter(scriptLabels, this);
this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);
this->scriptCompleter->setFilterMode(Qt::MatchContains);
this->combo_script->setCompleter(this->scriptCompleter);
this->populateScriptDropdown(this->combo_script, project);
}