From 9c19655ce286bb889de623d54cef89836d5fafef Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 26 Dec 2023 16:37:09 -0600 Subject: [PATCH] [nostalgia/core] Fix build, add SubSheet ID to SubSheet Editor view --- .../tilesheeteditor/tilesheeteditor-imgui.cpp | 33 ++++++++++--------- .../tilesheeteditor/tilesheeteditor-imgui.hpp | 2 +- .../tilesheeteditor/tilesheeteditormodel.cpp | 2 +- src/nostalgia/modules/core/src/tilesheet.cpp | 20 +++++------ 4 files changed, 30 insertions(+), 27 deletions(-) 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 d0ab8d6b..b010d581 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -205,12 +205,13 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept { } TileSheet::SubSheetIdx path; static constexpr auto flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; - if (ImGui::BeginTable("Subsheets", 3, flags)) { + if (ImGui::BeginTable("Subsheets", 4, flags)) { ImGui::TableSetupColumn("Subsheet", ImGuiTableColumnFlags_NoHide); ImGui::TableSetupColumn("Columns", ImGuiTableColumnFlags_WidthFixed, 50); ImGui::TableSetupColumn("Rows", ImGuiTableColumnFlags_WidthFixed, 50); + ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_NoHide); ImGui::TableHeadersRow(); - drawSubsheetSelector(&m_view.img().subsheet, &path); + drawSubsheetSelector(m_view.img().subsheet, path); ImGui::EndTable(); } } @@ -221,44 +222,46 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept { m_exportMenu.draw(); } -void TileSheetEditorImGui::drawSubsheetSelector(TileSheet::SubSheet *subsheet, TileSheet::SubSheetIdx *path) { +void TileSheetEditorImGui::drawSubsheetSelector(TileSheet::SubSheet &subsheet, TileSheet::SubSheetIdx &path) { ImGui::TableNextRow(0, 5); using Str = ox::BasicString<100>; - auto pathStr = ox::join("##", *path).value; - auto lbl = ox::sfmt("{}##{}", subsheet->name, pathStr); - const auto rowSelected = *path == m_model.activeSubSheetIdx(); + auto pathStr = ox::join("##", path).value; + auto lbl = ox::sfmt("{}##{}", subsheet.name, pathStr); + const auto rowSelected = path == m_model.activeSubSheetIdx(); const auto flags = ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_DefaultOpen - | (subsheet->subsheets.empty() ? ImGuiTreeNodeFlags_Leaf : 0) + | (subsheet.subsheets.empty() ? ImGuiTreeNodeFlags_Leaf : 0) | (rowSelected ? ImGuiTreeNodeFlags_Selected : 0); ImGui::TableNextColumn(); const auto open = ImGui::TreeNodeEx(lbl.c_str(), flags); ImGui::SameLine(); if (ImGui::IsItemClicked()) { - m_model.setActiveSubsheet(*path); + m_model.setActiveSubsheet(path); } if (ImGui::IsMouseDoubleClicked(0) && ImGui::IsItemHovered()) { showSubsheetEditor(); } - if (subsheet->subsheets.empty()) { + if (subsheet.subsheets.empty()) { ImGui::TableNextColumn(); - ImGui::Text("%d", subsheet->columns); + ImGui::Text("%d", subsheet.columns); ImGui::TableNextColumn(); - ImGui::Text("%d", subsheet->rows); + ImGui::Text("%d", subsheet.rows); } else { ImGui::TableNextColumn(); ImGui::Text("--"); ImGui::TableNextColumn(); ImGui::Text("--"); } + ImGui::TableNextColumn(); + ImGui::Text("%d", subsheet.id); if (open) { - for (auto i = 0ul; auto &child : subsheet->subsheets) { - path->push_back(i); + for (auto i = 0ul; auto &child : subsheet.subsheets) { + path.push_back(i); ImGui::PushID(static_cast(i)); - drawSubsheetSelector(&child, path); + drawSubsheetSelector(child, path); ImGui::PopID(); - path->pop_back(); + path.pop_back(); ++i; } ImGui::TreePop(); 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 5f617702..de354065 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp @@ -83,7 +83,7 @@ class TileSheetEditorImGui: public studio::Editor { void draw(turbine::Context&) noexcept override; - void drawSubsheetSelector(TileSheet::SubSheet*, TileSheet::SubSheetIdx *path); + void drawSubsheetSelector(TileSheet::SubSheet&, TileSheet::SubSheetIdx &path); [[nodiscard]] static ox::Vec2 clickPos(ImVec2 const&winPos, ox::Vec2 clickPos) noexcept; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index b0f4d8e7..0945f763 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -239,7 +239,7 @@ void TileSheetEditorModel::ackUpdate() noexcept { ox::Error TileSheetEditorModel::saveFile() noexcept { const auto sctx = applicationData(m_ctx); - return sctx->project->writeObj(m_path, m_img); + return sctx->project->writeObj(m_path, m_img, ox::ClawFormat::Organic); } bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept { diff --git a/src/nostalgia/modules/core/src/tilesheet.cpp b/src/nostalgia/modules/core/src/tilesheet.cpp index 98b1f782..0ec205a8 100644 --- a/src/nostalgia/modules/core/src/tilesheet.cpp +++ b/src/nostalgia/modules/core/src/tilesheet.cpp @@ -61,7 +61,7 @@ std::size_t TileSheet::SubSheet::idx(ox::Point const&pt) const noexcept { return ptToIdx(pt, columns); } -void TileSheet::SubSheet::readPixelsTo(ox::Vector *pPixels, int8_t pBpp) const noexcept { +void TileSheet::SubSheet::readPixelsTo(ox::Vector &pPixels, int8_t pBpp) const noexcept { if (!subsheets.empty()) { for (auto &s: subsheets) { s.readPixelsTo(pPixels); @@ -69,25 +69,25 @@ void TileSheet::SubSheet::readPixelsTo(ox::Vector *pPixels, int8_t pBpp } else { if (pBpp == 4) { for (auto p: this->pixels) { - pPixels->emplace_back(static_cast(p & 0b1111)); - pPixels->emplace_back(static_cast(p >> 4)); + pPixels.emplace_back(static_cast(p & 0b1111)); + pPixels.emplace_back(static_cast(p >> 4)); } } else { for (auto p: this->pixels) { - pPixels->emplace_back(p); + pPixels.emplace_back(p); } } } } -void TileSheet::SubSheet::readPixelsTo(ox::Vector *pPixels) const noexcept { +void TileSheet::SubSheet::readPixelsTo(ox::Vector &pPixels) const noexcept { if (!subsheets.empty()) { for (auto &s: subsheets) { s.readPixelsTo(pPixels); } } else { for (auto p : this->pixels) { - pPixels->emplace_back(p); + pPixels.emplace_back(p); } } } @@ -299,10 +299,10 @@ TileSheet::SubSheet &TileSheet::getSubSheet(TileSheet::SubSheetIdx const&idx) no ox::Error TileSheet::addSubSheet(TileSheet::SubSheetIdx const&idx) noexcept { auto &parent = getSubSheet(idx); if (parent.subsheets.size() < 2) { - parent.subsheets.emplace_back(idIt++, ox::sfmt("Subsheet {}", parent.subsheets.size()), 1, 1, bpp); + parent.subsheets.emplace_back(++idIt, ox::sfmt("Subsheet {}", parent.subsheets.size()), 1, 1, bpp); } else { - parent.subsheets.emplace_back(idIt++, "Subsheet 0", parent.columns, parent.rows, bpp); - parent.subsheets.emplace_back(idIt++, "Subsheet 1", 1, 1, bpp); + parent.subsheets.emplace_back(++idIt, "Subsheet 0", parent.columns, parent.rows, bpp); + parent.subsheets.emplace_back(++idIt, "Subsheet 1", 1, 1, bpp); } return OxError(0); } @@ -353,7 +353,7 @@ ox::Result TileSheet::getNameFor(SubSheetId pId) const noexcept ox::Vector TileSheet::pixels() const noexcept { ox::Vector out; - subsheet.readPixelsTo(&out); + subsheet.readPixelsTo(out); return out; }