feat(editor): enhance card-based editor functionality and streamline initialization

- Updated EditorManager to support new card-based editors, including Emulator, Hex, and Assembly editors.
- Added centralized registration of editor cards with EditorCardManager, improving visibility management.
- Implemented methods to retrieve editor types from categories and manage card visibility dynamically.
- Enhanced initialization processes for various editors to ensure proper card registration and default visibility settings.

Benefits:
- Improved user experience by organizing editor cards and providing quick access to new editor functionalities.
- Streamlined editor management, making it easier to switch between different editing contexts and enhancing overall workflow efficiency.
This commit is contained in:
scawful
2025-10-12 20:43:42 -04:00
parent bdb2d1ed14
commit e5aff24bfc
22 changed files with 595 additions and 670 deletions

View File

@@ -25,28 +25,17 @@ using ImGui::TableSetupColumn;
using ImGui::Text;
void SpriteEditor::Initialize() {
// Register cards with EditorCardManager during initialization (once)
auto& card_manager = gui::EditorCardManager::Get();
card_manager.RegisterCard({
.card_id = "sprite.vanilla_editor",
.display_name = "Vanilla Sprites",
.icon = ICON_MD_SMART_TOY,
.category = "Sprite",
.shortcut_hint = "Alt+Shift+1",
.visibility_flag = &show_vanilla_editor_,
.priority = 10
});
card_manager.RegisterCard({.card_id = "sprite.vanilla_editor", .display_name = "Vanilla Sprites",
.icon = ICON_MD_SMART_TOY, .category = "Sprite",
.shortcut_hint = "Alt+Shift+1", .priority = 10});
card_manager.RegisterCard({.card_id = "sprite.custom_editor", .display_name = "Custom Sprites",
.icon = ICON_MD_ADD_CIRCLE, .category = "Sprite",
.shortcut_hint = "Alt+Shift+2", .priority = 20});
card_manager.RegisterCard({
.card_id = "sprite.custom_editor",
.display_name = "Custom Sprites",
.icon = ICON_MD_ADD_CIRCLE,
.category = "Sprite",
.shortcut_hint = "Alt+Shift+2",
.visibility_flag = &show_custom_editor_,
.priority = 20
});
// Show vanilla editor by default
card_manager.ShowCard("sprite.vanilla_editor");
}
absl::Status SpriteEditor::Load() {
@@ -56,29 +45,26 @@ absl::Status SpriteEditor::Load() {
absl::Status SpriteEditor::Update() {
if (rom()->is_loaded() && !sheets_loaded_) {
// Load the values for current_sheets_ array
sheets_loaded_ = true;
}
DrawToolset();
gui::VerticalSpacing(2.0f);
auto& card_manager = gui::EditorCardManager::Get();
// Create session-aware cards (non-static for multi-session support)
gui::EditorCard vanilla_card(MakeCardTitle("Vanilla Sprites").c_str(), ICON_MD_PEST_CONTROL_RODENT);
gui::EditorCard custom_card(MakeCardTitle("Custom Sprites").c_str(), ICON_MD_ADD_MODERATOR);
static gui::EditorCard vanilla_card("Vanilla Sprites", ICON_MD_SMART_TOY);
static gui::EditorCard custom_card("Custom Sprites", ICON_MD_ADD_CIRCLE);
if (show_vanilla_editor_) {
if (vanilla_card.Begin(&show_vanilla_editor_)) {
DrawVanillaSpriteEditor();
}
vanilla_card.End(); // ALWAYS call End after Begin
vanilla_card.SetDefaultSize(900, 700);
custom_card.SetDefaultSize(800, 600);
// Get visibility flags from card manager and pass to Begin()
if (vanilla_card.Begin(card_manager.GetVisibilityFlag("sprite.vanilla_editor"))) {
DrawVanillaSpriteEditor();
vanilla_card.End();
}
if (show_custom_editor_) {
if (custom_card.Begin(&show_custom_editor_)) {
DrawCustomSprites();
}
custom_card.End(); // ALWAYS call End after Begin
if (custom_card.Begin(card_manager.GetVisibilityFlag("sprite.custom_editor"))) {
DrawCustomSprites();
custom_card.End();
}
return status_.ok() ? absl::OkStatus() : status_;

View File

@@ -37,8 +37,8 @@ constexpr ImGuiTableFlags kSpriteTableFlags =
*/
class SpriteEditor : public Editor {
public:
explicit SpriteEditor(Rom* rom = nullptr) : rom_(rom) {
type_ = EditorType::kSprite;
explicit SpriteEditor(Rom* rom = nullptr) : rom_(rom) {
type_ = EditorType::kSprite;
}
void Initialize() override;
@@ -51,10 +51,10 @@ class SpriteEditor : public Editor {
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
absl::Status Find() override { return absl::UnimplementedError("Find"); }
absl::Status Save() override { return absl::UnimplementedError("Save"); }
// Set the ROM pointer
void set_rom(Rom* rom) { rom_ = rom; }
// Get the ROM pointer
Rom* rom() const { return rom_; }
@@ -84,11 +84,6 @@ class SpriteEditor : public Editor {
void DrawAnimationFrames();
void DrawToolset();
// Card visibility - ALL FALSE by default to prevent crash on ROM load
// Cards only shown when user explicitly opens them via View menu or shortcuts
bool show_vanilla_editor_ = false;
bool show_custom_editor_ = false;
ImVector<int> active_sprites_; /**< Active sprites. */
int current_sprite_id_; /**< Current sprite ID. */