From d85b76035b32e1e86dc84f9aa91f2e5c467b9a5d Mon Sep 17 00:00:00 2001 From: Leonx254 Date: Wed, 26 Jun 2024 16:54:12 -0300 Subject: [PATCH] PaletteEditor small tweaks --- RetroEDv2/tools/gameconfigeditorv4.cpp | 3 +- RetroEDv2/tools/gameconfigeditorv5.cpp | 3 +- RetroEDv2/tools/paletteeditor.cpp | 41 ++++++++++++++++---------- RetroEDv2/tools/paletteeditor.hpp | 4 +-- RetroEDv2/tools/paletteeditor.ui | 5 +++- RetroEDv2/tools/sceneeditor.cpp | 4 +-- RetroEDv2/tools/sceneeditorv5.cpp | 7 ++--- 7 files changed, 37 insertions(+), 30 deletions(-) diff --git a/RetroEDv2/tools/gameconfigeditorv4.cpp b/RetroEDv2/tools/gameconfigeditorv4.cpp index 3e58b1e..5b970e9 100644 --- a/RetroEDv2/tools/gameconfigeditorv4.cpp +++ b/RetroEDv2/tools/gameconfigeditorv4.cpp @@ -62,11 +62,10 @@ GameConfigEditorv4::GameConfigEditorv4(QString path, QWidget *parent) connect(ui->editPalette, &QPushButton::clicked, [this] { Palette *configPal = &gameConfig.palette; - PaletteEditor *edit = new PaletteEditor(gameConfig.filePath, PALTYPE_GAMECONFIGv4); + PaletteEditor *edit = new PaletteEditor(gameConfig.filePath, PALTYPE_GAMECONFIGv4, true); edit->palette.clear(); for (auto &c : configPal->colors) edit->palette.append(PaletteColor(c.r, c.g, c.b)); - edit->mainWindow = false; edit->setWindowTitle("Edit GameConfig Palette"); edit->exec(); diff --git a/RetroEDv2/tools/gameconfigeditorv5.cpp b/RetroEDv2/tools/gameconfigeditorv5.cpp index 9ce3831..3b75ad0 100644 --- a/RetroEDv2/tools/gameconfigeditorv5.cpp +++ b/RetroEDv2/tools/gameconfigeditorv5.cpp @@ -540,7 +540,7 @@ void GameConfigEditorv5::setupUI(bool allowRowChange) RSDKv5::Palette *configPal = nullptr; RSDKv5::Palette *editPal = nullptr; - PaletteEditor *edit = new PaletteEditor(gameConfig.filePath, (oldVer ? PALTYPE_GAMECONFIGv5_rev01 : PALTYPE_GAMECONFIGv5)); + PaletteEditor *edit = new PaletteEditor(gameConfig.filePath, (oldVer ? PALTYPE_GAMECONFIGv5_rev01 : PALTYPE_GAMECONFIGv5), true); edit->palette.clear(); for (int b = 0; b < 8; ++b){ configPal = &gameConfig.palettes[b]; @@ -552,7 +552,6 @@ void GameConfigEditorv5::setupUI(bool allowRowChange) } } } - edit->mainWindow = false; edit->setWindowTitle("Edit GameConfig Palette"); edit->exec(); diff --git a/RetroEDv2/tools/paletteeditor.cpp b/RetroEDv2/tools/paletteeditor.cpp index fcafc7e..c73a2a3 100644 --- a/RetroEDv2/tools/paletteeditor.cpp +++ b/RetroEDv2/tools/paletteeditor.cpp @@ -6,13 +6,15 @@ #include "paletteeditor/colourdialog.hpp" #include "paletteeditor/paletteimport.hpp" -PaletteEditor::PaletteEditor(QString path, byte type, QWidget *parent) +PaletteEditor::PaletteEditor(QString path, byte type, bool external, QWidget *parent) : QDialog(parent), widget(new PaletteWidget(this)), ui(new Ui::PaletteEditor) { ui->setupUi(this); + + externalWindow = external; InitEditor(); - if (QFile::exists(path)) { + if (QFile::exists(path) || external) { LoadPalette(path, type); filePath = path; } @@ -80,7 +82,6 @@ void PaletteEditor::InitEditor() for (int b = 0; b < 8; ++b) { connect(bankSwitches[b], &QToolButton::clicked, [this, b] { SwitchBank(b); }); } - connect(ui->palRows, QOverload::of(&QSpinBox::valueChanged), [this](int r){ UpdatePaletteRows(r * 0x10); }); ui->widgetLayout->addWidget(widget, 1); @@ -101,10 +102,11 @@ void PaletteEditor::LoadPalette(QString path, byte type) } - ui->palRows->setEnabled(false); + ui->palRows->setDisabled(true); palType = type; bankID = 0; switch (type) { + default: break; case PALTYPE_ACT: { //.act QList pal; Reader reader(path); @@ -115,7 +117,7 @@ void PaletteEditor::LoadPalette(QString path, byte type) pal.append(clr); } palette = pal; - ui->palRows->setEnabled(true); + ui->palRows->setDisabled(false); ui->palRows->setValue(pal.count() / 16); ui->exportPal->setDisabled(true); break; @@ -124,15 +126,19 @@ void PaletteEditor::LoadPalette(QString path, byte type) case PALTYPE_GAMECONFIGv5: case PALTYPE_GAMECONFIGv5_rev01: case PALTYPE_STAGECONFIGv5: { - if (palType == PALTYPE_STAGECONFIGv5) + if (palType == PALTYPE_STAGECONFIGv5){ stageConfigv5 = RSDKv5::StageConfig(path); - else + configPalv5 = &stageConfigv5.palettes[bankID]; + } + else{ gameConfigv5 = RSDKv5::GameConfig(path, type == PALTYPE_GAMECONFIGv5_rev01); + configPalv5 = &gameConfigv5.palettes[bankID]; + } - configPalv5 = &gameConfigv5.palettes[bankID]; SwitchBank(0); bankSwitches[0]->setDown(true); for (int b = 0; b < 8; ++b) bankSwitches[b]->setDisabled(false); + ui->palRows->setValue(16); break; } @@ -169,6 +175,7 @@ void PaletteEditor::LoadPalette(QString path, byte type) for (auto &c : configPal->colors) { palette.append(PaletteColor(c.r, c.g, c.b)); } + ui->palRows->setValue(palette.count() / 16); break; } } @@ -193,7 +200,7 @@ void PaletteEditor::ImportPalette(QString path, byte type) if (importFile->exec() != QDialog::Accepted) { palette = backup; } else { - DoAction("Imported Palette", mainWindow ? true : false); + DoAction("Imported Palette", !externalWindow); }; importFile = nullptr; break; @@ -238,7 +245,7 @@ void PaletteEditor::ImportPalette(QString path, byte type) if (importFile->exec() != QDialog::Accepted) { palette = backup; } else { - DoAction("Imported Palette", mainWindow ? true : false); + DoAction("Imported Palette", !externalWindow); }; importFile = nullptr; break; @@ -277,7 +284,7 @@ void PaletteEditor::ImportPalette(QString path, byte type) if (importFile->exec() != QDialog::Accepted) { palette = backup; } else { - DoAction("Imported Palette", mainWindow ? true : false); + DoAction("Imported Palette", !externalWindow); }; importFile = nullptr; break; @@ -449,7 +456,7 @@ void PaletteWidget::mouseDoubleClickEvent(QMouseEvent *) palette->replace(selection, clr); if (prev.r != clr.r || prev.g != clr.g || prev.b != clr.b) - editor->DoAction("Changed color", editor->mainWindow ? true : false); + editor->DoAction("Changed color", !editor->externalWindow); } delete dlg; @@ -487,7 +494,7 @@ void PaletteWidget::mouseMoveEvent(QMouseEvent *event) editor->gameConfigv5.palettes[editor->bankID].activeRows[y] = enabling; if (prev != enabling) - editor->DoAction("Changed row active", editor->mainWindow ? true : false); + editor->DoAction("Changed row active", !editor->externalWindow); } } else if (editor->palType == PALTYPE_STAGECONFIGv5) { @@ -496,7 +503,7 @@ void PaletteWidget::mouseMoveEvent(QMouseEvent *event) editor->stageConfigv5.palettes[editor->bankID].activeRows[y] = enabling; if (prev != enabling) - editor->DoAction("Changed row active", editor->mainWindow ? true : false); + editor->DoAction("Changed row active", !editor->externalWindow); } } @@ -583,9 +590,10 @@ bool PaletteEditor::event(QEvent *event) for (int s = 0; s < 256; ++s) pal.append(clr); palette = pal; - ui->palRows->setEnabled(true); - ui->palRows->setValue(pal.count() / 16); + ui->palRows->setDisabled(false); + ui->palRows->setValue(16); filePath = ""; + tabTitle = "New Palette"; ClearActions(); return true; @@ -606,6 +614,7 @@ bool PaletteEditor::event(QEvent *event) SetStatus("Loaded palette from " + tabTitle); appConfig.addRecentFile(palType, TOOL_PALETTEDITOR, filePath, QList{}); + ClearActions(); return true; } } diff --git a/RetroEDv2/tools/paletteeditor.hpp b/RetroEDv2/tools/paletteeditor.hpp index 1f1a4e0..fa0189b 100644 --- a/RetroEDv2/tools/paletteeditor.hpp +++ b/RetroEDv2/tools/paletteeditor.hpp @@ -75,7 +75,7 @@ class PaletteEditor : public QDialog RSDKv1::StageConfig stageConfigv1; }; - explicit PaletteEditor(QString path = "", byte type = 0xFF, QWidget *parent = nullptr); + explicit PaletteEditor(QString path = "", byte type = 0xFF, bool external = false, QWidget *parent = nullptr); ~PaletteEditor(); void SavePalette(QString filepath); @@ -92,7 +92,7 @@ class PaletteEditor : public QDialog } QList palette; - bool mainWindow = true; + bool externalWindow = false; RSDKv5::GameConfig gameConfigv5; RSDKv5::StageConfig stageConfigv5; diff --git a/RetroEDv2/tools/paletteeditor.ui b/RetroEDv2/tools/paletteeditor.ui index 5b5433e..e1d52c9 100644 --- a/RetroEDv2/tools/paletteeditor.ui +++ b/RetroEDv2/tools/paletteeditor.ui @@ -6,7 +6,7 @@ 0 0 - 496 + 538 350 @@ -187,6 +187,9 @@ + + false + 16 diff --git a/RetroEDv2/tools/sceneeditor.cpp b/RetroEDv2/tools/sceneeditor.cpp index e981f46..0942162 100644 --- a/RetroEDv2/tools/sceneeditor.cpp +++ b/RetroEDv2/tools/sceneeditor.cpp @@ -961,11 +961,10 @@ SceneEditor::SceneEditor(QWidget *parent) : QWidget(parent), ui(new Ui::SceneEdi connect(scnProp->editPAL, &QPushButton::clicked, [this] { Palette *SCPal = &stageConfig.palette; PaletteEditor *edit = - new PaletteEditor(stageConfig.filePath, viewer->gameType + PALTYPE_STAGECONFIGv4); + new PaletteEditor(stageConfig.filePath, viewer->gameType + PALTYPE_STAGECONFIGv4, true); edit->palette.clear(); for (auto &c : SCPal->colors) edit->palette.append(PaletteColor(c.r, c.g, c.b)); - edit->mainWindow = false; edit->setWindowTitle("Edit StageConfig Palette"); edit->exec(); @@ -2232,6 +2231,7 @@ void SceneEditor::CreateNewScene(QString scnPath, byte scnVer, bool loadGC, QStr AddStatusProgress(0.2); // finish unloading + gameConfig = FormatHelpers::GameConfig(); if (loadGC){ if (QFileInfo(gcPath).suffix().toLower().contains("xml")) ParseGameXML(gcPath); diff --git a/RetroEDv2/tools/sceneeditorv5.cpp b/RetroEDv2/tools/sceneeditorv5.cpp index 83ea74a..36cdcc2 100644 --- a/RetroEDv2/tools/sceneeditorv5.cpp +++ b/RetroEDv2/tools/sceneeditorv5.cpp @@ -1206,7 +1206,7 @@ SceneEditorv5::SceneEditorv5(QWidget *parent) : QWidget(parent), ui(new Ui::Scen RSDKv5::Palette *configPal = nullptr; RSDKv5::Palette *editPal = nullptr; - PaletteEditor *edit = new PaletteEditor(stageConfig.filePath, PALTYPE_STAGECONFIGv5); edit->palette.clear(); + PaletteEditor *edit = new PaletteEditor(stageConfig.filePath, PALTYPE_STAGECONFIGv5, true); edit->palette.clear(); for (int b = 0; b < 8; ++b){ configPal = &stageConfig.palettes[b]; for (int r = 0; r < 16; ++r){ @@ -1217,7 +1217,6 @@ SceneEditorv5::SceneEditorv5(QWidget *parent) : QWidget(parent), ui(new Ui::Scen } } } - edit->mainWindow = false; edit->setWindowTitle("Edit StageConfig Palette"); edit->exec(); @@ -2879,6 +2878,7 @@ void SceneEditorv5::CreateNewScene(QString scnPath, bool prePlus, bool loadGC, Q initStorage(dataStorage); AddStatusProgress(0.2); // finish unloading + gameConfig = RSDKv5::GameConfig(); if (loadGC){ if (QFileInfo(gcPath).suffix().toLower().contains("xml")) ParseGameXML(gcPath); @@ -3019,8 +3019,6 @@ void SceneEditorv5::CreateNewScene(QString scnPath, bool prePlus, bool loadGC, Q } } - InitGameLink(); - SetupObjects(); ui->layerList->blockSignals(true); @@ -3320,7 +3318,6 @@ void SceneEditorv5::LoadScene(QString scnPath, QString gcfPath, byte sceneVer) AddStatusProgress(1. / 6); // finish tileset loading - ClearActions(); SetupObjects(); ui->layerList->blockSignals(true);