From 694d56f6388f83db076a4824458d1ec392c71d54 Mon Sep 17 00:00:00 2001 From: myst6re Date: Wed, 17 Jan 2024 20:48:59 +0100 Subject: [PATCH] Add 'check errors' button to know if the background can be saved before saving everything. Fix crash on saving modified background --- src/core/field/BackgroundFilePC.cpp | 5 +++-- src/widgets/BackgroundEditor.cpp | 26 +++++++++++++++++++++++--- src/widgets/BackgroundEditor.h | 2 ++ translations/Makou_Reactor_fr.ts | 8 ++++++++ translations/Makou_Reactor_ja.ts | 8 ++++++++ 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/core/field/BackgroundFilePC.cpp b/src/core/field/BackgroundFilePC.cpp index c5f3f043..e5cdc84c 100644 --- a/src/core/field/BackgroundFilePC.cpp +++ b/src/core/field/BackgroundFilePC.cpp @@ -260,8 +260,9 @@ struct BackgroundTexturePCInfosAndColors quint8 findInRange(QList &unusedTextureIds, quint8 start, quint8 end) { for (quint8 i = start; i < end; ++i) { - if (unusedTextureIds.contains(i)) { - return unusedTextureIds.takeAt(i); + qsizetype index = unusedTextureIds.indexOf(i); + if (index >= 0) { + return unusedTextureIds.takeAt(index); } } diff --git a/src/widgets/BackgroundEditor.cpp b/src/widgets/BackgroundEditor.cpp index 0ded4e82..b7653aa3 100644 --- a/src/widgets/BackgroundEditor.cpp +++ b/src/widgets/BackgroundEditor.cpp @@ -58,6 +58,8 @@ BackgroundEditor::BackgroundEditor(QWidget *parent) _backgroundLayerScrollArea->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); _backgroundTileEditor = new BackgroundTileEditor(this); + + _compileButton = new QPushButton(tr("Check errors"), this); QWidget *topRow = new QWidget(this); QGridLayout *topRowLayout = new QGridLayout(topRow); @@ -65,9 +67,10 @@ BackgroundEditor::BackgroundEditor(QWidget *parent) topRowLayout->addWidget(_shiftX, 0, 1); topRowLayout->addWidget(new QLabel(tr("Shift Y:"), this), 0, 2); topRowLayout->addWidget(_shiftY, 0, 3); - topRowLayout->addWidget(_backgroundLayerScrollArea, 1, 0, 1, 6); - topRowLayout->addWidget(_backgroundTileEditor, 0, 6, 2, 1); - topRowLayout->setColumnStretch(4, 1); + topRowLayout->addWidget(_compileButton, 0, 6); + topRowLayout->addWidget(_backgroundLayerScrollArea, 1, 0, 1, 7); + topRowLayout->addWidget(_backgroundTileEditor, 0, 7, 2, 1); + topRowLayout->setColumnStretch(5, 1); topRowLayout->setRowStretch(1, 1); topRowLayout->setContentsMargins(QMargins(0, 0, 0, topRowLayout->contentsMargins().bottom())); @@ -108,6 +111,7 @@ BackgroundEditor::BackgroundEditor(QWidget *parent) connect(_texturesWidget, &ImageGridWidget::clicked, this, &BackgroundEditor::updateSelectedTileTexture); connect(_backgroundTileEditor, &BackgroundTileEditor::changed, this, &BackgroundEditor::updateTiles); connect(_backgroundTileEditor, &BackgroundTileEditor::changed, this, &BackgroundEditor::modified); + connect(_compileButton, &QPushButton::clicked, this, &BackgroundEditor::compile); } void BackgroundEditor::saveConfig() @@ -631,3 +635,19 @@ void BackgroundEditor::updateTiles(const QList &tiles) refreshImage(currentLayer(), currentSection(), currentParamState(), currentEffect()); refreshTexture(); } + +void BackgroundEditor::compile() +{ + if (_backgroundFile == nullptr) { + return; + } + + if (_backgroundFile->isModified() && _backgroundFile->field()->isPC()) { + BackgroundFilePC *backgroundFilePC = static_cast(_backgroundFile); + if (!backgroundFilePC->compile()) { + QMessageBox::warning(this, tr("Compilation error"), backgroundFilePC->lastErrorString()); + } else { + refreshTexture(); + } + } +} diff --git a/src/widgets/BackgroundEditor.h b/src/widgets/BackgroundEditor.h index a5761c2f..e92da16c 100644 --- a/src/widgets/BackgroundEditor.h +++ b/src/widgets/BackgroundEditor.h @@ -42,6 +42,7 @@ private slots: void updateSelectedTiles(const QList &cells); void updateSelectedTileTexture(const Cell &cell); void updateTiles(const QList &tiles); + void compile(); private: enum LayerSubType { SubLayer = QTreeWidgetItem::UserType, @@ -67,6 +68,7 @@ private slots: QScrollArea *_backgroundLayerScrollArea; ImageGridWidget *_backgroundLayerWidget, *_texturesWidget, *_palettesWidget; BackgroundTileEditor *_backgroundTileEditor; + QPushButton *_compileButton; BackgroundFile *_backgroundFile; QList _texIdKeys; diff --git a/translations/Makou_Reactor_fr.ts b/translations/Makou_Reactor_fr.ts index b5acd8bf..a59ee9b3 100644 --- a/translations/Makou_Reactor_fr.ts +++ b/translations/Makou_Reactor_fr.ts @@ -221,6 +221,14 @@ Conflicts Conflits + + Compilation error + Erreur de compilation + + + Check errors + VĂ©rifier les erreurs + BackgroundPaletteEditor diff --git a/translations/Makou_Reactor_ja.ts b/translations/Makou_Reactor_ja.ts index e62aee44..2f4f7e8f 100644 --- a/translations/Makou_Reactor_ja.ts +++ b/translations/Makou_Reactor_ja.ts @@ -214,6 +214,14 @@ Conflicts + + Compilation error + + + + Check errors + + BackgroundPaletteEditor