[nostalgia/gfx] Add navigateTo handler to TileSheetEditor
This commit is contained in:
parent
d848f78fc9
commit
6e1ff6ddef
@ -426,6 +426,8 @@ ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept;
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubSheetIdx idx) noexcept;
|
||||
|
||||
ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetId pId) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet &getSubSheet(
|
||||
ox::SpanView<uint32_t> const&idx,
|
||||
|
@ -388,6 +388,17 @@ ox::Error TileSheetEditorImGui::saveItem() noexcept {
|
||||
return m_model.saveFile();
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
|
||||
auto const subSheetId = strToInt(arg);
|
||||
if (subSheetId.error) {
|
||||
return;
|
||||
}
|
||||
if (auto const [val, err] = getSubSheetIdx(m_model.img(), subSheetId.value);
|
||||
!err) {
|
||||
setActiveSubsheet(val);
|
||||
}
|
||||
}
|
||||
|
||||
void TileSheetEditorImGui::showSubsheetEditor() noexcept {
|
||||
auto const&sheet = m_model.activeSubSheet();
|
||||
if (!sheet.subsheets.empty()) {
|
||||
@ -451,7 +462,7 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
|
||||
if (wheelh != 0) {
|
||||
m_view.scrollH(fbSize, wheelh);
|
||||
}
|
||||
if (ImGui::IsMouseDown(0) && m_prevMouseDownPos != mousePos) {
|
||||
if (ImGui::IsMouseClicked(0) && m_prevMouseDownPos != mousePos) {
|
||||
m_prevMouseDownPos = mousePos;
|
||||
switch (m_tool) {
|
||||
case TileSheetTool::Draw:
|
||||
|
@ -87,6 +87,8 @@ class TileSheetEditorImGui: public studio::Editor {
|
||||
protected:
|
||||
ox::Error saveItem() noexcept override;
|
||||
|
||||
void navigateTo(ox::StringViewCR arg) noexcept override;
|
||||
|
||||
private:
|
||||
void showSubsheetEditor() noexcept;
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "nostalgia/gfx/tilesheet.hpp"
|
||||
|
||||
#include <ox/std/size.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
|
||||
@ -187,6 +189,28 @@ TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubShe
|
||||
return validateSubSheetIdx(std::move(idx), 0, ts.subsheet);
|
||||
}
|
||||
|
||||
static ox::Error getSubSheetIdx(TileSheet::SubSheet const &ss, SubSheetId const pId, TileSheet::SubSheetIdx &idx) noexcept {
|
||||
if (ss.id == pId) {
|
||||
return {};
|
||||
}
|
||||
for (uint32_t i{}; auto const &sub : ss.subsheets) {
|
||||
idx.emplace_back(i);
|
||||
auto const err = getSubSheetIdx(sub, pId, idx);
|
||||
if (!err) {
|
||||
return {};
|
||||
}
|
||||
idx.pop_back();
|
||||
++i;
|
||||
}
|
||||
return ox::Error{1, "SubSheet not found"};
|
||||
}
|
||||
|
||||
ox::Result<TileSheet::SubSheetIdx> getSubSheetIdx(TileSheet const &ts, SubSheetId const pId) noexcept {
|
||||
ox::Result<TileSheet::SubSheetIdx> out;
|
||||
OX_RETURN_ERROR(getSubSheetIdx(ts.subsheet, pId, out.value));
|
||||
return out;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 13
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-reference"
|
||||
|
Loading…
x
Reference in New Issue
Block a user