refactor(editor): centralize sidebar management for card-based editors

- Updated EditorManager to handle sidebar drawing for card-based editors, improving consistency across editor types.
- Removed individual toolbar implementations from GraphicsEditor, ScreenEditor, and SpriteEditor, as sidebar functionality is now centralized.
- Enhanced EditorCardManager to manage card visibility and selection more effectively, including improved UI feedback for empty card categories.

Benefits:
- Streamlined editor interface and improved user experience by consolidating sidebar management, making it easier to navigate and manage editor cards.
This commit is contained in:
scawful
2025-10-12 12:40:29 -04:00
parent d888ce598d
commit 8bb58c71ba
5 changed files with 101 additions and 114 deletions

View File

@@ -91,6 +91,7 @@ std::string GetEditorName(EditorType type) {
} // namespace } // namespace
// Static registry of editors that use the card-based layout system // Static registry of editors that use the card-based layout system
// These editors register their cards with EditorCardManager
bool EditorManager::IsCardBasedEditor(EditorType type) { bool EditorManager::IsCardBasedEditor(EditorType type) {
switch (type) { switch (type) {
case EditorType::kDungeon: case EditorType::kDungeon:
@@ -99,8 +100,7 @@ bool EditorManager::IsCardBasedEditor(EditorType type) {
case EditorType::kScreen: case EditorType::kScreen:
case EditorType::kSprite: case EditorType::kSprite:
case EditorType::kMessage: case EditorType::kMessage:
case EditorType::kMusic: case EditorType::kOverworld:
case EditorType::kEmulator:
return true; return true;
default: default:
return false; return false;
@@ -912,8 +912,8 @@ absl::Status EditorManager::Update() {
} }
} }
// Draw sidebar for current category editor // Draw sidebar for current card-based editor (only if sidebar is visible)
if (current_editor_) { if (show_card_sidebar_ && current_editor_ && IsCardBasedEditor(current_editor_->type())) {
std::string category = GetEditorCategory(current_editor_->type()); std::string category = GetEditorCategory(current_editor_->type());
auto& card_manager = gui::EditorCardManager::Get(); auto& card_manager = gui::EditorCardManager::Get();
card_manager.DrawSidebar(category); card_manager.DrawSidebar(category);

View File

@@ -169,23 +169,8 @@ absl::Status GraphicsEditor::Update() {
} }
void GraphicsEditor::DrawToolset() { void GraphicsEditor::DrawToolset() {
static gui::Toolset toolbar; // Sidebar is now drawn by EditorManager for card-based editors
toolbar.Begin(); // This method kept for compatibility but sidebar handles card toggles
if (toolbar.AddAction(ICON_MD_EDIT, "Sheet Editor")) {
show_sheet_editor_ = !show_sheet_editor_;
}
if (toolbar.AddAction(ICON_MD_VIEW_LIST, "Sheet Browser")) {
show_sheet_browser_ = !show_sheet_browser_;
}
if (toolbar.AddAction(ICON_MD_PERSON, "Player Animations")) {
show_player_animations_ = !show_player_animations_;
}
if (toolbar.AddAction(ICON_MD_CONSTRUCTION, "Prototype Viewer")) {
show_prototype_viewer_ = !show_prototype_viewer_;
}
toolbar.End();
} }

View File

@@ -164,26 +164,8 @@ absl::Status ScreenEditor::Update() {
} }
void ScreenEditor::DrawToolset() { void ScreenEditor::DrawToolset() {
static gui::Toolset toolbar; // Sidebar is now drawn by EditorManager for card-based editors
toolbar.Begin(); // This method kept for compatibility but sidebar handles card toggles
if (toolbar.AddAction(ICON_MD_MAP, "Dungeon Maps")) {
show_dungeon_maps_ = !show_dungeon_maps_;
}
if (toolbar.AddAction(ICON_MD_INVENTORY, "Inventory Menu")) {
show_inventory_menu_ = !show_inventory_menu_;
}
if (toolbar.AddAction(ICON_MD_PUBLIC, "Overworld Map")) {
show_overworld_map_ = !show_overworld_map_;
}
if (toolbar.AddAction(ICON_MD_TITLE, "Title Screen")) {
show_title_screen_ = !show_title_screen_;
}
if (toolbar.AddAction(ICON_MD_EDIT_ATTRIBUTES, "Naming Screen")) {
show_naming_screen_ = !show_naming_screen_;
}
toolbar.End();
} }
void ScreenEditor::DrawInventoryMenuEditor() { void ScreenEditor::DrawInventoryMenuEditor() {

View File

@@ -85,17 +85,8 @@ absl::Status SpriteEditor::Update() {
} }
void SpriteEditor::DrawToolset() { void SpriteEditor::DrawToolset() {
static gui::Toolset toolbar; // Sidebar is now drawn by EditorManager for card-based editors
toolbar.Begin(); // This method kept for compatibility but sidebar handles card toggles
if (toolbar.AddAction(ICON_MD_PEST_CONTROL_RODENT, "Vanilla Sprites")) {
show_vanilla_editor_ = !show_vanilla_editor_;
}
if (toolbar.AddAction(ICON_MD_ADD_MODERATOR, "Custom Sprites")) {
show_custom_editor_ = !show_custom_editor_;
}
toolbar.End();
} }

View File

@@ -723,9 +723,6 @@ void EditorCardManager::SetActiveCategory(const std::string& category) {
} }
void EditorCardManager::DrawSidebar(const std::string& category) { void EditorCardManager::DrawSidebar(const std::string& category) {
// Set this category as active when sidebar is drawn
SetActiveCategory(category);
// Use ThemeManager for consistent theming // Use ThemeManager for consistent theming
const auto& theme = ThemeManager::Get().GetCurrentTheme(); const auto& theme = ThemeManager::Get().GetCurrentTheme();
@@ -744,15 +741,46 @@ void EditorCardManager::DrawSidebar(const std::string& category) {
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoScrollWithMouse |
ImGuiWindowFlags_NoBringToFrontOnFocus; ImGuiWindowFlags_NoBringToFrontOnFocus;
ImGui::PushStyleColor(ImGuiCol_WindowBg, ConvertColorToImVec4(theme.child_bg)); // Make sidebar more opaque and visible
ImVec4 sidebar_bg = ConvertColorToImVec4(theme.child_bg);
sidebar_bg.w = 1.0f; // Full opacity
ImGui::PushStyleColor(ImGuiCol_WindowBg, sidebar_bg);
ImGui::PushStyleColor(ImGuiCol_Border, ConvertColorToImVec4(theme.border));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(4.0f, 8.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(4.0f, 8.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 6.0f)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 6.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
if (ImGui::Begin(absl::StrFormat("##%s_Sidebar", category).c_str(), nullptr, sidebar_flags)) { if (ImGui::Begin("##EditorCardSidebar", nullptr, sidebar_flags)) {
// Get cards for this category // Get cards for this category
auto cards = GetCardsInCategory(category); auto cards = GetCardsInCategory(category);
// Close All button at top // If no cards available, show editor selection instead
if (cards.empty()) {
ImGui::PushStyleColor(ImGuiCol_Text, ConvertColorToImVec4(theme.text_disabled));
ImGui::TextWrapped("No cards");
ImGui::PopStyleColor();
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
// Show editor selection buttons
ImGui::TextWrapped("Select Editor:");
ImGui::Dummy(ImVec2(0, 4.0f));
// TODO: Add editor selection buttons here
// For now, just show message
ImGui::PushStyleColor(ImGuiCol_Text, ConvertColorToImVec4(theme.text_secondary));
ImGui::TextWrapped("Open an editor to see cards");
ImGui::PopStyleColor();
} else {
// Set this category as active when cards are present
SetActiveCategory(category);
}
// Close All button at top (only if cards exist)
if (!cards.empty()) {
ImVec4 error_color = ConvertColorToImVec4(theme.error); ImVec4 error_color = ConvertColorToImVec4(theme.error);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4( ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(
error_color.x * 0.6f, error_color.y * 0.6f, error_color.z * 0.6f, 0.7f)); error_color.x * 0.6f, error_color.y * 0.6f, error_color.z * 0.6f, 0.7f));
@@ -809,11 +837,12 @@ void EditorCardManager::DrawSidebar(const std::string& category) {
ImGui::PopID(); ImGui::PopID();
} }
} // End if (!cards.empty())
} }
ImGui::End(); ImGui::End();
ImGui::PopStyleVar(2); ImGui::PopStyleVar(3); // WindowPadding, ItemSpacing, WindowBorderSize
ImGui::PopStyleColor(); ImGui::PopStyleColor(2); // WindowBg, Border
} }
} // namespace gui } // namespace gui