From a97487fd2c91d141b8ec1666ba3a8cedb5e1bc95 Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 24 Aug 2024 08:38:47 -0400 Subject: [PATCH] Refactor EditorManager --- src/app/editor/editor_manager.cc | 9 ++++---- src/app/editor/editor_manager.h | 22 ++++++++------------ src/app/gui/input.cc | 1 - src/app/gui/input.h | 8 +++----- src/app/rom.h | 35 ++++++++++++++++---------------- 5 files changed, 32 insertions(+), 43 deletions(-) diff --git a/src/app/editor/editor_manager.cc b/src/app/editor/editor_manager.cc index 04e35847..d03467b2 100644 --- a/src/app/editor/editor_manager.cc +++ b/src/app/editor/editor_manager.cc @@ -307,17 +307,16 @@ void EditorManager::ManageKeyboardShortcuts() { } } -void EditorManager::DrawFileDialog() {} - void EditorManager::DrawStatusPopup() { + static absl::Status prev_status; if (!status_.ok()) { show_status_ = true; - prev_status_ = status_; + prev_status = status_; } if (show_status_ && (BeginCentered("StatusWindow"))) { Text("%s", ICON_MD_ERROR); - Text("%s", prev_status_.ToString().c_str()); + Text("%s", prev_status.ToString().c_str()); Spacing(); NextColumn(); Columns(1); @@ -331,7 +330,7 @@ void EditorManager::DrawStatusPopup() { } SameLine(); if (Button(ICON_MD_CONTENT_COPY, ImVec2(50, 0))) { - SetClipboardText(prev_status_.ToString().c_str()); + SetClipboardText(prev_status.ToString().c_str()); } End(); } diff --git a/src/app/editor/editor_manager.h b/src/app/editor/editor_manager.h index 4ef14728..9cbbce49 100644 --- a/src/app/editor/editor_manager.h +++ b/src/app/editor/editor_manager.h @@ -6,7 +6,6 @@ #include "ImGuiColorTextEdit/TextEditor.h" #include "ImGuiFileDialog/ImGuiFileDialog.h" #include "absl/status/status.h" - #include "app/core/constants.h" #include "app/core/message.h" #include "app/core/project.h" @@ -42,8 +41,8 @@ namespace editor { /** * @class EditorManager - * @brief The EditorManager class represents the main editor for a Rom in the - * Yaze application. + * @brief The EditorManager controls the main editor window and manages the + * various editor classes. * * This class inherits from SharedRom, GfxContext, and ExperimentFlags, and * provides functionality for setting up the screen, updating the editor, and @@ -58,9 +57,7 @@ namespace editor { * @note This class assumes the presence of an SDL_Renderer object for rendering * graphics. */ -class EditorManager : public SharedRom, - public context::GfxContext, - public core::ExperimentFlags { +class EditorManager : public SharedRom, public core::ExperimentFlags { public: EditorManager() { current_editor_ = &overworld_editor_; @@ -77,13 +74,11 @@ class EditorManager : public SharedRom, auto emulator() -> emu::Emulator& { return emulator_; } auto quit() { return quit_; } - auto overworld_editor() -> OverworldEditor& { return overworld_editor_; } private: void ManageActiveEditors(); void ManageKeyboardShortcuts(); - void DrawFileDialog(); void DrawStatusPopup(); void DrawAboutPopup(); void DrawInfoPopup(); @@ -106,15 +101,18 @@ class EditorManager : public SharedRom, bool rom_assets_loaded_ = false; absl::Status status_; - absl::Status prev_status_; + ImVector active_tabs_; + std::vector active_editors_; + + core::MessageDispatcher dispatcher_; emu::Emulator emulator_; Project current_project_; yaze_editor_context editor_context_; ExtensionManager extension_manager_; - core::MessageDispatcher dispatcher_; + Editor* current_editor_ = nullptr; AssemblyEditor assembly_editor_; DungeonEditor dungeon_editor_; GraphicsEditor graphics_editor_; @@ -126,10 +124,6 @@ class EditorManager : public SharedRom, SettingsEditor settings_editor_; MessageEditor message_editor_; MemoryEditorWithDiffChecker memory_editor_; - - ImVector active_tabs_; - std::vector active_editors_; - Editor* current_editor_ = nullptr; }; } // namespace editor diff --git a/src/app/gui/input.cc b/src/app/gui/input.cc index c4ad7966..68ed413a 100644 --- a/src/app/gui/input.cc +++ b/src/app/gui/input.cc @@ -6,7 +6,6 @@ #include "ImGuiFileDialog/ImGuiFileDialog.h" #include "absl/strings/string_view.h" - #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" #include "app/gui/canvas.h" diff --git a/src/app/gui/input.h b/src/app/gui/input.h index eb56235a..040c286f 100644 --- a/src/app/gui/input.h +++ b/src/app/gui/input.h @@ -3,10 +3,6 @@ #define IMGUI_DEFINE_MATH_OPERATORS -#include "imgui/imgui.h" -#include "imgui/misc/cpp/imgui_stdlib.h" -#include "imgui_memory_editor.h" - #include #include #include @@ -15,11 +11,13 @@ #include #include "absl/strings/string_view.h" - #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" #include "app/gui/canvas.h" #include "app/gui/color.h" +#include "imgui/imgui.h" +#include "imgui/misc/cpp/imgui_stdlib.h" +#include "imgui_memory_editor.h" namespace yaze { namespace app { diff --git a/src/app/rom.h b/src/app/rom.h index f9f62518..60ae946e 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -452,14 +452,7 @@ class Rom : public core::ExperimentFlags { return rom_data_[i]; } - core::ResourceLabelManager* resource_label() { - return &resource_label_manager_; - } - VersionConstants version_constants() const { - return kVersionConstantsMap.at(version_); - } - - auto is_loaded() const { + bool is_loaded() const { if (!absl::StrContains(filename_, ".sfc") && !absl::StrContains(filename_, ".smc")) { return false; @@ -470,9 +463,18 @@ class Rom : public core::ExperimentFlags { // Full graphical data for the game std::vector graphics_buffer() const { return graphics_buffer_; } + auto title() const { return title_; } + auto size() const { return size_; } + auto begin() { return rom_data_.begin(); } + auto end() { return rom_data_.end(); } + auto data() { return rom_data_.data(); } + auto vector() const { return rom_data_; } + auto version() const { return version_; } + auto filename() const { return filename_; } + auto set_filename(std::string name) { filename_ = name; } + auto link_graphics() { return link_graphics_; } auto mutable_link_graphics() { return &link_graphics_; } - auto gfx_sheets() { return graphics_sheets_; } auto mutable_gfx_sheets() { return &graphics_sheets_; } @@ -483,15 +485,12 @@ class Rom : public core::ExperimentFlags { return palette_groups_.dungeon_main.mutable_palette(i); } - auto title() const { return title_; } - auto size() const { return size_; } - auto begin() { return rom_data_.begin(); } - auto end() { return rom_data_.end(); } - auto data() { return rom_data_.data(); } - auto vector() const { return rom_data_; } - auto version() const { return version_; } - auto filename() const { return filename_; } - auto set_filename(std::string name) { filename_ = name; } + core::ResourceLabelManager* resource_label() { + return &resource_label_manager_; + } + VersionConstants version_constants() const { + return kVersionConstantsMap.at(version_); + } std::vector> main_blockset_ids; std::vector> room_blockset_ids;