[jasper/world/studio] Put map resize in a popup
This commit is contained in:
parent
2a55a5762d
commit
d3578ab5bd
@ -32,21 +32,6 @@ ox::Error EditWorldSizeCommand::undo() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
bool EditWorldSizeCommand::mergeWith(studio::UndoCommand const&cmd) noexcept {
|
||||
auto const es = dynamic_cast<EditWorldSizeCommand const*>(&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<int>(WorldEditorCommand::EditWorldSize);
|
||||
}
|
||||
|
@ -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]]
|
||||
|
@ -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<EditWorldSizeCommand>(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<EditWorldSizeCommand>(
|
||||
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<EditWorldSizeCommand>(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user