touched up animation preview/timeline

This commit is contained in:
2026-05-11 15:57:07 -04:00
parent d05c0da393
commit d08f3d2231
2 changed files with 41 additions and 23 deletions
+13 -3
View File
@@ -380,10 +380,17 @@ namespace anm2ed::imgui
auto& isSound = settings.timelineIsSound; auto& isSound = settings.timelineIsSound;
auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers; auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers;
if (!animation)
{
playback.isPlaying = false;
playback.isFinished = false;
playback.timing_reset();
}
else
{
if (!manager.isRecording && !anm2.content.sounds.empty() && isSound) if (!manager.isRecording && !anm2.content.sounds.empty() && isSound)
{ {
if (auto animation = document.animation_get(); if (animation->triggers.isVisible && (!isOnlyShowLayers || manager.isRecording))
animation && animation->triggers.isVisible && (!isOnlyShowLayers || manager.isRecording))
{ {
if (auto trigger = animation->triggers.frame_generate(playback.time, anm2::TRIGGER); trigger.isVisible) if (auto trigger = animation->triggers.frame_generate(playback.time, anm2::TRIGGER); trigger.isVisible)
{ {
@@ -407,6 +414,7 @@ namespace anm2ed::imgui
frameTime = playback.time; frameTime = playback.time;
} }
}
if (wasPlaybackPlaying && !playback.isPlaying) stop_all_sounds(); if (wasPlaybackPlaying && !playback.isPlaying) stop_all_sounds();
wasPlaybackPlaying = playback.isPlaying; wasPlaybackPlaying = playback.isPlaying;
@@ -870,7 +878,9 @@ namespace anm2ed::imgui
{ {
if (!nullAnimation.isVisible || isOnlyShowLayers) continue; if (!nullAnimation.isVisible || isOnlyShowLayers) continue;
auto& isShowRect = anm2.content.nulls[id].isShowRect; auto nullInfo = anm2.content.nulls.find(id);
if (nullInfo == anm2.content.nulls.end()) continue;
auto& isShowRect = nullInfo->second.isShowRect;
auto draw_null = auto draw_null =
[&](float sampleTime, const glm::mat4& sampleTransform, vec3 sampleColor, float sampleAlpha, bool isOnion) [&](float sampleTime, const glm::mat4& sampleTransform, vec3 sampleColor, float sampleAlpha, bool isOnion)
+13 -5
View File
@@ -182,7 +182,7 @@ namespace anm2ed::imgui
auto frame_insert = [&](anm2::Item* item) auto frame_insert = [&](anm2::Item* item)
{ {
if (!item) return; if (!animation || !item) return;
auto behavior = [&, item]() auto behavior = [&, item]()
{ {
@@ -229,6 +229,7 @@ namespace anm2ed::imgui
auto frames_delete = [&]() auto frames_delete = [&]()
{ {
if (!animation) return;
if (auto item = animation->item_get(reference.itemType, reference.itemID); item) if (auto item = animation->item_get(reference.itemType, reference.itemID); item)
{ {
for (auto it = frames.selection.rbegin(); it != frames.selection.rend(); ++it) for (auto it = frames.selection.rbegin(); it != frames.selection.rend(); ++it)
@@ -460,6 +461,7 @@ namespace anm2ed::imgui
auto copy = [&]() auto copy = [&]()
{ {
if (!animation) return;
if (frames.selection.empty()) return; if (frames.selection.empty()) return;
if (auto item = animation->item_get(reference.itemType, reference.itemID); item) if (auto item = animation->item_get(reference.itemType, reference.itemID); item)
@@ -486,6 +488,7 @@ namespace anm2ed::imgui
auto behavior = [&]() auto behavior = [&]()
{ {
if (!animation) return;
if (auto item = animation->item_get(reference.itemType, reference.itemID)) if (auto item = animation->item_get(reference.itemType, reference.itemID))
{ {
document.snapshot(localize.get(EDIT_PASTE_FRAMES)); document.snapshot(localize.get(EDIT_PASTE_FRAMES));
@@ -1043,7 +1046,9 @@ namespace anm2ed::imgui
for (auto& id : animation->layerOrder | std::views::reverse) for (auto& id : animation->layerOrder | std::views::reverse)
{ {
if (!settings.timelineIsShowUnused && animation->layerAnimations[id].frames.empty()) continue; auto item = animation->item_get(anm2::LAYER, id);
if (!item) continue;
if (!settings.timelineIsShowUnused && item->frames.empty()) continue;
item_child_row(anm2::LAYER, id, index++); item_child_row(anm2::LAYER, id, index++);
} }
@@ -1194,6 +1199,8 @@ namespace anm2ed::imgui
auto frame_child = [&](anm2::Type type, int id, int& index, float width) auto frame_child = [&](anm2::Type type, int id, int& index, float width)
{ {
auto item = animation ? animation->item_get(type, id) : nullptr; auto item = animation ? animation->item_get(type, id) : nullptr;
if (type != anm2::NONE && !item) return;
auto isVisible = item ? item->isVisible : false; auto isVisible = item ? item->isVisible : false;
auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers; auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers;
if (isOnlyShowLayers && type != anm2::LAYER) isVisible = false; if (isOnlyShowLayers && type != anm2::LAYER) isVisible = false;
@@ -1816,7 +1823,7 @@ namespace anm2ed::imgui
ImGui::SameLine(); ImGui::SameLine();
auto item = animation->item_get(reference.itemType, reference.itemID); auto item = animation ? animation->item_get(reference.itemType, reference.itemID) : nullptr;
ImGui::BeginDisabled(!item); ImGui::BeginDisabled(!item);
{ {
@@ -1854,7 +1861,8 @@ namespace anm2ed::imgui
auto frameNum = animation ? animation->frameNum : dummy_value<int>(); auto frameNum = animation ? animation->frameNum : dummy_value<int>();
ImGui::SetNextItemWidth(widgetSize.x); ImGui::SetNextItemWidth(widgetSize.x);
if (input_int_range(localize.get(LABEL_ANIMATION_LENGTH), frameNum, anm2::FRAME_NUM_MIN, anm2::FRAME_NUM_MAX, if (input_int_range(localize.get(LABEL_ANIMATION_LENGTH), frameNum, anm2::FRAME_NUM_MIN, anm2::FRAME_NUM_MAX,
STEP, STEP_FAST, !animation ? ImGuiInputTextFlags_DisplayEmptyRefVal : 0)) STEP, STEP_FAST, !animation ? ImGuiInputTextFlags_DisplayEmptyRefVal : 0) &&
animation)
DOCUMENT_EDIT(document, localize.get(EDIT_ANIMATION_LENGTH), Document::ANIMATIONS, DOCUMENT_EDIT(document, localize.get(EDIT_ANIMATION_LENGTH), Document::ANIMATIONS,
animation->frameNum = frameNum); animation->frameNum = frameNum);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ANIMATION_LENGTH)); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ANIMATION_LENGTH));
@@ -1863,7 +1871,7 @@ namespace anm2ed::imgui
auto isLoop = animation ? animation->isLoop : dummy_value<bool>(); auto isLoop = animation ? animation->isLoop : dummy_value<bool>();
ImGui::SetNextItemWidth(widgetSize.x); ImGui::SetNextItemWidth(widgetSize.x);
if (ImGui::Checkbox(localize.get(LABEL_LOOP), &isLoop)) if (ImGui::Checkbox(localize.get(LABEL_LOOP), &isLoop) && animation)
DOCUMENT_EDIT(document, localize.get(EDIT_LOOP), Document::ANIMATIONS, animation->isLoop = isLoop); DOCUMENT_EDIT(document, localize.get(EDIT_LOOP), Document::ANIMATIONS, animation->isLoop = isLoop);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LOOP_ANIMATION)); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LOOP_ANIMATION));
} }