From 7f4e05a9276517e157141b8d6c9b821e6501f628 Mon Sep 17 00:00:00 2001 From: shweet Date: Tue, 13 Jan 2026 03:16:38 -0500 Subject: [PATCH] fixed event handling and a lot of ID stuff OOPS --- src/anm2/anm2.h | 3 +++ src/anm2/anm2_events.cpp | 9 +++++++++ src/anm2/anm2_sounds.cpp | 9 +++++++++ src/anm2/anm2_spritesheets.cpp | 8 ++++++++ src/anm2/frame.cpp | 3 ++- src/document.cpp | 6 +++--- src/imgui/imgui_.cpp | 24 ++++++++++++++++++++++++ src/imgui/imgui_.h | 1 + src/imgui/window/frame_properties.cpp | 9 ++++----- src/imgui/window/layers.cpp | 4 ++-- src/imgui/window/timeline.cpp | 4 ++-- src/storage.cpp | 11 ++++++++--- src/storage.h | 4 +++- 13 files changed, 78 insertions(+), 17 deletions(-) diff --git a/src/anm2/anm2.h b/src/anm2/anm2.h index 1599972..c71a8c2 100644 --- a/src/anm2/anm2.h +++ b/src/anm2/anm2.h @@ -40,6 +40,7 @@ namespace anm2ed::anm2 Spritesheet* spritesheet_get(int); bool spritesheet_add(const std::filesystem::path&, const std::filesystem::path&, int&); std::vector spritesheet_labels_get(); + std::vector spritesheet_ids_get(); std::set spritesheets_unused(); bool spritesheets_deserialize(const std::string&, const std::filesystem::path&, types::merge::Type type, std::string*); @@ -56,11 +57,13 @@ namespace anm2ed::anm2 void event_add(int&); std::vector event_labels_get(); + std::vector event_ids_get(); std::set events_unused(); bool events_deserialize(const std::string&, types::merge::Type, std::string*); bool sound_add(const std::filesystem::path& directory, const std::filesystem::path& path, int& id); std::vector sound_labels_get(); + std::vector sound_ids_get(); std::set sounds_unused(); bool sounds_deserialize(const std::string&, const std::filesystem::path&, types::merge::Type, std::string*); diff --git a/src/anm2/anm2_events.cpp b/src/anm2/anm2_events.cpp index 1bfba78..28c4d12 100644 --- a/src/anm2/anm2_events.cpp +++ b/src/anm2/anm2_events.cpp @@ -25,6 +25,15 @@ namespace anm2ed::anm2 return labels; } + std::vector Anm2::event_ids_get() + { + std::vector ids{}; + ids.emplace_back(-1); + for (auto& id : content.events | std::views::keys) + ids.emplace_back(id); + return ids; + } + std::set Anm2::events_unused() { std::set used{}; diff --git a/src/anm2/anm2_sounds.cpp b/src/anm2/anm2_sounds.cpp index d9c4b0e..5d7e146 100644 --- a/src/anm2/anm2_sounds.cpp +++ b/src/anm2/anm2_sounds.cpp @@ -29,6 +29,15 @@ namespace anm2ed::anm2 return labels; } + std::vector Anm2::sound_ids_get() + { + std::vector ids{}; + ids.emplace_back(-1); + for (auto& [id, sound] : content.sounds) + ids.emplace_back(id); + return ids; + } + std::set Anm2::sounds_unused() { std::set used; diff --git a/src/anm2/anm2_spritesheets.cpp b/src/anm2/anm2_spritesheets.cpp index f0d27cc..1bdd04d 100644 --- a/src/anm2/anm2_spritesheets.cpp +++ b/src/anm2/anm2_spritesheets.cpp @@ -47,6 +47,14 @@ namespace anm2ed::anm2 return labels; } + std::vector Anm2::spritesheet_ids_get() + { + std::vector ids{}; + for (auto& [id, spritesheet] : content.spritesheets) + ids.emplace_back(id); + return ids; + } + bool Anm2::spritesheets_deserialize(const std::string& string, const std::filesystem::path& directory, merge::Type type, std::string* errorString) { diff --git a/src/anm2/frame.cpp b/src/anm2/frame.cpp index a67de97..4b6970c 100644 --- a/src/anm2/frame.cpp +++ b/src/anm2/frame.cpp @@ -103,10 +103,11 @@ namespace anm2ed::anm2 element->SetAttribute("Interpolated", isInterpolated); break; case TRIGGER: - element->SetAttribute("EventId", eventID); + if (eventID != -1) element->SetAttribute("EventId", eventID); for (auto& id : soundIDs) { + if (id == -1) continue; auto soundChild = element->InsertNewChildElement("Sound"); soundChild->SetAttribute("Id", id); } diff --git a/src/document.cpp b/src/document.cpp index 5ac84e3..a28c8de 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -179,7 +179,7 @@ namespace anm2ed auto events_set = [&]() { event.unused = anm2.events_unused(); - event.labels_set(anm2.event_labels_get()); + event.labels_set(anm2.event_labels_get(), anm2.event_ids_get()); }; auto animations_set = [&]() { animation.labels_set(anm2.animation_labels_get()); }; @@ -187,13 +187,13 @@ namespace anm2ed auto spritesheets_set = [&]() { spritesheet.unused = anm2.spritesheets_unused(); - spritesheet.labels_set(anm2.spritesheet_labels_get()); + spritesheet.labels_set(anm2.spritesheet_labels_get(), anm2.spritesheet_ids_get()); }; auto sounds_set = [&]() { sound.unused = anm2.sounds_unused(); - sound.labels_set(anm2.sound_labels_get()); + sound.labels_set(anm2.sound_labels_get(), anm2.sound_ids_get()); }; switch (type) diff --git a/src/imgui/imgui_.cpp b/src/imgui/imgui_.cpp index 41aa3f8..59bed74 100644 --- a/src/imgui/imgui_.cpp +++ b/src/imgui/imgui_.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -106,6 +107,29 @@ namespace anm2ed::imgui return isActivated; } + bool combo_id_mapped(const std::string& label, int* id, const std::vector& ids, std::vector& labels) + { + if (!id) return false; + + int index = -1; + if (!ids.empty()) + { + auto it = std::find(ids.begin(), ids.end(), *id); + if (it != ids.end()) index = (int)std::distance(ids.begin(), it); + } + + bool isActivated = ImGui::Combo(label.c_str(), &index, labels.data(), (int)labels.size()); + if (isActivated) + { + if (index >= 0 && index < (int)ids.size()) + *id = ids[index]; + else + *id = -1; + } + + return isActivated; + } + edit::Type drag_int_persistent(const char* label, int* value, float speed, int min, int max, const char* format, ImGuiSliderFlags flags) { diff --git a/src/imgui/imgui_.h b/src/imgui/imgui_.h index 99697dd..9923156 100644 --- a/src/imgui/imgui_.h +++ b/src/imgui/imgui_.h @@ -191,6 +191,7 @@ namespace anm2ed::imgui types::edit::Type color_edit3_persistent(const char*, glm::vec3*, ImGuiColorEditFlags = 0); types::edit::Type color_edit4_persistent(const char*, glm::vec4*, ImGuiColorEditFlags = 0); bool combo_negative_one_indexed(const std::string&, int*, std::vector&); + bool combo_id_mapped(const std::string&, int*, const std::vector&, std::vector&); std::string& selectable_input_text_id(); bool selectable_input_text(const std::string& label, const std::string& id, std::string& text, bool isSelected, ImGuiSelectableFlags flags, RenameState& state); diff --git a/src/imgui/window/frame_properties.cpp b/src/imgui/window/frame_properties.cpp index e46ed5f..e5ed2d7 100644 --- a/src/imgui/window/frame_properties.cpp +++ b/src/imgui/window/frame_properties.cpp @@ -31,9 +31,8 @@ namespace anm2ed::imgui { if (type == anm2::TRIGGER) { - if (combo_negative_one_indexed(localize.get(BASIC_EVENT), - frame ? &useFrame.eventID : &dummy_value_negative(), - document.event.labels) && + if (combo_id_mapped(localize.get(BASIC_EVENT), frame ? &useFrame.eventID : &dummy_value_negative(), + document.event.ids, document.event.labels) && frame) DOCUMENT_EDIT(document, localize.get(EDIT_TRIGGER_EVENT), Document::FRAMES, frame->eventID = useFrame.eventID); @@ -64,8 +63,8 @@ namespace anm2ed::imgui for (auto [i, id] : std::views::enumerate(useFrame.soundIDs)) { ImGui::PushID(i); - if (combo_negative_one_indexed("##Sound", frame ? &id : &dummy_value_negative(), - document.sound.labels) && + if (combo_id_mapped("##Sound", frame ? &id : &dummy_value_negative(), document.sound.ids, + document.sound.labels) && frame) DOCUMENT_EDIT(document, localize.get(EDIT_TRIGGER_SOUND), Document::FRAMES, frame->soundIDs[i] = id); diff --git a/src/imgui/window/layers.cpp b/src/imgui/window/layers.cpp index eaeffe5..23e368c 100644 --- a/src/imgui/window/layers.cpp +++ b/src/imgui/window/layers.cpp @@ -176,8 +176,8 @@ namespace anm2ed::imgui input_text_string(localize.get(BASIC_NAME), &layer.name); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ITEM_NAME)); - ImGui::Combo(localize.get(LABEL_SPRITESHEET), &layer.spritesheetID, document.spritesheet.labels.data(), - (int)document.spritesheet.labels.size()); + combo_id_mapped(localize.get(LABEL_SPRITESHEET), &layer.spritesheetID, document.spritesheet.ids, + document.spritesheet.labels); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SPRITESHEET)); } ImGui::EndChild(); diff --git a/src/imgui/window/timeline.cpp b/src/imgui/window/timeline.cpp index f1c7463..c640dfc 100644 --- a/src/imgui/window/timeline.cpp +++ b/src/imgui/window/timeline.cpp @@ -1697,8 +1697,8 @@ namespace anm2ed::imgui ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ITEM_NAME)); if (type == anm2::LAYER) { - ImGui::Combo(localize.get(LABEL_SPRITESHEET), &addItemSpritesheetID, document.spritesheet.labels.data(), - (int)document.spritesheet.labels.size()); + combo_id_mapped(localize.get(LABEL_SPRITESHEET), &addItemSpritesheetID, document.spritesheet.ids, + document.spritesheet.labels); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SPRITESHEET)); } else if (type == anm2::NULL_) diff --git a/src/storage.cpp b/src/storage.cpp index 7f147d8..8001965 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1,14 +1,19 @@ #include "storage.h" +#include + namespace anm2ed { void Storage::clear() { *this = Storage(); } - void Storage::labels_set(std::vector labels) + void Storage::labels_set(std::vector labels) { labels_set(std::move(labels), {}); } + + void Storage::labels_set(std::vector labels, std::vector ids) { - labelsString = labels; + labelsString = std::move(labels); + this->ids = std::move(ids); this->labels.clear(); for (auto& label : labelsString) this->labels.emplace_back(label.c_str()); } -} \ No newline at end of file +} diff --git a/src/storage.h b/src/storage.h index f3cda62..219e6d5 100644 --- a/src/storage.h +++ b/src/storage.h @@ -12,9 +12,11 @@ namespace anm2ed std::set unused{}; std::vector labelsString{}; std::vector labels{}; + std::vector ids{}; imgui::MultiSelectStorage selection{}; void clear(); void labels_set(std::vector); + void labels_set(std::vector, std::vector); }; -} \ No newline at end of file +}