[jasper/world] Add navigateTo handling to editors
All checks were successful
Build / build (push) Successful in 1m31s

This commit is contained in:
2025-05-15 20:41:44 -05:00
parent 6e1ff6ddef
commit b7aff140bf
6 changed files with 40 additions and 9 deletions

View File

@@ -10,16 +10,16 @@ EditObjectSubSheet::EditObjectSubSheet(
WorldObjectSet &doc,
size_t const objIdx,
ngfx::SubSheetId const newSubSheet,
uint8_t const newFrames) noexcept:
uint8_t const newFrames):
m_doc{doc},
m_objIdx{objIdx},
m_oldSubSheet{m_doc.objects[objIdx].subsheetId},
m_newSubSheet{newSubSheet},
m_oldFrames{m_doc.objects[objIdx].frames},
m_newFrames{newFrames} {
setObsolete(
m_newSubSheet == m_oldSubSheet &&
m_newFrames == m_oldFrames);
if (m_newSubSheet == m_oldSubSheet && m_newFrames == m_oldFrames) {
throw ox::Exception{1, "EditObjectSubsheet: no change occurred"};
}
}
ox::Error EditObjectSubSheet::redo() noexcept {

View File

@@ -119,7 +119,7 @@ class EditObjectSubSheet: public studio::UndoCommand {
WorldObjectSet &doc,
size_t objIdx,
ngfx::SubSheetId newSubSheet,
uint8_t newFrames) noexcept;
uint8_t newFrames);
ox::Error redo() noexcept override;

View File

@@ -77,6 +77,18 @@ void WorldObjectSetEditorImGui::draw(studio::Context&) noexcept {
void WorldObjectSetEditorImGui::onActivated() noexcept {
}
void WorldObjectSetEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
auto const idx = ox::find_if(
m_doc.objects.begin(),
m_doc.objects.end(),
[arg](WorldObject const &wo) {
return wo.name == arg;
});
if (idx != m_doc.objects.end()) {
m_selectedObj = idx.offset();;
}
}
WorldObject const&WorldObjectSetEditorImGui::activeObj() const noexcept {
return m_doc.objects[m_selectedObj];
}
@@ -257,6 +269,9 @@ void WorldObjectSetEditorImGui::drawSubSheetNode(ngfx::TileSheet::SubSheet const
std::ignore = pushCommand<EditObjectSubSheet>(
m_doc, m_selectedObj, ss.id, static_cast<uint8_t>(ss.subsheets.size()));
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
studio::navigateTo(m_sctx, m_tilesheetPath, ox::intToStr(ss.id));
}
for (auto const&child : ss.subsheets) {
drawSubSheetNode(child);
}
@@ -266,11 +281,17 @@ void WorldObjectSetEditorImGui::drawSubSheetNode(ngfx::TileSheet::SubSheet const
std::ignore = pushCommand<EditObjectSubSheet>(
m_doc, m_selectedObj, ss.id, static_cast<uint8_t>(ss.subsheets.size()));
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
studio::navigateTo(m_sctx, m_tilesheetPath, ox::intToStr(ss.id));
}
}
} else if (ImGui::TreeNodeEx(ss.name.c_str(), ImGuiTreeNodeFlags_Leaf | selected)) {
if (ImGui::IsItemClicked()) {
std::ignore = pushCommand<EditObjectSubSheet>(m_doc, m_selectedObj, ss.id, static_cast<uint8_t>(1));
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
studio::navigateTo(m_sctx, m_tilesheetPath, ox::intToStr(ss.id));
}
ImGui::TreePop();
}
}
@@ -311,6 +332,12 @@ void WorldObjectSetEditorImGui::drawPaletteListItems() noexcept {
if (ImGui::Selectable("##PaletteSelection", i == m_selectedPal, ImGuiSelectableFlags_SpanAllColumns)) {
m_selectedPal = i;
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
auto const [p, err] = m_doc.palettes[i].getPath();
if (!err) {
studio::navigateTo(m_sctx, p);
}
}
++i;
}
}

View File

@@ -41,6 +41,8 @@ class WorldObjectSetEditorImGui: public studio::Editor {
void onActivated() noexcept override;
void navigateTo(ox::StringViewCR arg) noexcept override;
private:
WorldObject const&activeObj() const noexcept;