From d3578ab5bda343bf3b9609085b38a342d3bcbb13 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 24 May 2024 01:55:23 -0500 Subject: [PATCH] [jasper/world/studio] Put map resize in a popup --- .../studio/worldeditor/commands/editsize.cpp | 15 -------- .../studio/worldeditor/commands/editsize.hpp | 1 - .../studio/worldeditor/worldeditor-imgui.cpp | 34 ++++++++++++++----- .../studio/worldeditor/worldeditor-imgui.hpp | 7 ++++ 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/jasper/modules/world/src/studio/worldeditor/commands/editsize.cpp b/src/jasper/modules/world/src/studio/worldeditor/commands/editsize.cpp index 8368513..573d98c 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/commands/editsize.cpp +++ b/src/jasper/modules/world/src/studio/worldeditor/commands/editsize.cpp @@ -32,21 +32,6 @@ ox::Error EditWorldSizeCommand::undo() noexcept { return {}; } -bool EditWorldSizeCommand::mergeWith(studio::UndoCommand const&cmd) noexcept { - auto const es = dynamic_cast(&cmd); - if (!es || dimensionChanged() != es->dimensionChanged()) { - return false; - } - m_newSize = es->m_newSize; - // undo - resize(m_doc, m_oldSize); - m_doc.tiles = m_oldMap; - // redo - resize(m_doc, m_newSize); - oxLogError(loadWorldStatic(m_objCache, m_doc).moveTo(m_worldStatic)); - return true; -} - int EditWorldSizeCommand::commandId() const noexcept { return static_cast(WorldEditorCommand::EditWorldSize); } diff --git a/src/jasper/modules/world/src/studio/worldeditor/commands/editsize.hpp b/src/jasper/modules/world/src/studio/worldeditor/commands/editsize.hpp index 3d6c1fb..757b083 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/commands/editsize.hpp +++ b/src/jasper/modules/world/src/studio/worldeditor/commands/editsize.hpp @@ -29,7 +29,6 @@ class EditWorldSizeCommand: public studio::UndoCommand { ox::Size const&size); ox::Error redo() noexcept override; ox::Error undo() noexcept override; - bool mergeWith(studio::UndoCommand const&cmd) noexcept override; [[nodiscard]] int commandId() const noexcept override; [[nodiscard]] diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp index 993370f..3ee9d33 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp @@ -94,11 +94,12 @@ void WorldEditorImGui::draw(studio::StudioContext&) noexcept { ImGui::SameLine(); { ig::ChildStackItem const worldView{"RightPane"}; - drawPropEditor(); + drawMenu(); ImGui::Separator(); drawResources(); } m_objSetPicker.draw(); + drawPropEditor(); } void WorldEditorImGui::onActivated() noexcept { @@ -155,14 +156,31 @@ void WorldEditorImGui::drawObjSelector() noexcept { } void WorldEditorImGui::drawPropEditor() noexcept { - ig::IDStackItem const idStackItem("PropEditor"); - int width{m_doc.columns}; - int height{m_doc.rows}; - if (ImGui::InputInt("Map Width", &width, 1)) { - std::ignore = pushCommand(m_objCache, m_doc, m_worldStatic, ox::Size{width, m_doc.rows}); + if (m_sizeEditor.show) { + constexpr auto popupSz = ImVec2{285, 0}; + ig::IDStackItem const idStackItem("EditMapSize"); + if (ig::BeginPopup(m_sctx.tctx, "Edit Map Size", m_sizeEditor.show, popupSz)) { + ImGui::InputInt("Map Width", &m_sizeEditor.columns, 1); + ImGui::InputInt("Map Height", &m_sizeEditor.rows, 1); + const bool changed = m_doc.columns != m_sizeEditor.columns + || m_doc.rows != m_sizeEditor.rows; + if (ig::PopupControlsOkCancel(popupSz.x, m_sizeEditor.show) == ig::PopupResponse::OK) { + if (changed) { + std::ignore = pushCommand( + m_objCache, m_doc, m_worldStatic, ox::Size{m_sizeEditor.columns, m_sizeEditor.rows}); + } + } + ImGui::EndPopup(); + } } - if (ImGui::InputInt("Map Height", &height, 1)) { - std::ignore = pushCommand(m_objCache, m_doc, m_worldStatic, ox::Size{m_doc.columns, height}); +} + +void WorldEditorImGui::drawMenu() noexcept { + ig::IDStackItem const idStackItem("Menu"); + if (ig::PushButton("Resize")) { + m_sizeEditor.show = true; + m_sizeEditor.columns = m_doc.columns; + m_sizeEditor.rows = m_doc.rows; } } diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp index 1f9633a..f2a186e 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp @@ -45,6 +45,11 @@ class WorldEditorImGui: public studio::Editor { struct { size_t selectedIdx{}; } m_palMgr; + struct { + bool show{}; + int columns{}; + int rows{}; + } m_sizeEditor; public: WorldEditorImGui(studio::StudioContext &ctx, ox::StringView path); @@ -63,6 +68,8 @@ class WorldEditorImGui: public studio::Editor { void drawPropEditor() noexcept; + void drawMenu() noexcept; + void drawResources() noexcept; void drawWorldView() noexcept;