From 9f5ac2935e6bce4a64ebf883d3f574290cbf93d4 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 6 Aug 2025 17:57:48 -0400 Subject: [PATCH] Disallow invalid text in tileset selectors --- CHANGELOG.md | 1 + include/mainwindow.h | 6 ++---- src/mainwindow.cpp | 28 +++++++++++++++++++++------- src/scriptapi/apimap.cpp | 8 -------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c899c6..41fe7e4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp - Fix `Ctrl+Shift+Z` not being set as a default shortcut for Redo in the Palette Editor like it is for other windows. - Fix the Tileset Editor's status bar not updating while selecting tiles in the metatile layer view. - Fix the Region Map Editor incorrectly displaying whether a `MAPSEC` has region map data. +- Fix the Primary/Secondary Tileset selectors allowing invalid text, and considering a map unsaved if changed to invalid text then back again. - Fix broken error message for the primary tileset on the new map/layout dialogs. - Fix the dialog for duplicating/importing a map layout not allowing the tilesets to be changed. - Fix warning not appearing when the log file exceeds maximum size. diff --git a/include/mainwindow.h b/include/mainwindow.h index be4cc258..cd45fb5a 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -119,8 +119,8 @@ public: Q_INVOKABLE int getNumSecondaryTilesetTiles(); Q_INVOKABLE QString getPrimaryTileset(); Q_INVOKABLE QString getSecondaryTileset(); - Q_INVOKABLE void setPrimaryTileset(QString tileset); - Q_INVOKABLE void setSecondaryTileset(QString tileset); + Q_INVOKABLE void setPrimaryTileset(const QString &tileset); + Q_INVOKABLE void setSecondaryTileset(const QString &tileset); void saveMetatilesByMetatileId(int metatileId); void saveMetatileAttributesByMetatileId(int metatileId); Metatile * getMetatile(int metatileId); @@ -251,8 +251,6 @@ private slots: void on_pushButton_AddConnection_clicked(); void on_button_OpenDiveMap_clicked(); void on_button_OpenEmergeMap_clicked(); - void on_comboBox_PrimaryTileset_currentTextChanged(const QString &arg1); - void on_comboBox_SecondaryTileset_currentTextChanged(const QString &arg1); void on_pushButton_ChangeDimensions_clicked(); void resetMapViewScale(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index baf4c056..d1644528 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -320,10 +320,12 @@ void MainWindow::initExtraSignals() { connect(ui->action_NewMap, &QAction::triggered, this, &MainWindow::openNewMapDialog); connect(ui->action_NewLayout, &QAction::triggered, this, &MainWindow::openNewLayoutDialog); connect(ui->actionDuplicate_Current_Map_Layout, &QAction::triggered, this, &MainWindow::openDuplicateMapOrLayoutDialog); - connect(ui->comboBox_LayoutSelector->lineEdit(), &QLineEdit::editingFinished, this, &MainWindow::onLayoutSelectorEditingFinished); + connect(ui->comboBox_LayoutSelector, &NoScrollComboBox::editingFinished, this, &MainWindow::onLayoutSelectorEditingFinished); connect(ui->checkBox_smartPaths, &QCheckBox::toggled, this, &MainWindow::setSmartPathsEnabled); connect(ui->checkBox_ToggleBorder, &QCheckBox::toggled, this, &MainWindow::setBorderVisibility); connect(ui->checkBox_MirrorConnections, &QCheckBox::toggled, this, &MainWindow::setMirrorConnectionsEnabled); + connect(ui->comboBox_PrimaryTileset, &NoScrollComboBox::editingFinished, [this] { setPrimaryTileset(ui->comboBox_PrimaryTileset->currentText()); }); + connect(ui->comboBox_SecondaryTileset, &NoScrollComboBox::editingFinished, [this] { setSecondaryTileset(ui->comboBox_SecondaryTileset->currentText()); }); } void MainWindow::on_actionCheck_for_Updates_triggered() { @@ -2761,26 +2763,38 @@ void MainWindow::on_button_OpenEmergeMap_clicked() { userSetMap(ui->comboBox_EmergeMap->currentText()); } -void MainWindow::on_comboBox_PrimaryTileset_currentTextChanged(const QString &tilesetLabel) -{ - if (editor->project->primaryTilesetLabels.contains(tilesetLabel) && editor->layout) { +void MainWindow::setPrimaryTileset(const QString &tilesetLabel) { + if (!this->editor->layout || this->editor->layout->tileset_primary_label == tilesetLabel) + return; + + if (editor->project->primaryTilesetLabels.contains(tilesetLabel)) { editor->updatePrimaryTileset(tilesetLabel); redrawMapScene(); updateTilesetEditor(); prefab.updatePrefabUi(editor->layout); markLayoutEdited(); } + + // Restore valid text if input was invalid, or sync combo box with new valid setting. + const QSignalBlocker b(ui->comboBox_PrimaryTileset); + ui->comboBox_PrimaryTileset->setTextItem(this->editor->layout->tileset_primary_label); } -void MainWindow::on_comboBox_SecondaryTileset_currentTextChanged(const QString &tilesetLabel) -{ - if (editor->project->secondaryTilesetLabels.contains(tilesetLabel) && editor->layout) { +void MainWindow::setSecondaryTileset(const QString &tilesetLabel) { + if (!this->editor->layout || this->editor->layout->tileset_secondary_label == tilesetLabel) + return; + + if (editor->project->secondaryTilesetLabels.contains(tilesetLabel)) { editor->updateSecondaryTileset(tilesetLabel); redrawMapScene(); updateTilesetEditor(); prefab.updatePrefabUi(editor->layout); markLayoutEdited(); } + + // Restore valid text if input was invalid, or sync combo box with new valid setting. + const QSignalBlocker b(ui->comboBox_SecondaryTileset); + ui->comboBox_SecondaryTileset->setTextItem(this->editor->layout->tileset_secondary_label); } void MainWindow::on_pushButton_ChangeDimensions_clicked() { diff --git a/src/scriptapi/apimap.cpp b/src/scriptapi/apimap.cpp index 09e4c593..e653cafd 100644 --- a/src/scriptapi/apimap.cpp +++ b/src/scriptapi/apimap.cpp @@ -566,14 +566,6 @@ QString MainWindow::getSecondaryTileset() { return this->editor->layout->tileset_secondary->name; } -void MainWindow::setPrimaryTileset(QString tileset) { - this->on_comboBox_PrimaryTileset_currentTextChanged(tileset); -} - -void MainWindow::setSecondaryTileset(QString tileset) { - this->on_comboBox_SecondaryTileset_currentTextChanged(tileset); -} - void MainWindow::saveMetatilesByMetatileId(int metatileId) { Tileset * tileset = Tileset::getMetatileTileset(metatileId, this->editor->layout->tileset_primary, this->editor->layout->tileset_secondary); if (tileset)