From 6714f7751424e3a29b03cfcec79542c24bb6bbe1 Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 8 Mar 2025 00:31:30 -0500 Subject: [PATCH] Implement Initialize method in Editor class and override in derived editors --- src/app/editor/code/assembly_editor.cc | 4 ++++ src/app/editor/code/assembly_editor.h | 1 + src/app/editor/dungeon/dungeon_editor.cc | 22 +++++++++++++------- src/app/editor/dungeon/dungeon_editor.h | 2 +- src/app/editor/editor.h | 2 ++ src/app/editor/graphics/graphics_editor.cc | 2 ++ src/app/editor/graphics/graphics_editor.h | 6 +++--- src/app/editor/graphics/palette_editor.cc | 2 ++ src/app/editor/graphics/palette_editor.h | 7 +++++-- src/app/editor/graphics/screen_editor.cc | 2 ++ src/app/editor/graphics/screen_editor.h | 2 ++ src/app/editor/graphics/tile16_editor.cc | 4 ++-- src/app/editor/message/message_editor.cc | 14 ++++++------- src/app/editor/message/message_editor.h | 2 +- src/app/editor/music/music_editor.cc | 5 +++-- src/app/editor/music/music_editor.h | 2 +- src/app/editor/overworld/overworld_editor.cc | 20 +++++++++--------- src/app/editor/overworld/overworld_editor.h | 2 +- src/app/editor/sprite/sprite_editor.cc | 2 ++ src/app/editor/sprite/sprite_editor.h | 11 ++-------- src/app/editor/system/settings_editor.cc | 2 ++ src/app/editor/system/settings_editor.h | 3 +-- 22 files changed, 69 insertions(+), 50 deletions(-) diff --git a/src/app/editor/code/assembly_editor.cc b/src/app/editor/code/assembly_editor.cc index 9e76cd3c..49f9473f 100644 --- a/src/app/editor/code/assembly_editor.cc +++ b/src/app/editor/code/assembly_editor.cc @@ -97,6 +97,10 @@ FolderItem LoadFolder(const std::string& folder) { } // namespace +void AssemblyEditor::Initialize() { + // Set the language definition +} + void AssemblyEditor::OpenFolder(const std::string& folder_path) { current_folder_ = LoadFolder(folder_path); } diff --git a/src/app/editor/code/assembly_editor.h b/src/app/editor/code/assembly_editor.h index 9e837de7..bf794441 100644 --- a/src/app/editor/code/assembly_editor.h +++ b/src/app/editor/code/assembly_editor.h @@ -33,6 +33,7 @@ class AssemblyEditor : public Editor { file_is_loaded_ = false; } + void Initialize() override; void Update(bool &is_loaded); void InlineUpdate(); diff --git a/src/app/editor/dungeon/dungeon_editor.cc b/src/app/editor/dungeon/dungeon_editor.cc index 53af92ee..0be2d836 100644 --- a/src/app/editor/dungeon/dungeon_editor.cc +++ b/src/app/editor/dungeon/dungeon_editor.cc @@ -43,7 +43,7 @@ constexpr ImGuiTableFlags kDungeonObjectTableFlags = absl::Status DungeonEditor::Update() { if (!is_loaded_ && rom()->is_loaded()) { - RETURN_IF_ERROR(Initialize()); + Initialize(); is_loaded_ = true; } @@ -72,7 +72,7 @@ absl::Status DungeonEditor::Update() { return absl::OkStatus(); } -absl::Status DungeonEditor::Initialize() { +void DungeonEditor::Initialize() { auto dungeon_man_pal_group = rom()->palette_group().dungeon_main; for (int i = 0; i < 0x100 + 40; i++) { @@ -89,9 +89,11 @@ absl::Status DungeonEditor::Initialize() { } auto dungeon_palette_ptr = rom()->paletteset_ids[rooms_[i].palette][0]; - ASSIGN_OR_RETURN(auto palette_id, - rom()->ReadWord(0xDEC4B + dungeon_palette_ptr)); - int p_id = palette_id / 180; + auto palette_id = rom()->ReadWord(0xDEC4B + dungeon_palette_ptr); + if (palette_id.status() != absl::OkStatus()) { + continue; + } + int p_id = palette_id.value() / 180; auto color = dungeon_man_pal_group[p_id][3]; room_palette_[rooms_[i].palette] = color.rgb(); } @@ -108,15 +110,19 @@ absl::Status DungeonEditor::Initialize() { // Load the palette group and palette for the dungeon full_palette_ = dungeon_man_pal_group[current_palette_group_id_]; - ASSIGN_OR_RETURN(current_palette_group_, - gfx::CreatePaletteGroupFromLargePalette(full_palette_)); + auto current_palette_group = + gfx::CreatePaletteGroupFromLargePalette(full_palette_); + if (current_palette_group.ok()) { + current_palette_group_ = current_palette_group.value(); + } else { + // LOG(ERROR) << "Failed to create palette group from large palette"; + } graphics_bin_ = GraphicsSheetManager::GetInstance().gfx_sheets(); // Create a vector of pointers to the current block bitmaps for (int block : rooms_[current_room_id_].blocks()) { room_gfx_sheets_.emplace_back(&graphics_bin_[block]); } - return absl::OkStatus(); } absl::Status DungeonEditor::RefreshGraphics() { diff --git a/src/app/editor/dungeon/dungeon_editor.h b/src/app/editor/dungeon/dungeon_editor.h index d06e5619..60c8084d 100644 --- a/src/app/editor/dungeon/dungeon_editor.h +++ b/src/app/editor/dungeon/dungeon_editor.h @@ -42,6 +42,7 @@ class DungeonEditor : public Editor, public SharedRom { public: DungeonEditor() { type_ = EditorType::kDungeon; } + void Initialize() override; absl::Status Update() override; absl::Status Undo() override { return absl::UnimplementedError("Undo"); } absl::Status Redo() override { return absl::UnimplementedError("Redo"); } @@ -53,7 +54,6 @@ class DungeonEditor : public Editor, public SharedRom { void add_room(int i) { active_rooms_.push_back(i); } private: - absl::Status Initialize(); absl::Status RefreshGraphics(); void LoadDungeonRoomSize(); diff --git a/src/app/editor/editor.h b/src/app/editor/editor.h index 44c72844..3e4375c8 100644 --- a/src/app/editor/editor.h +++ b/src/app/editor/editor.h @@ -53,6 +53,8 @@ class Editor { Editor() = default; virtual ~Editor() = default; + virtual void Initialize() = 0; + virtual absl::Status Cut() = 0; virtual absl::Status Copy() = 0; virtual absl::Status Paste() = 0; diff --git a/src/app/editor/graphics/graphics_editor.cc b/src/app/editor/graphics/graphics_editor.cc index 975ffdac..4af61d48 100644 --- a/src/app/editor/graphics/graphics_editor.cc +++ b/src/app/editor/graphics/graphics_editor.cc @@ -40,6 +40,8 @@ constexpr ImGuiTableFlags kGfxEditTableFlags = ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_SizingFixedFit; +void GraphicsEditor::Initialize() {} + absl::Status GraphicsEditor::Update() { if (ImGui::BeginTabBar("##TabBar")) { status_ = UpdateGfxEdit(); diff --git a/src/app/editor/graphics/graphics_editor.h b/src/app/editor/graphics/graphics_editor.h index 4edad87b..a8b1f14a 100644 --- a/src/app/editor/graphics/graphics_editor.h +++ b/src/app/editor/graphics/graphics_editor.h @@ -58,8 +58,8 @@ class GraphicsEditor : public SharedRom, public Editor { public: GraphicsEditor() { type_ = EditorType::kGraphics; } + void Initialize() override; absl::Status Update() override; - absl::Status Undo() override { return absl::UnimplementedError("Undo"); } absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Cut() override { return absl::UnimplementedError("Cut"); } @@ -159,7 +159,7 @@ class GraphicsEditor : public SharedRom, public Editor { Rom temp_rom_; Rom tilemap_rom_; - zelda3::Overworld overworld_{ temp_rom_ }; + zelda3::Overworld overworld_{temp_rom_}; MemoryEditor cgx_memory_editor_; MemoryEditor col_memory_editor_; PaletteEditor palette_editor_; @@ -176,7 +176,7 @@ class GraphicsEditor : public SharedRom, public Editor { gfx::Bitmap bin_bitmap_; gfx::Bitmap link_full_sheet_; std::array gfx_sheets_; - std::array link_sheets_; + std::array link_sheets_; gfx::PaletteGroup col_file_palette_group_; gfx::SnesPalette z3_rom_palette_; diff --git a/src/app/editor/graphics/palette_editor.cc b/src/app/editor/graphics/palette_editor.cc index 5669825c..27889685 100644 --- a/src/app/editor/graphics/palette_editor.cc +++ b/src/app/editor/graphics/palette_editor.cc @@ -170,6 +170,8 @@ absl::Status DisplayPalette(gfx::SnesPalette& palette, bool loaded) { return absl::OkStatus(); } +void PaletteEditor::Initialize() {} + absl::Status PaletteEditor::Update() { if (rom()->is_loaded()) { // Initialize the labels diff --git a/src/app/editor/graphics/palette_editor.h b/src/app/editor/graphics/palette_editor.h index 775b033a..d238abc5 100644 --- a/src/app/editor/graphics/palette_editor.h +++ b/src/app/editor/graphics/palette_editor.h @@ -6,10 +6,10 @@ #include #include "absl/status/status.h" -#include "app/editor/graphics/gfx_group_editor.h" #include "app/editor/editor.h" -#include "app/gfx/snes_palette.h" +#include "app/editor/graphics/gfx_group_editor.h" #include "app/gfx/snes_color.h" +#include "app/gfx/snes_palette.h" #include "app/rom.h" #include "imgui/imgui.h" @@ -17,6 +17,7 @@ namespace yaze { namespace editor { namespace palette_internal { + struct PaletteChange { std::string group_name; size_t palette_index; @@ -83,6 +84,8 @@ class PaletteEditor : public SharedRom, public Editor { custom_palette_.push_back(gfx::SnesColor(0x7FFF)); } + void Initialize() override; + absl::Status Update() override; absl::Status Cut() override { return absl::OkStatus(); } diff --git a/src/app/editor/graphics/screen_editor.cc b/src/app/editor/graphics/screen_editor.cc index 2f5c87b3..39b8089f 100644 --- a/src/app/editor/graphics/screen_editor.cc +++ b/src/app/editor/graphics/screen_editor.cc @@ -26,6 +26,8 @@ using core::Renderer; constexpr uint32_t kRedPen = 0xFF0000FF; +void ScreenEditor::Initialize() {} + absl::Status ScreenEditor::Update() { if (ImGui::BeginTabBar("##ScreenEditorTabBar")) { if (ImGui::BeginTabItem("Dungeon Maps")) { diff --git a/src/app/editor/graphics/screen_editor.h b/src/app/editor/graphics/screen_editor.h index 4c61e09e..93f6fb08 100644 --- a/src/app/editor/graphics/screen_editor.h +++ b/src/app/editor/graphics/screen_editor.h @@ -38,6 +38,8 @@ class ScreenEditor : public SharedRom, public Editor { type_ = EditorType::kScreen; } + void Initialize() override; + absl::Status Update() override; absl::Status Undo() override { return absl::UnimplementedError("Undo"); } diff --git a/src/app/editor/graphics/tile16_editor.cc b/src/app/editor/graphics/tile16_editor.cc index 04d606b9..c2e30a2f 100644 --- a/src/app/editor/graphics/tile16_editor.cc +++ b/src/app/editor/graphics/tile16_editor.cc @@ -391,9 +391,9 @@ absl::Status Tile16Editor::UpdateTransferTileCanvas() { palette_ = transfer_overworld_.current_area_palette(); // Create the tile16 blockset image - RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap( + Renderer::GetInstance().CreateAndRenderBitmap( 0x80, 0x2000, 0x80, transfer_overworld_.tile16_blockset_data(), - transfer_blockset_bmp_, palette_)); + transfer_blockset_bmp_, palette_); transfer_blockset_loaded_ = true; } diff --git a/src/app/editor/message/message_editor.cc b/src/app/editor/message/message_editor.cc index 1309e1ee..2559d77b 100644 --- a/src/app/editor/message/message_editor.cc +++ b/src/app/editor/message/message_editor.cc @@ -44,7 +44,7 @@ constexpr ImGuiTableFlags kMessageTableFlags = ImGuiTableFlags_Hideable | constexpr ImGuiTableFlags kDictTableFlags = ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable; -absl::Status MessageEditor::Initialize() { +void MessageEditor::Initialize() { for (int i = 0; i < kWidthArraySize; i++) { width_array[i] = rom()->data()[kCharactersWidth + i]; } @@ -64,9 +64,9 @@ absl::Status MessageEditor::Initialize() { font_gfx16_data_ = gfx::SnesTo8bppSheet(data, /*bpp=*/2, /*num_sheets=*/2); // 4bpp - RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap( + Renderer::GetInstance().CreateAndRenderBitmap( kFontGfxMessageSize, kFontGfxMessageSize, kFontGfxMessageDepth, - font_gfx16_data_, font_gfx_bitmap_, font_preview_colors_)) + font_gfx16_data_, font_gfx_bitmap_, font_preview_colors_); current_font_gfx16_data_.reserve(kCurrentMessageWidth * kCurrentMessageHeight); @@ -75,21 +75,19 @@ absl::Status MessageEditor::Initialize() { } // 8bpp - RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap( + Renderer::GetInstance().CreateAndRenderBitmap( kCurrentMessageWidth, kCurrentMessageHeight, 64, current_font_gfx16_data_, - current_font_gfx16_bitmap_, font_preview_colors_)) + current_font_gfx16_bitmap_, font_preview_colors_); *font_gfx_bitmap_.mutable_palette() = font_preview_colors_; parsed_messages_ = ParseMessageData(list_of_texts_, all_dictionaries_); DrawMessagePreview(); - - return absl::OkStatus(); } absl::Status MessageEditor::Update() { if (rom()->is_loaded() && !data_loaded_) { - RETURN_IF_ERROR(Initialize()); + Initialize(); current_message_ = list_of_texts_[1]; data_loaded_ = true; } diff --git a/src/app/editor/message/message_editor.h b/src/app/editor/message/message_editor.h index 30cbf3f0..cf69144f 100644 --- a/src/app/editor/message/message_editor.h +++ b/src/app/editor/message/message_editor.h @@ -37,7 +37,7 @@ class MessageEditor : public Editor, public SharedRom { public: MessageEditor() { type_ = EditorType::kMessage; } - absl::Status Initialize(); + void Initialize() override; absl::Status Update() override; void DrawMessageList(); void DrawCurrentMessage(); diff --git a/src/app/editor/music/music_editor.cc b/src/app/editor/music/music_editor.cc index 06b0d058..dc26db60 100644 --- a/src/app/editor/music/music_editor.cc +++ b/src/app/editor/music/music_editor.cc @@ -1,15 +1,16 @@ #include "music_editor.h" -#include "imgui/imgui.h" - #include "absl/strings/str_format.h" #include "app/editor/code/assembly_editor.h" #include "app/gui/icons.h" #include "app/gui/input.h" +#include "imgui/imgui.h" namespace yaze { namespace editor { +void MusicEditor::Initialize() {} + absl::Status MusicEditor::Update() { if (ImGui::BeginTable("MusicEditorColumns", 2, music_editor_flags_, ImVec2(0, 0))) { diff --git a/src/app/editor/music/music_editor.h b/src/app/editor/music/music_editor.h index bdb543b5..5ce6fb4e 100644 --- a/src/app/editor/music/music_editor.h +++ b/src/app/editor/music/music_editor.h @@ -58,8 +58,8 @@ class MusicEditor : public SharedRom, public Editor { public: MusicEditor() { type_ = EditorType::kMusic; } + void Initialize() override; absl::Status Update() override; - absl::Status Undo() override { return absl::UnimplementedError("Undo"); } absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Cut() override { return absl::UnimplementedError("Cut"); } diff --git a/src/app/editor/overworld/overworld_editor.cc b/src/app/editor/overworld/overworld_editor.cc index b05424ff..f8c4a800 100644 --- a/src/app/editor/overworld/overworld_editor.cc +++ b/src/app/editor/overworld/overworld_editor.cc @@ -733,9 +733,9 @@ absl::Status OverworldEditor::DrawAreaGraphics() { overworld_.set_current_map(current_map_); palette_ = overworld_.current_area_palette(); gfx::Bitmap bmp; - RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap( - 0x80, kOverworldMapSize, 0x08, overworld_.current_graphics(), bmp, - palette_)); + Renderer::GetInstance().CreateAndRenderBitmap(0x80, kOverworldMapSize, 0x08, + overworld_.current_graphics(), + bmp, palette_); current_graphics_set_[current_map_] = bmp; } @@ -1028,15 +1028,15 @@ absl::Status OverworldEditor::LoadGraphics() { util::logf("Loading overworld graphics."); // Create the area graphics image - RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap( - 0x80, kOverworldMapSize, 0x40, overworld_.current_graphics(), - current_gfx_bmp_, palette_)); + Renderer::GetInstance().CreateAndRenderBitmap(0x80, kOverworldMapSize, 0x40, + overworld_.current_graphics(), + current_gfx_bmp_, palette_); util::logf("Loading overworld tileset."); // Create the tile16 blockset image - RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap( + Renderer::GetInstance().CreateAndRenderBitmap( 0x80, 0x2000, 0x08, overworld_.tile16_blockset_data(), - tile16_blockset_bmp_, palette_)); + tile16_blockset_bmp_, palette_); map_blockset_loaded_ = true; // Copy the tile16 data into individual tiles. @@ -1069,9 +1069,9 @@ absl::Status OverworldEditor::LoadGraphics() { overworld_.set_current_map(i); auto palette = overworld_.current_area_palette(); try { - RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap( + Renderer::GetInstance().CreateAndRenderBitmap( kOverworldMapSize, kOverworldMapSize, 0x80, - overworld_.current_map_bitmap_data(), maps_bmp_[i], palette)); + overworld_.current_map_bitmap_data(), maps_bmp_[i], palette); } catch (const std::bad_alloc &e) { std::cout << "Error: " << e.what() << std::endl; continue; diff --git a/src/app/editor/overworld/overworld_editor.h b/src/app/editor/overworld/overworld_editor.h index 4a6dfba3..20876339 100644 --- a/src/app/editor/overworld/overworld_editor.h +++ b/src/app/editor/overworld/overworld_editor.h @@ -76,7 +76,7 @@ class OverworldEditor : public Editor, public gfx::GfxContext { public: OverworldEditor(Rom& rom) : rom_(rom) { type_ = EditorType::kOverworld; } - void Initialize(); + void Initialize() override; absl::Status Update() final; absl::Status Undo() override { return absl::UnimplementedError("Undo"); } diff --git a/src/app/editor/sprite/sprite_editor.cc b/src/app/editor/sprite/sprite_editor.cc index 364c3cdb..0b4e38ce 100644 --- a/src/app/editor/sprite/sprite_editor.cc +++ b/src/app/editor/sprite/sprite_editor.cc @@ -21,6 +21,8 @@ using ImGui::TableNextRow; using ImGui::TableSetupColumn; using ImGui::Text; +void SpriteEditor::Initialize() {} + absl::Status SpriteEditor::Update() { if (rom()->is_loaded() && !sheets_loaded_) { // Load the values for current_sheets_ array diff --git a/src/app/editor/sprite/sprite_editor.h b/src/app/editor/sprite/sprite_editor.h index 04f29420..2e1f8170 100644 --- a/src/app/editor/sprite/sprite_editor.h +++ b/src/app/editor/sprite/sprite_editor.h @@ -5,8 +5,8 @@ #include #include "absl/status/status.h" -#include "app/editor/sprite/zsprite.h" #include "app/editor/editor.h" +#include "app/editor/sprite/zsprite.h" #include "app/gui/canvas.h" #include "app/rom.h" @@ -37,13 +37,8 @@ class SpriteEditor : public SharedRom, public Editor { public: SpriteEditor() { type_ = EditorType::kSprite; } - /** - * @brief Updates the sprite editor. - * - * @return An absl::Status indicating the success or failure of the update. - */ + void Initialize() override; absl::Status Update() override; - absl::Status Undo() override { return absl::UnimplementedError("Undo"); } absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Cut() override { return absl::UnimplementedError("Cut"); } @@ -68,9 +63,7 @@ class SpriteEditor : public SharedRom, public Editor { * @brief Draws the current sheets. */ void DrawCurrentSheets(); - void DrawCustomSprites(); - void DrawCustomSpritesMetadata(); /** diff --git a/src/app/editor/system/settings_editor.cc b/src/app/editor/system/settings_editor.cc index 33bd1d64..359ea31a 100644 --- a/src/app/editor/system/settings_editor.cc +++ b/src/app/editor/system/settings_editor.cc @@ -21,6 +21,8 @@ using ImGui::TableHeadersRow; using ImGui::TableNextColumn; using ImGui::TableSetupColumn; +void SettingsEditor::Initialize() {} + absl::Status SettingsEditor::Update() { if (BeginTabBar("Settings", ImGuiTabBarFlags_None)) { if (BeginTabItem("General")) { diff --git a/src/app/editor/system/settings_editor.h b/src/app/editor/system/settings_editor.h index ca13e09f..556ee421 100644 --- a/src/app/editor/system/settings_editor.h +++ b/src/app/editor/system/settings_editor.h @@ -208,9 +208,8 @@ static void ShowExampleAppPropertyEditor(bool* p_open) { class SettingsEditor : public Editor { public: SettingsEditor() : Editor() { type_ = EditorType::kSettings; } - + void Initialize() override; absl::Status Update() override; - absl::Status Undo() override { return absl::UnimplementedError("Undo"); } absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Cut() override { return absl::UnimplementedError("Cut"); }