From 3ccf433d1eb33e4e82419da016fb39ab8b146a8d Mon Sep 17 00:00:00 2001 From: BigBahss Date: Fri, 29 Jan 2021 22:05:40 -0500 Subject: [PATCH] Add completion suggestions for global event scripts --- include/project.h | 5 +++++ src/mainwindow.cpp | 9 ++++++--- src/project.cpp | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/project.h b/include/project.h index 085cd6d1..14e24939 100644 --- a/include/project.h +++ b/include/project.h @@ -60,6 +60,7 @@ public: QStringList *secretBaseIds = nullptr; QStringList *bgEventFacingDirections = nullptr; QStringList *trainerTypes = nullptr; + QStringList eventScriptLabels; QMap metatileBehaviorMap; QMap metatileBehaviorMapInverse; QMap facingDirections; @@ -167,6 +168,7 @@ public: bool readMetatileBehaviors(); bool readHealLocations(); bool readMiscellaneousConstants(); + bool readEventScriptLabels(); void loadEventPixmaps(QList objects); QMap getEventObjGfxConstants(); @@ -177,6 +179,7 @@ public: QString getScriptDefaultString(bool usePoryScript, QString mapName) const; QString getMapScriptsFilePath(const QString &mapName) const; QStringList getEventScriptsFilePaths() const; + QCompleter *getEventScriptLabelCompleter(const QStringList &additionalCompletions) const; bool loadMapBorder(Map *map); @@ -220,6 +223,8 @@ private: static int max_object_events; QWidget *parent; + QStringListModel *eventScriptLabelModel = nullptr; + QCompleter *eventScriptLabelCompleter = nullptr; signals: void reloadProject(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dd7f71bf..916a4d5e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -876,8 +876,9 @@ bool MainWindow::loadDataStructures() { && project->readHealLocations() && project->readMiscellaneousConstants() && project->readSpeciesIconPaths() - && project->readWildMonData(); - + && project->readWildMonData() + && project->readEventScriptLabels(); + return success && loadProjectCombos(); } @@ -1917,7 +1918,9 @@ void MainWindow::updateSelectedObjects() { "normal movement behavior actions."); combo->setMinimumContentsLength(4); } else if (key == "script_label") { - combo->addItems(editor->map->eventScriptLabels()); + const auto localScriptLabels = editor->map->eventScriptLabels(); + combo->addItems(localScriptLabels); + combo->setCompleter(editor->project->getEventScriptLabelCompleter(localScriptLabels)); combo->setToolTip("The script which is executed with this event."); } else if (key == "trainer_type") { combo->addItems(*editor->project->trainerTypes); diff --git a/src/project.cpp b/src/project.cpp index 8ef9b4b3..d0d308ef 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -2399,6 +2399,18 @@ bool Project::readMiscellaneousConstants() { return true; } +bool Project::readEventScriptLabels() { + for (const auto &filePath : getEventScriptsFilePaths()) + eventScriptLabels << ParseUtil::getGlobalScriptLabels(filePath); + + eventScriptLabelModel = new QStringListModel(eventScriptLabels, this); + eventScriptLabelCompleter = new QCompleter(eventScriptLabelModel, this); + eventScriptLabelCompleter->setCaseSensitivity(Qt::CaseInsensitive); + eventScriptLabelCompleter->setFilterMode(Qt::MatchContains); + + return true; +} + QString Project::fixPalettePath(QString path) { path = path.replace(QRegExp("\\.gbapal$"), ".pal"); return path; @@ -2462,6 +2474,11 @@ QStringList Project::getEventScriptsFilePaths() const { return filePaths; } +QCompleter *Project::getEventScriptLabelCompleter(const QStringList &additionalCompletions) const { + eventScriptLabelModel->setStringList(eventScriptLabels + additionalCompletions); + return eventScriptLabelCompleter; +} + void Project::loadEventPixmaps(QList objects) { bool needs_update = false; for (Event *object : objects) {