fixed event handling and a lot of ID stuff OOPS

This commit is contained in:
2026-01-13 03:16:38 -05:00
parent f9087b8ed3
commit 7f4e05a927
13 changed files with 78 additions and 17 deletions
+24
View File
@@ -1,5 +1,6 @@
#include <imgui/imgui_internal.h>
#include <algorithm>
#include <cmath>
#include <format>
#include <sstream>
@@ -106,6 +107,29 @@ namespace anm2ed::imgui
return isActivated;
}
bool combo_id_mapped(const std::string& label, int* id, const std::vector<int>& ids, std::vector<const char*>& 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)
{
+1
View File
@@ -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<const char*>&);
bool combo_id_mapped(const std::string&, int*, const std::vector<int>&, std::vector<const char*>&);
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);
+4 -5
View File
@@ -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<int>(),
document.event.labels) &&
if (combo_id_mapped(localize.get(BASIC_EVENT), frame ? &useFrame.eventID : &dummy_value_negative<int>(),
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<int>(),
document.sound.labels) &&
if (combo_id_mapped("##Sound", frame ? &id : &dummy_value_negative<int>(), document.sound.ids,
document.sound.labels) &&
frame)
DOCUMENT_EDIT(document, localize.get(EDIT_TRIGGER_SOUND), Document::FRAMES,
frame->soundIDs[i] = id);
+2 -2
View File
@@ -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();
+2 -2
View File
@@ -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_)