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