Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 49 additions & 20 deletions forms/preferenceeditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<item row="3" column="0">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -159,7 +159,7 @@
<item row="0" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -209,7 +209,7 @@
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -253,13 +253,42 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_AutocompleteAllScripts">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If checked, the list of suggestions when typing in an Event's Script field will include all global script labels in the project. Enabling this setting will make Porymap's startup slower.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Autocomplete Script labels using all possible scripts</string>
<widget class="QGroupBox" name="groupBox_ScriptAutocomplete">
<property name="title">
<string>Script label autocomplete</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QRadioButton" name="radioButton_AutocompleteAllScripts">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If checked, the list of suggestions when typing in an Event's Script field will include all global script labels in the project. This is the slowest option for Porymap's project opening.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>All possible scripts</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_AutocompleteCommonScripts">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If checked, the list of suggestions when typing in an Event's Script field will include script labels from the current map's scripts file, scripts in-use by the map's other events, and all script files in the &lt;span style=&quot; font-family:'SFMono-Regular','Menlo','Monaco','Consolas','Liberation Mono','Courier New','Courier','monospace'; font-size:11px; color:#e74c3c; background-color:#ffffff;&quot;&gt;data_scripts_folders &lt;/span&gt;folder.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Current map, and global script files</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_AutocompleteMapScripts">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If checked, the list of suggestions when typing in an Event's Script field will only include script labels from the current map's scripts file and scripts in-use by the map's other events. This is the fastest option for Porymap's project opening.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Current map only</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
Expand Down Expand Up @@ -294,7 +323,7 @@
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -323,7 +352,7 @@
<item>
<widget class="QScrollArea" name="scrollArea_TextEditor">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
Expand All @@ -333,21 +362,21 @@
<rect>
<x>0</x>
<y>0</y>
<width>476</width>
<height>343</height>
<width>495</width>
<height>376</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
<enum>QLayout::SizeConstraint::SetMinimumSize</enum>
</property>
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="label_TextEditorGotoLineHelp">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;When this command is set a button will appear next to the &lt;span style=&quot; font-weight:600; font-style:italic;&quot;&gt;Script&lt;/span&gt; combo-box in the &lt;span style=&quot; font-weight:600; font-style:italic;&quot;&gt;Events&lt;/span&gt; tab which executes this command.&lt;span style=&quot; font-weight:600;&quot;&gt; %F&lt;/span&gt; will be substituted with the file path of the script and &lt;span style=&quot; font-weight:600;&quot;&gt;%L&lt;/span&gt; will be substituted with the line number of the script in that file. &lt;span style=&quot; font-weight:600;&quot;&gt;%F &lt;/span&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;must&lt;/span&gt; be given if &lt;span style=&quot; font-weight:600;&quot;&gt;%L&lt;/span&gt; is given. If &lt;span style=&quot; font-weight:600;&quot;&gt;%F&lt;/span&gt; is &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; given then the script's file path will be added to the end of the command. If the script can't be found then the current map's scripts file is opened.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down Expand Up @@ -380,7 +409,7 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is the command that is executed when clicking &lt;span style=&quot; font-weight:600; font-style:italic;&quot;&gt;Open Project in Text Editor&lt;/span&gt; in the &lt;span style=&quot; font-weight:600; font-style:italic;&quot;&gt;Tools&lt;/span&gt; menu. &lt;span style=&quot; font-weight:600;&quot;&gt;%D&lt;/span&gt; will be substituted with the project's root directory. If &lt;span style=&quot; font-weight:600;&quot;&gt;%D&lt;/span&gt; is &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; specified then the project directory will be added to the end of the command.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down Expand Up @@ -410,10 +439,10 @@
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -426,7 +455,7 @@
<item row="7" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -447,7 +476,7 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Apply|QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
Expand Down
10 changes: 8 additions & 2 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ extern const QVersionNumber porymapVersion;

#define CONFIG_BACKWARDS_COMPATABILITY

enum ScriptAutocompleteMode {
MapOnly,
MapAndCommon,
All,
};

class KeyValueConfigBase
{
public:
Expand Down Expand Up @@ -101,7 +107,7 @@ class PorymapConfig: public KeyValueConfigBase
this->textEditorGotoLine = "";
this->paletteEditorBitDepth = 24;
this->projectSettingsTab = 0;
this->loadAllEventScripts = false;
this->scriptAutocompleteMode = ScriptAutocompleteMode::MapOnly;
this->warpBehaviorWarningDisabled = false;
this->eventDeleteWarningDisabled = false;
this->eventOverlayEnabled = false;
Expand Down Expand Up @@ -168,7 +174,7 @@ class PorymapConfig: public KeyValueConfigBase
QString textEditorGotoLine;
int paletteEditorBitDepth;
int projectSettingsTab;
bool loadAllEventScripts;
ScriptAutocompleteMode scriptAutocompleteMode;
bool warpBehaviorWarningDisabled;
bool eventDeleteWarningDisabled;
bool eventOverlayEnabled;
Expand Down
2 changes: 1 addition & 1 deletion include/core/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Map : public QObject
void modified();
void scriptsModified();
void mapDimensionsChanged(const QSize &size);
void openScriptRequested(QString label);
void openScriptRequested(const QString &label);
void connectionAdded(MapConnection*);
void connectionRemoved(MapConnection*);
void layoutChanged();
Expand Down
3 changes: 2 additions & 1 deletion include/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ class Editor : public QObject

public slots:
void openMapScripts() const;
void openScript(const QString &scriptLabel) const;
bool openScript(const QString &scriptLabel) const;
bool openScriptInFile(const QString &scriptLabel, const QString &filepath) const;
void openProjectInTextEditor() const;
void maskNonVisibleConnectionTiles();
void onBorderMetatilesChanged();
Expand Down
6 changes: 5 additions & 1 deletion include/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ class Project : public QObject

static QString getScriptFileExtension(bool usePoryScript);
QString getScriptDefaultString(bool usePoryScript, QString mapName) const;
QStringList getEventScriptsFilepaths() const;

QStringList getAllEventScriptsFilepaths() const;
QStringList getMapScriptsFilepaths() const;
QStringList getCommonEventScriptsFilepaths() const;
QStringList findScriptsFiles(const QString &searchDir, const QStringList &fileNames = {"*"}) const;
void insertGlobalScriptLabels(QStringList &scriptLabels) const;

QString getDefaultPrimaryTilesetLabel() const;
Expand Down
3 changes: 2 additions & 1 deletion include/ui/preferenceeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PREFERENCES_H

#include <QMainWindow>
#include "config.h"

class NoScrollComboBox;
class QAbstractButton;
Expand All @@ -23,7 +24,7 @@ class PreferenceEditor : public QMainWindow
signals:
void preferencesSaved();
void themeChanged(const QString &theme);
void scriptSettingsChanged(bool on);
void scriptSettingsChanged(ScriptAutocompleteMode mode);
void reloadProjectRequested();

private:
Expand Down
9 changes: 7 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,13 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
}
} else if (key == "project_settings_tab") {
this->projectSettingsTab = getConfigInteger(key, value, 0);
#ifdef CONFIG_BACKWARDS_COMPATABILITY
// Old setting replaced by script_autocomplete_mode
} else if (key == "load_all_event_scripts") {
this->loadAllEventScripts = getConfigBool(key, value);
this->scriptAutocompleteMode = getConfigBool(key, value) ? ScriptAutocompleteMode::All : ScriptAutocompleteMode::MapOnly;
#endif
} else if (key == "script_autocomplete_mode") {
this->scriptAutocompleteMode = static_cast<ScriptAutocompleteMode>(getConfigInteger(key, value, ScriptAutocompleteMode::MapOnly, ScriptAutocompleteMode::All));
} else if (key == "warp_behavior_warning_disabled") {
this->warpBehaviorWarningDisabled = getConfigBool(key, value);
} else if (key == "event_delete_warning_disabled") {
Expand Down Expand Up @@ -551,7 +556,7 @@ QMap<QString, QString> 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("script_autocomplete_mode", QString::number(this->scriptAutocompleteMode));
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));
Expand Down
32 changes: 20 additions & 12 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2355,21 +2355,29 @@ void Editor::openMapScripts() const {
openInTextEditor(map->getScriptsFilepath());
}

