Update custom scripts editor
This commit is contained in:
parent
6ee76f80d1
commit
dcba9ececd
11 changed files with 174 additions and 37 deletions
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>374</width>
|
<width>535</width>
|
||||||
<height>355</height>
|
<height>355</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -49,20 +49,40 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="button_AddNewScript">
|
<widget class="QPushButton" name="button_CreateNewScript">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Create a new Porymap script file with a default template</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add New Script...</string>
|
<string>Create New Script...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../resources/images.qrc">
|
<iconset resource="../resources/images.qrc">
|
||||||
<normaloff>:/icons/add.ico</normaloff>:/icons/add.ico</iconset>
|
<normaloff>:/icons/file_add.ico</normaloff>:/icons/file_add.ico</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="button_ReloadScripts">
|
<widget class="QPushButton" name="button_LoadScript">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Add an existing script file to the list below</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Reload Scripts</string>
|
<string>Load Script...</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../resources/images.qrc">
|
||||||
|
<normaloff>:/icons/file_put.ico</normaloff>:/icons/file_put.ico</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_RefreshScripts">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Refresh all loaded scripts to account for any recent edits</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Refresh Scripts</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../resources/images.qrc">
|
<iconset resource="../resources/images.qrc">
|
||||||
|
@ -128,7 +148,7 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="dragDropMode">
|
<property name="dragDropMode">
|
||||||
<enum>QAbstractItemView::NoDragDrop</enum>
|
<enum>QAbstractItemView::DragOnly</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="defaultDropAction">
|
<property name="defaultDropAction">
|
||||||
<enum>Qt::IgnoreAction</enum>
|
<enum>Qt::IgnoreAction</enum>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>129</width>
|
<width>151</width>
|
||||||
<height>34</height>
|
<height>34</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -24,16 +24,12 @@
|
||||||
<number>4</number>
|
<number>4</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="b_Choose">
|
<widget class="QCheckBox" name="checkBox_Enable">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Choose a new filepath for this script</string>
|
<string>If unchecked this script will be ignored</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>...</string>
|
<string/>
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../resources/images.qrc">
|
|
||||||
<normaloff>:/icons/folder.ico</normaloff>:/icons/folder.ico</iconset>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -51,12 +47,16 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkBox_Enable">
|
<widget class="QToolButton" name="b_Choose">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>If unchecked this script will be ignored</string>
|
<string>Choose a new filepath for this script</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../resources/images.qrc">
|
||||||
|
<normaloff>:/icons/folder.ico</normaloff>:/icons/folder.ico</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../resources/images.qrc">
|
<iconset resource="../resources/images.qrc">
|
||||||
<normaloff>:/icons/edit_document.ico</normaloff>:/icons/edit_document.ico</iconset>
|
<normaloff>:/icons/file_edit.ico</normaloff>:/icons/file_edit.ico</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -31,10 +31,11 @@ private:
|
||||||
Ui::CustomScriptsEditor *ui;
|
Ui::CustomScriptsEditor *ui;
|
||||||
|
|
||||||
bool hasUnsavedChanges = false;
|
bool hasUnsavedChanges = false;
|
||||||
QString importDir;
|
QString fileDialogDir;
|
||||||
const QString baseDir;
|
const QString baseDir;
|
||||||
|
|
||||||
void displayScript(const QString &filepath, bool enabled);
|
void displayScript(const QString &filepath, bool enabled);
|
||||||
|
void displayNewScript(QString filepath);
|
||||||
QString chooseScript(QString dir);
|
QString chooseScript(QString dir);
|
||||||
void removeScript(QListWidgetItem * item);
|
void removeScript(QListWidgetItem * item);
|
||||||
void replaceScript(QListWidgetItem * item);
|
void replaceScript(QListWidgetItem * item);
|
||||||
|
@ -52,8 +53,9 @@ private:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void dialogButtonClicked(QAbstractButton *button);
|
void dialogButtonClicked(QAbstractButton *button);
|
||||||
void addNewScript();
|
void createNewScript();
|
||||||
void reloadScripts();
|
void loadScript();
|
||||||
|
void refreshScripts();
|
||||||
void removeSelectedScripts();
|
void removeSelectedScripts();
|
||||||
void openSelectedScripts();
|
void openSelectedScripts();
|
||||||
};
|
};
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB |
BIN
resources/icons/file_add.ico
Executable file
BIN
resources/icons/file_add.ico
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
resources/icons/file_edit.ico
Executable file
BIN
resources/icons/file_edit.ico
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
resources/icons/file_put.ico
Executable file
BIN
resources/icons/file_put.ico
Executable file
Binary file not shown.
After Width: | Height: | Size: 1 KiB |
|
@ -4,8 +4,10 @@
|
||||||
<file>icons/collapse_all.ico</file>
|
<file>icons/collapse_all.ico</file>
|
||||||
<file>icons/cursor.ico</file>
|
<file>icons/cursor.ico</file>
|
||||||
<file>icons/delete.ico</file>
|
<file>icons/delete.ico</file>
|
||||||
<file>icons/edit_document.ico</file>
|
|
||||||
<file>icons/expand_all.ico</file>
|
<file>icons/expand_all.ico</file>
|
||||||
|
<file>icons/file_add.ico</file>
|
||||||
|
<file>icons/file_edit.ico</file>
|
||||||
|
<file>icons/file_put.ico</file>
|
||||||
<file>icons/fill_color_cursor.ico</file>
|
<file>icons/fill_color_cursor.ico</file>
|
||||||
<file>icons/fill_color.ico</file>
|
<file>icons/fill_color.ico</file>
|
||||||
<file>icons/folder_closed_map.ico</file>
|
<file>icons/folder_closed_map.ico</file>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
<file>text/prefabs_default_emerald.json</file>
|
<file>text/prefabs_default_emerald.json</file>
|
||||||
<file>text/prefabs_default_firered.json</file>
|
<file>text/prefabs_default_firered.json</file>
|
||||||
<file>text/prefabs_default_ruby.json</file>
|
<file>text/prefabs_default_ruby.json</file>
|
||||||
|
<file>text/script_template.js</file>
|
||||||
<file>../CHANGELOG.md</file>
|
<file>../CHANGELOG.md</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
71
resources/text/script_template.js
Normal file
71
resources/text/script_template.js
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
// Called when Porymap successfully opens a project.
|
||||||
|
export function onProjectOpened(projectPath) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when Porymap closes a project. For example, this is called when opening a different project.
|
||||||
|
export function onProjectClosed(projectPath) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when a map is opened.
|
||||||
|
export function onMapOpened(mapName) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when a block is changed on the map. For example, this is called when a user paints a new tile or changes the collision property of a block.
|
||||||
|
export function onBlockChanged(x, y, prevBlock, newBlock) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when a border metatile is changed.
|
||||||
|
export function onBorderMetatileChanged(x, y, prevMetatileId, newMetatileId) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the mouse enters a new map block.
|
||||||
|
export function onBlockHoverChanged(x, y) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the mouse exits the map.
|
||||||
|
export function onBlockHoverCleared() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the dimensions of the map are changed.
|
||||||
|
export function onMapResized(oldWidth, oldHeight, newWidth, newHeight) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the dimensions of the border are changed.
|
||||||
|
export function onBorderResized(oldWidth, oldHeight, newWidth, newHeight) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the map is updated by use of the Map Shift tool.
|
||||||
|
export function onMapShifted(xDelta, yDelta) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the currently loaded tileset is changed by switching to a new one or by saving changes to it in the Tileset Editor.
|
||||||
|
export function onTilesetUpdated(tilesetName) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the selected tab in the main tab bar is changed.
|
||||||
|
// Tabs are indexed from left to right, starting at 0 (0: Map, 1: Events, 2: Header, 3: Connections, 4: Wild Pokemon).
|
||||||
|
export function onMainTabChanged(oldTab, newTab) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the selected tab in the map view tab bar is changed.
|
||||||
|
// Tabs are indexed from left to right, starting at 0 (0: Metatiles, 1: Collision, 2: Prefabs).
|
||||||
|
export function onMapViewTabChanged(oldTab, newTab) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the visibility of the border and connecting maps is toggled on or off.
|
||||||
|
export function onBorderVisibilityToggled(visible) {
|
||||||
|
|
||||||
|
}
|
|
@ -23,10 +23,11 @@ CustomScriptsEditor::CustomScriptsEditor(QWidget *parent) :
|
||||||
for (int i = 0; i < paths.length(); i++)
|
for (int i = 0; i < paths.length(); i++)
|
||||||
this->displayScript(paths.at(i), enabled.at(i));
|
this->displayScript(paths.at(i), enabled.at(i));
|
||||||
|
|
||||||
this->importDir = userConfig.getProjectDir();
|
this->fileDialogDir = userConfig.getProjectDir();
|
||||||
|
|
||||||
connect(ui->button_AddNewScript, &QAbstractButton::clicked, this, &CustomScriptsEditor::addNewScript);
|
connect(ui->button_CreateNewScript, &QAbstractButton::clicked, this, &CustomScriptsEditor::createNewScript);
|
||||||
connect(ui->button_ReloadScripts, &QAbstractButton::clicked, this, &CustomScriptsEditor::reloadScripts);
|
connect(ui->button_LoadScript, &QAbstractButton::clicked, this, &CustomScriptsEditor::loadScript);
|
||||||
|
connect(ui->button_RefreshScripts, &QAbstractButton::clicked, this, &CustomScriptsEditor::refreshScripts);
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &CustomScriptsEditor::dialogButtonClicked);
|
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &CustomScriptsEditor::dialogButtonClicked);
|
||||||
|
|
||||||
this->initShortcuts();
|
this->initShortcuts();
|
||||||
|
@ -48,13 +49,17 @@ void CustomScriptsEditor::initShortcuts() {
|
||||||
shortcut_open->setObjectName("shortcut_open");
|
shortcut_open->setObjectName("shortcut_open");
|
||||||
shortcut_open->setWhatsThis("Open Selected Scripts");
|
shortcut_open->setWhatsThis("Open Selected Scripts");
|
||||||
|
|
||||||
auto *shortcut_addNew = new Shortcut(QKeySequence(), this, SLOT(addNewScript()));
|
auto *shortcut_createNew = new Shortcut(QKeySequence(), this, SLOT(createNewScript()));
|
||||||
shortcut_addNew->setObjectName("shortcut_addNew");
|
shortcut_createNew->setObjectName("shortcut_createNew");
|
||||||
shortcut_addNew->setWhatsThis("Add New Script...");
|
shortcut_createNew->setWhatsThis("Create New Script...");
|
||||||
|
|
||||||
auto *shortcut_reload = new Shortcut(QKeySequence(), this, SLOT(reloadScripts()));
|
auto *shortcut_load = new Shortcut(QKeySequence(), this, SLOT(loadScript()));
|
||||||
shortcut_reload->setObjectName("shortcut_reload");
|
shortcut_load->setObjectName("shortcut_load");
|
||||||
shortcut_reload->setWhatsThis("Reload Scripts");
|
shortcut_load->setWhatsThis("Load Script...");
|
||||||
|
|
||||||
|
auto *shortcut_refresh = new Shortcut(QKeySequence(), this, SLOT(refreshScripts()));
|
||||||
|
shortcut_refresh->setObjectName("shortcut_refresh");
|
||||||
|
shortcut_refresh->setWhatsThis("Refresh Scripts");
|
||||||
|
|
||||||
shortcutsConfig.load();
|
shortcutsConfig.load();
|
||||||
shortcutsConfig.setDefaultShortcuts(shortcutableObjects());
|
shortcutsConfig.setDefaultShortcuts(shortcutableObjects());
|
||||||
|
@ -145,13 +150,49 @@ QString CustomScriptsEditor::chooseScript(QString dir) {
|
||||||
return QFileDialog::getOpenFileName(this, "Choose Custom Script File", dir, "JavaScript Files (*.js)");
|
return QFileDialog::getOpenFileName(this, "Choose Custom Script File", dir, "JavaScript Files (*.js)");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomScriptsEditor::addNewScript() {
|
void CustomScriptsEditor::createNewScript() {
|
||||||
QString filepath = this->chooseScript(this->importDir);
|
QString filepath = QFileDialog::getSaveFileName(this, "Create New Script File", this->fileDialogDir + "/new_script.js", "JavaScript Files (*.js)");
|
||||||
if (filepath.isEmpty())
|
if (filepath.isEmpty())
|
||||||
return;
|
return;
|
||||||
this->importDir = filepath;
|
this->fileDialogDir = filepath;
|
||||||
|
|
||||||
|
QFile scriptFile(filepath);
|
||||||
|
if (!scriptFile.open(QIODevice::WriteOnly)) {
|
||||||
|
logError(QString("Error: Could not open %1 for writing").arg(filepath));
|
||||||
|
QMessageBox messageBox(this);
|
||||||
|
messageBox.setText("Failed to create new script file!");
|
||||||
|
messageBox.setInformativeText(QString("Could not open \"%1\" for writing").arg(filepath));
|
||||||
|
messageBox.setIcon(QMessageBox::Warning);
|
||||||
|
messageBox.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ParseUtil parser;
|
||||||
|
scriptFile.write(parser.readTextFile(":/text/script_template.js").toUtf8());
|
||||||
|
scriptFile.close();
|
||||||
|
// TODO: When this dialog closes, focus returns to the editor window
|
||||||
|
this->displayNewScript(filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomScriptsEditor::loadScript() {
|
||||||
|
QString filepath = this->chooseScript(this->fileDialogDir);
|
||||||
|
if (filepath.isEmpty())
|
||||||
|
return;
|
||||||
|
this->fileDialogDir = filepath;
|
||||||
|
this->displayNewScript(filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomScriptsEditor::displayNewScript(QString filepath) {
|
||||||
if (filepath.startsWith(this->baseDir))
|
if (filepath.startsWith(this->baseDir))
|
||||||
filepath.remove(0, this->baseDir.length());
|
filepath.remove(0, this->baseDir.length());
|
||||||
|
|
||||||
|
// Verify new script path is not already in list
|
||||||
|
for (int i = 0; i < ui->list->count(); i++) {
|
||||||
|
if (filepath == this->getScriptFilepath(ui->list->item(i), false)) {
|
||||||
|
QMessageBox::information(this, "", QString("The script '%1' is already loaded").arg(filepath));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this->displayScript(filepath, true);
|
this->displayScript(filepath, true);
|
||||||
this->markEdited();
|
this->markEdited();
|
||||||
}
|
}
|
||||||
|
@ -192,7 +233,7 @@ void CustomScriptsEditor::openSelectedScripts() {
|
||||||
this->openScript(item);
|
this->openScript(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomScriptsEditor::reloadScripts() {
|
void CustomScriptsEditor::refreshScripts() {
|
||||||
if (this->hasUnsavedChanges) {
|
if (this->hasUnsavedChanges) {
|
||||||
if (this->prompt("Scripts have been modified, save changes and reload the script engine?", QMessageBox::Yes) == QMessageBox::No)
|
if (this->prompt("Scripts have been modified, save changes and reload the script engine?", QMessageBox::Yes) == QMessageBox::No)
|
||||||
return;
|
return;
|
||||||
|
@ -218,7 +259,7 @@ void CustomScriptsEditor::save() {
|
||||||
|
|
||||||
userConfig.setCustomScripts(paths, enabledStates);
|
userConfig.setCustomScripts(paths, enabledStates);
|
||||||
this->hasUnsavedChanges = false;
|
this->hasUnsavedChanges = false;
|
||||||
this->reloadScripts();
|
this->refreshScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CustomScriptsEditor::prompt(const QString &text, QMessageBox::StandardButton defaultButton) {
|
int CustomScriptsEditor::prompt(const QString &text, QMessageBox::StandardButton defaultButton) {
|
||||||
|
|
Loading…
Reference in a new issue