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

View File

@@ -169,23 +169,8 @@ absl::Status GraphicsEditor::Update() {
}
void GraphicsEditor::DrawToolset() {
static gui::Toolset toolbar;
toolbar.Begin();
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();
// Sidebar is now drawn by EditorManager for card-based editors
// This method kept for compatibility but sidebar handles card toggles
}

View File

@@ -164,26 +164,8 @@ absl::Status ScreenEditor::Update() {
}
void ScreenEditor::DrawToolset() {
static gui::Toolset toolbar;
toolbar.Begin();
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();
// Sidebar is now drawn by EditorManager for card-based editors
// This method kept for compatibility but sidebar handles card toggles
}
void ScreenEditor::DrawInventoryMenuEditor() {

View File

@@ -85,17 +85,8 @@ absl::Status SpriteEditor::Update() {
}
void SpriteEditor::DrawToolset() {
static gui::Toolset toolbar;
toolbar.Begin();
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();
// Sidebar is now drawn by EditorManager for card-based editors
// This method kept for compatibility but sidebar handles card toggles
}

View File

@@ -723,9 +723,6 @@ void EditorCardManager::SetActiveCategory(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
const auto& theme = ThemeManager::Get().GetCurrentTheme();
@@ -744,76 +741,108 @@ void EditorCardManager::DrawSidebar(const std::string& category) {
ImGuiWindowFlags_NoScrollWithMouse |
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_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
auto cards = GetCardsInCategory(category);
// Close All button at top
ImVec4 error_color = ConvertColorToImVec4(theme.error);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(
error_color.x * 0.6f, error_color.y * 0.6f, error_color.z * 0.6f, 0.7f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, error_color);
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(
error_color.x * 1.2f, error_color.y * 1.2f, error_color.z * 1.2f, 1.0f));
if (ImGui::Button(ICON_MD_CLOSE, ImVec2(40.0f, 40.0f))) {
HideAllCardsInCategory(category);
}
ImGui::PopStyleColor(3);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Close All %s Cards", category.c_str());
}
ImGui::Dummy(ImVec2(0, 4.0f));
// Draw card buttons
ImVec4 accent_color = ConvertColorToImVec4(theme.accent);
ImVec4 button_bg = ConvertColorToImVec4(theme.button);
for (const auto& card : cards) {
ImGui::PushID(card.card_id.c_str());
bool is_active = card.visibility_flag && *card.visibility_flag;
// 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();
if (is_active) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(
accent_color.x, accent_color.y, accent_color.z, 0.5f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(
accent_color.x, accent_color.y, accent_color.z, 0.7f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, accent_color);
} else {
ImGui::PushStyleColor(ImGuiCol_Button, button_bg);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.button_hovered));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.button_active));
}
if (ImGui::Button(card.icon.c_str(), ImVec2(40.0f, 40.0f))) {
ToggleCard(card.card_id);
SetActiveCategory(category);
}
ImGui::PopStyleColor(3);
if (ImGui::IsItemHovered() || ImGui::IsItemActive()) {
SetActiveCategory(category);
ImGui::SetTooltip("%s\n%s", card.display_name.c_str(),
card.shortcut_hint.empty() ? "" : card.shortcut_hint.c_str());
}
ImGui::PopID();
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);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(
error_color.x * 0.6f, error_color.y * 0.6f, error_color.z * 0.6f, 0.7f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, error_color);
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(
error_color.x * 1.2f, error_color.y * 1.2f, error_color.z * 1.2f, 1.0f));
if (ImGui::Button(ICON_MD_CLOSE, ImVec2(40.0f, 40.0f))) {
HideAllCardsInCategory(category);
}
ImGui::PopStyleColor(3);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Close All %s Cards", category.c_str());
}
ImGui::Dummy(ImVec2(0, 4.0f));
// Draw card buttons
ImVec4 accent_color = ConvertColorToImVec4(theme.accent);
ImVec4 button_bg = ConvertColorToImVec4(theme.button);
for (const auto& card : cards) {
ImGui::PushID(card.card_id.c_str());
bool is_active = card.visibility_flag && *card.visibility_flag;
if (is_active) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(
accent_color.x, accent_color.y, accent_color.z, 0.5f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(
accent_color.x, accent_color.y, accent_color.z, 0.7f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, accent_color);
} else {
ImGui::PushStyleColor(ImGuiCol_Button, button_bg);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.button_hovered));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.button_active));
}
if (ImGui::Button(card.icon.c_str(), ImVec2(40.0f, 40.0f))) {
ToggleCard(card.card_id);
SetActiveCategory(category);
}
ImGui::PopStyleColor(3);
if (ImGui::IsItemHovered() || ImGui::IsItemActive()) {
SetActiveCategory(category);
ImGui::SetTooltip("%s\n%s", card.display_name.c_str(),
card.shortcut_hint.empty() ? "" : card.shortcut_hint.c_str());
}
ImGui::PopID();
}
} // End if (!cards.empty())
}
ImGui::End();
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
ImGui::PopStyleVar(3); // WindowPadding, ItemSpacing, WindowBorderSize
ImGui::PopStyleColor(2); // WindowBg, Border
}
} // namespace gui