[nostalgia/core/studio] Add ability to insert tile
This commit is contained in:
@@ -186,6 +186,34 @@ class UpdatePixelsCommand: public QUndoCommand {
|
||||
};
|
||||
|
||||
|
||||
class InsertTileCommand: public QUndoCommand {
|
||||
private:
|
||||
SheetData *m_sheetData = nullptr;
|
||||
int m_idx = 0;
|
||||
|
||||
public:
|
||||
InsertTileCommand(SheetData *sheetData, int idx) {
|
||||
m_sheetData = sheetData;
|
||||
m_idx = idx;
|
||||
}
|
||||
|
||||
virtual ~InsertTileCommand() = default;
|
||||
|
||||
int id() const override {
|
||||
return static_cast<int>(CommandId::InsertTile);
|
||||
}
|
||||
|
||||
void redo() override {
|
||||
m_sheetData->insertTile(m_idx);
|
||||
}
|
||||
|
||||
void undo() override {
|
||||
m_sheetData->deleteTile(m_idx);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
void SheetData::updatePixel(QVariant pixelItem) {
|
||||
auto p = qobject_cast<QQuickItem*>(pixelItem.value<QObject*>());
|
||||
if (p && p != m_prevPixelUpdated) {
|
||||
@@ -195,6 +223,18 @@ void SheetData::updatePixel(QVariant pixelItem) {
|
||||
}
|
||||
}
|
||||
|
||||
void SheetData::beginCmd() {
|
||||
++m_cmdIdx;
|
||||
}
|
||||
|
||||
void SheetData::endCmd() {
|
||||
m_prevPixelUpdated = nullptr;
|
||||
}
|
||||
|
||||
void SheetData::insertTileCmd(int tileIdx) {
|
||||
m_cmdStack.push(new InsertTileCommand(this, tileIdx));
|
||||
}
|
||||
|
||||
int SheetData::columns() const {
|
||||
return m_columns;
|
||||
}
|
||||
@@ -262,6 +302,17 @@ void SheetData::setPalette(const studio::Context *ctx, QString palPath) {
|
||||
emit changeOccurred();
|
||||
}
|
||||
|
||||
void SheetData::insertTile(int tileIdx) {
|
||||
m_pixels.insert(tileIdx * PixelsPerTile, PixelsPerTile, 0);
|
||||
emit pixelsChanged();
|
||||
emit changeOccurred();
|
||||
}
|
||||
|
||||
void SheetData::deleteTile(int tileIdx) {
|
||||
m_pixels.remove(tileIdx * PixelsPerTile, PixelsPerTile);
|
||||
emit pixelsChanged();
|
||||
}
|
||||
|
||||
void SheetData::setSelectedColor(int index) {
|
||||
m_selectedColor = index;
|
||||
}
|
||||
@@ -334,15 +385,6 @@ std::unique_ptr<NostalgiaGraphic> SheetData::toNostalgiaGraphic() const {
|
||||
return ng;
|
||||
}
|
||||
|
||||
void SheetData::beginCmd() {
|
||||
++m_cmdIdx;
|
||||
}
|
||||
|
||||
void SheetData::endCmd() {
|
||||
m_prevPixelUpdated = nullptr;
|
||||
}
|
||||
|
||||
|
||||
TileSheetEditor::TileSheetEditor(QString path, const studio::Context *ctx, QWidget *parent): studio::Editor(parent) {
|
||||
m_ctx = ctx;
|
||||
m_itemPath = path;
|
||||
|
||||
Reference in New Issue
Block a user