From 7ae0befc37a297a79efc093d490028a0e141913e Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 22 Mar 2020 01:34:09 -0500 Subject: [PATCH] [nostalgia/core/studio] Add delete tile --- src/nostalgia/core/studio/TileSheetEditor.qml | 8 +++++++ src/nostalgia/core/studio/tilesheeteditor.cpp | 21 ++++++++++++++++--- src/nostalgia/core/studio/tilesheeteditor.hpp | 2 ++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/nostalgia/core/studio/TileSheetEditor.qml b/src/nostalgia/core/studio/TileSheetEditor.qml index d783c6e1..460e7918 100644 --- a/src/nostalgia/core/studio/TileSheetEditor.qml +++ b/src/nostalgia/core/studio/TileSheetEditor.qml @@ -95,6 +95,14 @@ Rectangle { sheetData.insertTileCmd(tile.tileNumber); } } + + MenuItem { + text: "Delete Tile" + onTriggered: { + var tile = mouseArea.tileAt(contextMenu.x, contextMenu.y); + sheetData.deleteTileCmd(tile.tileNumber); + } + } } onPositionChanged: sheetData.updatePixel(pixelAt(mouseX, mouseY)) diff --git a/src/nostalgia/core/studio/tilesheeteditor.cpp b/src/nostalgia/core/studio/tilesheeteditor.cpp index 7f1942d2..e8526a12 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor.cpp @@ -190,11 +190,13 @@ class InsertTileCommand: public QUndoCommand { private: SheetData *m_sheetData = nullptr; int m_idx = 0; + bool m_delete = false; public: - InsertTileCommand(SheetData *sheetData, int idx) { + InsertTileCommand(SheetData *sheetData, int idx, bool del = false) { m_sheetData = sheetData; m_idx = idx; + m_delete = del; } virtual ~InsertTileCommand() = default; @@ -204,11 +206,19 @@ class InsertTileCommand: public QUndoCommand { } void redo() override { - m_sheetData->insertTile(m_idx); + if (m_delete) { + m_sheetData->deleteTile(m_idx); + } else { + m_sheetData->insertTile(m_idx); + } } void undo() override { - m_sheetData->deleteTile(m_idx); + if (m_delete) { + m_sheetData->insertTile(m_idx); + } else { + m_sheetData->deleteTile(m_idx); + } } }; @@ -235,6 +245,10 @@ void SheetData::insertTileCmd(int tileIdx) { m_cmdStack.push(new InsertTileCommand(this, tileIdx)); } +void SheetData::deleteTileCmd(int tileIdx) { + m_cmdStack.push(new InsertTileCommand(this, tileIdx, true)); +} + int SheetData::columns() const { return m_columns; } @@ -311,6 +325,7 @@ void SheetData::insertTile(int tileIdx) { void SheetData::deleteTile(int tileIdx) { m_pixels.remove(tileIdx * PixelsPerTile, PixelsPerTile); emit pixelsChanged(); + emit changeOccurred(); } void SheetData::setSelectedColor(int index) { diff --git a/src/nostalgia/core/studio/tilesheeteditor.hpp b/src/nostalgia/core/studio/tilesheeteditor.hpp index 7b463306..48f9d66b 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor.hpp @@ -45,6 +45,8 @@ class SheetData: public QObject { Q_INVOKABLE void insertTileCmd(int tileIdx); + Q_INVOKABLE void deleteTileCmd(int tileIdx); + [[nodiscard]] int columns() const; [[nodiscard]] int rows() const;