Refactoring, FFmpeg updates

This commit is contained in:
2025-11-03 00:16:05 -05:00
parent 62cd94ca78
commit 1e35910b0a
65 changed files with 2322 additions and 2236 deletions

View File

@@ -2,6 +2,10 @@
#include <ranges>
#include "toast.h"
#include "vector_.h"
using namespace anm2ed::util;
using namespace anm2ed::resource;
using namespace anm2ed::types;
@@ -12,10 +16,11 @@ namespace anm2ed::imgui
auto& document = *manager.get();
auto& anm2 = document.anm2;
auto& reference = document.reference;
auto& hovered = document.hoveredAnimation;
auto& multiSelect = document.animationMultiSelect;
auto& mergeMultiSelect = document.animationMergeMultiSelect;
auto& mergeTarget = document.mergeTarget;
auto& hovered = document.animation.hovered;
auto& selection = document.animation.selection;
auto& mergeSelection = document.merge.selection;
auto& mergeReference = document.merge.reference;
auto& overlayIndex = document.overlayIndex;
hovered = -1;
@@ -25,7 +30,7 @@ namespace anm2ed::imgui
if (ImGui::BeginChild("##Animations Child", childSize, ImGuiChildFlags_Borders))
{
multiSelect.start(anm2.animations.items.size());
selection.start(anm2.animations.items.size());
for (auto [i, animation] : std::views::enumerate(anm2.animations.items))
{
@@ -40,11 +45,11 @@ namespace anm2ed::imgui
: font::REGULAR;
ImGui::PushFont(resources.fonts[font].get(), font::SIZE);
ImGui::SetNextItemSelectionUserData(i);
ImGui::SetNextItemSelectionUserData((int)i);
if (selectable_input_text(animation.name, std::format("###Document #{} Animation #{}", manager.selected, i),
animation.name, multiSelect.contains(i)))
document.animation_set(i);
if (ImGui::IsItemHovered()) hovered = i;
animation.name, selection.contains((int)i)))
reference = {(int)i};
if (ImGui::IsItemHovered()) hovered = (int)i;
ImGui::PopFont();
if (ImGui::BeginItemTooltip())
@@ -69,11 +74,12 @@ namespace anm2ed::imgui
if (ImGui::BeginDragDropSource())
{
static std::vector<int> selection;
selection.assign(multiSelect.begin(), multiSelect.end());
ImGui::SetDragDropPayload("Animation Drag Drop", selection.data(), selection.size() * sizeof(int));
for (auto& i : selection)
ImGui::TextUnformatted(anm2.animations.items[i].name.c_str());
static std::vector<int> dragDropSelection{};
dragDropSelection.assign(selection.begin(), selection.end());
ImGui::SetDragDropPayload("Animation Drag Drop", dragDropSelection.data(),
dragDropSelection.size() * sizeof(int));
for (auto& i : dragDropSelection)
ImGui::Text("%s", anm2.animations.items[(int)i].name.c_str());
ImGui::EndDragDropSource();
}
@@ -85,7 +91,8 @@ namespace anm2ed::imgui
auto payloadCount = payload->DataSize / sizeof(int);
std::vector<int> indices(payloadIndices, payloadIndices + payloadCount);
std::sort(indices.begin(), indices.end());
document.animations_move(indices, i);
DOCUMENT_EDIT(document, "Move Animation(s)", Document::ANIMATIONS,
selection = vector::move_indices(anm2.animations.items, indices, i));
}
ImGui::EndDragDropTarget();
}
@@ -93,14 +100,14 @@ namespace anm2ed::imgui
ImGui::PopID();
}
multiSelect.finish();
selection.finish();
auto copy = [&]()
{
if (!multiSelect.empty())
if (!selection.empty())
{
std::string clipboardText{};
for (auto& i : multiSelect)
for (auto& i : selection)
clipboardText += anm2.animations.items[i].to_string();
clipboard.set(clipboardText);
}
@@ -111,13 +118,41 @@ namespace anm2ed::imgui
auto cut = [&]()
{
copy();
document.animations_remove();
auto remove = [&]()
{
if (!selection.empty())
{
for (auto& i : selection | std::views::reverse)
anm2.animations.items.erase(anm2.animations.items.begin() + i);
selection.clear();
}
else if (hovered > -1)
{
anm2.animations.items.erase(anm2.animations.items.begin() + hovered);
hovered = -1;
}
};
DOCUMENT_EDIT(document, "Cut Animation(s)", Document::ANIMATIONS, remove());
};
auto paste = [&]()
{
auto clipboardText = clipboard.get();
document.animations_deserialize(clipboardText);
auto deserialize = [&]()
{
auto start = selection.empty() ? anm2.animations.items.size() : *selection.rbegin() + 1;
std::set<int> indices{};
std::string errorString{};
if (anm2.animations_deserialize(clipboardText, start, indices, &errorString))
selection = indices;
else
toasts.error(std::format("Failed to deserialize animation(s): {}", errorString));
};
DOCUMENT_EDIT(document, "Paste Animation(s)", Document::ANIMATIONS, deserialize());
};
if (shortcut(settings.shortcutCut, shortcut::FOCUSED)) cut();
@@ -126,15 +161,9 @@ namespace anm2ed::imgui
if (ImGui::BeginPopupContextWindow("##Context Menu", ImGuiPopupFlags_MouseButtonRight))
{
ImGui::BeginDisabled(multiSelect.empty() && hovered == -1);
if (ImGui::MenuItem("Cut", settings.shortcutCut.c_str())) cut();
if (ImGui::MenuItem("Copy", settings.shortcutCopy.c_str())) copy();
ImGui::EndDisabled();
ImGui::BeginDisabled(clipboard.is_empty());
if (ImGui::MenuItem("Paste", settings.shortcutPaste.c_str())) paste();
ImGui::EndDisabled();
if (ImGui::MenuItem("Cut", settings.shortcutCut.c_str(), false, !selection.empty() || hovered > -1)) cut();
if (ImGui::MenuItem("Copy", settings.shortcutCopy.c_str(), false, !selection.empty() || hovered > -1)) copy();
if (ImGui::MenuItem("Paste", settings.shortcutPaste.c_str(), false, !clipboard.is_empty())) paste();
ImGui::EndPopup();
}
}
@@ -143,33 +172,98 @@ namespace anm2ed::imgui
auto widgetSize = widget_size_with_row_get(5);
shortcut(settings.shortcutAdd);
if (ImGui::Button("Add", widgetSize)) document.animation_add();
if (ImGui::Button("Add", widgetSize))
{
auto add = [&]()
{
anm2::Animation animation;
if (anm2::Animation* referenceAnimation = document.animation_get())
{
for (auto [id, layerAnimation] : referenceAnimation->layerAnimations)
animation.layerAnimations[id] = anm2::Item();
animation.layerOrder = referenceAnimation->layerOrder;
for (auto [id, nullAnimation] : referenceAnimation->nullAnimations)
animation.nullAnimations[id] = anm2::Item();
}
animation.rootAnimation.frames.emplace_back(anm2::Frame());
auto index = 0;
if (!anm2.animations.items.empty())
index = selection.empty() ? (int)anm2.animations.items.size() - 1 : *selection.rbegin() + 1;
anm2.animations.items.insert(anm2.animations.items.begin() + index, animation);
selection = {index};
reference = {index};
};
DOCUMENT_EDIT(document, "Add Animation", Document::ANIMATIONS, add());
}
set_item_tooltip_shortcut("Add a new animation.", settings.shortcutAdd);
ImGui::SameLine();
ImGui::BeginDisabled(multiSelect.empty());
ImGui::BeginDisabled(selection.empty());
{
shortcut(settings.shortcutDuplicate);
if (ImGui::Button("Duplicate", widgetSize)) document.animation_duplicate();
if (ImGui::Button("Duplicate", widgetSize))
{
auto duplicate = [&]()
{
auto duplicated = selection;
auto end = std::ranges::max(duplicated);
for (auto& id : duplicated)
{
anm2.animations.items.insert(anm2.animations.items.begin() + end, anm2.animations.items[id]);
selection.insert(++end);
selection.erase(id);
}
};
DOCUMENT_EDIT(document, "Duplicate Animation(s)", Document::ANIMATIONS, duplicate());
}
set_item_tooltip_shortcut("Duplicate the selected animation(s).", settings.shortcutDuplicate);
ImGui::SameLine();
if (shortcut(settings.shortcutMerge, shortcut::FOCUSED))
if (multiSelect.size() > 0) document.animations_merge_quick();
if (shortcut(settings.shortcutMerge, shortcut::FOCUSED) && !selection.empty())
{
auto merge_quick = [&]()
{
int merged{};
if (selection.contains(overlayIndex)) overlayIndex = -1;
ImGui::BeginDisabled(multiSelect.size() != 1);
if (selection.size() > 1)
merged = anm2.animations_merge(*selection.begin(), selection);
else if (selection.size() == 1 && *selection.begin() != (int)anm2.animations.items.size() - 1)
{
auto start = *selection.begin();
auto next = *selection.begin() + 1;
std::set<int> animationSet{};
animationSet.insert(start);
animationSet.insert(next);
merged = anm2.animations_merge(start, animationSet);
}
else
return;
selection = {merged};
reference = {merged};
};
DOCUMENT_EDIT(document, "Merge Animations", Document::ANIMATIONS, merge_quick())
}
ImGui::BeginDisabled(selection.size() != 1);
{
if (ImGui::Button("Merge", widgetSize))
{
mergePopup.open();
mergeMultiSelect.clear();
mergeTarget = *multiSelect.begin();
mergeSelection.clear();
mergeReference = *selection.begin();
}
}
ImGui::EndDisabled();
set_item_tooltip_shortcut("Open the merge popup.\nUsing the shortcut will merge the animations with\nthe last "
"configured merge settings.",
settings.shortcutMerge);
@@ -177,14 +271,31 @@ namespace anm2ed::imgui
ImGui::SameLine();
shortcut(settings.shortcutRemove);
if (ImGui::Button("Remove", widgetSize)) document.animations_remove();
if (ImGui::Button("Remove", widgetSize))
{
auto remove = [&]()
{
for (auto& i : selection | std::views::reverse)
{
if (i == overlayIndex) overlayIndex = -1;
anm2.animations.items.erase(anm2.animations.items.begin() + i);
}
selection.clear();
};
DOCUMENT_EDIT(document, "Remove Animation(s)", Document::ANIMATIONS, remove());
}
set_item_tooltip_shortcut("Remove the selected animation(s).", settings.shortcutDuplicate);
ImGui::SameLine();
shortcut(settings.shortcutDefault);
ImGui::BeginDisabled(multiSelect.size() != 1);
if (ImGui::Button("Default", widgetSize)) document.animation_default();
ImGui::BeginDisabled(selection.size() != 1);
if (ImGui::Button("Default", widgetSize))
{
DOCUMENT_EDIT(document, "Default Animation", Document::ANIMATIONS,
anm2.animations.defaultAnimation = anm2.animations.items[*selection.begin()].name);
}
ImGui::EndDisabled();
set_item_tooltip_shortcut("Set the selected animation as the default.", settings.shortcutDefault);
}
@@ -196,7 +307,7 @@ namespace anm2ed::imgui
{
auto merge_close = [&]()
{
mergeMultiSelect.clear();
mergeSelection.clear();
mergePopup.close();
};
@@ -212,19 +323,21 @@ namespace anm2ed::imgui
if (ImGui::BeginChild("Animations", animationsSize, ImGuiChildFlags_Borders))
{
mergeMultiSelect.start(anm2.animations.items.size());
mergeSelection.start(anm2.animations.items.size());
for (auto [i, animation] : std::views::enumerate(anm2.animations.items))
{
if (i == mergeReference) continue;
ImGui::PushID(i);
ImGui::SetNextItemSelectionUserData(i);
ImGui::Selectable(animation.name.c_str(), mergeMultiSelect.contains(i));
ImGui::Selectable(animation.name.c_str(), mergeSelection.contains(i));
ImGui::PopID();
}
mergeMultiSelect.finish();
mergeSelection.finish();
}
ImGui::EndChild();
@@ -258,7 +371,17 @@ namespace anm2ed::imgui
if (ImGui::Button("Merge", widgetSize))
{
document.animations_merge((merge::Type)type, isDeleteAnimationsAfter);
auto merge = [&]()
{
if (mergeSelection.contains(overlayIndex)) overlayIndex = -1;
auto merged =
anm2.animations_merge(mergeReference, mergeSelection, (merge::Type)type, isDeleteAnimationsAfter);
selection = {merged};
reference = {merged};
};
DOCUMENT_EDIT(document, "Merge Animations", Document::ANIMATIONS, merge());
merge_close();
}
ImGui::SameLine();