Child triggers fire; Auto Resource Reload; animation layer labels
Playback, renders and the preview's event label include the triggers of child animations (from this file or a library) as each child reaches them; libraries' sounds load with them, and a frame can mix several sounds. The reload setting is now Auto Resource Reload and covers libraries too. Animation layers are labeled by their animation (not a spritesheet) in the timeline and Item Properties as well as the Layers window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
280adaa189
commit
76c2186c81
16 files changed
+201
-97
No files matched your search
@@ -9,14 +9,14 @@ namespace anm2ed::imgui
|
||||
if (auto document = manager.get(); document)
|
||||
if (settings.windowIsAnimationPreview) animationPreview.tick(manager, settings, deltaSeconds);
|
||||
|
||||
// Files changed on disk are picked up every few seconds: libraries always, spritesheets when set to.
|
||||
// Spritesheets and libraries changed on disk are picked up every few seconds.
|
||||
if (!settings.fileIsAutoReloadResources) return;
|
||||
reloadTime += deltaSeconds;
|
||||
if (reloadTime < AUTO_RELOAD_INTERVAL) return;
|
||||
reloadTime = 0.0f;
|
||||
for (auto& document : manager.documents)
|
||||
{
|
||||
document.libraries_reload();
|
||||
if (!settings.fileIsAutoReloadSpritesheets) continue;
|
||||
if (auto ids = document.spritesheets_changed_get(); !ids.empty()) document.spritesheets_reload(ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,9 +140,7 @@ namespace anm2ed::imgui::popup
|
||||
{
|
||||
if (auto layer = model::item_get(model.content.layers, id))
|
||||
{
|
||||
auto label = std::vformat(localize.get(FORMAT_LAYER),
|
||||
std::make_format_args(id, layer->name, layer->spritesheetId));
|
||||
if (ImGui::Selectable(label.c_str(), isSelected))
|
||||
if (ImGui::Selectable(layer_label_get(*layer).c_str(), isSelected))
|
||||
{
|
||||
edit.id = id;
|
||||
}
|
||||
|
||||
@@ -123,24 +123,6 @@ namespace anm2ed::imgui
|
||||
return rect;
|
||||
}
|
||||
|
||||
int trigger_sound_id_get(Document& document, const model::Animation* animation, float time,
|
||||
int deterministicIndex = -1)
|
||||
{
|
||||
if (!animation || !animation->triggers.isVisible) return -1;
|
||||
|
||||
auto trigger = model::frame_generate(animation->triggers, time);
|
||||
if (!trigger.isVisible || trigger.soundIds.empty()) return -1;
|
||||
|
||||
size_t soundIndex{};
|
||||
if (trigger.soundIds.size() > 1)
|
||||
soundIndex = deterministicIndex >= 0 ? (size_t)deterministicIndex % trigger.soundIds.size()
|
||||
: (size_t)math::random_in_range(0.0f, (float)trigger.soundIds.size());
|
||||
soundIndex = std::min(soundIndex, trigger.soundIds.size() - 1);
|
||||
|
||||
auto soundID = trigger.soundIds[soundIndex];
|
||||
return document.sound_get(soundID) ? soundID : -1;
|
||||
}
|
||||
|
||||
void AnimationPreview::tick(Manager& manager, Settings& settings, float deltaSeconds)
|
||||
{
|
||||
auto& document = *manager.get();
|
||||
@@ -150,8 +132,8 @@ namespace anm2ed::imgui
|
||||
|
||||
auto stop_all_sounds = [&]()
|
||||
{
|
||||
for (auto& [id, _] : document.sounds)
|
||||
if (auto sound = document.sound_get(id)) audio::stop(*sound, mixer);
|
||||
for (auto sound : document.sounds_get())
|
||||
audio::stop(*sound, mixer);
|
||||
};
|
||||
|
||||
if (manager.isRecording)
|
||||
@@ -190,9 +172,9 @@ namespace anm2ed::imgui
|
||||
for (int step = 0; soundFrame != frame && step < range.y - range.x; ++step)
|
||||
{
|
||||
soundFrame = soundFrame + 1 >= range.y || soundFrame + 1 < range.x ? range.x : soundFrame + 1;
|
||||
if (manager.isRecording || document.sounds.empty() || !isSound) continue;
|
||||
if (auto soundID = trigger_sound_id_get(document, animation, (float)soundFrame); soundID != -1)
|
||||
if (auto sound = document.sound_get(soundID)) audio::play(*sound, false, mixer);
|
||||
if (manager.isRecording || !isSound) continue;
|
||||
for (auto sound : document.trigger_sounds_get(*animation, soundFrame))
|
||||
audio::play(*sound, false, mixer);
|
||||
}
|
||||
|
||||
frameTime = playback.time;
|
||||
@@ -806,10 +788,10 @@ namespace anm2ed::imgui
|
||||
|
||||
if (isRecordingFrame)
|
||||
{
|
||||
auto soundId = settings.timelineIsSound && animation && recorder.is_sound_frame()
|
||||
? trigger_sound_id_get(document, animation, frameTime, recorder.index)
|
||||
: -1;
|
||||
if (!recorder.frame_capture(pixels_get(), size, soundId))
|
||||
auto sounds = settings.timelineIsSound && animation && recorder.is_sound_frame()
|
||||
? document.trigger_sounds_get(*animation, (int)frameTime, recorder.index)
|
||||
: std::vector<const resource::AudioData*>{};
|
||||
if (!recorder.frame_capture(pixels_get(), size, sounds))
|
||||
{
|
||||
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_ANIMATION_FAILED, path::to_utf8(recorder.options.path));
|
||||
recorder.cancel();
|
||||
@@ -826,27 +808,27 @@ namespace anm2ed::imgui
|
||||
}
|
||||
image_premultiplied_draw(texture, to_imvec2(size));
|
||||
|
||||
if (animation && animation->triggers.isVisible && !isOnlyShowLayers && !manager.isRecording)
|
||||
{
|
||||
if (auto trigger = model::frame_generate(animation->triggers, frameTime);
|
||||
trigger.isVisible && !trigger.eventIds.empty())
|
||||
{
|
||||
auto clipMin = ImGui::GetItemRectMin();
|
||||
auto clipMax = ImGui::GetItemRectMax();
|
||||
auto drawList = ImGui::GetWindowDrawList();
|
||||
auto textPos = to_imvec2(to_vec2(cursorScreenPos) + to_vec2(ImGui::GetStyle().WindowPadding));
|
||||
|
||||
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;
|
||||
std::string names{};
|
||||
// The events triggers (the animation's and its children's) fire on this frame.
|
||||
std::string names{};
|
||||
if (animation && !isOnlyShowLayers && !manager.isRecording)
|
||||
for (const auto& [source, trigger] :
|
||||
model::animation_triggers_get(model, *animation, (int)frameTime, document.library_resolver_get()))
|
||||
for (auto eventId : trigger.eventIds)
|
||||
if (auto event = model::item_get(model.content.events, eventId))
|
||||
if (auto event = model::item_get(source->content.events, eventId))
|
||||
names += (names.empty() ? "" : ", ") + event->name;
|
||||
drawList->AddText(textPos, ImGui::GetColorU32(triggerTextColor), names.c_str());
|
||||
ImGui::PopFont();
|
||||
drawList->PopClipRect();
|
||||
}
|
||||
if (!names.empty())
|
||||
{
|
||||
auto clipMin = ImGui::GetItemRectMin();
|
||||
auto clipMax = ImGui::GetItemRectMax();
|
||||
auto drawList = ImGui::GetWindowDrawList();
|
||||
auto textPos = to_imvec2(to_vec2(cursorScreenPos) + to_vec2(ImGui::GetStyle().WindowPadding));
|
||||
|
||||
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;
|
||||
drawList->AddText(textPos, ImGui::GetColorU32(triggerTextColor), names.c_str());
|
||||
ImGui::PopFont();
|
||||
drawList->PopClipRect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -23,6 +23,15 @@ namespace anm2ed::imgui
|
||||
ImGui::TextUnformatted(std::vformat(localize.get(FORMAT_ID), std::make_format_args(id)).c_str());
|
||||
}
|
||||
|
||||
// "#id name", then what the layer shows: its spritesheet or its animation.
|
||||
std::string layer_label_get(const model::Layer& layer)
|
||||
{
|
||||
if (layer.is_animation())
|
||||
return std::vformat(localize.get(FORMAT_LAYER_ANIMATION),
|
||||
std::make_format_args(layer.id, layer.name, layer.animation));
|
||||
return std::vformat(localize.get(FORMAT_LAYER), std::make_format_args(layer.id, layer.name, layer.spritesheetId));
|
||||
}
|
||||
|
||||
model::Layer item_edit_layer_get(const Manager::ItemEdit& edit)
|
||||
{
|
||||
return {.name = edit.name,
|
||||
@@ -159,16 +168,7 @@ namespace anm2ed::imgui
|
||||
TOOLTIP_ADD_LAYER, TOOLTIP_REMOVE_UNUSED_LAYERS, EDIT_REMOVE_UNUSED_LAYERS,
|
||||
EDIT_PASTE_LAYERS, TOAST_DESERIALIZE_LAYERS_FAILED, layers_get);
|
||||
ListRows rows{
|
||||
.label_get =
|
||||
[&](int id)
|
||||
{
|
||||
auto layer = model::item_get(layers, id);
|
||||
if (layer->is_animation())
|
||||
return std::vformat(localize.get(FORMAT_LAYER_ANIMATION),
|
||||
std::make_format_args(layer->id, layer->name, layer->animation));
|
||||
return std::vformat(localize.get(FORMAT_LAYER),
|
||||
std::make_format_args(layer->id, layer->name, layer->spritesheetId));
|
||||
},
|
||||
.label_get = [&](int id) { return layer_label_get(*model::item_get(layers, id)); },
|
||||
.tooltip_draw =
|
||||
[&](int id)
|
||||
{
|
||||
|
||||
@@ -149,6 +149,7 @@ namespace anm2ed::imgui
|
||||
void nulls_update(Panel&);
|
||||
void events_update(Panel&);
|
||||
void sounds_update(Panel&);
|
||||
std::string layer_label_get(const model::Layer&);
|
||||
model::Layer item_edit_layer_get(const Manager::ItemEdit&);
|
||||
model::Null item_edit_null_get(const Manager::ItemEdit&);
|
||||
void layer_source_draw(Document&, Manager::ItemEdit&);
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto layer = model::item_get(model.content.layers, id);
|
||||
if (!layer) return localize.get(TYPE_STRINGS[type]);
|
||||
return std::vformat(localize.get(FORMAT_LAYER), std::make_format_args(id, layer->name, layer->spritesheetId));
|
||||
return layer_label_get(*layer);
|
||||
}
|
||||
if (type == NULL_)
|
||||
{
|
||||
|
||||
@@ -69,10 +69,10 @@ namespace anm2ed::imgui::wizard
|
||||
ImGui::Checkbox(localize.get(BASIC_ENABLED), &temporary.fileIsAutosave);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_AUTOSAVE_ENABLED));
|
||||
|
||||
ImGui::SeparatorText(localize.get(LABEL_AUTO_SPRITESHEET_RELOAD));
|
||||
ImGui::PushID(LABEL_AUTO_SPRITESHEET_RELOAD);
|
||||
ImGui::Checkbox(localize.get(BASIC_ENABLED), &temporary.fileIsAutoReloadSpritesheets);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_AUTO_SPRITESHEET_RELOAD));
|
||||
ImGui::SeparatorText(localize.get(LABEL_AUTO_RESOURCE_RELOAD));
|
||||
ImGui::PushID(LABEL_AUTO_RESOURCE_RELOAD);
|
||||
ImGui::Checkbox(localize.get(BASIC_ENABLED), &temporary.fileIsAutoReloadResources);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_AUTO_RESOURCE_RELOAD));
|
||||
ImGui::PopID();
|
||||
|
||||
ImGui::SeparatorText(localize.get(LABEL_SNAPSHOTS));
|
||||
|
||||
Reference in new issue
Block a user