Add edit-undo history for tileset palette changes
This commit is contained in:
parent
7a47c64509
commit
bbfecba1ba
3 changed files with 89 additions and 1 deletions
|
@ -38,7 +38,11 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QSpinBox" name="spinBox_PaletteId"/>
|
<widget class="QSpinBox" name="spinBox_PaletteId">
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -1640,8 +1644,32 @@
|
||||||
<height>21</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QMenu" name="menuEdit">
|
||||||
|
<property name="title">
|
||||||
|
<string>Edit</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionUndo"/>
|
||||||
|
<addaction name="actionRedo"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuEdit"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<action name="actionUndo">
|
||||||
|
<property name="text">
|
||||||
|
<string>Undo</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+Z</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRedo">
|
||||||
|
<property name="text">
|
||||||
|
<string>Redo</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+Y</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
|
@ -6,11 +6,20 @@
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
|
#include "history.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class PaletteEditor;
|
class PaletteEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PaletteHistoryItem {
|
||||||
|
public:
|
||||||
|
QList<QRgb> colors;
|
||||||
|
PaletteHistoryItem(QList<QRgb> colors) {
|
||||||
|
this->colors = colors;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class PaletteEditor : public QMainWindow {
|
class PaletteEditor : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -26,6 +35,7 @@ private:
|
||||||
QList<QLabel*> rgbLabels;
|
QList<QLabel*> rgbLabels;
|
||||||
Tileset *primaryTileset;
|
Tileset *primaryTileset;
|
||||||
Tileset *secondaryTileset;
|
Tileset *secondaryTileset;
|
||||||
|
QList<History<PaletteHistoryItem*>> palettesHistory;
|
||||||
void disableSliderSignals();
|
void disableSliderSignals();
|
||||||
void enableSliderSignals();
|
void enableSliderSignals();
|
||||||
void initColorSliders();
|
void initColorSliders();
|
||||||
|
@ -33,6 +43,8 @@ private:
|
||||||
void refreshColors();
|
void refreshColors();
|
||||||
void refreshColor(int);
|
void refreshColor(int);
|
||||||
void setColor(int);
|
void setColor(int);
|
||||||
|
void commitEditHistory();
|
||||||
|
void setColorsFromHistory(PaletteHistoryItem*, int);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void closed();
|
void closed();
|
||||||
|
@ -40,6 +52,8 @@ signals:
|
||||||
void changedPalette(int);
|
void changedPalette(int);
|
||||||
private slots:
|
private slots:
|
||||||
void on_spinBox_PaletteId_valueChanged(int arg1);
|
void on_spinBox_PaletteId_valueChanged(int arg1);
|
||||||
|
void on_actionUndo_triggered();
|
||||||
|
void on_actionRedo_triggered();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PALETTEEDITOR_H
|
#endif // PALETTEEDITOR_H
|
||||||
|
|
|
@ -100,6 +100,11 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset
|
||||||
this->rgbLabels.append(this->ui->label_rgb14);
|
this->rgbLabels.append(this->ui->label_rgb14);
|
||||||
this->rgbLabels.append(this->ui->label_rgb15);
|
this->rgbLabels.append(this->ui->label_rgb15);
|
||||||
|
|
||||||
|
// Setup edit-undo history for each of the palettes.
|
||||||
|
for (int i = 0; i < Project::getNumPalettesTotal(); i++) {
|
||||||
|
this->palettesHistory.append(History<PaletteHistoryItem*>());
|
||||||
|
}
|
||||||
|
|
||||||
this->initColorSliders();
|
this->initColorSliders();
|
||||||
this->refreshColorSliders();
|
this->refreshColorSliders();
|
||||||
this->refreshColors();
|
this->refreshColors();
|
||||||
|
@ -188,6 +193,7 @@ void PaletteEditor::setColor(int colorIndex) {
|
||||||
: this->secondaryTileset;
|
: this->secondaryTileset;
|
||||||
(*tileset->palettes)[paletteNum][colorIndex] = qRgb(red, green, blue);
|
(*tileset->palettes)[paletteNum][colorIndex] = qRgb(red, green, blue);
|
||||||
this->refreshColor(colorIndex);
|
this->refreshColor(colorIndex);
|
||||||
|
this->commitEditHistory();
|
||||||
emit this->changedPaletteColor();
|
emit this->changedPaletteColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,3 +202,43 @@ void PaletteEditor::on_spinBox_PaletteId_valueChanged(int paletteId) {
|
||||||
this->refreshColors();
|
this->refreshColors();
|
||||||
emit this->changedPalette(paletteId);
|
emit this->changedPalette(paletteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaletteEditor::commitEditHistory() {
|
||||||
|
int paletteId = this->ui->spinBox_PaletteId->value();
|
||||||
|
QList<QRgb> colors;
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
colors.append(qRgb(this->sliders[i][0]->value() * 8, this->sliders[i][1]->value() * 8, this->sliders[i][2]->value() * 8));
|
||||||
|
}
|
||||||
|
PaletteHistoryItem *commit = new PaletteHistoryItem(colors);
|
||||||
|
this->palettesHistory[paletteId].push(commit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaletteEditor::on_actionUndo_triggered()
|
||||||
|
{
|
||||||
|
int paletteId = this->ui->spinBox_PaletteId->value();
|
||||||
|
PaletteHistoryItem *prev = this->palettesHistory[paletteId].back();
|
||||||
|
this->setColorsFromHistory(prev, paletteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaletteEditor::on_actionRedo_triggered()
|
||||||
|
{
|
||||||
|
int paletteId = this->ui->spinBox_PaletteId->value();
|
||||||
|
PaletteHistoryItem *next = this->palettesHistory[paletteId].next();
|
||||||
|
this->setColorsFromHistory(next, paletteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaletteEditor::setColorsFromHistory(PaletteHistoryItem *history, int paletteId) {
|
||||||
|
if (!history) return;
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
if (paletteId < Project::getNumPalettesPrimary()) {
|
||||||
|
(*this->primaryTileset->palettes)[paletteId][i] = history->colors.at(i);
|
||||||
|
} else {
|
||||||
|
(*this->secondaryTileset->palettes)[paletteId][i] = history->colors.at(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->refreshColorSliders();
|
||||||
|
this->refreshColors();
|
||||||
|
emit this->changedPaletteColor();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue