[jasper/world] Make obj frames default to SubSheet children count
All checks were successful
Build / build (push) Successful in 3m40s
All checks were successful
Build / build (push) Successful in 3m40s
This commit is contained in:
parent
028d98cc41
commit
4d8a3dc0e9
@ -1,5 +1,6 @@
|
|||||||
target_sources(
|
target_sources(
|
||||||
JasperWorld-Studio PRIVATE
|
JasperWorld-Studio PRIVATE
|
||||||
|
commands/editobject.cpp
|
||||||
commands/addobject.cpp
|
commands/addobject.cpp
|
||||||
commands/rmobject.cpp
|
commands/rmobject.cpp
|
||||||
commands/addpalette.cpp
|
commands/addpalette.cpp
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "editobject.hpp"
|
||||||
|
|
||||||
|
namespace jasper::world {
|
||||||
|
|
||||||
|
EditObjectSubSheet::EditObjectSubSheet(
|
||||||
|
WorldObjectSet &doc,
|
||||||
|
size_t const objIdx,
|
||||||
|
ncore::SubSheetId const newSubSheet,
|
||||||
|
uint8_t const newFrames) noexcept:
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error EditObjectSubSheet::redo() noexcept {
|
||||||
|
auto &obj = m_doc.objects[m_objIdx];
|
||||||
|
obj.subsheetId = m_newSubSheet;
|
||||||
|
obj.frames = m_newFrames;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error EditObjectSubSheet::undo() noexcept {
|
||||||
|
auto &obj = m_doc.objects[m_objIdx];
|
||||||
|
obj.subsheetId = m_oldSubSheet;
|
||||||
|
obj.frames = m_oldFrames;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
int EditObjectSubSheet::commandId() const noexcept {
|
||||||
|
return static_cast<int>(WorldObjCommand::EditObjectSubSheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -87,12 +87,6 @@ using EditObjectInterval = EditObject<
|
|||||||
return obj.intervalMs;
|
return obj.intervalMs;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
using EditObjectSubSheet = EditObject<
|
|
||||||
WorldObjCommand::EditObjectSubSheet,
|
|
||||||
[](WorldObject &obj) -> auto& {
|
|
||||||
return obj.subsheetId;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
using EditObjectPalette = EditObject<
|
using EditObjectPalette = EditObject<
|
||||||
WorldObjCommand::EditObjectPalette,
|
WorldObjCommand::EditObjectPalette,
|
||||||
[](WorldObject &obj) -> auto& {
|
[](WorldObject &obj) -> auto& {
|
||||||
@ -106,4 +100,27 @@ using EditObjectCollisionMap = EditObject<
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
|
||||||
|
class EditObjectSubSheet: public studio::UndoCommand {
|
||||||
|
private:
|
||||||
|
WorldObjectSet &m_doc;
|
||||||
|
size_t const m_objIdx{};
|
||||||
|
ncore::SubSheetId const m_oldSubSheet{};
|
||||||
|
ncore::SubSheetId m_newSubSheet{};
|
||||||
|
uint8_t const m_oldFrames{};
|
||||||
|
uint8_t m_newFrames{};
|
||||||
|
public:
|
||||||
|
EditObjectSubSheet(
|
||||||
|
WorldObjectSet &doc,
|
||||||
|
size_t objIdx,
|
||||||
|
ncore::SubSheetId newSubSheet,
|
||||||
|
uint8_t newFrames) noexcept;
|
||||||
|
|
||||||
|
ox::Error redo() noexcept override;
|
||||||
|
|
||||||
|
ox::Error undo() noexcept override;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
int commandId() const noexcept override;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -233,19 +233,28 @@ void WorldObjectSetEditorImGui::drawObjEditor() noexcept {
|
|||||||
|
|
||||||
void WorldObjectSetEditorImGui::drawSubSheetNode(ncore::TileSheet::SubSheet const&ss) noexcept {
|
void WorldObjectSetEditorImGui::drawSubSheetNode(ncore::TileSheet::SubSheet const&ss) noexcept {
|
||||||
auto constexpr dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
auto constexpr dirFlags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||||
auto &obj = activeObj();
|
auto const&obj = activeObj();
|
||||||
auto const selected = ss.id == obj.subsheetId ? ImGuiTreeNodeFlags_Selected : 0;
|
auto const selected = ss.id == obj.subsheetId ? ImGuiTreeNodeFlags_Selected : 0;
|
||||||
ig::IDStackItem const idStackItem{ss.name};
|
ig::IDStackItem const idStackItem{ss.name};
|
||||||
if (!ss.subsheets.empty()) {
|
if (!ss.subsheets.empty()) {
|
||||||
if (ImGui::TreeNodeEx(ss.name.c_str(), dirFlags)) {
|
if (ImGui::TreeNodeEx(ss.name.c_str(), dirFlags | selected)) {
|
||||||
|
if (ImGui::IsItemClicked()) {
|
||||||
|
std::ignore = pushCommand<EditObjectSubSheet>(
|
||||||
|
m_doc, m_selectedObj, ss.id, static_cast<uint8_t>(ss.subsheets.size()));
|
||||||
|
}
|
||||||
for (auto const&child : ss.subsheets) {
|
for (auto const&child : ss.subsheets) {
|
||||||
drawSubSheetNode(child);
|
drawSubSheetNode(child);
|
||||||
}
|
}
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
|
} else {
|
||||||
|
if (ImGui::IsItemClicked()) {
|
||||||
|
std::ignore = pushCommand<EditObjectSubSheet>(
|
||||||
|
m_doc, m_selectedObj, ss.id, static_cast<uint8_t>(ss.subsheets.size()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (ImGui::TreeNodeEx(ss.name.c_str(), ImGuiTreeNodeFlags_Leaf | selected)) {
|
} else if (ImGui::TreeNodeEx(ss.name.c_str(), ImGuiTreeNodeFlags_Leaf | selected)) {
|
||||||
if (ImGui::IsItemClicked()) {
|
if (ImGui::IsItemClicked()) {
|
||||||
std::ignore = pushCommand<EditObjectSubSheet>(m_doc, m_selectedObj, ss.id);
|
std::ignore = pushCommand<EditObjectSubSheet>(m_doc, m_selectedObj, ss.id, static_cast<uint8_t>(1));
|
||||||
}
|
}
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user