- Moved core components such as `Controller` and `Window` from `src/app/core/` to `src/app/` and `src/app/platform/`, respectively, to improve modularity and clarity. - Updated include paths across the codebase to reflect the new locations of these components. - Introduced a new foundational core library in `src/core/` for project management and ROM patching logic, enhancing the separation of concerns. - Adjusted CMake configurations to ensure proper compilation of the new core library and updated dependencies in various modules. Benefits: - Streamlines the application structure, making it easier to navigate and maintain. - Enhances code organization by clearly delineating core functionalities from application-specific logic. - Improves overall architecture by promoting a clearer separation of concerns between different components.
348 lines
12 KiB
C++
348 lines
12 KiB
C++
#ifndef YAZE_APP_EDITOR_EDITOR_MANAGER_H
|
|
#define YAZE_APP_EDITOR_EDITOR_MANAGER_H
|
|
|
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
|
|
|
#include "app/editor/editor.h"
|
|
#include "app/editor/system/user_settings.h"
|
|
#include "app/editor/ui/workspace_manager.h"
|
|
#include "app/editor/session_types.h"
|
|
|
|
#include "imgui/imgui.h"
|
|
|
|
#include <cstddef>
|
|
#include <deque>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "absl/status/status.h"
|
|
#include "core/project.h"
|
|
#include "app/editor/agent/agent_chat_history_popup.h"
|
|
#include "app/editor/code/project_file_editor.h"
|
|
#include "app/editor/system/editor_card_registry.h"
|
|
#include "app/editor/system/editor_registry.h"
|
|
#include "app/editor/system/menu_orchestrator.h"
|
|
#include "app/editor/system/popup_manager.h"
|
|
#include "app/editor/system/project_manager.h"
|
|
#include "app/editor/system/proposal_drawer.h"
|
|
#include "app/editor/system/rom_file_manager.h"
|
|
#include "app/editor/system/session_coordinator.h"
|
|
#include "app/editor/system/toast_manager.h"
|
|
#include "app/editor/system/window_delegate.h"
|
|
#include "app/editor/ui/editor_selection_dialog.h"
|
|
#include "app/editor/ui/layout_manager.h"
|
|
#include "app/editor/ui/menu_builder.h"
|
|
#include "app/editor/ui/ui_coordinator.h"
|
|
#include "app/editor/ui/welcome_screen.h"
|
|
#include "app/emu/emulator.h"
|
|
#include "zelda3/overworld/overworld.h"
|
|
#include "app/rom.h"
|
|
#include "yaze_config.h"
|
|
|
|
#ifdef YAZE_WITH_GRPC
|
|
#include "app/editor/agent/agent_editor.h"
|
|
#include "app/editor/agent/automation_bridge.h"
|
|
|
|
// Forward declarations for gRPC-dependent types
|
|
namespace yaze::agent {
|
|
class AgentControlServer;
|
|
}
|
|
#endif
|
|
|
|
namespace yaze {
|
|
namespace editor {
|
|
|
|
/**
|
|
* @class EditorManager
|
|
* @brief The EditorManager controls the main editor window and manages the
|
|
* various editor classes.
|
|
*
|
|
* The EditorManager class contains instances of various editor classes such as
|
|
* AssemblyEditor, DungeonEditor, GraphicsEditor, MusicEditor, OverworldEditor,
|
|
* PaletteEditor, ScreenEditor, and SpriteEditor. The current_editor_ member
|
|
* variable points to the currently active editor in the tab view.
|
|
*
|
|
*/
|
|
class EditorManager {
|
|
public:
|
|
// Constructor and destructor must be defined in .cc file for std::unique_ptr with forward-declared types
|
|
EditorManager();
|
|
~EditorManager();
|
|
|
|
void Initialize(gfx::IRenderer* renderer, const std::string& filename = "");
|
|
|
|
// Processes startup flags to open a specific editor and cards.
|
|
void OpenEditorAndCardsFromFlags(const std::string& editor_name,
|
|
const std::string& cards_str);
|
|
absl::Status Update();
|
|
void DrawMenuBar();
|
|
|
|
auto emulator() -> emu::Emulator& { return emulator_; }
|
|
auto quit() const { return quit_; }
|
|
auto version() const { return version_; }
|
|
|
|
MenuBuilder& menu_builder() { return menu_builder_; }
|
|
WorkspaceManager* workspace_manager() { return &workspace_manager_; }
|
|
|
|
absl::Status SetCurrentRom(Rom* rom);
|
|
auto GetCurrentRom() const -> Rom* { return session_coordinator_ ? session_coordinator_->GetCurrentRom() : nullptr; }
|
|
auto GetCurrentEditorSet() const -> EditorSet* { return session_coordinator_ ? session_coordinator_->GetCurrentEditorSet() : nullptr; }
|
|
auto GetCurrentEditor() const -> Editor* { return current_editor_; }
|
|
size_t GetCurrentSessionId() const { return session_coordinator_ ? session_coordinator_->GetActiveSessionIndex() : 0; }
|
|
UICoordinator* ui_coordinator() { return ui_coordinator_.get(); }
|
|
auto overworld() const -> yaze::zelda3::Overworld* {
|
|
if (auto* editor_set = GetCurrentEditorSet()) {
|
|
return &editor_set->overworld_editor_.overworld();
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
// Session management helpers
|
|
size_t GetCurrentSessionIndex() const;
|
|
|
|
// Get current session's feature flags (falls back to global if no session)
|
|
core::FeatureFlags::Flags* GetCurrentFeatureFlags() {
|
|
size_t current_index = GetCurrentSessionIndex();
|
|
if (current_index < sessions_.size()) {
|
|
return &sessions_[current_index].feature_flags;
|
|
}
|
|
return &core::FeatureFlags::get(); // Fallback to global
|
|
}
|
|
|
|
void SetFontGlobalScale(float scale) {
|
|
user_settings_.prefs().font_global_scale = scale;
|
|
ImGui::GetIO().FontGlobalScale = scale;
|
|
auto status = user_settings_.Save();
|
|
if (!status.ok()) {
|
|
LOG_WARN("EditorManager", "Failed to save user settings: %s",
|
|
status.ToString().c_str());
|
|
}
|
|
}
|
|
|
|
// Workspace management (delegates to WorkspaceManager)
|
|
void RefreshWorkspacePresets() { workspace_manager_.RefreshPresets(); }
|
|
void SaveWorkspacePreset(const std::string& name) {
|
|
workspace_manager_.SaveWorkspacePreset(name);
|
|
}
|
|
void LoadWorkspacePreset(const std::string& name) {
|
|
workspace_manager_.LoadWorkspacePreset(name);
|
|
}
|
|
|
|
// Jump-to functionality for cross-editor navigation
|
|
void JumpToDungeonRoom(int room_id);
|
|
void JumpToOverworldMap(int map_id);
|
|
void SwitchToEditor(EditorType editor_type);
|
|
|
|
// Card-based editor registry
|
|
static bool IsCardBasedEditor(EditorType type);
|
|
bool IsSidebarVisible() const {
|
|
return ui_coordinator_ ? ui_coordinator_->IsCardSidebarVisible() : false;
|
|
}
|
|
void SetSidebarVisible(bool visible) {
|
|
if (ui_coordinator_) {
|
|
ui_coordinator_->SetCardSidebarVisible(visible);
|
|
}
|
|
}
|
|
|
|
// Clean up cards when switching editors
|
|
void HideCurrentEditorCards();
|
|
|
|
// Session management
|
|
void CreateNewSession();
|
|
void DuplicateCurrentSession();
|
|
void CloseCurrentSession();
|
|
void RemoveSession(size_t index);
|
|
void SwitchToSession(size_t index);
|
|
size_t GetActiveSessionCount() const;
|
|
|
|
// Workspace layout management
|
|
// Window management - inline delegation (reduces EditorManager bloat)
|
|
void SaveWorkspaceLayout() { window_delegate_.SaveWorkspaceLayout(); }
|
|
void LoadWorkspaceLayout() { window_delegate_.LoadWorkspaceLayout(); }
|
|
void ResetWorkspaceLayout() { window_delegate_.ResetWorkspaceLayout(); }
|
|
void ShowAllWindows() {
|
|
if (ui_coordinator_)
|
|
ui_coordinator_->ShowAllWindows();
|
|
}
|
|
void HideAllWindows() {
|
|
if (ui_coordinator_)
|
|
ui_coordinator_->HideAllWindows();
|
|
}
|
|
|
|
// Layout presets (inline delegation)
|
|
void LoadDeveloperLayout() { window_delegate_.LoadDeveloperLayout(); }
|
|
void LoadDesignerLayout() { window_delegate_.LoadDesignerLayout(); }
|
|
void LoadModderLayout() { window_delegate_.LoadModderLayout(); }
|
|
|
|
// Helper methods
|
|
std::string GenerateUniqueEditorTitle(EditorType type,
|
|
size_t session_index) const;
|
|
bool HasDuplicateSession(const std::string& filepath);
|
|
void RenameSession(size_t index, const std::string& new_name);
|
|
void Quit() { quit_ = true; }
|
|
|
|
// UI visibility controls (public for MenuOrchestrator)
|
|
// UI visibility controls - inline for performance (single-line wrappers delegating to UICoordinator)
|
|
void ShowGlobalSearch() {
|
|
if (ui_coordinator_)
|
|
ui_coordinator_->ShowGlobalSearch();
|
|
}
|
|
void ShowCommandPalette() {
|
|
if (ui_coordinator_)
|
|
ui_coordinator_->ShowCommandPalette();
|
|
}
|
|
void ShowPerformanceDashboard() {
|
|
if (ui_coordinator_)
|
|
ui_coordinator_->SetPerformanceDashboardVisible(true);
|
|
}
|
|
void ShowImGuiDemo() {
|
|
if (ui_coordinator_)
|
|
ui_coordinator_->SetImGuiDemoVisible(true);
|
|
}
|
|
void ShowImGuiMetrics() {
|
|
if (ui_coordinator_)
|
|
ui_coordinator_->SetImGuiMetricsVisible(true);
|
|
}
|
|
void ShowHexEditor();
|
|
void ShowEmulator() { if (ui_coordinator_) ui_coordinator_->SetEmulatorVisible(true); }
|
|
void ShowMemoryEditor() { if (ui_coordinator_) ui_coordinator_->SetMemoryEditorVisible(true); }
|
|
void ShowResourceLabelManager() { if (ui_coordinator_) ui_coordinator_->SetResourceLabelManagerVisible(true); }
|
|
void ShowCardBrowser() {
|
|
if (ui_coordinator_)
|
|
ui_coordinator_->ShowCardBrowser();
|
|
}
|
|
void ShowWelcomeScreen() {
|
|
if (ui_coordinator_)
|
|
ui_coordinator_->SetWelcomeScreenVisible(true);
|
|
}
|
|
|
|
#ifdef YAZE_ENABLE_TESTING
|
|
void ShowTestDashboard() { show_test_dashboard_ = true; }
|
|
#endif
|
|
|
|
#ifdef YAZE_WITH_GRPC
|
|
void ShowAIAgent();
|
|
void ShowChatHistory();
|
|
void ShowProposalDrawer() { proposal_drawer_.Show(); }
|
|
#endif
|
|
|
|
// ROM and Project operations (public for MenuOrchestrator)
|
|
absl::Status LoadRom();
|
|
absl::Status SaveRom();
|
|
absl::Status SaveRomAs(const std::string& filename);
|
|
absl::Status OpenRomOrProject(const std::string& filename);
|
|
absl::Status CreateNewProject(
|
|
const std::string& template_name = "Basic ROM Hack");
|
|
absl::Status OpenProject();
|
|
absl::Status SaveProject();
|
|
absl::Status SaveProjectAs();
|
|
absl::Status ImportProject(const std::string& project_path);
|
|
absl::Status RepairCurrentProject();
|
|
|
|
private:
|
|
absl::Status DrawRomSelector() = delete; // Moved to UICoordinator
|
|
void DrawContextSensitiveCardControl(); // Card control for current editor
|
|
|
|
absl::Status LoadAssets();
|
|
|
|
// Testing system
|
|
void InitializeTestSuites();
|
|
|
|
bool quit_ = false;
|
|
|
|
// Note: All show_* flags are being moved to UICoordinator
|
|
// Access via ui_coordinator_->IsXxxVisible() or SetXxxVisible()
|
|
|
|
// Workspace dialog flags (managed by EditorManager, not UI)
|
|
bool show_workspace_layout = false;
|
|
size_t session_to_rename_ = 0;
|
|
char session_rename_buffer_[256] = {};
|
|
|
|
// Note: Most UI visibility flags have been moved to UICoordinator
|
|
// Access via ui_coordinator_->IsXxxVisible() or SetXxxVisible()
|
|
|
|
// Agent proposal drawer
|
|
ProposalDrawer proposal_drawer_;
|
|
bool show_proposal_drawer_ = false;
|
|
|
|
#ifdef YAZE_WITH_GRPC
|
|
AutomationBridge harness_telemetry_bridge_;
|
|
#endif
|
|
|
|
// Agent chat history popup
|
|
AgentChatHistoryPopup agent_chat_history_popup_;
|
|
bool show_chat_history_popup_ = false;
|
|
|
|
// Project file editor
|
|
ProjectFileEditor project_file_editor_;
|
|
|
|
// Note: Editor selection dialog and welcome screen are now managed by UICoordinator
|
|
// Kept here for backward compatibility during transition
|
|
EditorSelectionDialog editor_selection_dialog_;
|
|
WelcomeScreen welcome_screen_;
|
|
|
|
#ifdef YAZE_WITH_GRPC
|
|
// Agent editor - manages chat, collaboration, and network coordination
|
|
AgentEditor agent_editor_;
|
|
std::unique_ptr<yaze::agent::AgentControlServer> agent_control_server_;
|
|
#endif
|
|
|
|
std::string version_ = "";
|
|
absl::Status status_;
|
|
emu::Emulator emulator_;
|
|
|
|
public:
|
|
|
|
private:
|
|
std::deque<RomSession> sessions_;
|
|
Editor* current_editor_ = nullptr;
|
|
EditorSet blank_editor_set_{};
|
|
// Tracks which session is currently active so delegators (menus, popups,
|
|
// shortcuts) stay in sync without relying on per-editor context.
|
|
|
|
gfx::IRenderer* renderer_ = nullptr;
|
|
|
|
project::YazeProject current_project_;
|
|
EditorDependencies::SharedClipboard shared_clipboard_;
|
|
std::unique_ptr<PopupManager> popup_manager_;
|
|
ToastManager toast_manager_;
|
|
MenuBuilder menu_builder_;
|
|
ShortcutManager shortcut_manager_;
|
|
UserSettings user_settings_;
|
|
|
|
// New delegated components (dependency injection architecture)
|
|
EditorCardRegistry card_registry_; // Card management with session awareness
|
|
EditorRegistry editor_registry_;
|
|
std::unique_ptr<MenuOrchestrator> menu_orchestrator_;
|
|
ProjectManager project_manager_;
|
|
RomFileManager rom_file_manager_;
|
|
std::unique_ptr<UICoordinator> ui_coordinator_;
|
|
WindowDelegate window_delegate_;
|
|
std::unique_ptr<SessionCoordinator> session_coordinator_;
|
|
std::unique_ptr<LayoutManager> layout_manager_; // DockBuilder layout management
|
|
WorkspaceManager workspace_manager_{&toast_manager_};
|
|
|
|
float autosave_timer_ = 0.0f;
|
|
|
|
// RAII helper for clean session context switching
|
|
class SessionScope {
|
|
public:
|
|
SessionScope(EditorManager* manager, size_t session_id);
|
|
~SessionScope();
|
|
|
|
private:
|
|
EditorManager* manager_;
|
|
Rom* prev_rom_;
|
|
EditorSet* prev_editor_set_;
|
|
size_t prev_session_id_;
|
|
};
|
|
|
|
void ConfigureEditorDependencies(EditorSet* editor_set, Rom* rom,
|
|
size_t session_id);
|
|
};
|
|
|
|
} // namespace editor
|
|
} // namespace yaze
|
|
|
|
#endif // YAZE_APP_EDITOR_EDITOR_MANAGER_H
|