yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
editor_manager.cc
Go to the documentation of this file.
1#include "editor_manager.h"
2
3#include "absl/status/status.h"
4#include "absl/strings/match.h"
5#include "app/core/features.h"
7#include "app/core/project.h"
16#include "app/emu/emulator.h"
17#include "app/gui/icons.h"
18#include "app/gui/input.h"
19#include "app/gui/style.h"
20#include "app/rom.h"
21#include "editor/editor.h"
22#include "imgui/imgui.h"
23#include "imgui/misc/cpp/imgui_stdlib.h"
24#include "util/macro.h"
25
26namespace yaze {
27namespace editor {
28
29using namespace ImGui;
30using core::FileDialogWrapper;
31
32namespace {
33
34bool BeginCentered(const char *name) {
35 ImGuiIO const &io = GetIO();
36 ImVec2 pos(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
37 SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
38 ImGuiWindowFlags flags =
39 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration |
40 ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings;
41 return Begin(name, nullptr, flags);
42}
43
44bool IsEditorActive(Editor *editor, std::vector<Editor *> &active_editors) {
45 return std::ranges::find(active_editors, editor) != active_editors.end();
46}
47
48std::string GetEditorName(EditorType type) {
49 return kEditorNames[static_cast<int>(type)];
50}
51
52} // namespace
53
54constexpr const char *kOverworldEditorName = ICON_MD_LAYERS " Overworld Editor";
55constexpr const char *kGraphicsEditorName = ICON_MD_PHOTO " Graphics Editor";
56constexpr const char *kPaletteEditorName = ICON_MD_PALETTE " Palette Editor";
57constexpr const char *kScreenEditorName = ICON_MD_SCREENSHOT " Screen Editor";
58constexpr const char *kSpriteEditorName = ICON_MD_SMART_TOY " Sprite Editor";
59constexpr const char *kMessageEditorName = ICON_MD_MESSAGE " Message Editor";
60constexpr const char *kSettingsEditorName = ICON_MD_SETTINGS " Settings Editor";
61constexpr const char *kAssemblyEditorName = ICON_MD_CODE " Assembly Editor";
62constexpr const char *kDungeonEditorName = ICON_MD_CASTLE " Dungeon Editor";
63constexpr const char *kMusicEditorName = ICON_MD_MUSIC_NOTE " Music Editor";
64
65void EditorManager::Initialize(const std::string &filename) {
66 // Create a blank editor set
67 auto blank_editor_set = std::make_unique<EditorSet>();
68 editor_sets_[nullptr] = std::move(blank_editor_set);
69 current_editor_set_ = editor_sets_[nullptr].get();
70
71 if (!filename.empty()) {
73 }
74
75 // Initialize popup manager
76 popup_manager_ = std::make_unique<PopupManager>(this);
77 popup_manager_->Initialize();
78
79 // Set the popup manager in the context
80 context_.popup_manager = popup_manager_.get();
81
82 context_.shortcut_manager.RegisterShortcut(
83 "Open", {ImGuiKey_O, ImGuiMod_Ctrl}, [&]() { status_ = LoadRom(); });
84 context_.shortcut_manager.RegisterShortcut(
85 "Save", {ImGuiKey_S, ImGuiMod_Ctrl}, [&]() { status_ = SaveRom(); });
86 context_.shortcut_manager.RegisterShortcut(
87 "Close", {ImGuiKey_W, ImGuiMod_Ctrl}, [&]() {
88 if (current_rom_) current_rom_->Close();
89 });
90 context_.shortcut_manager.RegisterShortcut(
91 "Quit", {ImGuiKey_Q, ImGuiMod_Ctrl}, [&]() { quit_ = true; });
92
93 context_.shortcut_manager.RegisterShortcut(
94 "Undo", {ImGuiKey_Z, ImGuiMod_Ctrl},
95 [&]() { status_ = current_editor_->Undo(); });
96 context_.shortcut_manager.RegisterShortcut(
97 "Redo", {ImGuiKey_Y, ImGuiMod_Ctrl},
98 [&]() { status_ = current_editor_->Redo(); });
99 context_.shortcut_manager.RegisterShortcut(
100 "Cut", {ImGuiKey_X, ImGuiMod_Ctrl},
101 [&]() { status_ = current_editor_->Cut(); });
102 context_.shortcut_manager.RegisterShortcut(
103 "Copy", {ImGuiKey_C, ImGuiMod_Ctrl},
104 [&]() { status_ = current_editor_->Copy(); });
105 context_.shortcut_manager.RegisterShortcut(
106 "Paste", {ImGuiKey_V, ImGuiMod_Ctrl},
107 [&]() { status_ = current_editor_->Paste(); });
108 context_.shortcut_manager.RegisterShortcut(
109 "Find", {ImGuiKey_F, ImGuiMod_Ctrl},
110 [&]() { status_ = current_editor_->Find(); });
111
112 context_.shortcut_manager.RegisterShortcut(
113 "Load Last ROM", {ImGuiKey_R, ImGuiMod_Ctrl}, [&]() {
114 static RecentFilesManager manager("recent_files.txt");
115 manager.Load();
116 if (!manager.GetRecentFiles().empty()) {
117 auto front = manager.GetRecentFiles().front();
118 status_ = OpenRomOrProject(front);
119 }
120 });
121
122 context_.shortcut_manager.RegisterShortcut(
123 "F1", ImGuiKey_F1, [&]() { popup_manager_->Show("About"); });
124
125 // Initialize menu items
126 std::vector<gui::MenuItem> recent_files;
127 static RecentFilesManager manager("recent_files.txt");
128 manager.Load();
129 if (manager.GetRecentFiles().empty()) {
130 recent_files.emplace_back("No Recent Files", "", nullptr);
131 } else {
132 for (const auto &filePath : manager.GetRecentFiles()) {
133 recent_files.emplace_back(filePath, "", [filePath, this]() {
134 status_ = OpenRomOrProject(filePath);
135 });
136 }
137 }
138
139 std::vector<gui::MenuItem> options_subitems;
140 options_subitems.emplace_back(
141 "Backup ROM", "", [&]() { backup_rom_ |= backup_rom_; },
142 [&]() { return backup_rom_; });
143 options_subitems.emplace_back(
144 "Save New Auto", "", [&]() { save_new_auto_ |= save_new_auto_; },
145 [&]() { return save_new_auto_; });
146
147 std::vector<gui::MenuItem> project_menu_subitems;
148 project_menu_subitems.emplace_back(
149 "New Project", "", [&]() { popup_manager_->Show("New Project"); });
150 project_menu_subitems.emplace_back("Open Project", "",
151 [&]() { status_ = OpenProject(); });
152 project_menu_subitems.emplace_back(
153 "Save Project", "", [&]() { status_ = SaveProject(); },
154 [&]() { return current_project_.project_opened_; });
155
156 gui::kMainMenu = {
157 {"File",
158 {},
159 {},
160 {},
161 {
162 {absl::StrCat(ICON_MD_FILE_OPEN, " Open"),
163 context_.shortcut_manager.GetKeys("Open"),
164 context_.shortcut_manager.GetCallback("Open")},
165 {"Open Recent", "", [&]() {},
166 []() { return !manager.GetRecentFiles().empty(); }, recent_files},
167 {absl::StrCat(ICON_MD_FILE_DOWNLOAD, " Save"),
168 context_.shortcut_manager.GetKeys("Save"),
169 context_.shortcut_manager.GetCallback("Save")},
170 {absl::StrCat(ICON_MD_SAVE_AS, " Save As.."), "",
171 [&]() { popup_manager_->Show("Save As.."); }},
172 {absl::StrCat(ICON_MD_BALLOT, " Project"), "", [&]() {},
173 []() { return true; }, project_menu_subitems},
174 {absl::StrCat(ICON_MD_CLOSE, " Close"), "",
175 [&]() {
176 if (current_rom_) current_rom_->Close();
177 }},
178 {gui::kSeparator, "", nullptr, []() { return true; }},
179 {absl::StrCat(ICON_MD_MISCELLANEOUS_SERVICES, " Options"), "",
180 [&]() {}, []() { return true; }, options_subitems},
181 {absl::StrCat(ICON_MD_EXIT_TO_APP, " Quit"), "Ctrl+Q",
182 [&]() { quit_ = true; }},
183 }},
184 {"Edit",
185 {},
186 {},
187 {},
188 {
189 {absl::StrCat(ICON_MD_CONTENT_CUT, " Cut"),
190 context_.shortcut_manager.GetKeys("Cut"),
191 context_.shortcut_manager.GetCallback("Cut")},
192 {absl::StrCat(ICON_MD_CONTENT_COPY, " Copy"),
193 context_.shortcut_manager.GetKeys("Copy"),
194 context_.shortcut_manager.GetCallback("Copy")},
195 {absl::StrCat(ICON_MD_CONTENT_PASTE, " Paste"),
196 context_.shortcut_manager.GetKeys("Paste"),
197 context_.shortcut_manager.GetCallback("Paste")},
198 {gui::kSeparator, "", nullptr, []() { return true; }},
199 {absl::StrCat(ICON_MD_UNDO, " Undo"),
200 context_.shortcut_manager.GetKeys("Undo"),
201 context_.shortcut_manager.GetCallback("Undo")},
202 {absl::StrCat(ICON_MD_REDO, " Redo"),
203 context_.shortcut_manager.GetKeys("Redo"),
204 context_.shortcut_manager.GetCallback("Redo")},
205 {gui::kSeparator, "", nullptr, []() { return true; }},
206 {absl::StrCat(ICON_MD_SEARCH, " Find"),
207 context_.shortcut_manager.GetKeys("Find"),
208 context_.shortcut_manager.GetCallback("Find")},
209 }},
210 {"View",
211 {},
212 {},
213 {},
214 {
215 {absl::StrCat(ICON_MD_HOME, " Home"), "",
216 [&]() { show_homepage_ = true; }},
217 {kAssemblyEditorName, "", [&]() { show_asm_editor_ = true; },
218 [&]() { return show_asm_editor_; }},
220 [&]() { current_editor_set_->dungeon_editor_.set_active(true); },
221 [&]() { return *current_editor_set_->dungeon_editor_.active(); }},
223 [&]() { current_editor_set_->graphics_editor_.set_active(true); },
224 [&]() { return *current_editor_set_->graphics_editor_.active(); }},
225 {kMusicEditorName, "",
226 [&]() { current_editor_set_->music_editor_.set_active(true); },
227 [&]() { return *current_editor_set_->music_editor_.active(); }},
229 [&]() { current_editor_set_->overworld_editor_.set_active(true); },
230 [&]() { return *current_editor_set_->overworld_editor_.active(); }},
232 [&]() { current_editor_set_->palette_editor_.set_active(true); },
233 [&]() { return *current_editor_set_->palette_editor_.active(); }},
235 [&]() { current_editor_set_->screen_editor_.set_active(true); },
236 [&]() { return *current_editor_set_->screen_editor_.active(); }},
238 [&]() { current_editor_set_->sprite_editor_.set_active(true); },
239 [&]() { return *current_editor_set_->sprite_editor_.active(); }},
241 [&]() { current_editor_set_->message_editor_.set_active(true); },
242 [&]() { return *current_editor_set_->message_editor_.active(); }},
244 [&]() { current_editor_set_->settings_editor_.set_active(true); },
245 [&]() { return *current_editor_set_->settings_editor_.active(); }},
246 {gui::kSeparator, "", nullptr, []() { return true; }},
247 {absl::StrCat(ICON_MD_GAMEPAD, " Emulator"), "",
248 [&]() { show_emulator_ = true; }},
249 {absl::StrCat(ICON_MD_MEMORY, " Memory Editor"), "",
250 [&]() { show_memory_editor_ = true; }},
251 {absl::StrCat(ICON_MD_SIM_CARD, " ROM Metadata"), "",
252 [&]() { popup_manager_->Show("ROM Information"); }},
253 {gui::kSeparator, "", nullptr, []() { return true; }},
254 {absl::StrCat(ICON_MD_HELP, " ImGui Demo"), "",
255 [&]() { show_imgui_demo_ = true; }},
256 {absl::StrCat(ICON_MD_HELP, " ImGui Metrics"), "",
257 [&]() { show_imgui_metrics_ = true; }},
258 }},
259 {"Workspace",
260 {},
261 {},
262 {},
263 {
264 {absl::StrCat(ICON_MD_SPACE_DASHBOARD, " Layout"), "",
265 [&]() { show_workspace_layout = true; }},
266 }},
267 {"Help",
268 {},
269 {},
270 {},
271 {
272 {absl::StrCat(ICON_MD_HELP, " How to open a ROM"), "",
273 [&]() { popup_manager_->Show("Open a ROM"); }},
274 {absl::StrCat(ICON_MD_HELP, " Supported Features"), "",
275 [&]() { popup_manager_->Show("Supported Features"); }},
276 {absl::StrCat(ICON_MD_HELP, " How to manage a project"), "",
277 [&]() { popup_manager_->Show("Manage Project"); }},
278 {absl::StrCat(ICON_MD_HELP, " About"), "F1",
279 [&]() { popup_manager_->Show("About"); }},
280 }}};
281}
282
283absl::Status EditorManager::Update() {
284 popup_manager_->DrawPopups();
285 ExecuteShortcuts(context_.shortcut_manager);
286
288 for (auto editor : current_editor_set_->active_editors_) {
289 if (*editor->active()) {
290 if (editor->type() == EditorType::kOverworld) {
291 auto &overworld_editor = static_cast<OverworldEditor &>(*editor);
292 if (overworld_editor.jump_to_tab() != -1) {
293 current_editor_set_->dungeon_editor_.set_active(true);
294 // Set the dungeon editor to the jump to tab
295 current_editor_set_->dungeon_editor_.add_room(
296 overworld_editor.jump_to_tab());
297 overworld_editor.jump_to_tab_ = -1;
298 }
299 }
300
301 if (ImGui::Begin(GetEditorName(editor->type()).c_str(),
302 editor->active())) {
304 status_ = editor->Update();
305 }
306 ImGui::End();
307 }
308 }
309
310 static uint64_t last_cleanup_time = 0;
311 uint64_t current_time = SDL_GetTicks64();
312
313 // Clean up unused textures every 5 seconds
314 if (current_time - last_cleanup_time > 5000) {
315 current_editor_set_->CleanupUnusedTextures(current_time, 5000);
316 last_cleanup_time = current_time;
317 }
318 }
319
320 if (show_homepage_) {
321 ImGui::Begin("Home", &show_homepage_);
322 DrawHomepage();
323 ImGui::End();
324 }
325 return absl::OkStatus();
326}
327
329 TextWrapped("Welcome to the Yet Another Zelda3 Editor (yaze)!");
330 TextWrapped(
331 "Comprehensive tool for editing the Legend of Zelda: A Link to the "
332 "Past.");
333 TextWrapped(
334 "The editor is still in development, so please report any bugs or issues "
335 "you encounter.");
336
337 // Hyperlink to github
338 if (gui::ClickableText("https://github.com/scawful/yaze")) {
339 gui::OpenUrl("https://github.com/scawful/yaze");
340 }
341
342 if (!current_rom_) {
343 TextWrapped("No ROM loaded.");
344 if (gui::ClickableText("Open a ROM")) {
345 status_ = LoadRom();
346 }
347 // Checkbox for loading a ROM with custom overworld flag.
348 Checkbox("Load custom overworld features",
349 &core::FeatureFlags::get().overworld.kLoadCustomOverworld);
350
351 // Recent Files list
352 TextWrapped("Recent Files");
353 static RecentFilesManager manager("recent_files.txt");
354 manager.Load();
355 for (const auto &file : manager.GetRecentFiles()) {
356 if (gui::ClickableText(file.c_str())) {
358 }
359 }
360 return;
361 }
362
363 TextWrapped("Current ROM: %s", current_rom_->filename().c_str());
364
365 // Quick buttons for opening editors
366 if (Button(kOverworldEditorName)) {
367 current_editor_set_->overworld_editor_.set_active(true);
368 }
369 ImGui::SameLine();
370 if (Button(kDungeonEditorName)) {
371 current_editor_set_->dungeon_editor_.set_active(true);
372 }
373 ImGui::SameLine();
374 if (Button(kGraphicsEditorName)) {
375 current_editor_set_->graphics_editor_.set_active(true);
376 }
377 ImGui::SameLine();
378 if (Button(kPaletteEditorName)) {
379 current_editor_set_->palette_editor_.set_active(true);
380 }
381 ImGui::SameLine();
382 if (Button(kScreenEditorName)) {
383 current_editor_set_->screen_editor_.set_active(true);
384 }
385 ImGui::SameLine();
386 if (Button(kSpriteEditorName)) {
387 current_editor_set_->sprite_editor_.set_active(true);
388 }
389 ImGui::SameLine();
390 if (Button(kMessageEditorName)) {
391 current_editor_set_->message_editor_.set_active(true);
392 }
393}
394
396 SameLine((GetWindowWidth() / 2) - 100);
397 if (current_rom_ && current_rom_->is_loaded()) {
398 SetNextItemWidth(GetWindowWidth() / 6);
399 if (BeginCombo("##ROMSelector", current_rom_->short_name().c_str())) {
400 for (const auto &rom : roms_) {
401 if (MenuItem(rom->short_name().c_str())) {
402 RETURN_IF_ERROR(SetCurrentRom(rom.get()));
403 }
404 }
405 EndCombo();
406 }
407 } else {
408 Text("No ROM loaded");
409 }
410 return absl::OkStatus();
411}
412
414 static bool show_display_settings = false;
415 static bool save_as_menu = false;
416
417 if (BeginMenuBar()) {
418 gui::DrawMenu(gui::kMainMenu);
419
421
422 SameLine(GetWindowWidth() - GetStyle().ItemSpacing.x -
423 CalcTextSize(ICON_MD_DISPLAY_SETTINGS).x - 110);
424 PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
425 if (Button(ICON_MD_DISPLAY_SETTINGS)) {
426 show_display_settings = !show_display_settings;
427 }
428 PopStyleColor();
429 Text("yaze v%s", version_.c_str());
430 EndMenuBar();
431 }
432
433 if (show_display_settings) {
434 Begin("Display Settings", &show_display_settings, ImGuiWindowFlags_None);
436 End();
437 }
438
439 if (show_imgui_demo_) ShowDemoWindow();
440 if (show_imgui_metrics_) ShowMetricsWindow(&show_imgui_metrics_);
442 current_editor_set_->memory_editor_.Update(show_memory_editor_);
443 }
445 current_editor_set_->assembly_editor_.Update(show_asm_editor_);
446 }
447
448 if (show_emulator_) {
449 Begin("Emulator", &show_emulator_, ImGuiWindowFlags_MenuBar);
450 emulator_.Run();
451 End();
452 }
453
455 Begin("Palette Editor", &show_palette_editor_);
456 status_ = current_editor_set_->palette_editor_.Update();
457 End();
458 }
459
461 current_rom_->resource_label()->DisplayLabels(&show_resource_label_manager);
462 if (current_project_.project_opened_ &&
463 !current_project_.labels_filename_.empty()) {
464 current_project_.labels_filename_ =
465 current_rom_->resource_label()->filename_;
466 }
467 }
468
469 if (save_as_menu) {
470 static std::string save_as_filename = "";
471 Begin("Save As..", &save_as_menu, ImGuiWindowFlags_AlwaysAutoResize);
472 InputText("Filename", &save_as_filename);
473 if (Button("Save", gui::kDefaultModalSize)) {
474 status_ = SaveRom();
475 save_as_menu = false;
476 }
477 SameLine();
478 if (Button("Cancel", gui::kDefaultModalSize)) {
479 save_as_menu = false;
480 }
481 End();
482 }
483
484 if (new_project_menu) {
485 Begin("New Project", &new_project_menu, ImGuiWindowFlags_AlwaysAutoResize);
486 static std::string save_as_filename = "";
487 InputText("Project Name", &save_as_filename);
488 if (Button("Destination Filepath", gui::kDefaultModalSize)) {
490 }
491 SameLine();
492 Text("%s", current_project_.filepath.c_str());
493 if (Button("ROM File", gui::kDefaultModalSize)) {
495 }
496 SameLine();
497 Text("%s", current_project_.rom_filename_.c_str());
498 if (Button("Labels File", gui::kDefaultModalSize)) {
499 current_project_.labels_filename_ =
501 }
502 SameLine();
503 Text("%s", current_project_.labels_filename_.c_str());
504 if (Button("Code Folder", gui::kDefaultModalSize)) {
506 }
507 SameLine();
508 Text("%s", current_project_.code_folder_.c_str());
509
510 Separator();
511 if (Button("Create", gui::kDefaultModalSize)) {
512 new_project_menu = false;
513 status_ = current_project_.Create(save_as_filename);
514 if (status_.ok()) {
515 status_ = current_project_.Save();
516 }
517 }
518 SameLine();
519 if (Button("Cancel", gui::kDefaultModalSize)) {
520 new_project_menu = false;
521 }
522 End();
523 }
524}
525
527 auto file_name = FileDialogWrapper::ShowOpenFileDialog();
528 auto new_rom = std::make_unique<Rom>();
529 RETURN_IF_ERROR(new_rom->LoadFromFile(file_name));
530
531 current_rom_ = new_rom.get();
532 roms_.push_back(std::move(new_rom));
533
534 // Create new editor set for this ROM
535 auto editor_set = std::make_unique<EditorSet>(current_rom_);
536 for (auto *editor : editor_set->active_editors_) {
537 editor->set_context(&context_);
538 }
539 current_editor_set_ = editor_set.get();
540 editor_sets_[current_rom_] = std::move(editor_set);
541
542 static RecentFilesManager manager("recent_files.txt");
543 manager.Load();
544 manager.AddFile(file_name);
545 manager.Save();
547
548 return absl::OkStatus();
549}
550
553 return absl::FailedPreconditionError("No ROM or editor set loaded");
554 }
555 current_editor_set_->overworld_editor_.Initialize();
556 current_editor_set_->message_editor_.Initialize();
557
558 auto &sheet_manager = GraphicsSheetManager::GetInstance();
559 ASSIGN_OR_RETURN(*sheet_manager.mutable_gfx_sheets(),
561 RETURN_IF_ERROR(current_editor_set_->overworld_editor_.Load());
562 RETURN_IF_ERROR(current_editor_set_->dungeon_editor_.Load());
563 return absl::OkStatus();
564}
565
568 return absl::FailedPreconditionError("No ROM or editor set loaded");
569 }
570
571 if (core::FeatureFlags::get().kSaveDungeonMaps) {
572 RETURN_IF_ERROR(current_editor_set_->screen_editor_.SaveDungeonMaps());
573 }
574
575 RETURN_IF_ERROR(current_editor_set_->overworld_editor_.Save());
576
577 if (core::FeatureFlags::get().kSaveGraphicsSheet)
580
581 return current_rom_->SaveToFile(backup_rom_, save_new_auto_);
582}
583
584absl::Status EditorManager::OpenRomOrProject(const std::string &filename) {
585 if (absl::StrContains(filename, ".yaze")) {
586 RETURN_IF_ERROR(current_project_.Open(filename));
588 } else {
589 auto new_rom = std::make_unique<Rom>();
590 RETURN_IF_ERROR(new_rom->LoadFromFile(filename));
591 current_rom_ = new_rom.get();
593 roms_.push_back(std::move(new_rom));
594
595 // Create new editor set for this ROM
596 auto editor_set = std::make_unique<EditorSet>(current_rom_);
597 for (auto *editor : editor_set->active_editors_) {
598 editor->set_context(&context_);
599 }
600 current_editor_set_ = editor_set.get();
601 editor_sets_[current_rom_] = std::move(editor_set);
603 }
604 return absl::OkStatus();
605}
606
608 auto new_rom = std::make_unique<Rom>();
609 RETURN_IF_ERROR(new_rom->LoadFromFile(current_project_.rom_filename_));
610 current_rom_ = new_rom.get();
611 roms_.push_back(std::move(new_rom));
612
613 if (!current_rom_->resource_label()->LoadLabels(
614 current_project_.labels_filename_)) {
615 return absl::InternalError(
616 "Could not load labels file, update your project file.");
617 }
618
619 // Create new editor set for this ROM
620 auto editor_set = std::make_unique<EditorSet>(current_rom_);
621 for (auto *editor : editor_set->active_editors_) {
622 editor->set_context(&context_);
623 }
624 current_editor_set_ = editor_set.get();
625 editor_sets_[current_rom_] = std::move(editor_set);
626
627 static RecentFilesManager manager("recent_files.txt");
628 manager.Load();
629 manager.AddFile(current_project_.filepath + "/" + current_project_.name +
630 ".yaze");
631 manager.Save();
633 current_editor_set_->assembly_editor_.OpenFolder(
634 current_project_.code_folder_);
635 }
636 current_project_.project_opened_ = true;
638 return absl::OkStatus();
639}
640
642 if (current_project_.project_opened_) {
644 } else {
645 new_project_menu = true;
646 }
647 return absl::OkStatus();
648}
649
651 if (!rom) {
652 return absl::InvalidArgumentError("Invalid ROM pointer");
653 }
654
655 auto it = editor_sets_.find(rom);
656 if (it == editor_sets_.end()) {
657 // Create new editor set if it doesn't exist
658 auto editor_set = std::make_unique<EditorSet>(rom);
659 for (auto *editor : editor_set->active_editors_) {
660 editor->set_context(&context_);
661 }
662 current_editor_set_ = editor_set.get();
663
664 editor_sets_[rom] = std::move(editor_set);
665 current_rom_ = rom;
668 } else {
669 current_editor_set_ = it->second.get();
670 current_rom_ = rom;
672 }
673
674 return absl::OkStatus();
675}
676
677} // namespace editor
678} // namespace yaze
static GraphicsSheetManager & GetInstance()
Definition rom.h:272
const std::vector< std::string > & GetRecentFiles() const
Definition project.h:122
void AddFile(const std::string &file_path)
Definition project.h:88
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:59
static void set_rom(Rom *rom)
Definition rom.h:392
static Flags & get()
Definition features.h:69
std::unordered_map< Rom *, std::unique_ptr< EditorSet > > editor_sets_
void Initialize(const std::string &filename="")
absl::Status OpenRomOrProject(const std::string &filename)
std::vector< std::shared_ptr< Rom > > roms_
std::unique_ptr< PopupManager > popup_manager_
absl::Status SetCurrentRom(Rom *rom)
Interface for editor classes.
Definition editor.h:53
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
static std::string ShowOpenFolderDialog()
ShowOpenFolderDialog opens a file dialog and returns the selected folder path.
Manipulates the Overworld and OverworldMap data in a Rom.
#define ICON_MD_CONTENT_CUT
Definition icons.h:464
#define ICON_MD_SETTINGS
Definition icons.h:1697
#define ICON_MD_FILE_OPEN
Definition icons.h:745
#define ICON_MD_EXIT_TO_APP
Definition icons.h:697
#define ICON_MD_MEMORY
Definition icons.h:1193
#define ICON_MD_SEARCH
Definition icons.h:1671
#define ICON_MD_SIM_CARD
Definition icons.h:1762
#define ICON_MD_FILE_DOWNLOAD
Definition icons.h:742
#define ICON_MD_SAVE_AS
Definition icons.h:1644
#define ICON_MD_CODE
Definition icons.h:432
#define ICON_MD_REDO
Definition icons.h:1568
#define ICON_MD_MESSAGE
Definition icons.h:1199
#define ICON_MD_CASTLE
Definition icons.h:378
#define ICON_MD_SCREENSHOT
Definition icons.h:1664
#define ICON_MD_MUSIC_NOTE
Definition icons.h:1262
#define ICON_MD_CONTENT_PASTE
Definition icons.h:465
#define ICON_MD_HOME
Definition icons.h:951
#define ICON_MD_LAYERS
Definition icons.h:1066
#define ICON_MD_DISPLAY_SETTINGS
Definition icons.h:585
#define ICON_MD_BALLOT
Definition icons.h:235
#define ICON_MD_SPACE_DASHBOARD
Definition icons.h:1803
#define ICON_MD_PALETTE
Definition icons.h:1368
#define ICON_MD_CONTENT_COPY
Definition icons.h:463
#define ICON_MD_MISCELLANEOUS_SERVICES
Definition icons.h:1211
#define ICON_MD_PHOTO
Definition icons.h:1449
#define ICON_MD_CLOSE
Definition icons.h:416
#define ICON_MD_GAMEPAD
Definition icons.h:864
#define ICON_MD_HELP
Definition icons.h:931
#define ICON_MD_UNDO
Definition icons.h:2034
#define ICON_MD_SMART_TOY
Definition icons.h:1776
#define PRINT_IF_ERROR(expression)
Definition macro.h:25
#define RETURN_IF_ERROR(expression)
Definition macro.h:51
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:59
bool IsEditorActive(Editor *editor, std::vector< Editor * > &active_editors)
Editors are the view controllers for the application.
constexpr std::array< const char *, 10 > kEditorNames
Definition editor.h:42
constexpr const char * kDungeonEditorName
constexpr const char * kMessageEditorName
constexpr const char * kGraphicsEditorName
constexpr const char * kScreenEditorName
constexpr const char * kSettingsEditorName
constexpr const char * kMusicEditorName
constexpr const char * kOverworldEditorName
constexpr const char * kAssemblyEditorName
constexpr const char * kSpriteEditorName
void ExecuteShortcuts(const ShortcutManager &shortcut_manager)
constexpr const char * kPaletteEditorName
constexpr std::string kSeparator
Definition input.h:91
bool ClickableText(const std::string &text)
Definition input.cc:200
void DrawMenu(Menu &menu)
Definition input.cc:397
void DrawDisplaySettings(ImGuiStyle *ref)
Definition style.cc:396
bool OpenUrl(const std::string &url)
Definition input.cc:426
constexpr ImVec2 kDefaultModalSize
Definition input.h:21
Main namespace for the application.
Definition controller.cc:18
absl::StatusOr< std::array< gfx::Bitmap, kNumGfxSheets > > LoadAllGraphicsData(Rom &rom, bool defer_render)
This function iterates over all graphics sheets in the Rom and loads them into memory....
Definition rom.cc:77
absl::Status SaveAllGraphicsData(Rom &rom, std::array< gfx::Bitmap, kNumGfxSheets > &gfx_sheets)
Definition rom.cc:136