add ManageActiveEditors, reorderable tabbed editor view

This commit is contained in:
scawful
2024-07-13 17:19:10 -04:00
parent 93d0aa2ca5
commit b5465be6d3
2 changed files with 131 additions and 53 deletions

View File

@@ -169,9 +169,63 @@ absl::Status MasterEditor::Update() {
rom_assets_loaded_ = true; rom_assets_loaded_ = true;
} }
TAB_BAR("##TabBar") ManageActiveEditors();
auto current_tab_bar = ImGui::GetCurrentContext()->CurrentTabBar;
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 (overworld_editor_.jump_to_tab() == -1) {
if (ImGui::BeginTabItem("Overworld")) { if (ImGui::BeginTabItem("Overworld")) {
current_editor_ = &overworld_editor_; current_editor_ = &overworld_editor_;
@@ -179,7 +233,8 @@ absl::Status MasterEditor::Update() {
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
} }
break;
case EditorType::kDungeon:
if (ImGui::BeginTabItem("Dungeon")) { if (ImGui::BeginTabItem("Dungeon")) {
current_editor_ = &dungeon_editor_; current_editor_ = &dungeon_editor_;
status_ = dungeon_editor_.Update(); status_ = dungeon_editor_.Update();
@@ -189,42 +244,60 @@ absl::Status MasterEditor::Update() {
} }
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
break;
case EditorType::kGraphics:
current_editor_ = &graphics_editor_;
if (ImGui::BeginTabItem("Graphics")) { if (ImGui::BeginTabItem("Graphics")) {
status_ = graphics_editor_.Update(); status_ = graphics_editor_.Update();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
break;
if (ImGui::BeginTabItem("Sprites")) { case EditorType::kMusic:
status_ = sprite_editor_.Update(); current_editor_ = &music_editor_;
if (ImGui::BeginTabItem("Music")) {
status_ = music_editor_.Update();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
break;
if (ImGui::BeginTabItem("Palettes")) { case EditorType::kPalette:
current_editor_ = &palette_editor_;
if (ImGui::BeginTabItem("Palette")) {
status_ = palette_editor_.Update(); status_ = palette_editor_.Update();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
break;
if (ImGui::BeginTabItem("Screens")) { case EditorType::kScreen:
screen_editor_.Update(); current_editor_ = &screen_editor_;
if (ImGui::BeginTabItem("Screen")) {
status_ = screen_editor_.Update();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
break;
if (ImGui::BeginTabItem("Music")) { case EditorType::kSprite:
music_editor_.Update(); current_editor_ = &sprite_editor_;
if (ImGui::BeginTabItem("Sprite")) {
status_ = sprite_editor_.Update();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
break;
case EditorType::kAssembly:
if (ImGui::BeginTabItem("Code")) { if (ImGui::BeginTabItem("Code")) {
current_editor_ = &assembly_editor_;
assembly_editor_.UpdateCodeView(); assembly_editor_.UpdateCodeView();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
break;
default:
break;
}
}
END_TAB_BAR() if (ImGui::TabItemButton("+", ImGuiTabItemFlags_Trailing)) {
show_add_editor = true;
}
ImGui::End(); ImGui::EndTabBar();
}
return absl::OkStatus();
} }
void MasterEditor::DrawFileDialog() { void MasterEditor::DrawFileDialog() {

View File

@@ -12,10 +12,10 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/core/common.h" #include "app/core/common.h"
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/editor/code/assembly_editor.h"
#include "app/editor/context/gfx_context.h" #include "app/editor/context/gfx_context.h"
#include "app/editor/dungeon_editor.h" #include "app/editor/dungeon_editor.h"
#include "app/editor/graphics_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/music_editor.h"
#include "app/editor/modules/palette_editor.h" #include "app/editor/modules/palette_editor.h"
#include "app/editor/overworld_editor.h" #include "app/editor/overworld_editor.h"
@@ -66,6 +66,8 @@ class MasterEditor : public SharedRom,
auto quit() { return quit_; } auto quit() { return quit_; }
private: private:
void ManageActiveEditors();
void DrawFileDialog(); void DrawFileDialog();
void DrawStatusPopup(); void DrawStatusPopup();
void DrawAboutPopup(); void DrawAboutPopup();
@@ -104,6 +106,9 @@ class MasterEditor : public SharedRom,
ScreenEditor screen_editor_; ScreenEditor screen_editor_;
SpriteEditor sprite_editor_; SpriteEditor sprite_editor_;
std::vector<Editor*> active_editors_;
ImVector<int> active_tabs_;
Editor* current_editor_ = nullptr; Editor* current_editor_ = nullptr;
}; };