From 7e20f7200963cd0b22f84cc46e10db12b6c13806 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 19 Jan 2025 19:03:50 -0600 Subject: [PATCH] Squashed 'deps/nostalgia/' changes from 6b53eaf6..6bc629e0 6bc629e0 [nostalgia/core/studio/tilesheeteditor] Replace Palette combobox with a readonly text input 0146d384 [nostalgia/core/studio/tilesheeteditor] Manually merge in changes that were lost in conflict 75d8e7bb [nostalgia/core/studio/paletteeditor] Fix crash that occurs when removing last color git-subtree-dir: deps/nostalgia git-subtree-split: 6bc629e02c60e86739f0f3da3a0f3e15855637ce --- .../paletteeditor/paletteeditor-imgui.cpp | 3 ++- .../tilesheeteditor/tilesheeteditor-imgui.cpp | 26 ++++++------------- .../tilesheeteditor/tilesheeteditor-imgui.hpp | 2 +- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp index 1ae4f7b..d6bc4a3 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -107,7 +107,7 @@ void PaletteEditorImGui::colorInput(ox::CStringView label, int &v, bool &inputFo void PaletteEditorImGui::drawColorsEditor() noexcept { constexpr auto tableFlags = ImGuiTableFlags_RowBg; auto const colorsSz = ImGui::GetContentRegionAvail(); - auto const colorEditor = m_selectedColorRow < colorCnt(m_pal, m_page); + auto colorEditor = m_selectedColorRow < colorCnt(m_pal, m_page); auto const colorEditorWidth = 220; static constexpr auto toolbarHeight = 40; { @@ -123,6 +123,7 @@ void PaletteEditorImGui::drawColorsEditor() noexcept { if (ImGui::Button("Remove", sz)) { std::ignore = pushCommand(m_pal, m_selectedColorRow); m_selectedColorRow = ox::min(colorCnt(m_pal, m_page) - 1, m_selectedColorRow); + colorEditor = m_selectedColorRow < colorCnt(m_pal, m_page); } ImGui::SameLine(); ImGui::BeginDisabled(m_selectedColorRow <= 0); diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp index 8cc7c9a..4d5c4f7 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -437,19 +437,17 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept { } void TileSheetEditorImGui::drawPaletteMenu() noexcept { - auto const&files = m_sctx.project->fileList(core::FileExt_npal); - auto const comboWidthSub = 62; + auto constexpr comboWidthSub = 62; ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub); - if (ig::ComboBox("Palette", files, m_selectedPaletteIdx)) { - oxLogError(m_model.setPalette(files[m_selectedPaletteIdx])); + auto constexpr palTags = ImGuiInputTextFlags_ReadOnly; + if (ig::InputText("Palette", m_selectedPalette, palTags)) { + oxLogError(m_model.setPalette(m_selectedPalette)); } if (ig::DragDropTarget const dragDropTarget; dragDropTarget) { auto const [ref, err] = ig::getDragDropPayload("FileRef"); - if (!err && endsWith(ref.path, FileExt_npal)) { - auto const oldVal = m_selectedPaletteIdx; - std::ignore = ox::findIdx(files.begin(), files.end(), ref.path).moveTo(m_selectedPaletteIdx); - if (oldVal != m_selectedPaletteIdx) { - oxLogError(m_model.setPalette(files[m_selectedPaletteIdx])); + if (!err) { + if (ref.path != m_selectedPalette) { + oxLogError(m_model.setPalette(ref.path)); } } } @@ -523,15 +521,7 @@ ox::Error TileSheetEditorImGui::updateActiveSubsheet(ox::StringView const&name, } ox::Error TileSheetEditorImGui::setPaletteSelection() noexcept { - auto const&palPath = m_model.palPath(); - auto const&palList = m_sctx.project->fileList(core::FileExt_npal); - for (std::size_t i = 0; auto const&pal : palList) { - if (palPath == pal) { - m_selectedPaletteIdx = i; - break; - } - ++i; - } + m_selectedPalette = m_model.palPath(); return {}; } diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp index 40acda3..46797d0 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp @@ -46,7 +46,7 @@ class TileSheetEditorImGui: public studio::Editor { constexpr bool isOpen() const noexcept { return m_show; } }; static constexpr float s_palViewWidth = 300; - std::size_t m_selectedPaletteIdx = 0; + ox::String m_selectedPalette; studio::StudioContext &m_sctx; turbine::Context &m_tctx; ox::Vector m_paletteList;