refactor(editor): remove EditorCardManager references from various editors

- Eliminated the inclusion of EditorCardManager from multiple editor header files, streamlining dependencies and reducing coupling.
- Updated comments in PaletteEditor to reflect the transition to EditorCardRegistry for card management.

Benefits:
- Enhances modularity by decoupling editor components from the centralized card manager.
- Improves maintainability and clarity in the codebase by aligning with the new card management approach.
This commit is contained in:
scawful
2025-10-15 16:55:07 -04:00
parent 49c59191ac
commit 7ee8f90574
15 changed files with 11 additions and 1311 deletions

View File

@@ -8,7 +8,6 @@
#include "app/editor/editor.h"
#include "app/gui/widgets/text_editor.h"
#include "app/gui/app/editor_layout.h"
#include "app/gui/app/editor_card_manager.h"
#include "app/gui/core/style.h"
#include "app/rom.h"

View File

@@ -14,7 +14,6 @@
#include "dungeon_object_selector.h"
#include "dungeon_room_loader.h"
#include "object_editor_card.h"
#include "app/gui/app/editor_card_manager.h"
#include "zelda3/dungeon/room.h"
#include "zelda3/dungeon/room_entrance.h"
#include "app/gui/app/editor_layout.h"

View File

@@ -7,7 +7,6 @@
#include "app/editor/editor.h"
#include "app/editor/palette/palette_editor.h"
#include "app/gfx/core/bitmap.h"
#include "app/gui/app/editor_card_manager.h"
#include "app/gfx/types/snes_tile.h"
#include "app/gui/canvas/canvas.h"
#include "app/gui/app/editor_layout.h"

View File

@@ -7,7 +7,6 @@
#include "app/editor/editor.h"
#include "app/gfx/core/bitmap.h"
#include "app/gfx/types/snes_palette.h"
#include "app/gui/app/editor_card_manager.h"
#include "app/gfx/render/tilemap.h"
#include "app/gui/canvas/canvas.h"
#include "app/rom.h"

View File

@@ -9,7 +9,6 @@
#include "app/editor/editor.h"
#include "app/editor/message/message_data.h"
#include "app/editor/message/message_preview.h"
#include "app/gui/app/editor_card_manager.h"
#include "app/gui/app/editor_layout.h"
#include "app/gfx/core/bitmap.h"
#include "app/gui/canvas/canvas.h"

View File

@@ -4,7 +4,6 @@
#include "app/editor/code/assembly_editor.h"
#include "app/editor/editor.h"
#include "app/emu/audio/apu.h"
#include "app/gui/app/editor_card_manager.h"
#include "app/gui/app/editor_layout.h"
#include "app/rom.h"
#include "zelda3/music/tracker.h"

View File

@@ -5,7 +5,6 @@
#include "app/editor/editor.h"
#include "app/editor/graphics/gfx_group_editor.h"
#include "app/editor/palette/palette_editor.h"
#include "app/gui/app/editor_card_manager.h"
#include "app/editor/overworld/tile16_editor.h"
#include "app/editor/overworld/map_properties.h"
#include "app/editor/overworld/overworld_entity_renderer.h"

View File

