Skip to content

Commit

Permalink
PaletteEditor small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonx254 committed Jun 26, 2024
1 parent 2925d86 commit d85b760
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 30 deletions.
3 changes: 1 addition & 2 deletions RetroEDv2/tools/gameconfigeditorv4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions RetroEDv2/tools/gameconfigeditorv5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -552,7 +552,6 @@ void GameConfigEditorv5::setupUI(bool allowRowChange)
}
}
}
edit->mainWindow = false;
edit->setWindowTitle("Edit GameConfig Palette");
edit->exec();

Expand Down
41 changes: 25 additions & 16 deletions RetroEDv2/tools/paletteeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<int>::of(&QSpinBox::valueChanged), [this](int r){ UpdatePaletteRows(r * 0x10); });

ui->widgetLayout->addWidget(widget, 1);
Expand All @@ -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<PaletteColor> pal;
Reader reader(path);
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -606,6 +614,7 @@ bool PaletteEditor::event(QEvent *event)
SetStatus("Loaded palette from " + tabTitle);

appConfig.addRecentFile(palType, TOOL_PALETTEDITOR, filePath, QList<QString>{});
ClearActions();
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions RetroEDv2/tools/paletteeditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -92,7 +92,7 @@ class PaletteEditor : public QDialog
}

QList<PaletteColor> palette;
bool mainWindow = true;
bool externalWindow = false;

RSDKv5::GameConfig gameConfigv5;
RSDKv5::StageConfig stageConfigv5;
Expand Down
5 changes: 4 additions & 1 deletion RetroEDv2/tools/paletteeditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>496</width>
<width>538</width>
<height>350</height>
</rect>
</property>
Expand Down Expand Up @@ -187,6 +187,9 @@
</item>
<item row="1" column="10">
<widget class="QSpinBox" name="palRows">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<number>16</number>
</property>
Expand Down
4 changes: 2 additions & 2 deletions RetroEDv2/tools/sceneeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions RetroEDv2/tools/sceneeditorv5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -1217,7 +1217,6 @@ SceneEditorv5::SceneEditorv5(QWidget *parent) : QWidget(parent), ui(new Ui::Scen
}
}
}
edit->mainWindow = false;
edit->setWindowTitle("Edit StageConfig Palette");
edit->exec();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -3019,8 +3019,6 @@ void SceneEditorv5::CreateNewScene(QString scnPath, bool prePlus, bool loadGC, Q
}
}

InitGameLink();

SetupObjects();

ui->layerList->blockSignals(true);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d85b760

Please sign in to comment.