Split window.cpp per window and drive menus from one flag table

- WINDOW_FLAGS table builds every context menu, footer and shortcut set
- Shared list-row and card-row renderers replace per-window copies
- Layers/nulls/events share one properties popup; Manager keeps one item popup API
- Regions, spritesheets and sounds drop hand-built menus, footers and shortcut blocks
- Animation remove and cut share one erase path that also clears group ids
- Index-mapped multi-select fixes shift-range over non-contiguous ids
- Fix Remove Unused tooltip showing the Add shortcut and the missing break in item properties

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 13:27:34 -04:00
1 parent 3f31cedeed
commit d926fc6677
13 files changed
+2811 -4466

No files matched your search

+96 -45
View File
@@ -1,6 +1,7 @@
#pragma once
#include <functional>
#include <map>
#include <set>
#include <string>
#include <vector>
@@ -16,30 +17,69 @@
namespace anm2ed::imgui
{
#define WINDOW_FLAGS \
X(PLAY, ACTION_PLAY, play) \
X(RENAME, ACTION_RENAME, rename) \
X(PROPERTIES, ACTION_PROPERTIES, properties) \
X(OPEN_DIRECTORY, ACTION_OPEN_DIRECTORY, open) \
X(SET_FILE_PATH, ACTION_SET_FILE_PATH, path_set) \
X(ADD, ACTION_ADD, add) \
X(DUPLICATE, ACTION_DUPLICATE, duplicate) \
X(REMOVE_UNUSED, ACTION_REMOVE_UNUSED, remove_unused) \
X(RELOAD, ACTION_RELOAD, reload) \
X(REPLACE, ACTION_REPLACE, replace) \
X(MERGE, ACTION_MERGE, merge) \
X(GROUP, ACTION_GROUP, group) \
X(REMOVE, ACTION_REMOVE, remove) \
X(DEFAULT, ACTION_DEFAULT, default_set) \
X(TRIM, ACTION_TRIM, trim) \
X(EXPORT, ACTION_EXPORT, export_open) \
X(PACK, ACTION_PACK, pack_open) \
X(SAVE, ACTION_SAVE, save) \
X(CUT, ACTION_CUT, cut) \
X(COPY, ACTION_COPY, copy) \
X(PASTE, ACTION_PASTE, paste)
enum WindowFlagIndex
{
#define X(symbol, action, command) WINDOW_INDEX_##symbol,
WINDOW_FLAGS
#undef X
WINDOW_INDEX_COUNT
};
enum WindowFlag
{
WINDOW_ADD = 1 << 0,
WINDOW_REMOVE = 1 << 1,
WINDOW_REMOVE_UNUSED = 1 << 2,
WINDOW_DUPLICATE = 1 << 3,
WINDOW_MERGE = 1 << 4,
WINDOW_DEFAULT = 1 << 5,
WINDOW_CUT = 1 << 6,
WINDOW_COPY = 1 << 7,
WINDOW_PASTE = 1 << 8,
WINDOW_RENAME = 1 << 9,
WINDOW_PROPERTIES = 1 << 10,
WINDOW_REFERENCE_ITALIC = 1 << 11,
WINDOW_GROUP = 1 << 12
#define X(symbol, action, command) WINDOW_##symbol = 1 << WINDOW_INDEX_##symbol,
WINDOW_FLAGS
#undef X
WINDOW_REFERENCE_ITALIC = 1 << WINDOW_INDEX_COUNT
};
using WindowFlags = int;
inline constexpr int WINDOW_GROUP_KEY_OFFSET = 2;
constexpr int window_group_key_get(int groupId) { return -groupId - WINDOW_GROUP_KEY_OFFSET; }
constexpr int window_group_id_from_key_get(int key) { return -key - WINDOW_GROUP_KEY_OFFSET; }
constexpr bool is_window_group_key(int key) { return key <= -WINDOW_GROUP_KEY_OFFSET; }
struct WindowCardImage
{
resource::Texture* texture{};
glm::vec2 size{};
glm::vec2 uvMin{};
glm::vec2 uvMax{1.0f};
bool isValid{};
};
constexpr bool window_flag_has(WindowFlags flags, WindowFlag flag) { return (flags & flag) != 0; }
struct Window
{
using StorageGet = std::function<Storage&(Document&)>;
using ContainerGet = std::function<Element*(Document&)>;
using IndexGet = std::function<int(Document&)>;
using ElementGet = std::function<Element*(Anm2&, int)>;
using ElementKeyGet = std::function<int(const Element&, int)>;
using RowLabelGet = std::function<std::string(Document&, const Element&)>;
@@ -48,11 +88,11 @@ namespace anm2ed::imgui
using RenameFinish = std::function<void(Document&, Element&, int, int)>;
using TooltipDraw = std::function<void(Document&, Resources&, const Element&)>;
using RowDragDropUpdate = std::function<bool(Window&, Manager&, Document&, const Element&, int)>;
using CardImageGet = std::function<WindowCardImage(Document&, Resources&, const Element&)>;
using PropertiesOpen = std::function<void(Manager&, int)>;
using Command = std::function<void(Window&, Manager&, Settings&, Document&, Clipboard&)>;
using IsAvailable = std::function<bool(Document&)>;
using IsEnabled = std::function<bool(Window&, Document&)>;
using Update = std::function<void(Window&, Manager&, Settings&, Resources&, Clipboard&, Document&)>;
using RowsUpdate = std::function<void(Window&, Manager&, Settings&, Resources&, Clipboard&, Document&, ImVec2)>;
StringType title{};
bool Settings::* isOpen{};
@@ -60,24 +100,21 @@ namespace anm2ed::imgui
ElementType containerType{ElementType::UNKNOWN};
ElementType elementType{ElementType::UNKNOWN};
const char* childLabel{"##Window Child"};
StringType addTooltip{};
StringType duplicateTooltip{};
StringType mergeTooltip{};
StringType removeTooltip{};
StringType removeUnusedTooltip{};
StringType defaultTooltip{};
std::map<WindowFlag, StringType> tooltips{};
std::vector<std::vector<WindowFlag>> footer{};
StringType addEdit{};
StringType propertiesEdit{};
StringType renameEdit{};
StringType pasteEdit{};
StringType removeUnusedEdit{};
StringType deserializeFailedToast{};
StringType unavailableText{STRING_UNDEFINED};
int cardLines{};
int newElementId{-1};
int scrollQueued{-1};
int renameQueued{-1};
int renameId{-1};
int editId{-1};
int footerRows{-1};
RenameState renameState{RENAME_SELECTABLE};
std::string renameText{};
PopupHelper popup{STRING_UNDEFINED};
@@ -90,11 +127,12 @@ namespace anm2ed::imgui
Element editElement{};
Dialog* dialog{};
WindowFlags flags{WINDOW_COPY | WINDOW_PASTE};
bool isChildPaddingZero{};
bool isPreserveEditElementOnOpen{};
ImVec2 tooltipWindowPadding{};
ImVec2 tooltipItemSpacing{};
StorageGet storage_get{};
ContainerGet container_get{};
IndexGet insert_index_get{};
ElementGet element_get{};
ElementKeyGet element_key_get{};
RowLabelGet row_label_get{};
@@ -103,30 +141,15 @@ namespace anm2ed::imgui
RenameFinish rename_finish{};
TooltipDraw tooltip_draw{};
RowDragDropUpdate row_drag_drop_update{};
CardImageGet card_image_get{};
PropertiesOpen properties_open{};
Command add{};
Command remove{};
Command duplicate{};
Command merge{};
#define X(symbol, action, command) Command command{};
WINDOW_FLAGS
#undef X
Command merge_open{};
Command group{};
Command default_set{};
Command cut{};
Command copy{};
Command paste{};
Command reload{};
Command replace{};
Command save{};
Command pack{};
Command trim{};
Command properties{};
Command open{};
Command path_set{};
IsAvailable is_available{};
Update begin_update{};
RowsUpdate rows_update{};
Update context_update{};
Update footer_update{};
std::map<WindowFlag, IsEnabled> enabled{};
IsEnabled is_available{};
Update rows_update{};
Update body_update{};
Update popup_update{};
Update post_update{};
@@ -140,4 +163,32 @@ namespace anm2ed::imgui
Window nulls_window_register();
Window events_window_register();
void window_update(Window&, Manager&, Settings&, Resources&, Dialog&, Clipboard&);
enum class PopupButton
{
NONE,
CONFIRM,
CANCEL
};
inline constexpr auto DRAG_DROP_SOURCE_FLAGS =
ImGuiDragDropFlags_SourceNoPreviewTooltip | ImGuiDragDropFlags_SourceNoHoldToOpenOthers;
inline constexpr ImVec4 CARD_TINT_INVALID = ImVec4(1.0f, 0.25f, 0.25f, 1.0f);
inline constexpr ImVec4 CARD_TINT_VALID = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
bool is_drag_drop_active();
Element* window_container_get(const Window&, Document&);
Element* window_element_get(const Window&, Document&, int);
void window_element_apply_push(Window&, Manager&, const Element&, int);
void window_edit(Document&, Document::ChangeType, const std::string&, const std::function<void()>&);
void window_command_push(Window&, Manager&, Settings&, Clipboard&, const Window::Command&);
int window_selection_start(Window&, Document&, const std::vector<int>&);
void window_selection_finish(Window&, Manager&, Settings&, Clipboard&, Document&, int);
bool window_row_draw(Window&, Manager&, Resources&, Document&, Element&, int, int, int);
void window_cards_draw(Window&, Manager&, Settings&, Resources&, Clipboard&, Document&, Element*);
void window_tooltip_name_draw(Resources&, const std::string&);
void window_tooltip_image_draw(const WindowCardImage&, const std::function<void()>&);
void window_directory_open(Dialog&, Document&, const std::filesystem::path&);
std::filesystem::path window_asset_path_get(Document&, const std::filesystem::path&);
PopupButton window_popup_buttons_draw(Manager&, const char*, bool = true, StringType = BASIC_CANCEL);
}