Add completion suggestions for global event scripts

This commit is contained in:
BigBahss
2021-01-29 22:05:40 -05:00
parent d2386fac9b
commit 3ccf433d1e
3 changed files with 28 additions and 3 deletions

View File

@@ -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);

View File

@@ -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<Event*> objects) {
bool needs_update = false;
for (Event *object : objects) {