diff --git a/src/nostalgia/core/studio/module.cpp b/src/nostalgia/core/studio/module.cpp index ccef63f2f..51951206e 100644 --- a/src/nostalgia/core/studio/module.cpp +++ b/src/nostalgia/core/studio/module.cpp @@ -13,7 +13,7 @@ ox::Vector Module::editors(core::Context *ctx) noexcept { return { { {"ng"}, - [ctx](const ox::String &path) -> ox::Result { + [ctx](const ox::String &path) -> ox::Result { try { return new TileSheetEditorImGui(ctx, path); } catch (const ox::Exception &ex) { @@ -23,7 +23,7 @@ ox::Vector Module::editors(core::Context *ctx) noexcept { }, { {"npal"}, - [ctx](const ox::String &path) -> ox::Result { + [ctx](const ox::String &path) -> ox::Result { return PaletteEditorImGui::make(ctx, path); } } diff --git a/src/nostalgia/core/studio/paletteeditor-imgui.cpp b/src/nostalgia/core/studio/paletteeditor-imgui.cpp index f9956904e..27b050f9a 100644 --- a/src/nostalgia/core/studio/paletteeditor-imgui.cpp +++ b/src/nostalgia/core/studio/paletteeditor-imgui.cpp @@ -21,11 +21,10 @@ ox::Result PaletteEditorImGui::make(Context *ctx, const ox: out->m_itemName = out->m_itemPath.substr(lastSlash + 1); oxRequire(pal, core::readObj(out->m_ctx, out->m_itemPath)); out->m_pal = *pal.get(); - out->undoStack()->changeTriggered.connect(out.get(), &PaletteEditorImGui::markUnsavedChanges); return out.release(); } -const ox::String &PaletteEditorImGui::itemName() const { +const ox::String &PaletteEditorImGui::itemName() const noexcept { return m_itemPath; } @@ -33,10 +32,6 @@ const ox::String &PaletteEditorImGui::itemDisplayName() const noexcept { return m_itemName; } -studio::UndoStack *PaletteEditorImGui::undoStack() noexcept { - return &m_undoStack; -} - void PaletteEditorImGui::draw(core::Context*) noexcept { static constexpr auto flags = ImGuiTableFlags_RowBg; const auto paneSize = ImGui::GetContentRegionAvail(); @@ -50,20 +45,20 @@ void PaletteEditorImGui::draw(core::Context*) noexcept { { const auto sz = ImVec2(70, 24); if (ImGui::Button("Add", sz)) { - m_undoStack.push(new AddColorCommand(&m_pal, 0, m_pal.colors.size())); + undoStack()->push(new AddColorCommand(&m_pal, 0, m_pal.colors.size())); } ImGui::SameLine(); ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size()); { if (ImGui::Button("Remove", sz)) { - m_undoStack.push(new RemoveColorCommand(&m_pal, m_pal.colors[static_cast(m_selectedRow)], m_selectedRow)); + undoStack()->push(new RemoveColorCommand(&m_pal, m_pal.colors[static_cast(m_selectedRow)], m_selectedRow)); m_selectedRow = ox::min(m_pal.colors.size() - 1, m_selectedRow); } ImGui::SameLine(); ImGui::BeginDisabled(m_selectedRow <= 0); { if (ImGui::Button("Move Up", sz)) { - m_undoStack.push(new MoveColorCommand(&m_pal, m_selectedRow, -1)); + undoStack()->push(new MoveColorCommand(&m_pal, m_selectedRow, -1)); --m_selectedRow; } } @@ -72,7 +67,7 @@ void PaletteEditorImGui::draw(core::Context*) noexcept { ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size() - 1); { if (ImGui::Button("Move Down", sz)) { - m_undoStack.push(new MoveColorCommand(&m_pal, m_selectedRow, 1)); + undoStack()->push(new MoveColorCommand(&m_pal, m_selectedRow, 1)); ++m_selectedRow; } } @@ -132,7 +127,7 @@ void PaletteEditorImGui::draw(core::Context*) noexcept { ImGui::InputInt("Blue", &b, 1, 5); const auto newColor = color16(r, g, b, a); if (c != newColor) { - m_undoStack.push(new UpdateColorCommand(&m_pal, m_selectedRow, c, newColor)); + undoStack()->push(new UpdateColorCommand(&m_pal, m_selectedRow, c, newColor)); } } ImGui::EndChild(); @@ -148,9 +143,4 @@ ox::Error PaletteEditorImGui::saveItem() noexcept { return OxError(0); } -ox::Error PaletteEditorImGui::markUnsavedChanges(int) noexcept { - setUnsavedChanges(true); - return OxError(0); -} - } diff --git a/src/nostalgia/core/studio/paletteeditor-imgui.hpp b/src/nostalgia/core/studio/paletteeditor-imgui.hpp index 2c8e5c90b..3ef53e3a9 100644 --- a/src/nostalgia/core/studio/paletteeditor-imgui.hpp +++ b/src/nostalgia/core/studio/paletteeditor-imgui.hpp @@ -17,7 +17,6 @@ class PaletteEditorImGui: public studio::Editor { ox::String m_itemPath; Palette m_pal; std::size_t m_selectedRow = 0; - studio::UndoStack m_undoStack; PaletteEditorImGui() noexcept = default; @@ -27,19 +26,14 @@ class PaletteEditorImGui: public studio::Editor { /** * Returns the name of item being edited. */ - const ox::String &itemName() const override; + const ox::String &itemName() const noexcept final; - const ox::String &itemDisplayName() const noexcept override; + const ox::String &itemDisplayName() const noexcept final; - void draw(core::Context*) noexcept override; + void draw(core::Context*) noexcept final; protected: - studio::UndoStack *undoStack() noexcept final; - - ox::Error saveItem() noexcept override; - - private: - ox::Error markUnsavedChanges(int) noexcept; + ox::Error saveItem() noexcept final; }; diff --git a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp index 9d01bab7b..7d3f6562e 100644 --- a/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor-imgui.hpp @@ -23,7 +23,7 @@ enum class Tool { Select, }; -class TileSheetEditorImGui: public studio::Editor { +class TileSheetEditorImGui: public studio::BaseEditor { private: class SubSheetEditor { diff --git a/src/nostalgia/studio/lib/editor.cpp b/src/nostalgia/studio/lib/editor.cpp index d9f931401..424b2f965 100644 --- a/src/nostalgia/studio/lib/editor.cpp +++ b/src/nostalgia/studio/lib/editor.cpp @@ -8,27 +8,27 @@ namespace nostalgia::studio { -const ox::String &Editor::itemDisplayName() const { +const ox::String &BaseEditor::itemDisplayName() const noexcept { return itemName(); } -void Editor::cut() { +void BaseEditor::cut() { } -void Editor::copy() { +void BaseEditor::copy() { } -void Editor::paste() { +void BaseEditor::paste() { } -void Editor::exportFile() { +void BaseEditor::exportFile() { } -void Editor::close() { +void BaseEditor::close() { this->closed.emit(itemName()); } -void Editor::save() noexcept { +void BaseEditor::save() noexcept { const auto err = saveItem(); if (!err) { setUnsavedChanges(false); @@ -37,52 +37,61 @@ void Editor::save() noexcept { } } -void Editor::setUnsavedChanges(bool uc) { +void BaseEditor::setUnsavedChanges(bool uc) { m_unsavedChanges = uc; unsavedChangesChanged.emit(uc); } -bool Editor::unsavedChanges() const noexcept { +bool BaseEditor::unsavedChanges() const noexcept { return m_unsavedChanges; } -void Editor::setExportable(bool exportable) { +void BaseEditor::setExportable(bool exportable) { m_exportable = exportable; exportableChanged.emit(exportable); } -bool Editor::exportable() const { +bool BaseEditor::exportable() const { return m_exportable; } -void Editor::setCutEnabled(bool v) { +void BaseEditor::setCutEnabled(bool v) { m_cutEnabled = v; cutEnabledChanged.emit(v); } -bool Editor::cutEnabled() const { +bool BaseEditor::cutEnabled() const { return m_cutEnabled; } -void Editor::setCopyEnabled(bool v) { +void BaseEditor::setCopyEnabled(bool v) { m_copyEnabled = v; copyEnabledChanged.emit(v); } -bool Editor::copyEnabled() const { +bool BaseEditor::copyEnabled() const { return m_copyEnabled; } -void Editor::setPasteEnabled(bool v) { +void BaseEditor::setPasteEnabled(bool v) { m_pasteEnabled = v; pasteEnabledChanged.emit(v); } -bool Editor::pasteEnabled() const { +bool BaseEditor::pasteEnabled() const { return m_pasteEnabled; } -ox::Error Editor::saveItem() noexcept { +ox::Error BaseEditor::saveItem() noexcept { + return OxError(0); +} + +Editor::Editor() noexcept { + m_undoStack.changeTriggered.connect(this, &Editor::markUnsavedChanges); +} + +ox::Error Editor::markUnsavedChanges(int) noexcept { + setUnsavedChanges(true); return OxError(0); } diff --git a/src/nostalgia/studio/lib/editor.hpp b/src/nostalgia/studio/lib/editor.hpp index a0ec1a3da..112548603 100644 --- a/src/nostalgia/studio/lib/editor.hpp +++ b/src/nostalgia/studio/lib/editor.hpp @@ -17,7 +17,7 @@ class StudioUI; namespace nostalgia::studio { -class NOSTALGIASTUDIO_EXPORT Editor: public Widget { +class NOSTALGIASTUDIO_EXPORT BaseEditor: public Widget { friend StudioUI; @@ -29,16 +29,16 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget { bool m_pasteEnabled = false; public: - ~Editor() override = default; + ~BaseEditor() override = default; /** * Returns the name of item being edited. */ [[nodiscard]] - virtual const ox::String &itemName() const = 0; + virtual const ox::String &itemName() const noexcept = 0; [[nodiscard]] - virtual const ox::String &itemDisplayName() const; + virtual const ox::String &itemDisplayName() const noexcept; virtual void cut(); @@ -109,4 +109,20 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget { }; +class Editor: public studio::BaseEditor { + private: + studio::UndoStack m_undoStack; + + public: + Editor() noexcept; + + UndoStack *undoStack() noexcept final { + return &m_undoStack; + } + + private: + ox::Error markUnsavedChanges(int) noexcept; +}; + + } diff --git a/src/nostalgia/studio/lib/module.hpp b/src/nostalgia/studio/lib/module.hpp index 58f641c6c..3cd4376c1 100644 --- a/src/nostalgia/studio/lib/module.hpp +++ b/src/nostalgia/studio/lib/module.hpp @@ -14,7 +14,7 @@ namespace nostalgia::studio { struct EditorMaker { - using Func = std::function(const ox::String&)>; + using Func = std::function(const ox::String&)>; ox::Vector fileTypes; Func make; }; diff --git a/src/nostalgia/studio/studioapp.hpp b/src/nostalgia/studio/studioapp.hpp index 0f78ec370..7fccd74d7 100644 --- a/src/nostalgia/studio/studioapp.hpp +++ b/src/nostalgia/studio/studioapp.hpp @@ -24,13 +24,13 @@ class StudioUI: public ox::SignalHandler { ox::UniquePtr m_project; studio::TaskRunner m_taskRunner; core::Context *m_ctx = nullptr; - ox::Vector> m_editors; + ox::Vector> m_editors; ox::Vector> m_widgets; ox::HashMap m_editorMakers; ProjectExplorer *m_projectExplorer = nullptr; ox::Vector m_openFiles; - studio::Editor *m_activeEditor = nullptr; - studio::Editor *m_activeEditorUpdatePending = nullptr; + studio::BaseEditor *m_activeEditor = nullptr; + studio::BaseEditor *m_activeEditorUpdatePending = nullptr; bool m_saveEnabled = false; bool m_aboutEnabled = false; bool m_showProjectExplorer = true;