diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp index ca5461b..a645014 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -243,7 +243,7 @@ void PaletteEditorImGui::drawColorEditor() noexcept { auto const¤tName = m_pal.colorNames[m_selectedColorRow]; ox::IString<50> name; name = currentName; - auto const nameUpdated = ImGui::InputText("Name", name.data(), name.cap() + 1); + auto const nameUpdated = ig::InputText("Name", name); bool inputFocused = ImGui::IsItemFocused(); ImGui::Separator(); colorInput("Red", r, inputFocused); @@ -271,7 +271,7 @@ void PaletteEditorImGui::drawColorEditor() noexcept { } if (nameUpdated) { std::ignore = pushCommand( - m_pal, m_selectedColorRow, ox::String{name.data()}); + m_pal, m_selectedColorRow, ox::String{name}); } } diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp index 854bc28..0762c73 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp @@ -188,19 +188,21 @@ UpdateColorInfoCommand::UpdateColorInfoCommand( } } -bool UpdateColorInfoCommand::mergeWith(UndoCommand const&cmd) noexcept { - if (cmd.commandId() != static_cast(PaletteEditorCommandId::UpdateColor)) { +bool UpdateColorInfoCommand::mergeWith(UndoCommand &cmd) noexcept { + if (cmd.commandId() != static_cast(PaletteEditorCommandId::UpdateColorInfo)) { return false; } - auto ucCmd = static_cast(&cmd); + auto ucCmd = dynamic_cast(&cmd); if (m_idx != ucCmd->m_idx) { return false; } + m_pal.colorNames[m_idx] = std::move(ucCmd->m_pal.colorNames[m_idx]); + setObsolete(m_altColorInfo == m_pal.colorNames[m_idx]); return true; } int UpdateColorInfoCommand::commandId() const noexcept { - return static_cast(PaletteEditorCommandId::UpdateColor); + return static_cast(PaletteEditorCommandId::UpdateColorInfo); } ox::Error UpdateColorInfoCommand::redo() noexcept { @@ -232,11 +234,11 @@ UpdateColorCommand::UpdateColorCommand( } } -bool UpdateColorCommand::mergeWith(UndoCommand const&cmd) noexcept { +bool UpdateColorCommand::mergeWith(UndoCommand &cmd) noexcept { if (cmd.commandId() != static_cast(PaletteEditorCommandId::UpdateColor)) { return false; } - auto ucCmd = static_cast(&cmd); + auto ucCmd = dynamic_cast(&cmd); if (m_idx != ucCmd->m_idx) { return false; } diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp index 60efb60..7f61d16 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp @@ -163,7 +163,7 @@ class UpdateColorInfoCommand: public studio::UndoCommand { ~UpdateColorInfoCommand() noexcept override = default; [[nodiscard]] - bool mergeWith(const UndoCommand &cmd) noexcept final; + bool mergeWith(UndoCommand &cmd) noexcept final; [[nodiscard]] int commandId() const noexcept final; @@ -194,7 +194,7 @@ class UpdateColorCommand: public studio::UndoCommand { ~UpdateColorCommand() noexcept override = default; [[nodiscard]] - bool mergeWith(const UndoCommand &cmd) noexcept final; + bool mergeWith(UndoCommand &cmd) noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/deps/nostalgia/src/olympic/studio/modlib/include/studio/undocommand.hpp b/deps/nostalgia/src/olympic/studio/modlib/include/studio/undocommand.hpp index 93aa2a2..ffd0009 100644 --- a/deps/nostalgia/src/olympic/studio/modlib/include/studio/undocommand.hpp +++ b/deps/nostalgia/src/olympic/studio/modlib/include/studio/undocommand.hpp @@ -17,13 +17,22 @@ class NoChangesException: public ox::Exception { }; class UndoCommand { + private: + bool m_obsolete{}; public: virtual ~UndoCommand() noexcept = default; virtual ox::Error redo() noexcept = 0; virtual ox::Error undo() noexcept = 0; [[nodiscard]] virtual int commandId() const noexcept = 0; - virtual bool mergeWith(UndoCommand const&cmd) noexcept; + virtual bool mergeWith(UndoCommand &cmd) noexcept; + constexpr void setObsolete(bool obsolete) noexcept { + m_obsolete = obsolete; + } + [[nodiscard]] + constexpr bool isObsolete() const noexcept { + return m_obsolete; + } }; } diff --git a/deps/nostalgia/src/olympic/studio/modlib/src/undocommand.cpp b/deps/nostalgia/src/olympic/studio/modlib/src/undocommand.cpp index 6a929ca..96dec70 100644 --- a/deps/nostalgia/src/olympic/studio/modlib/src/undocommand.cpp +++ b/deps/nostalgia/src/olympic/studio/modlib/src/undocommand.cpp @@ -3,7 +3,7 @@ namespace studio { -bool UndoCommand::mergeWith(UndoCommand const&) noexcept { +bool UndoCommand::mergeWith(UndoCommand&) noexcept { return false; } diff --git a/deps/nostalgia/src/olympic/studio/modlib/src/undostack.cpp b/deps/nostalgia/src/olympic/studio/modlib/src/undostack.cpp index 77cb049..1bcf209 100644 --- a/deps/nostalgia/src/olympic/studio/modlib/src/undostack.cpp +++ b/deps/nostalgia/src/olympic/studio/modlib/src/undostack.cpp @@ -17,6 +17,10 @@ ox::Error UndoStack::push(ox::UPtr &&cmd) noexcept { m_stack.emplace_back(std::move(cmd)); ++m_stackIdx; } + if ((*m_stack.back().unwrap())->isObsolete()) { + m_stack.pop_back(); + --m_stackIdx; + } return {}; }