yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
editor_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_EDITOR_MANAGER_H
2#define YAZE_APP_EDITOR_EDITOR_MANAGER_H
3
4#define IMGUI_DEFINE_MATH_OPERATORS
5
6#include <cstddef>
7#include <functional>
8#include <memory>
9#include <string>
10#include <vector>
11
12#include "absl/status/status.h"
15#include "app/editor/editor.h"
44#include "app/emu/emulator.h"
45#include "app/startup_flags.h"
46#include "rom/rom.h"
47#include "core/project.h"
49#include "imgui/imgui.h"
50#include "yaze_config.h"
52
53// Forward declarations for gRPC-dependent types
54namespace yaze::agent {
55class AgentControlServer;
56}
57
58namespace yaze {
59class CanvasAutomationServiceImpl;
60}
61
62namespace yaze::editor {
63class AgentEditor;
64}
65
66namespace yaze {
67
68// Forward declaration for AppConfig
69struct AppConfig;
70
71namespace editor {
72
87 public:
88 // Constructor and destructor must be defined in .cc file for std::unique_ptr
89 // with forward-declared types
91 ~EditorManager() override;
92
93 void Initialize(gfx::IRenderer* renderer, const std::string& filename = "");
94
95 // SessionObserver implementation
96 void OnSessionSwitched(size_t new_index, RomSession* session) override;
97 void OnSessionCreated(size_t index, RomSession* session) override;
98 void OnSessionClosed(size_t index) override;
99 void OnSessionRomLoaded(size_t index, RomSession* session) override;
100
101 // Processes startup flags to open a specific editor and panels.
102 void OpenEditorAndPanelsFromFlags(const std::string& editor_name,
103 const std::string& panels_str);
104
105 // Apply startup actions based on AppConfig
106 void ProcessStartupActions(const AppConfig& config);
107 void ApplyStartupVisibility(const AppConfig& config);
108
109 absl::Status Update();
110 void DrawMenuBar();
111
112 auto emulator() -> emu::Emulator& { return emulator_; }
113 auto quit() const { return quit_; }
114 auto version() const { return version_; }
115
116
123 const PanelManager& panel_manager() const { return panel_manager_; }
124
125 // Deprecated compatibility wrappers
127 const PanelManager& card_registry() const { return panel_manager_; }
128
129 // Layout offset calculation for dockspace adjustment
130 // Delegates to LayoutCoordinator for cleaner separation of concerns
140
141 absl::Status SetCurrentRom(Rom* rom);
142 auto GetCurrentRom() const -> Rom* {
143 return session_coordinator_ ? session_coordinator_->GetCurrentRom()
144 : nullptr;
145 }
146 auto GetCurrentGameData() const -> zelda3::GameData* {
147 return session_coordinator_ ? session_coordinator_->GetCurrentGameData()
148 : nullptr;
149 }
151 return session_coordinator_ ? session_coordinator_->GetCurrentEditorSet()
152 : nullptr;
153 }
154 auto GetCurrentEditor() const -> Editor* { return current_editor_; }
155 void SetCurrentEditor(Editor* editor) {
156 current_editor_ = editor;
157 // Update help panel's editor context for context-aware help
158 if (right_panel_manager_ && editor) {
159 right_panel_manager_->SetActiveEditor(editor->type());
160 }
161 }
162 size_t GetCurrentSessionId() const {
163 return session_coordinator_ ? session_coordinator_->GetActiveSessionIndex()
164 : 0;
165 }
167 auto overworld() const -> yaze::zelda3::Overworld* {
168 if (auto* editor_set = GetCurrentEditorSet()) {
169 return &editor_set->GetOverworldEditor()->overworld();
170 }
171 return nullptr;
172 }
173
174 // Session management helpers
175 size_t GetCurrentSessionIndex() const;
176
177 // Get current session's feature flags (falls back to global if no session)
179 size_t current_index = GetCurrentSessionIndex();
180 if (session_coordinator_ && current_index < session_coordinator_->GetTotalSessionCount()) {
181 auto* session = static_cast<RomSession*>(session_coordinator_->GetSession(current_index));
182 if (session) {
183 return &session->feature_flags;
184 }
185 }
186 return &core::FeatureFlags::get(); // Fallback to global
187 }
188
189 void SetFontGlobalScale(float scale) {
191 ImGui::GetIO().FontGlobalScale = scale;
192 auto status = user_settings_.Save();
193 if (!status.ok()) {
194 LOG_WARN("EditorManager", "Failed to save user settings: %s",
195 status.ToString().c_str());
196 }
197 }
198
199 // Workspace management (delegates to WorkspaceManager)
201 void SaveWorkspacePreset(const std::string& name) {
203 }
204 void LoadWorkspacePreset(const std::string& name) {
206 }
207
208 // Jump-to functionality for cross-editor navigation
209 void JumpToDungeonRoom(int room_id);
210 void JumpToOverworldMap(int map_id);
211 void SwitchToEditor(EditorType editor_type, bool force_visible = false,
212 bool from_dialog = false);
213
214 // Panel-based editor registry
215 static bool IsPanelBasedEditor(EditorType type);
216 bool IsSidebarVisible() const {
217 return ui_coordinator_ ? ui_coordinator_->IsPanelSidebarVisible() : false;
218 }
219 void SetSidebarVisible(bool visible) {
220 if (ui_coordinator_) {
221 ui_coordinator_->SetPanelSidebarVisible(visible);
222 }
223 }
224
225 // Clean up cards when switching editors
227
228 // Session management
229 void CreateNewSession();
231 void CloseCurrentSession();
232 void RemoveSession(size_t index);
233 void SwitchToSession(size_t index);
234 size_t GetActiveSessionCount() const;
235
236 // Workspace layout management
237 // Window management - inline delegation (reduces EditorManager bloat)
242 if (ui_coordinator_)
243 ui_coordinator_->ShowAllWindows();
244 }
246 if (ui_coordinator_)
247 ui_coordinator_->HideAllWindows();
248 }
249
250 // Layout presets (inline delegation)
254
255 // Panel layout presets (command palette accessible)
256 void ApplyLayoutPreset(const std::string& preset_name);
258
259 // Helper methods
260 std::string GenerateUniqueEditorTitle(EditorType type,
261 size_t session_index) const;
262 bool HasDuplicateSession(const std::string& filepath);
263 void RenameSession(size_t index, const std::string& new_name);
264 void Quit() { quit_ = true; }
265
266 // Deferred action queue - actions executed safely on next frame
267 // Use this to avoid modifying ImGui state during menu/popup rendering
268 void QueueDeferredAction(std::function<void()> action) {
269 deferred_actions_.push_back(std::move(action));
270 }
271
272 // Public for SessionCoordinator to configure new sessions
273 void ConfigureSession(RomSession* session);
274
275#ifdef YAZE_WITH_GRPC
276 void SetCanvasAutomationService(CanvasAutomationServiceImpl* service) {
277 canvas_automation_service_ = service;
278 }
279#endif
280
281 // UI visibility controls (public for MenuOrchestrator)
282 // UI visibility controls - inline for performance (single-line wrappers
283 // delegating to UICoordinator)
285 if (ui_coordinator_)
286 ui_coordinator_->SetImGuiDemoVisible(true);
287 }
289 if (ui_coordinator_)
290 ui_coordinator_->SetImGuiMetricsVisible(true);
291 }
292
293#ifdef YAZE_ENABLE_TESTING
294 void ShowTestDashboard() { show_test_dashboard_ = true; }
295#endif
296
297#ifdef YAZE_BUILD_AGENT_UI
298 void ShowAIAgent();
299 void ShowChatHistory();
300 AgentEditor* GetAgentEditor() { return agent_ui_.GetAgentEditor(); }
301 AgentUiController* GetAgentUiController() { return &agent_ui_; }
302#else
303 AgentEditor* GetAgentEditor() { return nullptr; }
305#endif
306#ifdef YAZE_BUILD_AGENT_UI
307 void ShowProposalDrawer() { proposal_drawer_.Show(); }
308#endif
309
310 // ROM and Project operations (public for MenuOrchestrator)
311 absl::Status LoadRom();
312 absl::Status SaveRom();
313 absl::Status SaveRomAs(const std::string& filename);
314 absl::Status OpenRomOrProject(const std::string& filename);
315 absl::Status CreateNewProject(
316 const std::string& template_name = "Basic ROM Hack");
317 absl::Status OpenProject();
318 absl::Status SaveProject();
319 absl::Status SaveProjectAs();
320 absl::Status ImportProject(const std::string& project_path);
321 absl::Status RepairCurrentProject();
322
323 // Project management
324 absl::Status LoadProjectWithRom();
328
329 // Show project management panel in right sidebar
331
332 // Show project file editor
334
335 private:
336 absl::Status DrawRomSelector() = delete; // Moved to UICoordinator
337 // DrawContextSensitivePanelControl removed - card control moved to sidebar
338
339 // Optional loading_handle for WASM progress tracking (0 = create new)
340 absl::Status LoadAssets(uint64_t loading_handle = 0);
341
342 // Testing system
345
346 bool quit_ = false;
347
348 // Note: All show_* flags are being moved to UICoordinator
349 // Access via ui_coordinator_->IsXxxVisible() or SetXxxVisible()
350
351 // Workspace dialog flags (managed by EditorManager, not UI)
355
356 // Note: Most UI visibility flags have been moved to UICoordinator
357 // Access via ui_coordinator_->IsXxxVisible() or SetXxxVisible()
358
359 // Agent proposal drawer
362
363 // Agent UI (chat + editor), no-op when agent UI is disabled
365
366 // Project file editor
368
369 // Note: Editor selection dialog and welcome screen are now managed by
370 // UICoordinator Kept here for backward compatibility during transition
371 std::unique_ptr<DashboardPanel> dashboard_panel_;
378
379 // Properties panel for selection editing
381
382 // Project management panel for version control and ROM management
383 std::unique_ptr<ProjectManagementPanel> project_management_panel_;
384
385 std::string version_ = "";
386 absl::Status status_;
388
389 public:
390 private:
392 // Tracks which session is currently active so delegators (menus, popups,
393 // shortcuts) stay in sync without relying on per-editor context.
394
396
398 std::unique_ptr<core::VersionManager> version_manager_;
400 std::unique_ptr<PopupManager> popup_manager_;
405
406 // New delegated components (dependency injection architecture)
407 PanelManager panel_manager_; // Panel management with session awareness
409 std::unique_ptr<MenuOrchestrator> menu_orchestrator_;
412 std::unique_ptr<UICoordinator> ui_coordinator_;
415 std::unique_ptr<SessionCoordinator> session_coordinator_;
416 std::unique_ptr<LayoutManager>
417 layout_manager_; // DockBuilder layout management
418 LayoutCoordinator layout_coordinator_; // Facade for layout operations
419 std::unique_ptr<RightPanelManager>
420 right_panel_manager_; // Right-side panel system
421 StatusBar status_bar_; // Bottom status bar
422 std::unique_ptr<ActivityBar> activity_bar_;
424
427
428 float autosave_timer_ = 0.0f;
429
430 // Deferred action queue - executed at the start of each frame
431 std::vector<std::function<void()>> deferred_actions_;
432
433 // Core Event Bus and Context
435 std::unique_ptr<GlobalEditorContext> editor_context_;
436
437#ifdef YAZE_WITH_GRPC
438 CanvasAutomationServiceImpl* canvas_automation_service_ = nullptr;
439#endif
440
441 // RAII helper for clean session context switching
443 public:
444 SessionScope(EditorManager* manager, size_t session_id);
446
447 private:
452 };
453
454 void ConfigureEditorDependencies(EditorSet* editor_set, Rom* rom,
455 size_t session_id);
456};
457
458} // namespace editor
459} // namespace yaze
460
461#endif // YAZE_APP_EDITOR_EDITOR_MANAGER_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
static Flags & get()
Definition features.h:92
Manages project versioning (Git) and ROM artifact snapshots.
Comprehensive AI Agent Platform & Bot Creator.
Central coordinator for all agent UI components.
Handles editor switching, layout initialization, and jump-to navigation.
SessionScope(EditorManager *manager, size_t session_id)
The EditorManager controls the main editor window and manages the various editor classes.
std::unique_ptr< SessionCoordinator > session_coordinator_
void SaveWorkspacePreset(const std::string &name)
void OnSessionClosed(size_t index) override
Called when a session is closed.
StartupVisibility welcome_mode_override_
PanelManager * GetPanelManager()
std::unique_ptr< GlobalEditorContext > editor_context_
auto GetCurrentGameData() const -> zelda3::GameData *
const PanelManager & card_registry() const
absl::Status SaveRomAs(const std::string &filename)
project::YazeProject current_project_
void ConfigureSession(RomSession *session)
void JumpToDungeonRoom(int room_id)
void SwitchToSession(size_t index)
bool HasDuplicateSession(const std::string &filepath)
WorkspaceManager * workspace_manager()
std::unique_ptr< LayoutManager > layout_manager_
std::unique_ptr< DashboardPanel > dashboard_panel_
void ProcessStartupActions(const AppConfig &config)
void LoadWorkspacePreset(const std::string &name)
std::string GenerateUniqueEditorTitle(EditorType type, size_t session_index) const
void RenameSession(size_t index, const std::string &new_name)
void DrawMenuBar()
Draw the main menu bar.
UICoordinator * ui_coordinator()
void ShowProjectManagement()
Injects dependencies into all editors within an EditorSet.
void Initialize(gfx::IRenderer *renderer, const std::string &filename="")
absl::Status CreateNewProject(const std::string &template_name="Basic ROM Hack")
LayoutCoordinator layout_coordinator_
absl::Status LoadAssets(uint64_t loading_handle=0)
auto overworld() const -> yaze::zelda3::Overworld *
auto GetCurrentEditorSet() const -> EditorSet *
void OnSessionRomLoaded(size_t index, RomSession *session) override
Called when a ROM is loaded into a session.
const PanelManager & panel_manager() const
void SetFontGlobalScale(float scale)
std::unique_ptr< MenuOrchestrator > menu_orchestrator_
ProjectFileEditor project_file_editor_
void SetSidebarVisible(bool visible)
void ApplyLayoutPreset(const std::string &preset_name)
void ApplyStartupVisibility(const AppConfig &config)
auto GetCurrentEditor() const -> Editor *
void SetCurrentEditor(Editor *editor)
void PersistInputConfig(const emu::input::InputConfig &config)
std::unique_ptr< RightPanelManager > right_panel_manager_
absl::Status DrawRomSelector()=delete
const project::YazeProject * GetCurrentProject() const
std::unique_ptr< core::VersionManager > version_manager_
StartupVisibility sidebar_mode_override_
void JumpToOverworldMap(int map_id)
void OnSessionSwitched(size_t new_index, RomSession *session) override
Called when the active session changes.
RomLoadOptionsDialog rom_load_options_dialog_
absl::Status LoadRom()
Load a ROM file into a new or existing session.
std::vector< std::function< void()> > deferred_actions_
void OpenEditorAndPanelsFromFlags(const std::string &editor_name, const std::string &panels_str)
StartupVisibility dashboard_mode_override_
static bool IsPanelBasedEditor(EditorType type)
absl::Status Update()
Main update loop for the editor application.
absl::Status ImportProject(const std::string &project_path)
AgentUiController * GetAgentUiController()
core::VersionManager * GetVersionManager()
void OnSessionCreated(size_t index, RomSession *session) override
Called when a new session is created.
project::YazeProject * GetCurrentProject()
void QueueDeferredAction(std::function< void()> action)
SelectionPropertiesPanel selection_properties_panel_
std::unique_ptr< ActivityBar > activity_bar_
ShortcutManager shortcut_manager_
auto emulator() -> emu::Emulator &
emu::input::InputConfig BuildInputConfigFromSettings() const
EditorDependencies::SharedClipboard shared_clipboard_
void SwitchToEditor(EditorType editor_type, bool force_visible=false, bool from_dialog=false)
core::FeatureFlags::Flags * GetCurrentFeatureFlags()
WorkspaceManager workspace_manager_
auto GetCurrentRom() const -> Rom *
void ConfigureEditorDependencies(EditorSet *editor_set, Rom *rom, size_t session_id)
std::unique_ptr< ProjectManagementPanel > project_management_panel_
absl::Status OpenRomOrProject(const std::string &filename)
void RemoveSession(size_t index)
std::unique_ptr< PopupManager > popup_manager_
std::unique_ptr< UICoordinator > ui_coordinator_
EditorActivator editor_activator_
absl::Status SaveRom()
Save the current ROM file.
absl::Status SetCurrentRom(Rom *rom)
RightPanelManager * right_panel_manager()
Manages editor types, categories, and lifecycle.
Contains a complete set of editors for a single ROM instance.
Interface for editor classes.
Definition editor.h:179
EditorType type() const
Definition editor.h:214
Facade class that coordinates all layout-related operations.
float GetBottomLayoutOffset() const
Get the bottom margin needed for status bar.
float GetRightLayoutOffset() const
Get the right margin needed for panels.
float GetLeftLayoutOffset() const
Get the left margin needed for sidebar (Activity Bar + Side Panel)
Fluent interface for building ImGui menus with icons.
Central registry for all editor cards with session awareness and dependency injection.
Editor for .yaze project files with syntax highlighting and validation.
Handles all project file operations with ROM-first workflow.
ImGui drawer for displaying and managing agent proposals.
Manages right-side sliding panels for agent chat, proposals, settings.
Handles all ROM file I/O operations.
ROM load options and ZSCustomOverworld upgrade dialog.
Full-editing properties panel for selected entities.
Observer interface for session state changes.
A session-aware status bar displayed at the bottom of the application.
Definition status_bar.h:38
Handles all UI drawing operations and state management.
Manages user preferences and settings persistence.
Modern welcome screen with project grid and quick actions.
Low-level window operations with minimal dependencies.
Manages workspace layouts, sessions, and presets.
void SaveWorkspacePreset(const std::string &name)
void LoadWorkspacePreset(const std::string &name)
A class for emulating and debugging SNES games.
Definition emulator.h:39
Defines an abstract interface for all rendering operations.
Definition irenderer.h:40
#define LOG_WARN(category, format,...)
Definition log.h:107
Editors are the view controllers for the application.
StartupVisibility
Tri-state toggle used for startup UI visibility controls.
Configuration options for the application startup.
Definition application.h:24
Represents a single session, containing a ROM and its associated editors.
core::FeatureFlags::Flags feature_flags
Input configuration (platform-agnostic key codes)
Modern project structure with comprehensive settings consolidation.
Definition project.h:84