From e0732ee6b91d3c951d493837a54bea5c89a113b4 Mon Sep 17 00:00:00 2001 From: shweet Date: Sun, 14 Sep 2025 21:00:54 -0400 Subject: [PATCH] Fixes for exit confirmation when saved --- src/anm2.h | 46 +++++++++++++++++++++++++++++++--------------- src/imgui.cpp | 3 +++ src/imgui.h | 6 ++++-- src/texture.h | 2 ++ 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/anm2.h b/src/anm2.h index cc21449..631e7d3 100644 --- a/src/anm2.h +++ b/src/anm2.h @@ -137,23 +137,31 @@ struct Anm2Spritesheet std::string path{}; Texture texture; std::vector pixels; + + auto operator<=>(const Anm2Spritesheet&) const = default; }; struct Anm2Layer { std::string name = "New Layer"; - s32 spritesheetID{}; + s32 spritesheetID{} + + auto operator<=>(const Anm2Layer&) const = default; }; struct Anm2Null { std::string name = "New Null"; bool isShowRect = false; + + auto operator<=>(const Anm2Null&) const = default; }; struct Anm2Event { std::string name = "New Event"; + + auto operator<=>(const Anm2Event&) const = default; }; struct Anm2Frame @@ -171,27 +179,16 @@ struct Anm2Frame vec2 scale = {100, 100}; vec3 offsetRGB = COLOR_OFFSET_NONE; vec4 tintRGBA = COLOR_OPAQUE; -}; -struct Anm2FrameChange -{ - std::optional isVisible; - std::optional isInterpolated; - std::optional rotation; - std::optional delay; - std::optional crop; - std::optional pivot; - std::optional position; - std::optional size; - std::optional scale; - std::optional offsetRGB; - std::optional tintRGBA; + auto operator<=>(const Anm2Frame&) const = default; }; struct Anm2Item { bool isVisible = true; std::vector frames; + + auto operator<=>(const Anm2Item&) const = default; }; struct Anm2Animation @@ -204,6 +201,8 @@ struct Anm2Animation std::vector layerOrder; std::map nullAnimations; Anm2Item triggers; + + auto operator<=>(const Anm2Animation&) const = default; }; struct Anm2 @@ -219,6 +218,8 @@ struct Anm2 s32 defaultAnimationID = ID_NONE; s32 fps = ANM2_FPS_DEFAULT; s32 version{}; + + auto operator<=>(const Anm2&) const = default; }; struct Anm2Reference @@ -231,6 +232,21 @@ struct Anm2Reference auto operator<=>(const Anm2Reference&) const = default; }; +struct Anm2FrameChange +{ + std::optional isVisible; + std::optional isInterpolated; + std::optional rotation; + std::optional delay; + std::optional crop; + std::optional pivot; + std::optional position; + std::optional size; + std::optional scale; + std::optional offsetRGB; + std::optional tintRGBA; +}; + enum Anm2MergeType { ANM2_MERGE_APPEND_FRAMES, diff --git a/src/imgui.cpp b/src/imgui.cpp index 1ce0ece..68f95bb 100644 --- a/src/imgui.cpp +++ b/src/imgui.cpp @@ -3012,6 +3012,8 @@ void imgui_init self->window = window; self->glContext = glContext; + self->saveAnm2 = *anm2; + ImGui::CreateContext(); ImGui::StyleColorsDark(); @@ -3032,6 +3034,7 @@ void imgui_init if (!SETTINGS_HOTKEY_MEMBERS[i]) continue; imgui_hotkey_chord_registry()[i] = imgui_chord_from_string_get(*&(self->settings->*SETTINGS_HOTKEY_MEMBERS[i])); } + } void imgui_update(Imgui* self) diff --git a/src/imgui.h b/src/imgui.h index 937085a..9549cb1 100644 --- a/src/imgui.h +++ b/src/imgui.h @@ -209,6 +209,7 @@ struct Imgui ImguiPopupType pendingPopupType = IMGUI_POPUP_NONE; ImVec2 pendingPopupPosition{}; std::vector log; + Anm2 saveAnm2; SDL_SystemCursor cursor; SDL_SystemCursor pendingCursor; bool isCursorSet = false; @@ -217,7 +218,6 @@ struct Imgui bool isTryQuit = false; }; - static inline void imgui_snapshot(Imgui* self, const std::string& action = SNAPSHOT_ACTION) { self->snapshots->action = action; @@ -252,6 +252,8 @@ static inline void imgui_file_save(Imgui* self) anm2_serialize(self->anm2, self->anm2->path); imgui_log_push(self, std::format(IMGUI_LOG_FILE_SAVE_FORMAT, self->anm2->path)); } + + self->saveAnm2 = *self->anm2; } static inline void imgui_file_new(Imgui* self) @@ -269,7 +271,7 @@ static inline void imgui_file_save_as(Imgui* self) static inline void imgui_quit(Imgui* self) { - if (!self->snapshots->undoStack.is_empty()) + if (self->saveAnm2 != *self->anm2) self->isTryQuit = true; else self->isQuit = true; diff --git a/src/texture.h b/src/texture.h index c0cb7e1..3c55c1a 100644 --- a/src/texture.h +++ b/src/texture.h @@ -13,6 +13,8 @@ struct Texture GLuint id = GL_ID_NONE; ivec2 size{}; bool isInvalid = true; + + auto operator<=>(const Texture&) const = default; }; bool texture_from_encoded_data_init(Texture* self, ivec2 size, const u8* data, u32 length);