From d66476234418a119d4f6b55c601b730ae4d4333a Mon Sep 17 00:00:00 2001 From: scawful Date: Mon, 18 Nov 2024 14:07:22 -0500 Subject: [PATCH] Implement dynamic layout support and enhance window management commands in EditorManager --- src/app/editor/editor_manager.cc | 89 +++++++++++++++++++++++++++++++- src/app/editor/editor_manager.h | 13 +++-- 2 files changed, 97 insertions(+), 5 deletions(-) diff --git a/src/app/editor/editor_manager.cc b/src/app/editor/editor_manager.cc index 1a440e81..6843c787 100644 --- a/src/app/editor/editor_manager.cc +++ b/src/app/editor/editor_manager.cc @@ -19,6 +19,7 @@ #include "app/gui/input.h" #include "app/gui/style.h" #include "app/rom.h" +#include "editor/editor.h" #include "imgui/imgui.h" #include "imgui/misc/cpp/imgui_stdlib.h" @@ -71,7 +72,10 @@ absl::Status EditorManager::Update() { rom_assets_loaded_ = true; } - ManageActiveEditors(); + if (dynamic_layout_) + RETURN_IF_ERROR(DrawDynamicLayout()) + else + ManageActiveEditors(); return absl::OkStatus(); } @@ -239,6 +243,13 @@ void EditorManager::ManageActiveEditors() { } } +absl::Status EditorManager::DrawDynamicLayout() { + // Dynamic layout for multiple editors to be open at once + // Allows for tiling and resizing of editors using ImGui + + return DrawEditor(&root_layout_); +} + void EditorManager::ManageKeyboardShortcuts() { bool ctrl_or_super = (GetIO().KeyCtrl || GetIO().KeySuper); @@ -298,6 +309,80 @@ void EditorManager::ManageKeyboardShortcuts() { } } +void EditorManager::InitializeCommands() { + if (root_layout_.editor == nullptr) { + root_layout_.editor = &overworld_editor_; + } + + // New editor popup for window management commands + static EditorLayoutParams new_layout; + if (ImGui::BeginPopup("NewEditor")) { + ImGui::Text("New Editor"); + ImGui::Separator(); + if (ImGui::Button("Overworld")) { + new_layout.editor = &overworld_editor_; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Dungeon")) { + new_layout.editor = &dungeon_editor_; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Graphics")) { + new_layout.editor = &graphics_editor_; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Music")) { + new_layout.editor = &music_editor_; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Palette")) { + new_layout.editor = &palette_editor_; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Screen")) { + new_layout.editor = &screen_editor_; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Sprite")) { + new_layout.editor = &sprite_editor_; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Code")) { + new_layout.editor = &assembly_editor_; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Settings")) { + new_layout.editor = &settings_editor_; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Message")) { + new_layout.editor = &message_editor_; + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + + command_manager_.RegisterPrefix("window", 'w', "window management", ""); + command_manager_.RegisterSubcommand( + "window", "vsplit", '/', "vertical split", + "split windows vertically and place editor in new window", [this]() { + ImGui::OpenPopup("NewEditor"); + root_layout_.v_split = true; + }); + command_manager_.RegisterSubcommand( + "window", "hsplit", '-', "horizontal split", + "split windows horizontally and place editor in new window", [this]() { + ImGui::OpenPopup("NewEditor"); + root_layout_.h_split = true; + }); + command_manager_.RegisterSubcommand("window", "close", 'd', "close", + "close the current editor", [this]() { + if (root_layout_.editor != nullptr) { + root_layout_.editor = nullptr; + } + }); +} + void EditorManager::DrawStatusPopup() { static absl::Status prev_status; if (!status_.ok()) { @@ -557,6 +642,7 @@ void EditorManager::DrawYazeMenuBar() { } if (BeginMenu("View")) { + MenuItem("Dynamic Layout", nullptr, &dynamic_layout_); MenuItem("Emulator", nullptr, &show_emulator); Separator(); MenuItem("Memory Editor", nullptr, &show_memory_editor); @@ -572,7 +658,6 @@ void EditorManager::DrawYazeMenuBar() { static bool show_resource_label_manager = false; if (current_project_.project_opened_) { - // Project Menu if (BeginMenu("Project")) { Text("Name: %s", current_project_.name.c_str()); Text("ROM: %s", current_project_.rom_filename_.c_str()); diff --git a/src/app/editor/editor_manager.h b/src/app/editor/editor_manager.h index 18f5c2f8..9f8168dd 100644 --- a/src/app/editor/editor_manager.h +++ b/src/app/editor/editor_manager.h @@ -67,7 +67,10 @@ class EditorManager : public SharedRom, public core::ExperimentFlags { private: void ManageActiveEditors(); + absl::Status DrawDynamicLayout(); + void ManageKeyboardShortcuts(); + void InitializeCommands(); void DrawStatusPopup(); void DrawAboutPopup(); @@ -89,20 +92,22 @@ class EditorManager : public SharedRom, public core::ExperimentFlags { bool save_new_auto_ = true; bool show_status_ = false; bool rom_assets_loaded_ = false; + bool dynamic_layout_ = false; absl::Status status_; - std::vector active_editors_; - emu::Emulator emulator_; + std::vector active_editors_; + std::vector active_layouts_; + Project current_project_; CommandManager command_manager_; ConstantManager constant_manager_; ExtensionManager extension_manager_; - yaze_editor_context editor_context_; Editor *current_editor_ = nullptr; + EditorLayoutParams root_layout_; AssemblyEditor assembly_editor_; DungeonEditor dungeon_editor_; GraphicsEditor graphics_editor_; @@ -114,6 +119,8 @@ class EditorManager : public SharedRom, public core::ExperimentFlags { SettingsEditor settings_editor_; MessageEditor message_editor_; MemoryEditorWithDiffChecker memory_editor_; + + yaze_editor_context editor_context_; }; } // namespace editor