From ef61d31c188ce40fada01a60b793883204f56704 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 00:28:03 -0400 Subject: [PATCH] add mosaic editor user interface --- src/app/editor/master_editor.cc | 1 + src/app/editor/screen_editor.cc | 57 +++++++++++++++++++++++++++++---- src/app/editor/screen_editor.h | 9 +++++- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index 54b95ba9..871c2d34 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -102,6 +102,7 @@ void MasterEditor::DrawFileDialog() { std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); status_ = rom_.LoadFromFile(filePathName); overworld_editor_.SetupROM(rom_); + screen_editor_.SetupROM(rom_); } ImGuiFileDialog::Instance()->Close(); } diff --git a/src/app/editor/screen_editor.cc b/src/app/editor/screen_editor.cc index 14e533fb..0df6f91c 100644 --- a/src/app/editor/screen_editor.cc +++ b/src/app/editor/screen_editor.cc @@ -9,6 +9,7 @@ #include #include "absl/status/statusor.h" +#include "absl/strings/str_format.h" #include "absl/strings/string_view.h" #include "app/asm/script.h" #include "app/core/common.h" @@ -16,6 +17,7 @@ #include "app/gfx/bitmap.h" #include "app/gfx/snes_tile.h" #include "gui/canvas.h" +#include "gui/input.h" namespace yaze { namespace app { @@ -35,17 +37,60 @@ void ScreenEditor::Update() { END_TAB_BAR() } +void ScreenEditor::DrawWorldGrid(int world, int h, int w) { + const float time = (float)ImGui::GetTime(); + + int i = 0; + if (world == 1) { + i = 64; + } else if (world == 2) { + i = 128; + } + for (int y = 0; y < h; y++) + for (int x = 0; x < w; x++) { + if (x > 0) ImGui::SameLine(); + ImGui::PushID(y * 4 + x); + std::string label = absl::StrCat(" #", absl::StrFormat("%x", i)); + if (ImGui::Selectable(label.c_str(), mosaic_tiles_[i] != 0, 0, + ImVec2(35, 25))) { + mosaic_tiles_[i] ^= 1; + } + ImGui::PopID(); + i++; + } +} + void ScreenEditor::DrawMosaicEditor() { TAB_ITEM("Mosaic Transitions") - if (ImGui::Button("GenerateMosaicChangeAssembly")) { - auto mosaic = mosaic_script_.GenerateMosaicChangeAssembly(mosaic_tiles_); + + if (ImGui::BeginTable("Worlds", 3, ImGuiTableFlags_Borders)) { + ImGui::TableSetupColumn("Light World"); + ImGui::TableSetupColumn("Dark World"); + ImGui::TableSetupColumn("Special World"); + ImGui::TableHeadersRow(); + + ImGui::TableNextColumn(); + DrawWorldGrid(0); + + ImGui::TableNextColumn(); + DrawWorldGrid(1); + + ImGui::TableNextColumn(); + DrawWorldGrid(2, 4); + + ImGui::EndTable(); + } + + gui::InputHex("Routine Location", &overworldCustomMosaicASM); + + if (ImGui::Button("Generate Mosaic Assembly")) { + auto mosaic = mosaic_script_.GenerateMosaicChangeAssembly( + rom_, mosaic_tiles_, overworldCustomMosaicASM); if (!mosaic.ok()) { - std::cout << "Failed to generate mosaic change assembly"; - } else { - std::cout << "Successfully generated mosaic change assembly"; - std::cout << mosaic.value(); + std::cout << mosaic; } } + END_TAB_ITEM() } diff --git a/src/app/editor/screen_editor.h b/src/app/editor/screen_editor.h index bd9a900c..413e8d4b 100644 --- a/src/app/editor/screen_editor.h +++ b/src/app/editor/screen_editor.h @@ -9,6 +9,7 @@ #include "app/core/constants.h" #include "app/gfx/bitmap.h" #include "app/gfx/snes_tile.h" +#include "app/rom.h" #include "app/zelda3/screen.h" #include "gui/canvas.h" @@ -17,9 +18,12 @@ namespace app { namespace editor { using MosaicArray = std::array; +static int overworldCustomMosaicASM = 0x1301D0; +static int overworldCustomMosaicArray = 0x1301F0; class ScreenEditor { public: + void SetupROM(ROM &rom) { rom_ = rom; } ScreenEditor(); void Update(); @@ -34,8 +38,11 @@ class ScreenEditor { void DrawCanvas(); void DrawToolset(); + void DrawWorldGrid(int world, int h = 8, int w = 8); - std::array mosaic_tiles_; + char mosaic_tiles_[core::kNumOverworldMaps]; + + ROM rom_; snes_asm::Script mosaic_script_; zelda3::Screen current_screen_; gui::Canvas screen_canvas_;