[nostalgia/core/studio] Add SubSheet editor
This commit is contained in:
@@ -19,6 +19,7 @@ enum class CommandId {
|
||||
Draw = 1,
|
||||
AddSubSheet = 2,
|
||||
RmSubSheet = 3,
|
||||
UpdateSubSheet = 4,
|
||||
};
|
||||
|
||||
constexpr bool operator==(CommandId c, int i) noexcept {
|
||||
@@ -180,6 +181,46 @@ struct RmSubSheetCommand: public studio::UndoCommand {
|
||||
|
||||
};
|
||||
|
||||
struct UpdateSubSheetCommand: public studio::UndoCommand {
|
||||
private:
|
||||
TileSheet *m_img = nullptr;
|
||||
TileSheet::SubSheetIdx m_idx;
|
||||
TileSheet::SubSheet m_sheet;
|
||||
ox::String m_newName;
|
||||
int m_newCols = 0;
|
||||
int m_newRows = 0;
|
||||
|
||||
public:
|
||||
constexpr UpdateSubSheetCommand(TileSheet *img, const TileSheet::SubSheetIdx &idx,
|
||||
const ox::String &name, int cols, int rows) noexcept {
|
||||
m_img = img;
|
||||
m_idx = idx;
|
||||
m_sheet = img->getSubSheet(idx);
|
||||
m_newName = name;
|
||||
m_newCols = cols;
|
||||
m_newRows = rows;
|
||||
}
|
||||
|
||||
void redo() noexcept final {
|
||||
auto &sheet = m_img->getSubSheet(m_idx);
|
||||
sheet.name = m_newName;
|
||||
sheet.columns = m_newCols;
|
||||
sheet.rows = m_newRows;
|
||||
sheet.pixels.resize(static_cast<std::size_t>(m_newCols * m_newRows * PixelsPerTile));
|
||||
}
|
||||
|
||||
void undo() noexcept final {
|
||||
auto &sheet = m_img->getSubSheet(m_idx);
|
||||
sheet = m_sheet;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int commandId() const noexcept final {
|
||||
return static_cast<int>(CommandId::UpdateSubSheet);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct TileSheetClipboard {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
@@ -262,6 +303,8 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
||||
|
||||
void rmSubsheet(const TileSheet::SubSheetIdx &idx) noexcept;
|
||||
|
||||
ox::Error updateActiveSubsheet(const ox::String &name, int cols, int rows) noexcept;
|
||||
|
||||
void setActiveSubsheet(const TileSheet::SubSheetIdx&) noexcept;
|
||||
|
||||
constexpr const TileSheet::SubSheet *activeSubSheet() const noexcept {
|
||||
|
||||
Reference in New Issue
Block a user