3#include "absl/status/status.h"
4#include "absl/strings/match.h"
22#include "imgui/imgui.h"
23#include "imgui/misc/cpp/imgui_stdlib.h"
31using core::FileDialogWrapper;
36 ImGuiIO
const &io = GetIO();
37 ImVec2 pos(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
38 SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
39 ImGuiWindowFlags flags =
40 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration |
41 ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings;
42 return Begin(name,
nullptr, flags);
46 return std::find(active_editors.begin(), active_editors.end(),
editor) !=
53 if (!filename.empty()) {
78 return absl::OkStatus();
83 static bool show_add_editor =
false;
84 if (show_add_editor) OpenPopup(
"AddEditor");
86 if (BeginPopup(
"AddEditor", ImGuiWindowFlags_AlwaysAutoResize)) {
87 if (MenuItem(
"Overworld",
nullptr,
false,
92 if (MenuItem(
"Dungeon",
nullptr,
false,
97 if (MenuItem(
"Graphics",
nullptr,
false,
102 if (MenuItem(
"Music",
nullptr,
false,
107 if (MenuItem(
"Palette",
nullptr,
false,
112 if (MenuItem(
"Screen",
nullptr,
false,
117 if (MenuItem(
"Sprite",
nullptr,
false,
122 if (MenuItem(
"Code",
nullptr,
false,
127 if (MenuItem(
"Message",
nullptr,
false,
132 if (MenuItem(
"Settings",
nullptr,
false,
140 if (!IsPopupOpen(
"AddEditor")) {
141 show_add_editor =
false;
144 if (BeginTabBar(
"##TabBar", ImGuiTabBarFlags_Reorderable |
145 ImGuiTabBarFlags_AutoSelectNewTabs)) {
151 if (BeginTabItem(
"Overworld", &open)) {
159 if (BeginTabItem(
"Dungeon", &open)) {
170 if (BeginTabItem(
"Graphics", &open)) {
177 if (BeginTabItem(
"Music", &open)) {
185 if (BeginTabItem(
"Palette", &open)) {
192 if (BeginTabItem(
"Screen", &open)) {
199 if (BeginTabItem(
"Sprite", &open)) {
206 if (BeginTabItem(
"Code", &open)) {
213 if (BeginTabItem(
"Settings", &open)) {
220 if (BeginTabItem(
"Message", &open)) {
236 if (TabItemButton(
ICON_MD_ADD, ImGuiTabItemFlags_Trailing)) {
237 show_add_editor =
true;
245 bool ctrl_or_super = (GetIO().KeyCtrl || GetIO().KeySuper);
250 if (IsKeyDown(ImGuiKey_R) && ctrl_or_super) {
259 if (IsKeyDown(ImGuiKey_F1)) {
264 if (IsKeyDown(ImGuiKey_Q) && ctrl_or_super) {
269 if (IsKeyDown(ImGuiKey_O) && ctrl_or_super) {
274 if (IsKeyDown(ImGuiKey_S) && ctrl_or_super) {
278 if (IsKeyDown(ImGuiKey_X) && ctrl_or_super) {
282 if (IsKeyDown(ImGuiKey_C) && ctrl_or_super) {
286 if (IsKeyDown(ImGuiKey_V) && ctrl_or_super) {
290 if (IsKeyDown(ImGuiKey_Z) && ctrl_or_super) {
294 if (IsKeyDown(ImGuiKey_Y) && ctrl_or_super) {
298 if (IsKeyDown(ImGuiKey_F) && ctrl_or_super) {
304 static absl::Status prev_status;
312 Text(
"%s", prev_status.ToString().c_str());
325 SetClipboardText(prev_status.ToString().c_str());
330 if (
about_) OpenPopup(
"About");
331 if (BeginPopupModal(
"About",
nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
332 Text(
"Yet Another Zelda3 Editor - v%s",
version_.c_str());
333 Text(
"Written by: scawful");
335 Text(
"Special Thanks: Zarby89, JaredBrian");
345 if (
rom_info_) OpenPopup(
"ROM Information");
346 if (BeginPopupModal(
"ROM Information",
nullptr,
347 ImGuiWindowFlags_AlwaysAutoResize)) {
348 Text(
"Title: %s",
rom()->title().c_str());
352 IsKeyPressed(ImGuiKey_Escape)) {
361 TextWrapped(
"Welcome to the Yet Another Zelda3 Editor (yaze)!");
363 "This editor is designed to be a comprehensive tool for editing the "
364 "Legend of Zelda: A Link to the Past.");
366 "The editor is still in development, so please report any bugs or issues "
369 static bool managed_startup =
false;
371 if (Button(
"Open ROM", ImVec2(200, 0))) {
375 ImGui::Checkbox(
"Manage Startup", &managed_startup);
382 static bool show_display_settings =
false;
384 if (BeginMenuBar()) {
387 SameLine(GetWindowWidth() - GetStyle().ItemSpacing.x -
389 PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
391 show_display_settings = !show_display_settings;
398 if (show_display_settings) {
399 Begin(
"Display Settings", &show_display_settings, ImGuiWindowFlags_None);
406 static bool save_as_menu =
false;
407 static bool new_project_menu =
false;
409 if (BeginMenu(
"File")) {
410 if (MenuItem(
"Open",
"Ctrl+O")) {
414 if (BeginMenu(
"Open Recent")) {
418 MenuItem(
"No Recent Files",
nullptr,
false,
false);
421 if (MenuItem(filePath.c_str())) {
430 if (
rom()->is_loaded()) {
434 MENU_ITEM(
"Save As..") { save_as_menu =
true; }
436 if (
rom()->is_loaded()) {
445 if (BeginMenu(
"Project")) {
446 if (MenuItem(
"Create New Project")) {
448 new_project_menu =
true;
450 if (MenuItem(
"Open Project")) {
458 if (MenuItem(
"Save Project")) {
466 if (BeginMenu(
"Options")) {
471 if (BeginMenu(
"System Flags")) {
475 if (BeginMenu(
"Overworld Flags")) {
479 if (BeginMenu(
"Dungeon Flags")) {
483 if (BeginMenu(
"Resource Flags")) {
492 if (MenuItem(
"Quit",
"Ctrl+Q")) {
500 static std::string save_as_filename =
"";
501 Begin(
"Save As..", &save_as_menu, ImGuiWindowFlags_AlwaysAutoResize);
502 InputText(
"Filename", &save_as_filename);
505 save_as_menu =
false;
509 save_as_menu =
false;
514 if (new_project_menu) {
515 Begin(
"New Project", &new_project_menu, ImGuiWindowFlags_AlwaysAutoResize);
516 static std::string save_as_filename =
"";
517 InputText(
"Project Name", &save_as_filename);
542 new_project_menu =
false;
550 new_project_menu =
false;
555 if (BeginMenu(
"Edit")) {
567 static bool show_imgui_metrics =
false;
568 static bool show_memory_editor =
false;
569 static bool show_asm_editor =
false;
570 static bool show_imgui_demo =
false;
571 static bool show_palette_editor =
false;
572 static bool show_emulator =
false;
574 if (show_imgui_demo) ShowDemoWindow();
575 if (show_imgui_metrics) ShowMetricsWindow(&show_imgui_metrics);
576 if (show_memory_editor)
memory_editor_.Update(show_memory_editor);
580 Begin(
"Emulator", &show_emulator, ImGuiWindowFlags_MenuBar);
585 if (show_palette_editor) {
586 Begin(
"Palette Editor", &show_palette_editor);
591 if (BeginMenu(
"View")) {
592 MenuItem(
"Emulator",
nullptr, &show_emulator);
594 MenuItem(
"Memory Editor",
nullptr, &show_memory_editor);
595 MenuItem(
"Assembly Editor",
nullptr, &show_asm_editor);
596 MenuItem(
"Palette Editor",
nullptr, &show_palette_editor);
600 MenuItem(
"ImGui Demo",
nullptr, &show_imgui_demo);
601 MenuItem(
"ImGui Metrics",
nullptr, &show_imgui_metrics);
605 static bool show_resource_label_manager =
false;
607 if (BeginMenu(
"Project")) {
613 MenuItem(
"Resource Labels",
nullptr, &show_resource_label_manager);
618 static bool open_rom_help =
false;
619 static bool open_supported_features =
false;
620 static bool open_manage_project =
false;
621 if (BeginMenu(
"Help")) {
622 if (MenuItem(
"How to open a ROM")) open_rom_help =
true;
623 if (MenuItem(
"Supported Features")) open_supported_features =
true;
624 if (MenuItem(
"How to manage a project")) open_manage_project =
true;
626 if (MenuItem(
"About",
"F1"))
about_ =
true;
630 if (open_supported_features) OpenPopup(
"Supported Features");
631 if (BeginPopupModal(
"Supported Features",
nullptr,
632 ImGuiWindowFlags_AlwaysAutoResize)) {
634 BulletText(
"LW/DW/SW Tilemap Editing");
635 BulletText(
"LW/DW/SW Map Properties");
636 BulletText(
"Create/Delete/Update Entrances");
637 BulletText(
"Create/Delete/Update Exits");
638 BulletText(
"Create/Delete/Update Sprites");
639 BulletText(
"Create/Delete/Update Items");
642 BulletText(
"View Room Header Properties");
643 BulletText(
"View Entrance Properties");
646 BulletText(
"View Decompressed Graphics Sheets");
647 BulletText(
"View/Update Graphics Groups");
650 BulletText(
"View Palette Groups");
653 BulletText(
"All Listed Overworld Features");
654 BulletText(
"Hex Editor Changes");
657 open_supported_features =
false;
663 if (open_rom_help) OpenPopup(
"Open a ROM");
664 if (BeginPopupModal(
"Open a ROM",
nullptr,
665 ImGuiWindowFlags_AlwaysAutoResize)) {
666 Text(
"File -> Open");
667 Text(
"Select a ROM file to open");
668 Text(
"Supported ROMs (headered or unheadered):");
669 Text(
"The Legend of Zelda: A Link to the Past");
670 Text(
"US Version 1.0");
671 Text(
"JP Version 1.0");
674 open_rom_help =
false;
680 if (open_manage_project) OpenPopup(
"Manage Project");
681 if (BeginPopupModal(
"Manage Project",
nullptr,
682 ImGuiWindowFlags_AlwaysAutoResize)) {
683 Text(
"Project Menu");
684 Text(
"Create a new project or open an existing one.");
685 Text(
"Save the project to save the current state of the project.");
687 "To save a project, you need to first open a ROM and initialize your "
688 "code path and labels file. Label resource manager can be found in "
689 "the View menu. Code path is set in the Code editor after opening a "
693 open_manage_project =
false;
699 if (show_resource_label_manager) {
700 rom()->resource_label()->DisplayLabels(&show_resource_label_manager);
709 if (
roms_.empty())
return;
712 if (BeginMenu(
"ROM")) {
713 for (
size_t i = 0; i <
roms_.size(); ++i) {
714 if (MenuItem(
roms_[i]->title().c_str())) {
724 auto load_rom =
rom()->LoadFromFile(file_name);
751 if (absl::StrContains(filename,
".yaze")) {
767 return absl::InternalError(
768 "Could not load labels file, update your project file.");
781 return absl::OkStatus();
static GraphicsSheetManager & GetInstance()
const std::vector< std::string > & GetRecentFiles() const
void AddFile(const std::string &file_path)
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
void OpenRomOrProject(const std::string &filename)
void ManageKeyboardShortcuts()
absl::Status OpenProject()
OverworldEditor overworld_editor_
std::vector< std::unique_ptr< Rom > > roms_
void Initialize(std::string filename="")
MemoryEditorWithDiffChecker memory_editor_
SettingsEditor settings_editor_
SpriteEditor sprite_editor_
GraphicsEditor graphics_editor_
PaletteEditor palette_editor_
std::vector< Editor * > active_editors_
DungeonEditor dungeon_editor_
MusicEditor music_editor_
ScreenEditor screen_editor_
void ManageActiveEditors()
AssemblyEditor assembly_editor_
MessageEditor message_editor_
EditorContext editor_context_
Interface for editor classes.
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.
#define ICON_MD_DISPLAY_SETTINGS
#define ICON_MD_CONTENT_COPY
#define PRINT_IF_ERROR(expression)
#define RETURN_IF_ERROR(expression)
#define ASSIGN_OR_RETURN(type_variable_name, expression)
#define RETURN_VOID_IF_ERROR(expression)
bool BeginCentered(const char *name)
bool IsEditorActive(Editor *editor, std::vector< Editor * > &active_editors)
Editors are the view controllers for the application.
void DrawDisplaySettings(ImGuiStyle *ref)
constexpr ImVec2 kDefaultModalSize
std::string HexLongLong(uint64_t qword, HexStringParams params)
Main namespace for the application.
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....
absl::Status SaveAllGraphicsData(Rom &rom, std::array< gfx::Bitmap, kNumGfxSheets > &gfx_sheets)