diff --git a/release-notes.md b/release-notes.md index 783ce3e6..57449ad4 100644 --- a/release-notes.md +++ b/release-notes.md @@ -4,10 +4,11 @@ * Add PaletteV5 to accommodate namespace change. * Add TileSheetV5. TileSheetV5 retains the bpp field for the sake of CompactTileSheet, but always store it pixel as 8 bpp for itself. -* Replace file picker combo boxes with support for dragging files from the - project explorer. +* Replace file picker combo boxes with a browse button and file picker, and + support for dragging files from the project explorer. * Add ability to create directories. * Add ability to add files to specific directories. * Add ability to delete files from the project explorer. * Ctrl- keyboard shortcuts for jumping between tabs. * Fix Palette Editor to ignore keyboard input when popups are open. +* Palette Editor move color mechanism now uses drag and drop. diff --git a/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/movecolorcommand.cpp b/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/movecolorcommand.cpp index 282790f6..6b56a984 100644 --- a/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/movecolorcommand.cpp +++ b/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/movecolorcommand.cpp @@ -9,7 +9,10 @@ namespace nostalgia::gfx { MoveColorCommand::MoveColorCommand( - Palette &pal, size_t page, size_t srcIdx, size_t dstIdx) noexcept: + Palette &pal, + size_t const page, + size_t const srcIdx, + size_t const dstIdx) noexcept: m_pal(pal), m_page(page), m_srcIdx(srcIdx), @@ -29,10 +32,18 @@ ox::Error MoveColorCommand::undo() noexcept { return {}; } -void MoveColorCommand::moveColor(size_t srcIdx, size_t dstIdx) noexcept { - auto const c = color(m_pal, m_page, srcIdx); - std::ignore = colors(m_pal, m_page).erase(srcIdx); - colors(m_pal, m_page).emplace(dstIdx, c); +void MoveColorCommand::moveColor( + size_t const srcIdx, size_t const dstIdx) noexcept { + { + auto const c = color(m_pal, m_page, srcIdx); + std::ignore = colors(m_pal, m_page).erase(srcIdx); + colors(m_pal, m_page).emplace(dstIdx, c); + } + { + auto name = std::move(m_pal.colorNames[srcIdx]); + std::ignore = m_pal.colorNames.erase(srcIdx); + m_pal.colorNames.emplace(dstIdx, std::move(name)); + } } } diff --git a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp index 35e4b1e3..8ca65c23 100644 --- a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -23,6 +23,15 @@ namespace nostalgia::gfx { namespace ig = studio::ig; +struct ColorDragDrop { + static constexpr auto TypeName = "nostalgia.gfx.ColorDragDrop"; + static constexpr auto TypeVersion = 1; + uint32_t i{}; +}; + +OX_MODEL_BEGIN(ColorDragDrop) + OX_MODEL_FIELD(i) +OX_MODEL_END() void PaletteEditorImGui::PageRenameDialog::draw(turbine::Context &tctx) noexcept { if (!m_show) { @@ -125,26 +134,6 @@ void PaletteEditorImGui::drawColorsEditor() noexcept { 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); - { - if (ImGui::Button("Move Up", sz)) { - std::ignore = pushCommand( - m_pal, m_page, m_selectedColorRow, m_selectedColorRow - 1); - --m_selectedColorRow; - } - } - ImGui::EndDisabled(); - ImGui::SameLine(); - ImGui::BeginDisabled(m_selectedColorRow >= colorCnt(m_pal, m_page) - 1); - { - if (ImGui::Button("Move Down", sz)) { - std::ignore = pushCommand( - m_pal, m_page, m_selectedColorRow, m_selectedColorRow + 1); - ++m_selectedColorRow; - } - } - ImGui::EndDisabled(); } ImGui::EndDisabled(); } @@ -179,6 +168,16 @@ void PaletteEditorImGui::drawColorsEditor() noexcept { "##ColorRow", i == m_selectedColorRow, ImGuiSelectableFlags_SpanAllColumns)) { m_selectedColorRow = i; } + std::ignore = ig::dragDropSource([this, i] { + ImGui::Text("%s", m_pal.colorNames[i].c_str()); + return ig::setDragDropPayload(ColorDragDrop{i}); + }, ImGuiDragDropFlags_SourceAllowNullID); + if (ig::DragDropTarget const d; d) { + auto const [src, err] = ig::getDragDropPayload(); + if (!err) { + std::ignore = pushCommand(m_pal, m_page, src.i, i); + } + } ++i; } }