@@ -7,7 +7,6 @@
#include "app/gfx/debug/performance/performance_profiler.h"
#include "app/gfx/types/snes_palette.h"
#include "app/gui/core/color.h"
#include "app/gui/app/editor_card_manager.h"
#include "app/gui/app/editor_layout.h"
#include "app/gui/core/icons.h"
#include "imgui/imgui.h"
@@ -185,7 +184,7 @@ absl::Status DisplayPalette(gfx::SnesPalette& palette, bool loaded) {
}
void PaletteEditor::Initialize() {
// Register all cards with EditorCardManager (done once during initialization)
// Register all cards with EditorCardRegistry (done once during initialization)
if (!dependencies_.card_registry) return;
auto* card_registry = dependencies_.card_registry;
@@ -751,9 +750,8 @@ absl::Status PaletteEditor::ResetColorToOriginal(
// ============================================================================
void PaletteEditor::DrawToolset() {
// Draw VSCode-style sidebar using EditorCardManager
// auto& card_manager = gui::EditorCardManager::Get();
// card_manager.DrawSidebar("Palette");
// Sidebar is drawn by EditorCardRegistry in EditorManager
// Cards registered in Initialize() appear in the sidebar automatically
}
void PaletteEditor::DrawControlPanel() {
@@ -936,10 +934,9 @@ void PaletteEditor::DrawControlPanel() {
"%s Palette Card Manager", ICON_MD_PALETTE);
ImGui::Separator();
// Use EditorCardManager to draw the menu
if (!dependencies_.card_registry) return;
auto* card_registry = dependencies_.card_registry;
// View menu section now handled by EditorCardRegistry in EditorManager
if (!dependencies_.card_registry) return;
auto* card_registry = dependencies_.card_registry;
ImGui::EndPopup();
}

View File

@@ -11,7 +11,6 @@
#include "absl/status/status.h"
#include "app/gfx/types/snes_color.h"
#include "app/gfx/types/snes_palette.h"
#include "app/gui/app/editor_card_manager.h"
#include "app/rom.h"
#include "imgui/imgui.h"
@@ -61,7 +60,7 @@ struct PaletteGroupMetadata {
* - Modified state tracking with visual indicators
* - Save/discard workflow
* - Common toolbar and color picker UI
* - EditorCardManager integration
* - EditorCardRegistry integration
*
* Derived classes implement specific grid layouts and palette access.
*/
@@ -260,9 +259,6 @@ class PaletteGroupCard {
bool auto_save_enabled_ = false; // Auto-save to ROM on every change
bool show_snes_format_ = true; // Show SNES $xxxx format in info
bool show_hex_format_ = true; // Show #xxxxxx hex in info
// Card registration
gui::CardRegistration card_registration_;
};
// ============================================================================

View File

@@ -8,7 +8,6 @@
#include "app/editor/editor.h"
#include "app/editor/sprite/zsprite.h"
#include "app/gui/canvas/canvas.h"
#include "app/gui/app/editor_card_manager.h"
#include "app/gui/app/editor_layout.h"
#include "app/rom.h"

View File

@@ -104,8 +104,6 @@ void UICoordinator::DrawAllUI() {
// Note: Theme styling is applied by ThemeManager, not here
// This is called from EditorManager::Update() - don't call menu bar stuff here
LOG_INFO("UICoordinator", "DrawAllUI() called");
// Draw UI windows and dialogs
// Session dialogs are drawn by SessionCoordinator separately to avoid duplication
DrawCommandPalette(); // Ctrl+Shift+P
@@ -114,8 +112,6 @@ void UICoordinator::DrawAllUI() {
DrawWelcomeScreen(); // Welcome screen
DrawProjectHelp(); // Project help
DrawWindowManagementUI(); // Window management
LOG_INFO("UICoordinator", "DrawAllUI() complete");
}
void UICoordinator::DrawMenuBarExtras() {
@@ -291,26 +287,20 @@ void UICoordinator::DrawWelcomeScreen() {
return;
}
LOG_INFO("UICoordinator", "Drawing welcome screen (rom_loaded=%s)",
rom_is_loaded ? "true" : "false");
// Reset first show flag to override ImGui ini state
// This ensures the window appears even if imgui.ini has it hidden
welcome_screen_->ResetFirstShow();
// Update recent projects before showing
welcome_screen_->RefreshRecentProjects();
// Show the welcome screen (it manages its own ImGui window)
// Show the welcome screen window
bool is_open = true;
bool action_taken = welcome_screen_->Show(&is_open);
welcome_screen_->Show(&is_open);
// If user closed the window via X button, mark as manually closed
// If user closed it via X button, respect that
if (!is_open) {
welcome_screen_manually_closed_ = true;
show_welcome_screen_ = false;
welcome_screen_->MarkManuallyClosed();
LOG_INFO("UICoordinator", "Welcome screen manually closed by user (X button)");
welcome_screen_manually_closed_ = true;
}
// If an action was taken (ROM loaded, project opened), the welcome screen will auto-hide
@@ -533,8 +523,6 @@ void UICoordinator::DrawTestingUI() {
void UICoordinator::DrawCommandPalette() {
if (!show_command_palette_) return;
LOG_INFO("UICoordinator", "DrawCommandPalette() - rendering command palette");
using namespace ImGui;
auto& theme = gui::ThemeManager::Get().GetCurrentTheme();

View File

@@ -92,10 +92,7 @@ class UICoordinator {
void HideCurrentEditorCards();
void ToggleCardSidebar() { show_card_sidebar_ = !show_card_sidebar_; }
void ShowGlobalSearch() { show_global_search_ = true; }
void ShowCommandPalette() {
LOG_INFO("UICoordinator", "ShowCommandPalette() called - setting flag to true");
show_command_palette_ = true;
}
void ShowCommandPalette() { show_command_palette_ = true; }
void ShowCardBrowser() { show_card_browser_ = true; }
// Window visibility management

File diff suppressed because it is too large Load Diff

View File

@@ -1,241 +0,0 @@
#ifndef YAZE_APP_GUI_EDITOR_CARD_MANAGER_H
#define YAZE_APP_GUI_EDITOR_CARD_MANAGER_H
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "imgui/imgui.h"
namespace yaze {
namespace gui {
class EditorCard; // Forward declaration
/**
* @brief Metadata for an editor card
*/
struct CardInfo {
std::string card_id; // Unique identifier (e.g., "dungeon.room_selector")
std::string display_name; // Human-readable name (e.g., "Room Selector")
std::string icon; // Material icon
std::string category; // Category (e.g., "Dungeon", "Graphics", "Palette")
std::string shortcut_hint; // Display hint (e.g., "Ctrl+Shift+R")
bool* visibility_flag; // Pointer to bool controlling visibility
EditorCard* card_instance; // Pointer to actual card (optional)
std::function<void()> on_show; // Callback when card is shown
std::function<void()> on_hide; // Callback when card is hidden
int priority; // Display priority for menus (lower = higher)
};
/**
* @brief Central registry and manager for all editor cards
*
* This singleton provides:
* - Global card registration across all editors
* - View menu integration
* - Keyboard shortcut management
* - Workspace preset system
* - Quick search/filter
* - Programmatic card control without GUI coupling
*
* Design Philosophy:
* - Cards register themselves on creation
* - Manager provides unified interface for visibility control
* - No direct GUI dependency in card logic
* - Supports dynamic card creation/destruction
*
* Usage:
* ```cpp
* // In editor initialization:
* auto& manager = EditorCardManager::Get();
* manager.RegisterCard({
* .card_id = "dungeon.room_selector",
* .display_name = "Room Selector",
* .icon = ICON_MD_LIST,
* .category = "Dungeon",
* .visibility_flag = &show_room_selector_,
* .on_show = []() { printf("Room selector opened\n"); }
* });
*
* // Programmatic control:
* manager.ShowCard("dungeon.room_selector");
* manager.HideCard("dungeon.room_selector");
* manager.ToggleCard("dungeon.room_selector");
*
* // In View menu:
* manager.DrawViewMenuSection("Dungeon");
* ```
*/
class EditorCardManager {
public:
static EditorCardManager& Get();
// Registration
void RegisterCard(const CardInfo& info);
// Register card with centralized visibility management (preferred method)
void RegisterCard(const std::string& card_id,
const std::string& display_name,
const std::string& icon,
const std::string& category,
const std::string& shortcut_hint = "",
int priority = 50,
std::function<void()> on_show = nullptr,
std::function<void()> on_hide = nullptr,
bool visible_by_default = false);
void UnregisterCard(const std::string& card_id);
void UnregisterCardsWithPrefix(const std::string& prefix);
void ClearAllCards();
// Card control (programmatic, no GUI)
bool ShowCard(const std::string& card_id);
bool HideCard(const std::string& card_id);
bool ToggleCard(const std::string& card_id);
bool IsCardVisible(const std::string& card_id) const;
// Get visibility flag pointer (for passing to EditorCard::Begin)
bool* GetVisibilityFlag(const std::string& card_id);
// Batch operations
void ShowAllCardsInCategory(const std::string& category);
void HideAllCardsInCategory(const std::string& category);
void ShowOnlyCard(const std::string& card_id); // Hide all others in category
// Query
std::vector<CardInfo> GetCardsInCategory(const std::string& category) const;
std::vector<CardInfo> GetCardsWithPrefix(const std::string& prefix) const;
std::vector<std::string> GetAllCategories() const;
const CardInfo* GetCardInfo(const std::string& card_id) const;
// View menu integration
void DrawViewMenuSection(const std::string& category);
void DrawViewMenuAll(); // Draw all categories as submenus
// VSCode-style sidebar (replaces Toolset)
void DrawSidebar(const std::string& category,
const std::vector<std::string>& active_categories = {},
std::function<void(const std::string&)> on_category_switch = nullptr,
std::function<void()> on_collapse = nullptr);
void DrawSidebarWithSessionFilter(const std::string& category,
const std::string& session_prefix = "",
const std::vector<std::string>& active_categories = {},
std::function<void(const std::string&)> on_category_switch = nullptr,
std::function<void()> on_collapse = nullptr);
static constexpr float GetSidebarWidth() { return 48.0f; }
// Active editor tracking (based on most recently interacted card)
void SetActiveCategory(const std::string& category);
std::string GetActiveCategory() const { return active_category_; }
bool IsCategoryActive(const std::string& category) const { return active_category_ == category; }
// Compact inline card control for menu bar
void DrawCompactCardControl(const std::string& category); // Shows only active editor's cards
void DrawCompactCardControlWithSession(const std::string& category, const std::string& session_prefix = "");
void DrawInlineCardToggles(const std::string& category); // Minimal inline checkboxes
// Card browser UI
void DrawCardBrowser(bool* p_open); // Visual card browser/toggler
void DrawCardBrowserTable(const char* search_filter, const std::string& category_filter);
void DrawPresetsTab();
// Workspace presets
struct WorkspacePreset {
std::string name;
std::vector<std::string> visible_cards; // Card IDs
std::string description;
};
void SavePreset(const std::string& name, const std::string& description = "");
bool LoadPreset(const std::string& name);
void DeletePreset(const std::string& name);
std::vector<WorkspacePreset> GetPresets() const;
// Quick actions
void ShowAll(); // Show all registered cards
void HideAll(); // Hide all registered cards
void ResetToDefaults(); // Reset to default visibility state
// Statistics
size_t GetCardCount() const { return cards_.size(); }
size_t GetVisibleCardCount() const;
private:
EditorCardManager() = default;
~EditorCardManager() = default;
EditorCardManager(const EditorCardManager&) = delete;
EditorCardManager& operator=(const EditorCardManager&) = delete;
std::unordered_map<std::string, CardInfo> cards_;
std::unordered_map<std::string, bool> centralized_visibility_; // Centralized card visibility flags
std::unordered_map<std::string, WorkspacePreset> presets_;
std::string active_category_; // Currently active editor category (based on last card interaction)
std::vector<std::string> recent_categories_; // Stack of recently used categories (max 5)
static constexpr size_t kMaxRecentCategories = 5;
// Helper methods
void SavePresetsToFile();
void LoadPresetsFromFile();
};
/**
* @brief RAII helper for auto-registering cards
*
* Usage:
* ```cpp
* class MyEditor {
* CardRegistration room_selector_reg_;
*
* MyEditor() {
* room_selector_reg_ = RegisterCard({
* .card_id = "myeditor.room_selector",
* .display_name = "Room Selector",
* .visibility_flag = &show_room_selector_
* });
* }
* };
* ```
*/
class CardRegistration {
public:
CardRegistration() = default;
explicit CardRegistration(const std::string& card_id) : card_id_(card_id) {}
~CardRegistration() {
if (!card_id_.empty()) {
EditorCardManager::Get().UnregisterCard(card_id_);
}
}
// No copy, allow move
CardRegistration(const CardRegistration&) = delete;
CardRegistration& operator=(const CardRegistration&) = delete;
CardRegistration(CardRegistration&& other) noexcept : card_id_(std::move(other.card_id_)) {
other.card_id_.clear();
}
CardRegistration& operator=(CardRegistration&& other) noexcept {
if (this != &other) {
card_id_ = std::move(other.card_id_);
other.card_id_.clear();
}
return *this;
}
private:
std::string card_id_;
};
// Convenience function for registration
inline CardRegistration RegisterCard(const CardInfo& info) {
EditorCardManager::Get().RegisterCard(info);
return CardRegistration(info.card_id);
}
} // namespace gui
} // namespace yaze
#endif // YAZE_APP_GUI_EDITOR_CARD_MANAGER_H

View File

@@ -58,7 +58,6 @@ set(GUI_AUTOMATION_SRC
set(GUI_APP_SRC
app/gui/app/agent_chat_widget.cc
app/gui/app/collaboration_panel.cc
app/gui/app/editor_card_manager.cc
app/gui/app/editor_layout.cc
)