fix to document order and bake into other frames works with colors
This commit is contained in:
1 parent
6d206045c7
commit
b5528bc118
7 files changed
+128
-3
No files matched your search
+9
-1
@@ -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<ItemType>(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),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <set>
|
||||
@@ -44,6 +45,7 @@ namespace anm2ed
|
||||
};
|
||||
|
||||
std::filesystem::path path{};
|
||||
uint64_t tabId{};
|
||||
|
||||
Snapshots snapshots{};
|
||||
Snapshot& current = snapshots.current;
|
||||
|
||||
+105
-1
@@ -1,8 +1,11 @@
|
||||
#include "documents.hpp"
|
||||
|
||||
#include <format>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
#include <imgui_internal.h>
|
||||
|
||||
#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<int> 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<int> remap(manager.documents.size(), -1);
|
||||
std::vector<Document> 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<int> closeIndices{};
|
||||
closeIndices.reserve(documentsCount);
|
||||
std::vector<DocumentTab> 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<uint64_t> 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;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "manager.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "settings.hpp"
|
||||
@@ -11,11 +14,13 @@ namespace anm2ed::imgui
|
||||
class Documents
|
||||
{
|
||||
int closeDocumentIndex{-1};
|
||||
std::vector<uint64_t> 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&);
|
||||
};
|
||||
}
|
||||
@@ -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 = {};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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]
|
||||
</description>
|
||||
<version>2.23</version>
|
||||
<version>2.24</version>
|
||||
<visibility>Public</visibility>
|
||||
</metadata>
|
||||
Reference in new issue
Block a user