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"
30using core::FileDialogWrapper;
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);
45 return std::find(active_editors.begin(), active_editors.end(), editor) !=
52 if (!filename.empty()) {
76 return absl::OkStatus();
81 static bool show_add_editor =
false;
82 if (show_add_editor) OpenPopup(
"AddEditor");
84 if (BeginPopup(
"AddEditor", ImGuiWindowFlags_AlwaysAutoResize)) {
85 if (MenuItem(
"Overworld",
nullptr,
false,
90 if (MenuItem(
"Dungeon",
nullptr,
false,
95 if (MenuItem(
"Graphics",
nullptr,
false,
100 if (MenuItem(
"Music",
nullptr,
false,
105 if (MenuItem(
"Palette",
nullptr,
false,
110 if (MenuItem(
"Screen",
nullptr,
false,
115 if (MenuItem(
"Sprite",
nullptr,
false,
120 if (MenuItem(
"Code",
nullptr,
false,
125 if (MenuItem(
"Message",
nullptr,
false,
130 if (MenuItem(
"Settings",
nullptr,
false,
138 if (!IsPopupOpen(
"AddEditor")) {
139 show_add_editor =
false;
142 if (BeginTabBar(
"##TabBar", ImGuiTabBarFlags_Reorderable |
143 ImGuiTabBarFlags_AutoSelectNewTabs)) {
146 switch (editor->type()) {
149 if (BeginTabItem(
"Overworld", &open)) {
157 if (BeginTabItem(
"Dungeon", &open)) {
168 if (BeginTabItem(
"Graphics", &open)) {
175 if (BeginTabItem(
"Music", &open)) {
183 if (BeginTabItem(
"Palette", &open)) {
190 if (BeginTabItem(
"Screen", &open)) {
197 if (BeginTabItem(
"Sprite", &open)) {
204 if (BeginTabItem(
"Code", &open)) {
211 if (BeginTabItem(
"Settings", &open)) {
218 if (BeginTabItem(
"Message", &open)) {
234 if (TabItemButton(
ICON_MD_ADD, ImGuiTabItemFlags_Trailing)) {
235 show_add_editor =
true;
243 bool ctrl_or_super = (GetIO().KeyCtrl || GetIO().KeySuper);
246 if (IsKeyDown(ImGuiKey_R) && ctrl_or_super) {
255 if (IsKeyDown(ImGuiKey_F1)) {
260 if (IsKeyDown(ImGuiKey_Q) && ctrl_or_super) {
265 if (IsKeyDown(ImGuiKey_O) && ctrl_or_super) {
270 if (IsKeyDown(ImGuiKey_S) && ctrl_or_super) {
274 if (IsKeyDown(ImGuiKey_X) && ctrl_or_super) {
278 if (IsKeyDown(ImGuiKey_C) && ctrl_or_super) {
282 if (IsKeyDown(ImGuiKey_V) && ctrl_or_super) {
286 if (IsKeyDown(ImGuiKey_Z) && ctrl_or_super) {
290 if (IsKeyDown(ImGuiKey_Y) && ctrl_or_super) {
294 if (IsKeyDown(ImGuiKey_F) && ctrl_or_super) {
300 static absl::Status prev_status;
308 Text(
"%s", prev_status.ToString().c_str());
316 IsKeyPressed(GetKeyIndex(ImGuiKey_Space))) {
322 SetClipboardText(prev_status.ToString().c_str());
329 if (
about_) OpenPopup(
"About");
330 if (BeginPopupModal(
"About",
nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
332 Text(
"Written by: scawful");
334 Text(
"Special Thanks: Zarby89, JaredBrian");
346 if (
rom_info_) OpenPopup(
"ROM Information");
347 if (BeginPopupModal(
"ROM Information",
nullptr,
348 ImGuiWindowFlags_AlwaysAutoResize)) {
349 Text(
"Title: %s",
rom()->title().c_str());
353 IsKeyPressed(GetKeyIndex(ImGuiKey_Space))) {
362 static bool show_display_settings =
false;
364 if (BeginMenuBar()) {
366 SameLine(GetWindowWidth() - GetStyle().ItemSpacing.x -
368 PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
370 show_display_settings = !show_display_settings;
377 if (show_display_settings) {
378 Begin(
"Display Settings", &show_display_settings, ImGuiWindowFlags_None);
385 static bool save_as_menu =
false;
386 static bool new_project_menu =
false;
388 if (BeginMenu(
"File")) {
389 if (MenuItem(
"Open",
"Ctrl+O")) {
393 if (BeginMenu(
"Open Recent")) {
397 MenuItem(
"No Recent Files",
nullptr,
false,
false);
400 if (MenuItem(filePath.c_str())) {
409 if (
rom()->is_loaded()) {
413 MENU_ITEM(
"Save As..") { save_as_menu =
true; }
415 if (
rom()->is_loaded()) {
424 if (BeginMenu(
"Project")) {
425 if (MenuItem(
"Create New Project")) {
427 new_project_menu =
true;
429 if (MenuItem(
"Open Project")) {
437 if (MenuItem(
"Save Project")) {
445 if (BeginMenu(
"Options")) {
449 if (BeginMenu(
"Experiment Flags")) {
459 if (MenuItem(
"Quit",
"Ctrl+Q")) {
467 static std::string save_as_filename =
"";
468 Begin(
"Save As..", &save_as_menu, ImGuiWindowFlags_AlwaysAutoResize);
469 InputText(
"Filename", &save_as_filename);
472 save_as_menu =
false;
476 save_as_menu =
false;
481 if (new_project_menu) {
482 Begin(
"New Project", &new_project_menu, ImGuiWindowFlags_AlwaysAutoResize);
483 static std::string save_as_filename =
"";
484 InputText(
"Project Name", &save_as_filename);
509 new_project_menu =
false;
517 new_project_menu =
false;
522 if (BeginMenu(
"Edit")) {
534 static bool show_imgui_metrics =
false;
535 static bool show_memory_editor =
false;
536 static bool show_asm_editor =
false;
537 static bool show_imgui_demo =
false;
538 static bool show_palette_editor =
false;
539 static bool show_emulator =
false;
541 if (show_imgui_demo) ShowDemoWindow();
542 if (show_imgui_metrics) ShowMetricsWindow(&show_imgui_metrics);
547 Begin(
"Emulator", &show_emulator, ImGuiWindowFlags_MenuBar);
552 if (show_palette_editor) {
553 Begin(
"Palette Editor", &show_palette_editor);
558 if (BeginMenu(
"View")) {
559 MenuItem(
"Emulator",
nullptr, &show_emulator);
561 MenuItem(
"Memory Editor",
nullptr, &show_memory_editor);
562 MenuItem(
"Assembly Editor",
nullptr, &show_asm_editor);
563 MenuItem(
"Palette Editor",
nullptr, &show_palette_editor);
567 MenuItem(
"ImGui Demo",
nullptr, &show_imgui_demo);
568 MenuItem(
"ImGui Metrics",
nullptr, &show_imgui_metrics);
572 static bool show_resource_label_manager =
false;
575 if (BeginMenu(
"Project")) {
581 MenuItem(
"Resource Labels",
nullptr, &show_resource_label_manager);
586 static bool open_rom_help =
false;
587 static bool open_supported_features =
false;
588 static bool open_manage_project =
false;
589 if (BeginMenu(
"Help")) {
590 if (MenuItem(
"How to open a ROM")) open_rom_help =
true;
591 if (MenuItem(
"Supported Features")) open_supported_features =
true;
592 if (MenuItem(
"How to manage a project")) open_manage_project =
true;
594 if (MenuItem(
"About",
"F1"))
about_ =
true;
598 if (open_supported_features) OpenPopup(
"Supported Features");
599 if (BeginPopupModal(
"Supported Features",
nullptr,
600 ImGuiWindowFlags_AlwaysAutoResize)) {
602 BulletText(
"LW/DW/SW Tilemap Editing");
603 BulletText(
"LW/DW/SW Map Properties");
604 BulletText(
"Create/Delete/Update Entrances");
605 BulletText(
"Create/Delete/Update Exits");
606 BulletText(
"Create/Delete/Update Sprites");
607 BulletText(
"Create/Delete/Update Items");
610 BulletText(
"View Room Header Properties");
611 BulletText(
"View Entrance Properties");
614 BulletText(
"View Decompressed Graphics Sheets");
615 BulletText(
"View/Update Graphics Groups");
618 BulletText(
"View Palette Groups");
621 BulletText(
"All Listed Overworld Features");
622 BulletText(
"Hex Editor Changes");
625 open_supported_features =
false;
631 if (open_rom_help) OpenPopup(
"Open a ROM");
632 if (BeginPopupModal(
"Open a ROM",
nullptr,
633 ImGuiWindowFlags_AlwaysAutoResize)) {
634 Text(
"File -> Open");
635 Text(
"Select a ROM file to open");
636 Text(
"Supported ROMs (headered or unheadered):");
637 Text(
"The Legend of Zelda: A Link to the Past");
638 Text(
"US Version 1.0");
639 Text(
"JP Version 1.0");
642 open_rom_help =
false;
648 if (open_manage_project) OpenPopup(
"Manage Project");
649 if (BeginPopupModal(
"Manage Project",
nullptr,
650 ImGuiWindowFlags_AlwaysAutoResize)) {
651 Text(
"Project Menu");
652 Text(
"Create a new project or open an existing one.");
653 Text(
"Save the project to save the current state of the project.");
655 "To save a project, you need to first open a ROM and initialize your "
656 "code path and labels file. Label resource manager can be found in "
657 "the View menu. Code path is set in the Code editor after opening a "
661 open_manage_project =
false;
667 if (show_resource_label_manager) {
668 rom()->resource_label()->DisplayLabels(&show_resource_label_manager);
678 auto load_rom =
rom()->LoadFromFile(file_name);
688 if (
flags()->kSaveDungeonMaps) {
700 if (absl::StrContains(filename,
".yaze")) {
714 return absl::InternalError(
715 "Could not load labels file, update your project file.");
728 return absl::OkStatus();
static std::string ShowOpenFileDialog()
static std::string ShowOpenFolderDialog()
void OpenFolder(const std::string &folder_path)
void Update(bool &is_loaded)
absl::Status Update() override
void ManageActiveEditors()
SpriteEditor sprite_editor_
AssemblyEditor assembly_editor_
GraphicsEditor graphics_editor_
SettingsEditor settings_editor_
void SetupScreen(std::string filename="")
PaletteEditor palette_editor_
ScreenEditor screen_editor_
MusicEditor music_editor_
void OpenRomOrProject(const std::string &filename)
absl::Status OpenProject()
std::vector< Editor * > active_editors_
void ManageKeyboardShortcuts()
MemoryEditorWithDiffChecker memory_editor_
OverworldEditor overworld_editor_
MessageEditor message_editor_
DungeonEditor dungeon_editor_
Interface for editor classes.
virtual absl::Status Cut()=0
virtual absl::Status Undo()=0
virtual absl::Status Find()=0
virtual absl::Status Redo()=0
virtual absl::Status Copy()=0
virtual absl::Status Paste()=0
absl::Status Update() override
absl::Status Update() override
absl::Status Update() override
absl::Status Update() final
absl::Status LoadGraphics()
Load the Bitmap objects for each OverworldMap.
absl::Status Update() override
const std::vector< std::string > & GetRecentFiles() const
void AddFile(const std::string &filePath)
absl::Status Update() override
absl::Status SaveDungeonMaps()
absl::Status Update() override
absl::Status Update() override
Updates the sprite editor.
#define PRINT_IF_ERROR(expression)
#define RETURN_IF_ERROR(expression)
#define RETURN_VOID_IF_ERROR(expression)
#define ICON_MD_DISPLAY_SETTINGS
#define ICON_MD_CONTENT_COPY
std::string UppercaseHexLongLong(uint64_t qword)
constexpr std::string_view kYazeVersion
bool BeginCentered(const char *name)
bool IsEditorActive(Editor *editor, std::vector< Editor * > &active_editors)
constexpr ImVec2 kDefaultModalSize
void DrawDisplaySettings(ImGuiStyle *ref)
absl::Status Open(const std::string &project_path)
std::string labels_filename_
absl::Status Create(const std::string &project_name)
Creates a new project.
std::string rom_filename_
void Update(bool &show_memory_editor)