From b5465be6d35db932efddec5136eb3b8d80d50cc1 Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 13 Jul 2024 17:19:10 -0400 Subject: [PATCH] add ManageActiveEditors, reorderable tabbed editor view --- src/app/editor/master_editor.cc | 177 ++++++++++++++++++++++---------- src/app/editor/master_editor.h | 7 +- 2 files changed, 131 insertions(+), 53 deletions(-) diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index 92ba88dd..4e056fce 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -169,64 +169,137 @@ absl::Status MasterEditor::Update() { rom_assets_loaded_ = true; } - TAB_BAR("##TabBar") - auto current_tab_bar = ImGui::GetCurrentContext()->CurrentTabBar; - - if (overworld_editor_.jump_to_tab() == -1) { - if (ImGui::BeginTabItem("Overworld")) { - current_editor_ = &overworld_editor_; - status_ = overworld_editor_.Update(); - ImGui::EndTabItem(); - } - } - - if (ImGui::BeginTabItem("Dungeon")) { - current_editor_ = &dungeon_editor_; - status_ = dungeon_editor_.Update(); - if (overworld_editor_.jump_to_tab() != -1) { - dungeon_editor_.add_room(overworld_editor_.jump_to_tab()); - overworld_editor_.jump_to_tab_ = -1; - } - ImGui::EndTabItem(); - } - - if (ImGui::BeginTabItem("Graphics")) { - status_ = graphics_editor_.Update(); - ImGui::EndTabItem(); - } - - if (ImGui::BeginTabItem("Sprites")) { - status_ = sprite_editor_.Update(); - ImGui::EndTabItem(); - } - - if (ImGui::BeginTabItem("Palettes")) { - status_ = palette_editor_.Update(); - ImGui::EndTabItem(); - } - - if (ImGui::BeginTabItem("Screens")) { - screen_editor_.Update(); - ImGui::EndTabItem(); - } - - if (ImGui::BeginTabItem("Music")) { - music_editor_.Update(); - ImGui::EndTabItem(); - } - - if (ImGui::BeginTabItem("Code")) { - assembly_editor_.UpdateCodeView(); - ImGui::EndTabItem(); - } - - END_TAB_BAR() + ManageActiveEditors(); ImGui::End(); return absl::OkStatus(); } +void MasterEditor::ManageActiveEditors() { + // Show popup pane to select an editor to add + static bool show_add_editor = false; + if (show_add_editor) ImGui::OpenPopup("AddEditor"); + + if (ImGui::BeginPopup("AddEditor", ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::MenuItem("Overworld")) { + active_editors_.push_back(&overworld_editor_); + ImGui::CloseCurrentPopup(); + } + if (ImGui::MenuItem("Dungeon")) { + active_editors_.push_back(&dungeon_editor_); + ImGui::CloseCurrentPopup(); + } + if (ImGui::MenuItem("Graphics")) { + active_editors_.push_back(&graphics_editor_); + ImGui::CloseCurrentPopup(); + } + if (ImGui::MenuItem("Music")) { + active_editors_.push_back(&music_editor_); + ImGui::CloseCurrentPopup(); + } + if (ImGui::MenuItem("Palette")) { + active_editors_.push_back(&palette_editor_); + ImGui::CloseCurrentPopup(); + } + if (ImGui::MenuItem("Screen")) { + active_editors_.push_back(&screen_editor_); + ImGui::CloseCurrentPopup(); + } + if (ImGui::MenuItem("Sprite")) { + active_editors_.push_back(&sprite_editor_); + ImGui::CloseCurrentPopup(); + } + if (ImGui::MenuItem("Code")) { + active_editors_.push_back(&assembly_editor_); + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + + if (!ImGui::IsPopupOpen("AddEditor")) { + show_add_editor = false; + } + + if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_Reorderable | + ImGuiTabBarFlags_AutoSelectNewTabs)) { + for (auto editor : active_editors_) { + switch (editor->type()) { + case EditorType::kOverworld: + if (overworld_editor_.jump_to_tab() == -1) { + if (ImGui::BeginTabItem("Overworld")) { + current_editor_ = &overworld_editor_; + status_ = overworld_editor_.Update(); + ImGui::EndTabItem(); + } + } + break; + case EditorType::kDungeon: + if (ImGui::BeginTabItem("Dungeon")) { + current_editor_ = &dungeon_editor_; + status_ = dungeon_editor_.Update(); + if (overworld_editor_.jump_to_tab() != -1) { + dungeon_editor_.add_room(overworld_editor_.jump_to_tab()); + overworld_editor_.jump_to_tab_ = -1; + } + ImGui::EndTabItem(); + } + break; + case EditorType::kGraphics: + current_editor_ = &graphics_editor_; + if (ImGui::BeginTabItem("Graphics")) { + status_ = graphics_editor_.Update(); + ImGui::EndTabItem(); + } + break; + case EditorType::kMusic: + current_editor_ = &music_editor_; + if (ImGui::BeginTabItem("Music")) { + status_ = music_editor_.Update(); + ImGui::EndTabItem(); + } + break; + case EditorType::kPalette: + current_editor_ = &palette_editor_; + if (ImGui::BeginTabItem("Palette")) { + status_ = palette_editor_.Update(); + ImGui::EndTabItem(); + } + break; + case EditorType::kScreen: + current_editor_ = &screen_editor_; + if (ImGui::BeginTabItem("Screen")) { + status_ = screen_editor_.Update(); + ImGui::EndTabItem(); + } + break; + case EditorType::kSprite: + current_editor_ = &sprite_editor_; + if (ImGui::BeginTabItem("Sprite")) { + status_ = sprite_editor_.Update(); + ImGui::EndTabItem(); + } + break; + case EditorType::kAssembly: + if (ImGui::BeginTabItem("Code")) { + current_editor_ = &assembly_editor_; + assembly_editor_.UpdateCodeView(); + ImGui::EndTabItem(); + } + break; + default: + break; + } + } + + if (ImGui::TabItemButton("+", ImGuiTabItemFlags_Trailing)) { + show_add_editor = true; + } + + ImGui::EndTabBar(); + } +} + void MasterEditor::DrawFileDialog() { gui::FileDialogPipeline("ChooseFileDlgKey", ".sfc,.smc", std::nullopt, [&]() { std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); diff --git a/src/app/editor/master_editor.h b/src/app/editor/master_editor.h index d7f016c6..a17de6c6 100644 --- a/src/app/editor/master_editor.h +++ b/src/app/editor/master_editor.h @@ -12,10 +12,10 @@ #include "absl/status/status.h" #include "app/core/common.h" #include "app/core/constants.h" +#include "app/editor/code/assembly_editor.h" #include "app/editor/context/gfx_context.h" #include "app/editor/dungeon_editor.h" #include "app/editor/graphics_editor.h" -#include "app/editor/code/assembly_editor.h" #include "app/editor/modules/music_editor.h" #include "app/editor/modules/palette_editor.h" #include "app/editor/overworld_editor.h" @@ -66,6 +66,8 @@ class MasterEditor : public SharedRom, auto quit() { return quit_; } private: + void ManageActiveEditors(); + void DrawFileDialog(); void DrawStatusPopup(); void DrawAboutPopup(); @@ -104,6 +106,9 @@ class MasterEditor : public SharedRom, ScreenEditor screen_editor_; SpriteEditor sprite_editor_; + std::vector active_editors_; + ImVector active_tabs_; + Editor* current_editor_ = nullptr; };