Several events per trigger, built-in stop and done events

A trigger holds a list of events (Frame Properties lists them like sounds);
the first stays its EventId, the rest are <Event Id> children in the
editor's copy, and the Isaac warning counts the dropped ones. In extended
documents, stop and done are offered as built-in events: listed in italics
at the top of Events, locked from renaming, and added to the file when a
trigger first uses one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-08 17:35:11 -04:00
1 parent 4375844c84
commit b31a28ebe9
19 files changed
+195 -101

No files matched your search

+6 -3
View File
@@ -828,7 +828,7 @@ namespace anm2ed::imgui
if (animation && animation->triggers.isVisible && !isOnlyShowLayers && !manager.isRecording)
{
if (auto trigger = model::frame_generate(animation->triggers, frameTime);
trigger.isVisible && trigger.eventId > -1)
trigger.isVisible && !trigger.eventIds.empty())
{
auto clipMin = ImGui::GetItemRectMin();
auto clipMax = ImGui::GetItemRectMax();
@@ -838,8 +838,11 @@ namespace anm2ed::imgui
drawList->PushClipRect(clipMin, clipMax);
ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE_LARGE);
auto triggerTextColor = isLightTheme ? TRIGGER_TEXT_COLOR_LIGHT : TRIGGER_TEXT_COLOR_DARK;
if (auto event = model::item_get(model.content.events, trigger.eventId))
drawList->AddText(textPos, ImGui::GetColorU32(triggerTextColor), event->name.c_str());
std::string names{};
for (auto eventId : trigger.eventIds)
if (auto event = model::item_get(model.content.events, eventId))
names += (names.empty() ? "" : ", ") + event->name;
drawList->AddText(textPos, ImGui::GetColorU32(triggerTextColor), names.c_str());
ImGui::PopFont();
drawList->PopClipRect();
}
+46 -51
View File
@@ -18,6 +18,8 @@ using namespace glm;
namespace anm2ed::imgui
{
constexpr int TRIGGER_EVENTS_ROWS = 3;
struct Vec2Field
{
StringType label;
@@ -115,17 +117,6 @@ namespace anm2ed::imgui
{
if (type == TRIGGER)
{
if (combo_id_mapped(localize.get(BASIC_EVENT), frame ? &useFrame.eventId : &dummy_value_negative<int>(),
events.ids, events.labels) &&
frame)
{
auto eventId = useFrame.eventId;
frame_edit(edit_state::COMPLETE, EDIT_TRIGGER_EVENT,
[eventId](Document&, model::Frame& frame, model::Track*, const Reference&)
{ frame.eventId = eventId; });
}
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_TRIGGER_EVENT));
if (input_int_range(localize.get(BASIC_AT_FRAME), frame ? useFrame.atFrame : dummy_value<int>(), 0,
std::numeric_limits<int>::max(), STEP, STEP_FAST,
!frame ? ImGuiInputTextFlags_DisplayEmptyRefVal : 0) &&
@@ -156,55 +147,59 @@ namespace anm2ed::imgui
}
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_TRIGGER_VISIBILITY));
ImGui::SeparatorText(localize.get(LABEL_SOUNDS));
auto childSize = imgui::size_without_footer_get();
if (ImGui::BeginChild("##Sounds Child", childSize, ImGuiChildFlags_Borders))
// A trigger's events or sounds: a combo for each, then Add and Remove (the last).
auto trigger_ids_draw = [&](StringType label, std::vector<int> model::Frame::* member,
const Choices& choices, ImVec2 size, StringType tooltip, StringType setEdit,
StringType addEdit, StringType addTooltip, StringType removeEdit,
StringType removeTooltip)
{
if (!useFrame.soundIds.empty())
{
for (auto [i, id] : std::views::enumerate(useFrame.soundIds))
ImGui::PushID(label);
ImGui::SeparatorText(localize.get(label));
if (ImGui::BeginChild("##Child", size, ImGuiChildFlags_Borders))
for (auto [i, id] : std::views::enumerate(useFrame.*member))
{
ImGui::PushID(i);
if (combo_id_mapped("##Sound", frame ? &id : &dummy_value_negative<int>(), sounds.ids,
sounds.labels) &&
frame)
{
auto soundIndex = (std::size_t)i;
auto soundId = id;
frame_edit(edit_state::COMPLETE, EDIT_TRIGGER_SOUND,
[soundIndex, soundId](Document&, model::Frame& frame, model::Track*, const Reference&)
if (combo_id_mapped("##Choice", &id, choices.ids, choices.labels) && frame)
frame_edit(edit_state::COMPLETE, setEdit,
[index = (std::size_t)i, id, member](Document& document, model::Frame& frame,
model::Track*, const Reference&)
{
if (soundIndex < frame.soundIds.size()) frame.soundIds[soundIndex] = soundId;
auto& ids = frame.*member;
if (index >= ids.size()) return;
ids[index] = member == &model::Frame::eventIds
? edit::event_id_resolve(document.model, id)
: id;
});
}
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_TRIGGER_SOUND));
ImGui::SetItemTooltip("%s", localize.get(tooltip));
ImGui::PopID();
}
}
}
ImGui::EndChild();
ImGui::EndChild();
auto widgetSize = imgui::widget_size_with_row_get(2);
auto widgetSize = imgui::widget_size_with_row_get(2);
if (ImGui::Button(localize.get(BASIC_ADD), widgetSize) && frame)
frame_edit(edit_state::COMPLETE, addEdit,
[member](Document&, model::Frame& frame, model::Track*, const Reference&)
{ (frame.*member).push_back(-1); });
ImGui::SetItemTooltip("%s", localize.get(addTooltip));
ImGui::SameLine();
ImGui::BeginDisabled((useFrame.*member).empty());
if (ImGui::Button(localize.get(BASIC_REMOVE), widgetSize) && frame)
frame_edit(edit_state::COMPLETE, removeEdit,
[member](Document&, model::Frame& frame, model::Track*, const Reference&)
{
if (!(frame.*member).empty()) (frame.*member).pop_back();
});
ImGui::SetItemTooltip("%s", localize.get(removeTooltip));
ImGui::EndDisabled();
ImGui::PopID();
};
if (ImGui::Button(localize.get(BASIC_ADD), widgetSize) && frame)
frame_edit(edit_state::COMPLETE, EDIT_ADD_TRIGGER_SOUND,
[](Document&, model::Frame& frame, model::Track*, const Reference&)
{ frame.soundIds.push_back(-1); });
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ADD_TRIGGER_SOUND));
ImGui::SameLine();
ImGui::BeginDisabled(useFrame.soundIds.empty());
if (ImGui::Button(localize.get(BASIC_REMOVE), widgetSize) && frame)
frame_edit(edit_state::COMPLETE, EDIT_REMOVE_TRIGGER_SOUND,
[](Document&, model::Frame& frame, model::Track*, const Reference&)
{
if (!frame.soundIds.empty()) frame.soundIds.pop_back();
});
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_REMOVE_TRIGGER_SOUND));
ImGui::EndDisabled();
trigger_ids_draw(LABEL_EVENTS, &model::Frame::eventIds, events, child_size_get(TRIGGER_EVENTS_ROWS),
TOOLTIP_TRIGGER_EVENT, EDIT_TRIGGER_EVENT, EDIT_ADD_TRIGGER_EVENT,
TOOLTIP_ADD_TRIGGER_EVENT, EDIT_REMOVE_TRIGGER_EVENT, TOOLTIP_REMOVE_TRIGGER_EVENT);
trigger_ids_draw(LABEL_SOUNDS, &model::Frame::soundIds, sounds, imgui::size_without_footer_get(),
TOOLTIP_TRIGGER_SOUND, EDIT_TRIGGER_SOUND, EDIT_ADD_TRIGGER_SOUND,
TOOLTIP_ADD_TRIGGER_SOUND, EDIT_REMOVE_TRIGGER_SOUND, TOOLTIP_REMOVE_TRIGGER_SOUND);
}
else
{
+27 -4
View File
@@ -5,6 +5,7 @@
#include "util/imgui/input.hpp"
#include "util/imgui/layout.hpp"
using namespace anm2ed::resource;
using namespace anm2ed::types;
namespace anm2ed::imgui
@@ -231,9 +232,10 @@ namespace anm2ed::imgui
if (ImGui::Begin(localize.get(LABEL_EVENTS_WINDOW), &settings.windowIsEvents))
{
auto selection = document.selected_ids_get(SelectionKind::EVENTS);
auto is_built_in = [&](int id) { return model::is_event_built_in(model::item_get(events, id)->name); };
Actions actions{};
actions.add(
ACTION_RENAME, [selection]() { return selection.size() == 1; },
ACTION_RENAME, [=]() { return selection.size() == 1 && !is_built_in(*selection.begin()); },
[&state, selection]() { state.newId = *selection.begin(); });
actions.add(
ACTION_ADD, {},
@@ -279,10 +281,31 @@ namespace anm2ed::imgui
});
});
},
.tooltip_draw = [&](int id)
{ item_tooltip_draw(resources, model::item_get(events, id)->name, id); }};
.is_locked = is_built_in,
.font_get = [&](int id) { return is_built_in(id) ? font::ITALICS : font::REGULAR; },
.tooltip_draw =
[&](int id)
{
item_tooltip_draw(resources, model::item_get(events, id)->name, id);
if (is_built_in(id)) ImGui::TextUnformatted(localize.get(TOOLTIP_EVENT_BUILT_IN));
}};
// Built-in events come first; an extended document lists the ones it doesn't have yet above them.
auto ids = item_ids_get(events);
std::ranges::stable_partition(ids, is_built_in);
list_panel_draw(panel, actions, {{ACTION_ADD, ACTION_REMOVE_UNUSED}},
[&]() { content_list_draw(panel, SelectionKind::EVENTS, item_ids_get(events), rows); });
[&]()
{
ImGui::PushFont(resources.fonts[font::ITALICS].get(), font::SIZE);
for (auto name : model::EVENT_BUILT_INS)
if (document.model.isExtendedFormat &&
std::ranges::find(events, name, &model::Event::name) == events.end())
{
ImGui::TextDisabled("%s", std::string(name).c_str());
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_EVENT_BUILT_IN));
}
ImGui::PopFont();
content_list_draw(panel, SelectionKind::EVENTS, ids, rows);
});
}
ImGui::End();
}
+1 -1
View File
@@ -128,7 +128,7 @@ namespace anm2ed::imgui
if (arrowKey == key) ImGui::SetKeyboardFocusHere();
bool isActivated{};
if (rows.rename)
if (rows.rename && !(rows.is_locked && rows.is_locked(key)))
{
if (state.newId == key)
{
+1
View File
@@ -71,6 +71,7 @@ namespace anm2ed::imgui
std::function<std::string(int)> label_get{};
std::function<std::string(int)> name_get{};
std::function<void(int, const std::string&)> rename{};
std::function<bool(int)> is_locked{};
std::function<resource::font::Type(int)> font_get{};
std::function<void(int)> tooltip_draw{};
std::function<CardImage(int)> image_get{};
+3 -3
View File
@@ -372,9 +372,9 @@ namespace anm2ed::imgui
if (property == edit::FrameProperty::SHADER && source->shaderId != -1 &&
!model::item_get(content.shaders, source->shaderId))
return false;
if (property == edit::FrameProperty::EVENT && source->eventId != -1 &&
!model::item_get(content.events, source->eventId))
return false;
if (property == edit::FrameProperty::EVENT)
for (auto eventId : source->eventIds)
if (eventId != -1 && !model::item_get(content.events, eventId)) return false;
if (property == edit::FrameProperty::SOUNDS)
for (auto soundId : source->soundIds)
if (soundId != -1 && !model::item_get(content.sounds, soundId)) return false;
+1 -1
View File
@@ -5,7 +5,7 @@ namespace anm2ed::imgui
constexpr StringType FRAME_PROPERTY_LABELS[] = {
BASIC_POSITION, BASIC_SCALE, BASIC_ROTATION, BASIC_SKEW, BASIC_PIVOT, BASIC_CROP, BASIC_SIZE,
BASIC_REGION, BASIC_TINT, BASIC_COLOR_OFFSET, BASIC_VISIBLE, BASIC_INTERPOLATED, BASIC_DURATION, BASIC_SHADER,
BASIC_DEPTH, BASIC_BLUR, LABEL_CHILD, BASIC_EVENT, LABEL_SOUNDS};
BASIC_DEPTH, BASIC_BLUR, LABEL_CHILD, LABEL_EVENTS, LABEL_SOUNDS};
static_assert(std::size(FRAME_PROPERTY_LABELS) == (std::size_t)edit::FrameProperty::COUNT);
void TimelineContext::frame_begin()