yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
editor_activator.cc
Go to the documentation of this file.
1#include "editor_activator.h"
2
10#include "app/gui/core/icons.h"
11#include "imgui/imgui.h"
12#include "imgui/imgui_internal.h"
13#include "util/log.h"
14
15namespace yaze {
16namespace editor {
17
19 deps_ = deps;
20 initialized_ = true;
21}
22
23void EditorActivator::SwitchToEditor(EditorType editor_type, bool force_visible,
24 bool from_dialog) {
25 if (!initialized_) {
26 LOG_WARN("EditorActivator", "Not initialized, cannot switch editor");
27 return;
28 }
29
30 // Avoid touching ImGui docking state when outside a frame
31 ImGuiContext* imgui_ctx = ImGui::GetCurrentContext();
32 const bool frame_active = imgui_ctx != nullptr && imgui_ctx->WithinFrameScope;
33 if (!frame_active && deps_.queue_deferred_action) {
34 deps_.queue_deferred_action([this, editor_type, force_visible, from_dialog]() {
35 SwitchToEditor(editor_type, force_visible, from_dialog);
36 });
37 return;
38 }
39
40 // If NOT coming from dialog, close editor selection UI
41 if (!from_dialog && deps_.ui_coordinator) {
43 }
44
45 auto* editor_set = deps_.get_current_editor_set ? deps_.get_current_editor_set() : nullptr;
46 if (!editor_set) {
47 return;
48 }
49
50 // Toggle the editor in the active editors list
51 for (auto* editor : editor_set->active_editors_) {
52 if (editor->type() == editor_type) {
53 if (force_visible) {
54 editor->set_active(true);
55 } else {
56 editor->toggle_active();
57 }
58
59 if (EditorRegistry::IsPanelBasedEditor(editor_type)) {
60 if (*editor->active()) {
61 ActivatePanelBasedEditor(editor_type, editor);
62 } else {
63 DeactivatePanelBasedEditor(editor_type, editor, editor_set);
64 }
65 }
66 return;
67 }
68 }
69
70 // Handle non-editor-class cases (Assembly, Emulator, Hex, Settings, Agent)
71 HandleNonEditorClassSwitch(editor_type, force_visible);
72}
73
75 if (!deps_.panel_manager) return;
76
77 std::string old_category = deps_.panel_manager->GetActiveCategory();
78 std::string new_category = EditorRegistry::GetEditorCategory(type);
79
80 // Only trigger OnEditorSwitch if category actually changes
81 if (old_category != new_category) {
82 deps_.panel_manager->OnEditorSwitch(old_category, new_category);
83 }
84
85 // Initialize default layout on first activation
88 deps_.queue_deferred_action([this, type]() {
90 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
91 deps_.layout_manager->InitializeEditorLayout(type, dockspace_id);
92 }
93 });
94 }
95 }
96}
97
99 EditorSet* editor_set) {
100 if (!deps_.panel_manager || !editor_set) return;
101
102 // Switch to another active panel-based editor
103 for (auto* other : editor_set->active_editors_) {
104 if (*other->active() && EditorRegistry::IsPanelBasedEditor(other->type()) &&
105 other != editor) {
106 std::string old_category = deps_.panel_manager->GetActiveCategory();
107 std::string new_category = EditorRegistry::GetEditorCategory(other->type());
108 if (old_category != new_category) {
109 deps_.panel_manager->OnEditorSwitch(old_category, new_category);
110 }
111 break;
112 }
113 }
114}
115
117 switch (type) {
119 if (deps_.ui_coordinator) {
122 }
123 break;
124
126 if (deps_.ui_coordinator) {
127 bool is_visible = !deps_.ui_coordinator->IsEmulatorVisible();
128 if (force_visible) is_visible = true;
129
131
132 if (is_visible && deps_.panel_manager) {
134
137 ImGuiContext* ctx = ImGui::GetCurrentContext();
138 if (deps_.layout_manager && ctx && ctx->WithinFrameScope) {
139 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
142 dockspace_id);
143 LOG_INFO("EditorActivator", "Initialized emulator layout");
144 }
145 }
146 });
147 }
148 }
149 }
150 break;
151
152 case EditorType::kHex:
155 }
156 break;
157
162 !force_visible) {
164 } else {
167 }
168 }
169 break;
170
171 default:
172 // Other editor types not handled here
173 break;
174 }
175}
176
178 if (!initialized_ || !deps_.layout_manager) return;
179
180 ImGuiContext* ctx = ImGui::GetCurrentContext();
181 if (!ctx || !ctx->WithinFrameScope) {
183 deps_.queue_deferred_action([this, type]() {
185 });
186 }
187 return;
188 }
189
191 ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
192 deps_.layout_manager->InitializeEditorLayout(type, dockspace_id);
193 LOG_INFO("EditorActivator", "Initialized layout for editor type %d",
194 static_cast<int>(type));
195 }
196}
197
199 auto* editor_set = deps_.get_current_editor_set ? deps_.get_current_editor_set() : nullptr;
200 if (!editor_set) return;
201
202 // Switch to dungeon editor
204
205 // Open the room in the dungeon editor
206 editor_set->GetDungeonEditor()->add_room(room_id);
207}
208
210 auto* editor_set = deps_.get_current_editor_set ? deps_.get_current_editor_set() : nullptr;
211 if (!editor_set) return;
212
213 // Switch to overworld editor
215
216 // Set the current map in the overworld editor
217 editor_set->GetOverworldEditor()->set_current_map(map_id);
218}
219
220} // namespace editor
221} // namespace yaze
222
void HandleNonEditorClassSwitch(EditorType type, bool force_visible)
void ActivatePanelBasedEditor(EditorType type, Editor *editor)
void SwitchToEditor(EditorType type, bool force_visible=false, bool from_dialog=false)
Switch to an editor, optionally forcing visibility.
void Initialize(const Dependencies &deps)
void InitializeEditorLayout(EditorType type)
Initialize the DockBuilder layout for an editor.
void JumpToDungeonRoom(int room_id)
Jump to a specific dungeon room.
void JumpToOverworldMap(int map_id)
Jump to a specific overworld map.
void DeactivatePanelBasedEditor(EditorType type, Editor *editor, EditorSet *editor_set)
static bool IsPanelBasedEditor(EditorType type)
static std::string GetEditorCategory(EditorType type)
Contains a complete set of editors for a single ROM instance.
std::vector< Editor * > active_editors_
Interface for editor classes.
Definition editor.h:179
bool IsLayoutInitialized(EditorType type) const
Check if a layout has been initialized for an editor.
void InitializeEditorLayout(EditorType type, ImGuiID dockspace_id)
Initialize the default layout for a specific editor type.
void OnEditorSwitch(const std::string &from_category, const std::string &to_category)
Handle editor/category switching for panel visibility.
bool ShowPanel(size_t session_id, const std::string &base_card_id)
std::string GetActiveCategory() const
void SetActiveCategory(const std::string &category)
void ClosePanel()
Close the currently active panel.
PanelType GetActivePanel() const
Get the currently active panel type.
void OpenPanel(PanelType type)
Open a specific panel.
void SetEmulatorVisible(bool visible)
void SetAsmEditorVisible(bool visible)
void SetEditorSelectionVisible(bool visible)
#define LOG_WARN(category, format,...)
Definition log.h:107
#define LOG_INFO(category, format,...)
Definition log.h:105
std::function< EditorSet *()> get_current_editor_set
std::function< void(std::function< void()>)> queue_deferred_action