From a1a2b4154eca896f8e456c2e593d7955b09f59d3 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 19 Jan 2025 19:12:20 -0600 Subject: [PATCH] [jasper/world/studio] Cleanup --- .../worldobjectseteditor-imgui.cpp | 35 ++++++++++--------- .../worldobjectseteditor-imgui.hpp | 6 ++-- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp index fb6308b..1857e25 100644 --- a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.cpp @@ -269,11 +269,11 @@ void WorldObjectSetEditorImGui::drawSubSheetNode(ncore::TileSheet::SubSheet cons void WorldObjectSetEditorImGui::drawPaletteList() noexcept { ig::IDStackItem const idStackItem{"PaletteList"}; if (ig::PushButton("+", btnSize)) { - addPalette(); + showAddPalette(); } ImGui::SameLine(); if (ig::PushButton("-", btnSize)) { - rmPalette(); + rmSelectedPalette(); } constexpr auto flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("Subsheets", 1, flags)) { @@ -285,12 +285,7 @@ void WorldObjectSetEditorImGui::drawPaletteList() noexcept { if (ig::DragDropTarget const d; d) { auto const [fr, err] = ig::getDragDropPayload("FileRef"); if (!err && endsWith(fr.path, ncore::FileExt_npal)) { - auto const [uuid, err] = keel::pathToUuid( - keelCtx(m_sctx), fr.path); - if (!err) { - auto const uuidUrl = ox::sfmt("uuid://{}", uuid.toString()); - std::ignore = pushCommand(m_doc, ox::FileAddress{uuidUrl}); - } + addPalette(fr.path); } } } @@ -322,23 +317,31 @@ void WorldObjectSetEditorImGui::drawAddPalettePopup() noexcept { auto const&palettes = m_sctx.project->fileList(ncore::FileExt_npal); ig::ComboBox("Palette", palettes, m_addPalPopup.selectedIdx); if (ig::PopupControlsOkCancel(popupSz.x, m_addPalPopup.show) == ig::PopupResponse::OK) { - auto [uuid, err] = keel::pathToUuid( - keelCtx(m_sctx.tctx), palettes[m_addPalPopup.selectedIdx]); - if (!err) { - auto const uuidUrl = ox::sfmt("uuid://{}", uuid.toString()); - std::ignore = pushCommand(m_doc, ox::FileAddress{uuidUrl}); - } + addPalette(palettes[m_addPalPopup.selectedIdx]); } ImGui::EndPopup(); } } -void WorldObjectSetEditorImGui::addPalette() noexcept { +void WorldObjectSetEditorImGui::addPalette(ox::StringViewCR path) noexcept { + auto const [uuid, err] = keel::pathToUuid( + keelCtx(m_sctx.tctx), path); + if (!err) { + auto const uuidUrl = ox::sfmt("uuid://{}", uuid.toString()); + ox::FileAddress addr{uuidUrl}; + auto const idx = ox::findIdx(m_doc.palettes.begin(), m_doc.palettes.end(), addr); + if (idx.error) { + std::ignore = pushCommand(m_doc, std::move(addr)); + } + } +} + +void WorldObjectSetEditorImGui::showAddPalette() noexcept { m_addPalPopup.show = true; m_addPalPopup.selectedIdx = 0; } -void WorldObjectSetEditorImGui::rmPalette() noexcept { +void WorldObjectSetEditorImGui::rmSelectedPalette() noexcept { std::ignore = pushCommand(m_doc, m_selectedPal); } diff --git a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp index f8f159a..63eb041 100644 --- a/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp +++ b/src/jasper/modules/world/src/studio/worldobjectseteditor/worldobjectseteditor-imgui.hpp @@ -66,9 +66,11 @@ class WorldObjectSetEditorImGui: public studio::Editor { void drawAddPalettePopup() noexcept; - void addPalette() noexcept; + void addPalette(ox::StringViewCR path) noexcept; - void rmPalette() noexcept; + void showAddPalette() noexcept; + + void rmSelectedPalette() noexcept; ox::Error setTileSheet(ox::StringViewCR path) noexcept;