[jasper/world] Add navigateTo handling to editors
All checks were successful
Build / build (push) Successful in 1m31s
All checks were successful
Build / build (push) Successful in 1m31s
This commit is contained in:
parent
6e1ff6ddef
commit
b7aff140bf
@ -14,8 +14,6 @@
|
||||
|
||||
namespace jasper::world {
|
||||
|
||||
namespace ngfx = nostalgia::gfx;
|
||||
|
||||
constexpr void setTopEdge(uint8_t &layerAttachments, uint8_t const val) noexcept {
|
||||
layerAttachments = static_cast<uint8_t>((layerAttachments & 0b11111100) | val);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <keel/media.hpp>
|
||||
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
#include "commands/addrmobjectset.hpp"
|
||||
@ -64,8 +65,8 @@ constexpr ox::Point fbPtToTileAddr(
|
||||
constexpr auto RowsOnScrn = 10;
|
||||
auto const fbX = static_cast<float>(fbPt.x);
|
||||
auto const fbY = static_cast<float>(fbPt.y);
|
||||
auto const tw = static_cast<float>(mapSz.x / ColumnsOnScrn);
|
||||
auto const th = static_cast<float>(mapSz.y / RowsOnScrn);
|
||||
auto const tw = mapSz.x / static_cast<float>(ColumnsOnScrn);
|
||||
auto const th = mapSz.y / static_cast<float>(RowsOnScrn);
|
||||
return {
|
||||
static_cast<int>(fbX / tw),
|
||||
static_cast<int>(fbY / th),
|
||||
@ -222,6 +223,9 @@ void WorldEditorImGui::drawObjSelector() noexcept {
|
||||
if (ImGui::TreeNodeEx(setName.c_str(), flags)) {
|
||||
for (auto const&obj : set->objects) {
|
||||
if (ImGui::TreeNodeEx(obj.name.c_str(), ImGuiTreeNodeFlags_Leaf)) {
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
||||
studio::navigateTo(m_sctx, setName, obj.name);
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
ig::dragDropSource([&] {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user