From b5528bc118c98c4e64f46c96937a3ceafa8bcad4 Mon Sep 17 00:00:00 2001 From: shweet Date: Tue, 23 Jun 2026 19:08:00 -0400 Subject: [PATCH] fix to document order and bake into other frames works with colors --- src/document.cpp | 10 +++- src/document.hpp | 2 + src/imgui/documents.cpp | 106 +++++++++++++++++++++++++++++++++- src/imgui/documents.hpp | 5 ++ src/imgui/window/timeline.cpp | 4 ++ src/state.cpp | 2 + workshop/metadata.xml | 2 +- 7 files changed, 128 insertions(+), 3 deletions(-) diff --git a/src/document.cpp b/src/document.cpp index 2b97146..48e58a3 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -28,6 +28,12 @@ using namespace glm; namespace anm2ed::document { + uint64_t document_tab_id_next() + { + static uint64_t next{1}; + return next++; + } + ItemType item_type_get(int type) { return static_cast(type); } int animation_count_get(const Anm2& data) @@ -260,6 +266,8 @@ namespace anm2ed { Document::Document(const std::filesystem::path& path, bool isNew, std::string* errorString) { + tabId = document::document_tab_id_next(); + if (isNew) { anm2 = Anm2(); @@ -288,7 +296,7 @@ namespace anm2ed } Document::Document(Document&& other) noexcept - : path(std::move(other.path)), snapshots(std::move(other.snapshots)), current(snapshots.current), + : path(std::move(other.path)), tabId(other.tabId), snapshots(std::move(other.snapshots)), current(snapshots.current), playback(current.playback), animation(current.animation), event(current.event), frames(current.frames), items(current.items), layer(current.layer), merge(current.merge), null(current.null), region(current.region), sound(current.sound), spritesheet(current.spritesheet), textures(current.textures), sounds(current.sounds), diff --git a/src/document.hpp b/src/document.hpp index aaa163b..b997cc7 100644 --- a/src/document.hpp +++ b/src/document.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -44,6 +45,7 @@ namespace anm2ed }; std::filesystem::path path{}; + uint64_t tabId{}; Snapshots snapshots{}; Snapshot& current = snapshots.current; diff --git a/src/imgui/documents.cpp b/src/imgui/documents.cpp index 44fa081..7d6ab26 100644 --- a/src/imgui/documents.cpp +++ b/src/imgui/documents.cpp @@ -1,8 +1,11 @@ #include "documents.hpp" #include +#include #include +#include + #include "log.hpp" #include "path.hpp" #include "strings.hpp" @@ -17,6 +20,12 @@ using namespace anm2ed::util; namespace anm2ed::imgui { + struct DocumentTab + { + ImGuiID imguiId{}; + uint64_t documentId{}; + }; + Options save_options_get(const Settings& settings) { Flags flags{}; @@ -28,8 +37,75 @@ namespace anm2ed::imgui return {.flags = flags}; } + void Documents::pending_document_order_apply(Manager& manager) + { + if (pendingDocumentTabIds.size() != manager.documents.size()) + { + pendingDocumentTabIds.clear(); + return; + } + + std::vector order{}; + order.reserve(manager.documents.size()); + for (auto documentId : pendingDocumentTabIds) + { + auto it = std::ranges::find_if(manager.documents, [documentId](const Document& document) + { return document.tabId == documentId; }); + if (it == manager.documents.end()) + { + pendingDocumentTabIds.clear(); + return; + } + order.push_back((int)std::distance(manager.documents.begin(), it)); + } + + bool isOrdered = true; + for (auto [i, index] : std::views::enumerate(order)) + if ((int)i != index) + { + isOrdered = false; + break; + } + + if (isOrdered) + { + pendingDocumentTabIds.clear(); + return; + } + + std::vector remap(manager.documents.size(), -1); + std::vector documents{}; + documents.reserve(manager.documents.size()); + for (auto [i, index] : std::views::enumerate(order)) + { + remap[index] = (int)i; + documents.push_back(std::move(manager.documents[index])); + } + + auto index_remap = [&](int& index) + { + if (index < 0 || index >= (int)remap.size()) + index = -1; + else + index = remap[index]; + }; + + manager.documents = std::move(documents); + index_remap(manager.selected); + index_remap(manager.pendingSelected); + index_remap(closeDocumentIndex); + for (auto& index : manager.selectionHistory) index_remap(index); + for (auto& command : manager.commands) + if (!command.runManager) index_remap(command.documentIndex); + std::erase(manager.selectionHistory, -1); + + pendingDocumentTabIds.clear(); + } + void Documents::update(Taskbar& taskbar, Manager& manager, Settings& settings, Resources& resources, bool& isQuitting) { + pending_document_order_apply(manager); + auto viewport = ImGui::GetMainViewport(); auto windowHeight = ImGui::GetFrameHeightWithSpacing(); bool isLightTheme = settings.theme == theme::LIGHT; @@ -78,6 +154,8 @@ namespace anm2ed::imgui std::vector closeIndices{}; closeIndices.reserve(documentsCount); + std::vector documentTabs{}; + documentTabs.reserve(documentsCount); for (int i = 0; i < documentsCount; ++i) { @@ -114,7 +192,9 @@ namespace anm2ed::imgui auto filename = path::to_utf8(document.filename_get()); auto string = isDocumentDirty ? std::vformat(localize.get(FORMAT_NOT_SAVED), std::make_format_args(filename)) : filename; - auto label = std::format("{}###Document{}", string, i); + auto label = std::format("{}###Document{}", string, document.tabId); + auto imguiId = ImGui::GetCurrentWindow()->GetID(label.c_str()); + documentTabs.push_back({imguiId, document.tabId}); auto flags = isDocumentDirty ? ImGuiTabItemFlags_UnsavedDocument : 0; if (isRequested) flags |= ImGuiTabItemFlags_SetSelected; @@ -134,6 +214,30 @@ namespace anm2ed::imgui ImGui::PopFont(); } + if (auto tabBar = ImGui::GetCurrentTabBar(); tabBar && documentTabs.size() == manager.documents.size()) + { + std::vector documentTabIds{}; + documentTabIds.reserve(manager.documents.size()); + for (auto& tab : tabBar->Tabs) + { + auto it = std::ranges::find_if(documentTabs, [&](const DocumentTab& documentTab) + { return documentTab.imguiId == tab.ID; }); + if (it != documentTabs.end()) documentTabIds.push_back(it->documentId); + } + + if (documentTabIds.size() == manager.documents.size()) + { + bool isOrdered = true; + for (auto [i, documentId] : std::views::enumerate(documentTabIds)) + if (manager.documents[i].tabId != documentId) + { + isOrdered = false; + break; + } + if (!isOrdered) pendingDocumentTabIds = std::move(documentTabIds); + } + } + for (auto it = closeIndices.rbegin(); it != closeIndices.rend(); ++it) { if (closePopup.is_open() && closeDocumentIndex > *it) --closeDocumentIndex; diff --git a/src/imgui/documents.hpp b/src/imgui/documents.hpp index 319cb2e..2122075 100644 --- a/src/imgui/documents.hpp +++ b/src/imgui/documents.hpp @@ -1,5 +1,8 @@ #pragma once +#include +#include + #include "manager.hpp" #include "resources.hpp" #include "settings.hpp" @@ -11,11 +14,13 @@ namespace anm2ed::imgui class Documents { int closeDocumentIndex{-1}; + std::vector pendingDocumentTabIds{}; imgui::PopupHelper closePopup{imgui::PopupHelper(LABEL_DOCUMENT_CLOSE, imgui::POPUP_TO_CONTENT)}; public: float height{}; + void pending_document_order_apply(Manager&); void update(Taskbar&, Manager&, Settings&, Resources&, bool&); }; } diff --git a/src/imgui/window/timeline.cpp b/src/imgui/window/timeline.cpp index ad10e4d..1c6cbdc 100644 --- a/src/imgui/window/timeline.cpp +++ b/src/imgui/window/timeline.cpp @@ -708,6 +708,8 @@ namespace anm2ed::imgui rootFrame.position + glm::vec2(offset.x * cos - offset.y * sin, offset.x * sin + offset.y * cos); frame.scale *= rootScale; frame.rotation += rootFrame.rotation; + frame.tint *= rootFrame.tint; + frame.colorOffset += rootFrame.colorOffset; if (isRoundScale) frame.scale = glm::round(frame.scale); if (isRoundRotation) frame.rotation = std::round(frame.rotation); @@ -793,6 +795,8 @@ namespace anm2ed::imgui rootFrame->position = {}; rootFrame->scale = {100.0f, 100.0f}; rootFrame->rotation = {}; + rootFrame->tint = types::color::WHITE; + rootFrame->colorOffset = {}; } }); }; diff --git a/src/state.cpp b/src/state.cpp index 0eaf295..b6a4ef8 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -159,6 +159,8 @@ namespace anm2ed ImGui_ImplOpenGL3_NewFrame(); ImGui::NewFrame(); + documents.pending_document_order_apply(manager); + if (ImGui::GetTopMostPopupModal() == nullptr) { constexpr ImGuiKey DOCUMENT_SHORTCUT_KEYS[] = {ImGuiKey_1, ImGuiKey_2, ImGuiKey_3, ImGuiKey_4, ImGuiKey_5, diff --git a/workshop/metadata.xml b/workshop/metadata.xml index 3a42c43..bef6451 100644 --- a/workshop/metadata.xml +++ b/workshop/metadata.xml @@ -53,6 +53,6 @@ Alternatively, if you have subscribed to the mod, you can find the latest releas [h3]Happy animating![/h3] [img]https://files.catbox.moe/4auc1c.gif[/img] - 2.23 + 2.24 Public