Skip to content

Commit

Permalink
Add 'check errors' button to know if the background can be saved befo…
Browse files Browse the repository at this point in the history
…re saving everything. Fix crash on saving modified background
  • Loading branch information
myst6re committed Jan 17, 2024
1 parent 6eb6297 commit 694d56f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/core/field/BackgroundFilePC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ struct BackgroundTexturePCInfosAndColors
quint8 findInRange(QList<quint8> &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);
}
}

Expand Down
26 changes: 23 additions & 3 deletions src/widgets/BackgroundEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ 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);
topRowLayout->addWidget(new QLabel(tr("Shift X:"), this), 0, 0);
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()));

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -631,3 +635,19 @@ void BackgroundEditor::updateTiles(const QList<Tile> &tiles)
refreshImage(currentLayer(), currentSection(), currentParamState(), currentEffect());
refreshTexture();
}

void BackgroundEditor::compile()
{
if (_backgroundFile == nullptr) {
return;
}

if (_backgroundFile->isModified() && _backgroundFile->field()->isPC()) {
BackgroundFilePC *backgroundFilePC = static_cast<BackgroundFilePC *>(_backgroundFile);
if (!backgroundFilePC->compile()) {
QMessageBox::warning(this, tr("Compilation error"), backgroundFilePC->lastErrorString());
} else {
refreshTexture();
}
}
}
2 changes: 2 additions & 0 deletions src/widgets/BackgroundEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private slots:
void updateSelectedTiles(const QList<Cell> &cells);
void updateSelectedTileTexture(const Cell &cell);
void updateTiles(const QList<Tile> &tiles);
void compile();
private:
enum LayerSubType {
SubLayer = QTreeWidgetItem::UserType,
Expand All @@ -67,6 +68,7 @@ private slots:
QScrollArea *_backgroundLayerScrollArea;
ImageGridWidget *_backgroundLayerWidget, *_texturesWidget, *_palettesWidget;
BackgroundTileEditor *_backgroundTileEditor;
QPushButton *_compileButton;

BackgroundFile *_backgroundFile;
QList<quint8> _texIdKeys;
Expand Down
8 changes: 8 additions & 0 deletions translations/Makou_Reactor_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@
<source>Conflicts</source>
<translation>Conflits</translation>
</message>
<message>
<source>Compilation error</source>
<translation>Erreur de compilation</translation>
</message>
<message>
<source>Check errors</source>
<translation>Vérifier les erreurs</translation>
</message>
</context>
<context>
<name>BackgroundPaletteEditor</name>
Expand Down
8 changes: 8 additions & 0 deletions translations/Makou_Reactor_ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@
<source>Conflicts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Compilation error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Check errors</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundPaletteEditor</name>
Expand Down

0 comments on commit 694d56f

Please sign in to comment.