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:
@@ -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);
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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,76 +741,108 @@ 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
|
||||||
ImVec4 error_color = ConvertColorToImVec4(theme.error);
|
if (cards.empty()) {
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(
|
ImGui::PushStyleColor(ImGuiCol_Text, ConvertColorToImVec4(theme.text_disabled));
|
||||||
error_color.x * 0.6f, error_color.y * 0.6f, error_color.z * 0.6f, 0.7f));
|
ImGui::TextWrapped("No cards");
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, error_color);
|
ImGui::PopStyleColor();
|
||||||
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::Spacing();
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(
|
ImGui::Separator();
|
||||||
accent_color.x, accent_color.y, accent_color.z, 0.5f));
|
ImGui::Spacing();
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(
|
|
||||||
accent_color.x, accent_color.y, accent_color.z, 0.7f));
|
// Show editor selection buttons
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, accent_color);
|
ImGui::TextWrapped("Select Editor:");
|
||||||
} else {
|
ImGui::Dummy(ImVec2(0, 4.0f));
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, button_bg);
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ConvertColorToImVec4(theme.button_hovered));
|
// TODO: Add editor selection buttons here
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ConvertColorToImVec4(theme.button_active));
|
// For now, just show message
|
||||||
}
|
ImGui::PushStyleColor(ImGuiCol_Text, ConvertColorToImVec4(theme.text_secondary));
|
||||||
|
ImGui::TextWrapped("Open an editor to see cards");
|
||||||
if (ImGui::Button(card.icon.c_str(), ImVec2(40.0f, 40.0f))) {
|
ImGui::PopStyleColor();
|
||||||
ToggleCard(card.card_id);
|
} else {
|
||||||
SetActiveCategory(category);
|
// Set this category as active when cards are present
|
||||||
}
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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::End();
|
||||||
|
|
||||||
ImGui::PopStyleVar(2);
|
ImGui::PopStyleVar(3); // WindowPadding, ItemSpacing, WindowBorderSize
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor(2); // WindowBg, Border
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
Reference in New Issue
Block a user