void Editor::openScript(const QString &scriptLabel) const {
bool Editor::openScript(const QString &scriptLabel) const {
// Find the location of scriptLabel.
QStringList scriptPaths(map->getScriptsFilepath());
scriptPaths << project->getEventScriptsFilepaths();
int lineNum = 0;
QString scriptPath = scriptPaths.first();
for (const auto &path : scriptPaths) {
lineNum = ParseUtil::getScriptLineNumber(path, scriptLabel);
if (lineNum != 0) {
scriptPath = path;
break;
}
// First, try the current map's scripts file.
if (openScriptInFile(scriptLabel, map->getScriptsFilepath()))
return true;

// Script is not in the current map's scripts file.
// Search all possible script files.
const QStringList paths = project->getAllEventScriptsFilepaths();
for (const auto &path : paths) {
if (openScriptInFile(scriptLabel, path))
return true;
}
return false;
}

bool Editor::openScriptInFile(const QString &scriptLabel, const QString &filepath) const {
int lineNum = ParseUtil::getScriptLineNumber(filepath, scriptLabel);
if (lineNum == 0)
return false;

openInTextEditor(scriptPath, lineNum);
openInTextEditor(filepath, lineNum);
return true;
}

void Editor::openMapJson(const QString &mapName) const {
Expand Down
70 changes: 46 additions & 24 deletions src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2970,13 +2970,19 @@ bool Project::readGlobalConstants() {
bool Project::readEventScriptLabels() {
this->globalScriptLabels.clear();

if (porymapConfig.loadAllEventScripts) {
for (const auto &filePath : getEventScriptsFilepaths())
this->globalScriptLabels << ParseUtil::getGlobalScriptLabels(filePath);
QStringList paths;
if (porymapConfig.scriptAutocompleteMode == ScriptAutocompleteMode::All) {
paths = getAllEventScriptsFilepaths();
} else if (porymapConfig.scriptAutocompleteMode == ScriptAutocompleteMode::MapAndCommon) {
paths = getCommonEventScriptsFilepaths();
}

this->globalScriptLabels.sort(Qt::CaseInsensitive);
this->globalScriptLabels.removeDuplicates();
for (const auto &path : paths) {
this->globalScriptLabels << ParseUtil::getGlobalScriptLabels(path);
}
this->globalScriptLabels.sort(Qt::CaseInsensitive);
this->globalScriptLabels.removeDuplicates();

emit eventScriptLabelsRead();
return true;
}
Expand Down Expand Up @@ -3012,30 +3018,46 @@ QString Project::getScriptDefaultString(bool usePoryScript, QString mapName) con
return QString("%1_MapScripts::\n\t.byte 0\n").arg(mapName);
}

QStringList Project::getEventScriptsFilepaths() const {
QStringList filePaths(QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_event_scripts)));
const QString scriptsDir = QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_scripts_folders));
const QString mapsDir = QDir::cleanPath(root + "/" + projectConfig.getFilePath(ProjectFilePath::data_map_folders));
QStringList Project::getAllEventScriptsFilepaths() const {
return getMapScriptsFilepaths() + getCommonEventScriptsFilepaths();
}

if (projectConfig.usePoryScript) {
QDirIterator it_pory_shared(scriptsDir, {"*.pory"}, QDir::Files);
while (it_pory_shared.hasNext())
filePaths << it_pory_shared.next();
// Get the paths for all "scripts.inc" / "scripts.pory" files in the data/maps/*/ folders.
QStringList Project::getMapScriptsFilepaths() const {
return findScriptsFiles(projectConfig.getFilePath(ProjectFilePath::data_map_folders), {"scripts"});
}

QDirIterator it_pory_maps(mapsDir, {"scripts.pory"}, QDir::Files, QDirIterator::Subdirectories);
while (it_pory_maps.hasNext())
filePaths << it_pory_maps.next();
}
// Get the paths for all "*.inc" / "*.pory" files in the data/scripts/ folder, + data/event_scripts.s.
QStringList Project::getCommonEventScriptsFilepaths() const {
QStringList paths = { QDir::cleanPath(this->root + "/" + projectConfig.getFilePath(ProjectFilePath::data_event_scripts)) };
return paths + findScriptsFiles(projectConfig.getFilePath(ProjectFilePath::data_scripts_folders));
}

QDirIterator it_inc_shared(scriptsDir, {"*.inc"}, QDir::Files);
while (it_inc_shared.hasNext())
filePaths << it_inc_shared.next();
QStringList Project::findScriptsFiles(const QString &searchDir, const QStringList &fileNames) const {
QStringList paths;

QDirIterator it_inc_maps(mapsDir, {"scripts.inc"}, QDir::Files, QDirIterator::Subdirectories);
while (it_inc_maps.hasNext())
filePaths << it_inc_maps.next();
QString dir = searchDir;
if (!dir.startsWith(this->root)) {
dir = QDir::cleanPath(this->root + "/" + dir);
}

QStringList filters;
for (const auto &s : fileNames) {
filters.append(s + getScriptFileExtension(false));
if (projectConfig.usePoryScript) {
filters.append(s + getScriptFileExtension(true));
}
}

return filePaths;
// TODO: Filter out .inc files that are generated by a .pory file.
// They won't cause problems for the user, but it'll create extra parsing work later.
if (!filters.isEmpty()) {
QDirIterator it(dir, filters, QDir::Files, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
while (it.hasNext()) {
paths.append(it.next());
}
}
return paths;
}

void Project::loadEventPixmap(Event *event, bool forceLoad) {
Expand Down
Loading