diff --git a/include/config.h b/include/config.h index 720bd8d0..0b8f3ee3 100644 --- a/include/config.h +++ b/include/config.h @@ -79,6 +79,7 @@ public: this->textEditorGotoLine = ""; this->paletteEditorBitDepth = 24; this->projectSettingsTab = 0; + this->loadAllEventScripts = false; this->warpBehaviorWarningDisabled = false; this->eventDeleteWarningDisabled = false; this->eventOverlayEnabled = false; @@ -135,6 +136,7 @@ public: QString textEditorGotoLine; int paletteEditorBitDepth; int projectSettingsTab; + bool loadAllEventScripts; bool warpBehaviorWarningDisabled; bool eventDeleteWarningDisabled; bool eventOverlayEnabled; diff --git a/include/project.h b/include/project.h index 38a31f4a..4a8ec1f7 100644 --- a/include/project.h +++ b/include/project.h @@ -219,6 +219,7 @@ public: static QString getScriptFileExtension(bool usePoryScript); QString getScriptDefaultString(bool usePoryScript, QString mapName) const; QStringList getEventScriptsFilePaths() const; + void insertGlobalScriptLabels(QStringList &scriptLabels) const; QString getDefaultPrimaryTilesetLabel() const; QString getDefaultSecondaryTilesetLabel() const; diff --git a/src/config.cpp b/src/config.cpp index b56baa4c..22c44b19 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -390,6 +390,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { } } else if (key == "project_settings_tab") { this->projectSettingsTab = getConfigInteger(key, value, 0); + } else if (key == "load_all_event_scripts") { + this->loadAllEventScripts = getConfigBool(key, value); } else if (key == "warp_behavior_warning_disabled") { this->warpBehaviorWarningDisabled = getConfigBool(key, value); } else if (key == "event_delete_warning_disabled") { @@ -479,6 +481,7 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("text_editor_goto_line", this->textEditorGotoLine); map.insert("palette_editor_bit_depth", QString::number(this->paletteEditorBitDepth)); map.insert("project_settings_tab", QString::number(this->projectSettingsTab)); + map.insert("load_all_event_scripts", QString::number(this->loadAllEventScripts)); map.insert("warp_behavior_warning_disabled", QString::number(this->warpBehaviorWarningDisabled)); map.insert("event_delete_warning_disabled", QString::number(this->eventDeleteWarningDisabled)); map.insert("event_overlay_enabled", QString::number(this->eventOverlayEnabled)); diff --git a/src/core/map.cpp b/src/core/map.cpp index d45a4c1f..7945ab42 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -152,13 +152,12 @@ QStringList Map::getScriptLabels(Event::Group group) { scriptLabels = scriptTracker.getScripts(); } - // Add scripts from map's scripts file, and empty names. + // Add labels from the map's scripts file scriptLabels.append(m_scriptsFileLabels); scriptLabels.sort(Qt::CaseInsensitive); - scriptLabels.prepend("0x0"); - scriptLabels.prepend("NULL"); - scriptLabels.removeAll(""); + scriptLabels.removeAll("0"); + scriptLabels.removeAll("0x0"); scriptLabels.removeDuplicates(); return scriptLabels; diff --git a/src/project.cpp b/src/project.cpp index bd4e9bf9..c8f12a34 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -2600,16 +2600,28 @@ bool Project::readMiscellaneousConstants() { } bool Project::readEventScriptLabels() { - globalScriptLabels.clear(); - for (const auto &filePath : getEventScriptsFilePaths()) - globalScriptLabels << ParseUtil::getGlobalScriptLabels(filePath); + this->globalScriptLabels.clear(); - globalScriptLabels.sort(Qt::CaseInsensitive); - globalScriptLabels.removeDuplicates(); + if (porymapConfig.loadAllEventScripts) + return true; + + for (const auto &filePath : getEventScriptsFilePaths()) + this->globalScriptLabels << ParseUtil::getGlobalScriptLabels(filePath); + + this->globalScriptLabels.sort(Qt::CaseInsensitive); + this->globalScriptLabels.removeDuplicates(); return true; } +void Project::insertGlobalScriptLabels(QStringList &scriptLabels) const { + if (this->globalScriptLabels.isEmpty()) + return; + scriptLabels.append(this->globalScriptLabels); + scriptLabels.sort(); + scriptLabels.removeDuplicates(); +} + QString Project::fixPalettePath(QString path) { static const QRegularExpression re_gbapal("\\.gbapal$"); path = path.replace(re_gbapal, ".pal"); diff --git a/src/ui/eventframes.cpp b/src/ui/eventframes.cpp index 40a545ab..45085e7c 100644 --- a/src/ui/eventframes.cpp +++ b/src/ui/eventframes.cpp @@ -173,12 +173,19 @@ void EventFrame::setActive(bool 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(this->event->getEventGroup())); + // The script dropdown and autocomplete are populated with scripts used by the map's events and from its scripts file. + if (!this->event->getMap()) + return; - // The dropdown's autocomplete has all script labels across the full project. - auto completer = new QCompleter(project->globalScriptLabels, combo); + QStringList scripts = this->event->getMap()->getScriptLabels(this->event->getEventGroup()); + combo->addItems(scripts); + + // Depending on the settings, the autocomplete may also contain all global scripts. + if (porymapConfig.loadAllEventScripts) { + project->insertGlobalScriptLabels(scripts); + } + + auto completer = new QCompleter(scripts, combo); completer->setCaseSensitivity(Qt::CaseInsensitive); completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel); completer->setFilterMode(Qt::MatchContains);