From 2b0c550274a384137e2969f836cd12cbda3b9102 Mon Sep 17 00:00:00 2001 From: scawful Date: Mon, 17 Jul 2023 08:25:22 -0400 Subject: [PATCH] SharedROM, Editor parent, housekeeping --- src/app/core/common.h | 26 +++++++++++++++++++++ src/app/editor/dungeon_editor.h | 3 ++- src/app/editor/master_editor.cc | 38 +++++++++++++++---------------- src/app/editor/overworld_editor.h | 8 ++++--- src/app/gui/input.h | 3 +++ src/app/gui/widgets.cc | 1 + src/app/rom.h | 14 +++++++++--- src/app/zelda3/dungeon/room.h | 2 -- 8 files changed, 66 insertions(+), 29 deletions(-) diff --git a/src/app/core/common.h b/src/app/core/common.h index 9db4a37e..14d2ee5c 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -3,11 +3,37 @@ #include #include +#include namespace yaze { namespace app { namespace core { +class Editor { + public: + Editor() = default; + virtual ~Editor() = default; + + virtual void Cut() = 0; + virtual void Copy() = 0; + virtual void Paste() = 0; + + virtual void Undo() = 0; + virtual void Redo() = 0; + + virtual void SelectAll() = 0; + + virtual void Delete() = 0; + + virtual void Find() = 0; + + virtual void Replace() = 0; + + virtual void Goto() = 0; + + virtual void Indent() = 0; +}; + unsigned int SnesToPc(unsigned int addr); int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3); int HexToDec(char *input, int length); diff --git a/src/app/editor/dungeon_editor.h b/src/app/editor/dungeon_editor.h index 09257ebe..918afe50 100644 --- a/src/app/editor/dungeon_editor.h +++ b/src/app/editor/dungeon_editor.h @@ -3,6 +3,7 @@ #include +#include "app/core/common.h" #include "app/gui/canvas.h" #include "app/gui/icons.h" #include "rom.h" @@ -11,7 +12,7 @@ namespace yaze { namespace app { namespace editor { -class DungeonEditor { +class DungeonEditor : public SharedROM { public: void Update(); diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index e85e93a9..ae9dd030 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -34,7 +34,7 @@ constexpr ImGuiWindowFlags kMainEditorFlags = void NewMasterFrame() { const ImGuiIO &io = ImGui::GetIO(); ImGui::NewFrame(); - ImGui::SetNextWindowPos(ImVec2(0, 0)); + ImGui::SetNextWindowPos(gui::kZeroPos); ImVec2 dimensions(io.DisplaySize.x, io.DisplaySize.y); ImGui::SetNextWindowSize(dimensions, ImGuiCond_Always); @@ -104,20 +104,18 @@ void MasterEditor::DrawStatusPopup() { prev_status_ = status_; } - if (show_status_) { - if (BeginCentered("StatusWindow")) { - ImGui::Text("%s", prev_status_.ToString().c_str()); - ImGui::Spacing(); - ImGui::NextColumn(); - ImGui::Columns(1); - ImGui::Separator(); - ImGui::NewLine(); - ImGui::SameLine(270); - if (ImGui::Button("OK", ImVec2(200, 0))) { - show_status_ = false; - } - ImGui::End(); + if (show_status_ && (BeginCentered("StatusWindow"))) { + ImGui::Text("%s", prev_status_.ToString().c_str()); + ImGui::Spacing(); + ImGui::NextColumn(); + ImGui::Columns(1); + ImGui::Separator(); + ImGui::NewLine(); + ImGui::SameLine(270); + if (ImGui::Button("OK", gui::kDefaultModalSize)) { + show_status_ = false; } + ImGui::End(); } } @@ -131,7 +129,7 @@ void MasterEditor::DrawAboutPopup() { ImGui::Text("Special Thanks: Zarby89, JaredBrian"); ImGui::Separator(); - if (ImGui::Button("Close", ImVec2(200, 0))) { + if (ImGui::Button("Close", gui::kDefaultModalSize)) { about_ = false; ImGui::CloseCurrentPopup(); } @@ -146,7 +144,7 @@ void MasterEditor::DrawInfoPopup() { ImGui::Text("Title: %s", rom_.GetTitle()); ImGui::Text("ROM Size: %ld", rom_.size()); - if (ImGui::Button("Close", ImVec2(200, 0))) { + if (ImGui::Button("Close", gui::kDefaultModalSize)) { rom_info_ = false; ImGui::CloseCurrentPopup(); } @@ -188,10 +186,10 @@ void MasterEditor::DrawFileMenu() { static std::string save_as_filename = ""; ImGui::Begin("Save As..", nullptr, ImGuiWindowFlags_AlwaysAutoResize); ImGui::InputText("Filename", &save_as_filename); - if (ImGui::Button("Save", ImVec2(200, 0))) { + if (ImGui::Button("Save", gui::kDefaultModalSize)) { status_ = rom_.SaveToFile(backup_rom_, save_as_filename); } - if (ImGui::Button("Cancel", ImVec2(200, 0))) { + if (ImGui::Button("Cancel", gui::kDefaultModalSize)) { save_as_menu = false; } ImGui::End(); @@ -242,7 +240,7 @@ void MasterEditor::DrawViewMenu() { if (show_palette_editor) { ImGui::Begin("Palette Editor", &show_palette_editor); - palette_editor_.Update(); + status_ = palette_editor_.Update(); ImGui::End(); } @@ -313,7 +311,7 @@ void MasterEditor::DrawDungeonEditor() { void MasterEditor::DrawGraphicsEditor() { TAB_ITEM("Graphics") - graphics_editor_.Update(); + status_ = graphics_editor_.Update(); END_TAB_ITEM() } diff --git a/src/app/editor/overworld_editor.h b/src/app/editor/overworld_editor.h index 5f3f9383..d1e406a2 100644 --- a/src/app/editor/overworld_editor.h +++ b/src/app/editor/overworld_editor.h @@ -19,7 +19,6 @@ #include "app/rom.h" #include "app/zelda3/overworld.h" - namespace yaze { namespace app { namespace editor { @@ -41,7 +40,7 @@ static constexpr absl::string_view kOverworldSettingsColumnNames[] = { "##1stCol", "##gfxCol", "##palCol", "##sprgfxCol", "##sprpalCol", "##msgidCol", "##2ndCol"}; -class OverworldEditor { +class OverworldEditor : public SharedROM { public: absl::Status Update(); absl::Status Undo() const { return absl::UnimplementedError("Undo"); } @@ -49,7 +48,10 @@ class OverworldEditor { absl::Status Cut() const { return absl::UnimplementedError("Cut"); } absl::Status Copy() const { return absl::UnimplementedError("Copy"); } absl::Status Paste() const { return absl::UnimplementedError("Paste"); } - void SetupROM(ROM &rom) { rom_ = rom; } + void SetupROM(ROM &rom) { + rom_ = rom; + shared_rom_ = std::make_shared(rom_); + } private: absl::Status DrawToolset(); diff --git a/src/app/gui/input.h b/src/app/gui/input.h index 11be3f2f..fc3a147b 100644 --- a/src/app/gui/input.h +++ b/src/app/gui/input.h @@ -12,6 +12,9 @@ namespace yaze { namespace gui { +constexpr ImVec2 kDefaultModalSize = ImVec2(200, 0); +constexpr ImVec2 kZeroPos = ImVec2(0, 0); + IMGUI_API bool InputHex(const char* label, int* data); IMGUI_API bool InputHexShort(const char* label, int* data); diff --git a/src/app/gui/widgets.cc b/src/app/gui/widgets.cc index a3b54e3f..ad6768fa 100644 --- a/src/app/gui/widgets.cc +++ b/src/app/gui/widgets.cc @@ -1,6 +1,7 @@ #include "widgets.h" #include +#include #include "absl/status/status.h" #include "app/core/constants.h" diff --git a/src/app/rom.h b/src/app/rom.h index 6e961ed7..7d49df6d 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -89,9 +89,8 @@ const std::map paletteGroupBaseAddresses = { {"sprites_aux2", core::spritePalettesAux2}, {"sprites_aux3", core::spritePalettesAux3}, {"dungeon_main", core::dungeonMainPalettes}, - {"grass", core::hardcodedGrassLW}, // Assuming LW is the first color - {"3d_object", - core::triforcePalette}, // Assuming triforcePalette is the first palette + {"grass", core::hardcodedGrassLW}, + {"3d_object", core::triforcePalette}, {"ow_mini_map", core::overworldMiniMapPalettes}, }; @@ -214,6 +213,15 @@ class ROM { std::unordered_map palette_groups_; }; +class SharedROM { + public: + SharedROM() = default; + virtual ~SharedROM() = default; + + protected: + std::shared_ptr shared_rom_; +}; + } // namespace app } // namespace yaze diff --git a/src/app/zelda3/dungeon/room.h b/src/app/zelda3/dungeon/room.h index 1dffb1b8..1efe8694 100644 --- a/src/app/zelda3/dungeon/room.h +++ b/src/app/zelda3/dungeon/room.h @@ -32,8 +32,6 @@ class DungeonDestination { // int RealY() { return AssociatedObject ? AssociatedObject->RealY : 0; } - // void Reset() { AssociatedObject = nullptr; } - std::string ToString() { return std::to_string(Index) + ": To " + std::to_string(Target); }