diff --git a/CHANGELOG.md b/CHANGELOG.md index c78b0d8c..e9b49704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - The window sizes and positions of the tileset editor, palette editor, and region map editor are now stored in `porymap.cfg`. - Add ruler tool for measuring metatile distance in events tab (Right-click to turn on/off, left-click to lock in place). - Add delete button to wild pokemon encounters tab. -- Add ability to specify preferred text editor commands in `Options -> Edit Preferences`. These allow `Open Map Scripts` to open directly to the script for the currently selected event, and to open the project root directory in a text editor directly from porymap. +- Add custom text editor commands in `Options -> Edit Preferences`, a tool-button next to the `Script` combo-box, and `Tools -> Open Project in Text Editor`. The tool-button will open the map's scripts file to the cooresponding script. ### Changed - Holding `shift` now toggles "Smart Path" drawing; when the "Smart Paths" checkbox is checked, holding `shift` will temporarily disable it. diff --git a/docsrc/manual/editing-map-events.rst b/docsrc/manual/editing-map-events.rst index e950e4e3..cc2f017a 100644 --- a/docsrc/manual/editing-map-events.rst +++ b/docsrc/manual/editing-map-events.rst @@ -225,11 +225,17 @@ Respawn NPC Open Map Scripts ---------------- -Clicking the ``Open Map Scripts`` button |open-map-scripts-button| will open the map's scripts file in your default text editor. If nothing happens when this button is clicked, you may need to associate a text editor with the `.inc` file extension (or `.pory` if you're using Porycript). `Alternatively`, you may specify a preferred text editor command in *Options -> Edit Preferences*. By specifying a text editor like this you can allow Porymap to open the scripts file directly to the script of the currently selected event. +Clicking the ``Open Map Scripts`` button |open-map-scripts-button| will open the map's scripts file in your default text editor. If nothing happens when this button is clicked, you may need to associate a text editor with the `.inc` file extension (or `.pory` if you're using Porycript). + +Additionally, if you specify a ``Goto Line Command`` in *Options -> Edit Preferences* then a tool-button will appear next to the `Script` combo-box for selected events. Clicking this button will open the map's scripts file directly to the cooresponding script (if the script can be found in that file). +|go-to-script-button| .. |open-map-scripts-button| image:: images/editing-map-events/open-map-scripts-button.png +.. |go-to-script-button| + image:: images/editing-map-events/go-to-script-button.png + Tool Buttons ------------ diff --git a/docsrc/manual/images/editing-map-events/go-to-script-button.png b/docsrc/manual/images/editing-map-events/go-to-script-button.png new file mode 100644 index 00000000..859ed2f3 Binary files /dev/null and b/docsrc/manual/images/editing-map-events/go-to-script-button.png differ diff --git a/docsrc/manual/settings-and-options.rst b/docsrc/manual/settings-and-options.rst index 84c01e20..2e0ce77f 100644 --- a/docsrc/manual/settings-and-options.rst +++ b/docsrc/manual/settings-and-options.rst @@ -31,7 +31,7 @@ determined by this file. ``monitor_files``, 1, global, yes, Whether porymap will monitor changes to project files ``region_map_dimensions``, 32x20, global, yes, The dimensions of the region map tilemap ``theme``, default, global, yes, The color theme for porymap windows and widgets - ``text_editor_goto_line``, , global, yes, Optional command that will be executed when clicking ``Open Map Scripts``. + ``text_editor_goto_line``, , global, yes, The command that will be executed when clicking the tool-button next the ``Script`` combo-box. ``text_editor_open_directory``, , global, yes, The command that will be executed when clicking ``Open Project in Text Editor``. ``base_game_version``, , project, no, The base pret repo for this project ``use_encounter_json``, 1, project, yes, Enables wild encounter table editing diff --git a/include/editor.h b/include/editor.h index a8646eb8..21b413b1 100644 --- a/include/editor.h +++ b/include/editor.h @@ -155,7 +155,8 @@ public: void scaleMapView(int); public slots: - void openMapScripts() const; + void openMapScripts(const QString &scriptLabel) const; + void openMapScripts() const { openMapScripts(QString()); } void openProjectInTextEditor() const; void maskNonVisibleConnectionTiles(); diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index a402e188..9b3ac1ff 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -422,6 +422,9 @@ bool ParseUtil::ensureFieldsExist(QJsonObject obj, QList fields) { } int ParseUtil::getScriptLineNumber(const QString &filePath, const QString &scriptLabel) { + if (scriptLabel.isEmpty()) + return 0; + if (filePath.endsWith(".inc")) return getRawScriptLineNumber(readTextFile(filePath), scriptLabel); else if (filePath.endsWith(".pory")) diff --git a/src/editor.cpp b/src/editor.cpp index a83f03d0..ed0fd424 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -2026,7 +2026,7 @@ void Editor::deleteEvent(Event *event) { //updateSelectedObjects(); } -void Editor::openMapScripts() const { +void Editor::openMapScripts(const QString &scriptLabel) const { const QString scriptsPath = project->getMapScriptsFilePath(map->name); QString command = porymapConfig.getTextEditorGotoLine(); if (command.isEmpty()) { @@ -2035,8 +2035,6 @@ void Editor::openMapScripts() const { } else { if (command.contains("%F")) { if (command.contains("%L")) { - const QString scriptLabel = selected_events->isEmpty() ? - QString() : selected_events->first()->event->get("script_label"); const int lineNum = ParseUtil::getScriptLineNumber(scriptsPath, scriptLabel); command.replace("%L", QString::number(lineNum)); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c0713226..ebb232e6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -169,7 +169,7 @@ void MainWindow::initEditor() { connect(this->editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged())); connect(this->editor, SIGNAL(wildMonDataChanged()), this, SLOT(onWildMonDataChanged())); connect(this->editor, &Editor::mapRulerStatusChanged, this, &MainWindow::onMapRulerStatusChanged); - connect(ui->toolButton_Open_Scripts, &QToolButton::clicked, this->editor, &Editor::openMapScripts); + connect(ui->toolButton_Open_Scripts, &QToolButton::pressed, this->editor, QOverload<>::of(&Editor::openMapScripts)); connect(ui->actionOpen_Project_in_Text_Editor, &QAction::triggered, this->editor, &Editor::openProjectInTextEditor); this->loadUserSettings(); @@ -1866,7 +1866,22 @@ void MainWindow::updateSelectedObjects() { } else { combo->setCurrentText(value); - fl->addRow(new QLabel(field_labels[key], widget), combo); + if (key == "script_label" && !porymapConfig.getTextEditorGotoLine().isEmpty()) { + // Add tool button next to combo to open scripts file to combo's current script label. + auto *hl = new QHBoxLayout(); + hl->setSpacing(3); + auto *openScriptButton = new QToolButton(widget); + openScriptButton->setFixedSize(combo->height(), combo->height()); + openScriptButton->setIcon(QFileIconProvider().icon(QFileIconProvider::File)); + openScriptButton->setToolTip("Go to this script definition in the map's scripts file."); + connect(openScriptButton, &QToolButton::clicked, + [this, combo]() { this->editor->openMapScripts(combo->currentText()); }); + hl->addWidget(combo); + hl->addWidget(openScriptButton); + fl->addRow(new QLabel(field_labels[key], widget), hl); + } else { + fl->addRow(new QLabel(field_labels[key], widget), combo); + } widget->setLayout(fl); frame->layout()->addWidget(widget);