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"
45#include "app/emu/emulator.h"
46#include "app/startup_flags.h"
47#include "rom/rom.h"
48#include "core/project.h"
50#include "imgui/imgui.h"
51#include "yaze_config.h"
53
54// Forward declarations for gRPC-dependent types
55namespace yaze::agent {
57}
58
59namespace yaze {
60class CanvasAutomationServiceImpl;
61}
62
63namespace yaze::editor {
64class AgentEditor;
65}
66
67namespace yaze {
68
69// Forward declaration for AppConfig
70struct AppConfig;
71
72namespace editor {
73
88 public:
89 // Constructor and destructor must be defined in .cc file for std::unique_ptr
90 // with forward-declared types
92 ~EditorManager() override;
93
94 void Initialize(gfx::IRenderer* renderer, const std::string& filename = "");
95
96 // SessionObserver implementation
97 void OnSessionSwitched(size_t new_index, RomSession* session) override;
98 void OnSessionCreated(size_t index, RomSession* session) override;
99 void OnSessionClosed(size_t index) override;
100 void OnSessionRomLoaded(size_t index, RomSession* session) override;
101
102 // Processes startup flags to open a specific editor and panels.
103 void OpenEditorAndPanelsFromFlags(const std::string& editor_name,
104 const std::string& panels_str);
105
106 // Apply startup actions based on AppConfig
107 void ProcessStartupActions(const AppConfig& config);
108 void ApplyStartupVisibility(const AppConfig& config);
109
110 absl::Status Update();
111 void DrawMenuBar();
112
113 auto emulator() -> emu::Emulator& { return emulator_; }
114 auto quit() const { return quit_; }
115 auto version() const { return version_; }
116
118
125 const PanelManager& panel_manager() const { return panel_manager_; }
126
127 // Deprecated compatibility wrappers
129 const PanelManager& card_registry() const { return panel_manager_; }
130
131 // Layout offset calculation for dockspace adjustment
132 // Delegates to LayoutCoordinator for cleaner separation of concerns
142
143 absl::Status SetCurrentRom(Rom* rom);
144 auto GetCurrentRom() const -> Rom* {
145 return session_coordinator_ ? session_coordinator_->GetCurrentRom()
146 : nullptr;
147 }
148 auto GetCurrentGameData() const -> zelda3::GameData* {
149 return session_coordinator_ ? session_coordinator_->GetCurrentGameData()
150 : nullptr;
151 }
153 return session_coordinator_ ? session_coordinator_->GetCurrentEditorSet()
154 : nullptr;
155 }
156 auto GetCurrentEditor() const -> Editor* { return current_editor_; }
157 void SetCurrentEditor(Editor* editor) {
158 current_editor_ = editor;
159 // Update help panel's editor context for context-aware help
160 if (right_panel_manager_ && editor) {
161 right_panel_manager_->SetActiveEditor(editor->type());
162 }
163 }
164 size_t GetCurrentSessionId() const {
165 return session_coordinator_ ? session_coordinator_->GetActiveSessionIndex()
166 : 0;
167 }
169 auto overworld() const -> yaze::zelda3::Overworld* {
170 if (auto* editor_set = GetCurrentEditorSet()) {
171 return &editor_set->GetOverworldEditor()->overworld();
172 }
173 return nullptr;
174 }
175
176 // Session management helpers
177 size_t GetCurrentSessionIndex() const;
178
179 // Get current session's feature flags (falls back to global if no session)
181 size_t current_index = GetCurrentSessionIndex();
182 if (session_coordinator_ && current_index < session_coordinator_->GetTotalSessionCount()) {
183 auto* session = static_cast<RomSession*>(session_coordinator_->GetSession(current_index));
184 if (session) {
185 return &session->feature_flags;
186 }
187 }
188 return &core::FeatureFlags::get(); // Fallback to global
189 }
190
191 void SetFontGlobalScale(float scale) {
193 ImGui::GetIO().FontGlobalScale = scale;
194 auto status = user_settings_.Save();
195 if (!status.ok()) {
196 LOG_WARN("EditorManager", "Failed to save user settings: %s",
197 status.ToString().c_str());
198 }
199 }
200
201 // Workspace management (delegates to WorkspaceManager)
203 void SaveWorkspacePreset(const std::string& name) {
205 }
206 void LoadWorkspacePreset(const std::string& name) {
208 }
209
210 // Jump-to functionality for cross-editor navigation
211 void JumpToDungeonRoom(int room_id);
212 void JumpToOverworldMap(int map_id);
213 void SwitchToEditor(EditorType editor_type, bool force_visible = false,
214 bool from_dialog = false);
215
216 // Panel-based editor registry
217 static bool IsPanelBasedEditor(EditorType type);
218 bool IsSidebarVisible() const {
219 return ui_coordinator_ ? ui_coordinator_->IsPanelSidebarVisible() : false;
220 }
221 void SetSidebarVisible(bool visible) {
222 if (ui_coordinator_) {
223 ui_coordinator_->SetPanelSidebarVisible(visible);
224 }
225 }
226
227 // Clean up cards when switching editors
229
230 // Session management
231 void CreateNewSession();
233 void CloseCurrentSession();
234 void RemoveSession(size_t index);
235 void SwitchToSession(size_t index);
236 size_t GetActiveSessionCount() const;
237
238 // Workspace layout management
239 // Window management - inline delegation (reduces EditorManager bloat)
244 if (ui_coordinator_)
245 ui_coordinator_->ShowAllWindows();
246 }
248 if (ui_coordinator_)
249 ui_coordinator_->HideAllWindows();
250 }
251
252 // Layout presets (inline delegation)
256
257 // Panel layout presets (command palette accessible)
258 void ApplyLayoutPreset(const std::string& preset_name);
260
261 // Helper methods
262 std::string GenerateUniqueEditorTitle(EditorType type,
263 size_t session_index) const;
264 bool HasDuplicateSession(const std::string& filepath);
265 void RenameSession(size_t index, const std::string& new_name);
266 void Quit() { quit_ = true; }
267
268 // Deferred action queue - actions executed safely on next frame
269 // Use this to avoid modifying ImGui state during menu/popup rendering
270 void QueueDeferredAction(std::function<void()> action) {
271 deferred_actions_.push_back(std::move(action));
272 }
273
274 // Public for SessionCoordinator to configure new sessions
275 void ConfigureSession(RomSession* session);
276
277#ifdef YAZE_WITH_GRPC
278 void SetCanvasAutomationService(CanvasAutomationServiceImpl* service) {
279 canvas_automation_service_ = service;
280 }
281#endif
282
283 // UI visibility controls (public for MenuOrchestrator)
284 // UI visibility controls - inline for performance (single-line wrappers
285 // delegating to UICoordinator)
287 if (ui_coordinator_)
288 ui_coordinator_->SetImGuiDemoVisible(true);
289 }
291 if (ui_coordinator_)
292 ui_coordinator_->SetImGuiMetricsVisible(true);
293 }
294
295#ifdef YAZE_ENABLE_TESTING
296 void ShowTestDashboard() { show_test_dashboard_ = true; }
297#endif
298
299#ifdef YAZE_BUILD_AGENT_UI
300 void ShowAIAgent();
301 void ShowChatHistory();
302 AgentEditor* GetAgentEditor() { return agent_ui_.GetAgentEditor(); }
303 AgentUiController* GetAgentUiController() { return &agent_ui_; }
304#else
305 AgentEditor* GetAgentEditor() { return nullptr; }
307#endif
308#ifdef YAZE_BUILD_AGENT_UI
309 void ShowProposalDrawer() { proposal_drawer_.Show(); }
310#endif
311
312 // ROM and Project operations (public for MenuOrchestrator)
313 absl::Status LoadRom();
314 absl::Status SaveRom();
315 absl::Status SaveRomAs(const std::string& filename);
316 absl::Status OpenRomOrProject(const std::string& filename);
317 absl::Status CreateNewProject(
318 const std::string& template_name = "Basic ROM Hack");
319 absl::Status OpenProject();
320 absl::Status SaveProject();
321 absl::Status SaveProjectAs();
322 absl::Status ImportProject(const std::string& project_path);
323 absl::Status RepairCurrentProject();
324
325 // Project management
326 absl::Status LoadProjectWithRom();
330
331 // Show project management panel in right sidebar
333
334 // Show project file editor
336
337 private:
338 absl::Status DrawRomSelector() = delete; // Moved to UICoordinator
339 // DrawContextSensitivePanelControl removed - card control moved to sidebar
340
341 // Optional loading_handle for WASM progress tracking (0 = create new)
342 absl::Status LoadAssets(uint64_t loading_handle = 0);
343
344 // Testing system
347
348 bool quit_ = false;
349
350 // Note: All show_* flags are being moved to UICoordinator
351 // Access via ui_coordinator_->IsXxxVisible() or SetXxxVisible()
352
353 // Workspace dialog flags (managed by EditorManager, not UI)
357
358 // Note: Most UI visibility flags have been moved to UICoordinator
359 // Access via ui_coordinator_->IsXxxVisible() or SetXxxVisible()
360
361 // Agent proposal drawer
364
365 // Agent UI (chat + editor), no-op when agent UI is disabled
367
368 // Project file editor
370
371 // Note: Editor selection dialog and welcome screen are now managed by
372 // UICoordinator Kept here for backward compatibility during transition
373 std::unique_ptr<DashboardPanel> dashboard_panel_;
380
381 // Properties panel for selection editing
383
384 // Project management panel for version control and ROM management
385 std::unique_ptr<ProjectManagementPanel> project_management_panel_;
386
387#ifdef YAZE_WITH_GRPC
388 std::unique_ptr<yaze::agent::AgentControlServer> agent_control_server_;
389#endif
390
391 std::string version_ = "";
392 absl::Status status_;
394
395 public:
396 private:
398 // Tracks which session is currently active so delegators (menus, popups,
399 // shortcuts) stay in sync without relying on per-editor context.
400
402
404 std::unique_ptr<core::VersionManager> version_manager_;
406 std::unique_ptr<PopupManager> popup_manager_;
411
412 // New delegated components (dependency injection architecture)
413 PanelManager panel_manager_; // Panel management with session awareness
415 std::unique_ptr<MenuOrchestrator> menu_orchestrator_;
418 std::unique_ptr<UICoordinator> ui_coordinator_;
421 std::unique_ptr<SessionCoordinator> session_coordinator_;
422 std::unique_ptr<LayoutManager>
423 layout_manager_; // DockBuilder layout management
424 LayoutCoordinator layout_coordinator_; // Facade for layout operations
425 std::unique_ptr<RightPanelManager>
426 right_panel_manager_; // Right-side panel system
427 StatusBar status_bar_; // Bottom status bar
428 std::unique_ptr<ActivityBar> activity_bar_;
431
434
435 float autosave_timer_ = 0.0f;
436
437 // Deferred action queue - executed at the start of each frame
438 std::vector<std::function<void()>> deferred_actions_;
439
440 // Core Event Bus and Context
442 std::unique_ptr<GlobalEditorContext> editor_context_;
443
444#ifdef YAZE_WITH_GRPC
445 CanvasAutomationServiceImpl* canvas_automation_service_ = nullptr;
446#endif
447
448 // RAII helper for clean session context switching
450 public:
451 SessionScope(EditorManager* manager, size_t session_id);
453
454 private:
459 };
460
461 void ConfigureEditorDependencies(EditorSet* editor_set, Rom* rom,
462 size_t session_id);
463};
464
465} // namespace editor
466} // namespace yaze
467
468#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")
layout_designer::LayoutDesignerWindow layout_designer_
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)
Main window for the WYSIWYG layout designer.
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.
Definition agent_chat.cc:23
StartupVisibility
Tri-state toggle used for startup UI visibility controls.
Configuration options for the application startup.
Definition application.h:23
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