diff --git a/src/app/editor/modules/tile16_editor.cc b/src/app/editor/modules/tile16_editor.cc index 25df916f..fe2dcee0 100644 --- a/src/app/editor/modules/tile16_editor.cc +++ b/src/app/editor/modules/tile16_editor.cc @@ -1,7 +1,143 @@ - #include "tile16_editor.h" +#include + +#include + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "app/core/editor.h" +#include "app/core/pipeline.h" +#include "app/editor/palette_editor.h" +#include "app/gfx/bitmap.h" +#include "app/gfx/snes_palette.h" +#include "app/gfx/snes_tile.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" +#include "app/rom.h" +#include "app/zelda3/overworld.h" + +namespace yaze { +namespace app { +namespace editor { + absl::Status Tile16Editor::Update() { - // TODO: Implement the Update method for the Tile16Editor class. + // Create a tab bar for Tile16 Editing and Tile16 Transfer + if (ImGui::BeginTabBar("Tile16 Editor Tabs")) { + // Create a tab for Tile16 Editing + if (ImGui::BeginTabItem("Tile16 Editing")) { + if (ImGui::BeginTable("#Tile16EditorTable", 2, + ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable, + ImVec2(0, 0))) { + ImGui::TableSetupColumn("Tiles", ImGuiTableColumnFlags_WidthFixed, + ImGui::GetContentRegionAvail().x); + ImGui::TableSetupColumn("Properties", + ImGuiTableColumnFlags_WidthStretch, + ImGui::GetContentRegionAvail().x); + ImGui::TableHeadersRow(); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + { + // Create a canvas for the Tile16 + core::BitmapCanvasPipeline(blockset_canvas_, tile16_blockset_bmp_, + 0x100, (8192 * 2), 0x20, + map_blockset_loaded_, true, 1); + } + ImGui::TableNextColumn(); + { + // Create various options for the Tile16 Editor + + ImGui::Separator(); + ImGui::Text("Options:"); + ImGui::Checkbox("X Flip", &x_flip); + ImGui::Checkbox("Y Flip", &y_flip); + ImGui::Checkbox("Priority Tile", &priority_tile); + ImGui::SliderInt("Tile Size", &tile_size, 8, 16); + static const char* items[] = {"Item 1", "Item 2", "Item 3"}; + static int item_current = 0; + ImGui::Combo("Combo", &item_current, items, IM_ARRAYSIZE(items)); + } + ImGui::EndTable(); + } + + ImGui::EndTabItem(); + } + + // Create a tab for Tile16 Transfer + if (ImGui::BeginTabItem("Tile16 Transfer")) { + if (ImGui::BeginTable("#Tile16TransferTable", 2, + ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable, + ImVec2(0, 0))) { + ImGui::TableSetupColumn("Current ROM Tiles", + ImGuiTableColumnFlags_WidthFixed, + ImGui::GetContentRegionAvail().x / 2); + ImGui::TableSetupColumn("Transfer ROM Tiles", + ImGuiTableColumnFlags_WidthFixed, + ImGui::GetContentRegionAvail().x / 2); + ImGui::TableHeadersRow(); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + { + // Create a canvas for holding the tiles which will be imported + core::BitmapCanvasPipeline(blockset_canvas_, tile16_blockset_bmp_, + 0x100, (8192 * 2), 0x20, + map_blockset_loaded_, true, 2); + } + ImGui::TableNextColumn(); + { + // Create a button for loading another ROM + if (ImGui::Button("Load ROM")) { + ImGuiFileDialog::Instance()->OpenDialog("ChooseTransferFileDlgKey", + "Open Transfer ROM", + ".sfc,.smc", "."); + } + core::FileDialogPipeline( + "ChooseTransferFileDlgKey", ".sfc,.smc", std::nullopt, [&]() { + std::string filePathName = + ImGuiFileDialog::Instance()->GetFilePathName(); + transfer_status_ = transfer_rom_.LoadFromFile(filePathName); + transfer_started_ = true; + }); + + if (transfer_started_ && !transfer_blockset_loaded_) { + PRINT_IF_ERROR(transfer_rom_.LoadAllGraphicsData()) + graphics_bin_ = transfer_rom_.GetGraphicsBin(); + + // Load the Link to the Past overworld. + PRINT_IF_ERROR(transfer_overworld_.Load(transfer_rom_)) + transfer_overworld_.SetCurrentMap(0); + palette_ = transfer_overworld_.AreaPalette(); + + // Create the tile16 blockset image + core::BuildAndRenderBitmapPipeline( + 0x80, 0x2000, 0x80, transfer_overworld_.Tile16Blockset(), + *rom(), transfer_blockset_bmp_, palette_); + transfer_blockset_loaded_ = true; + } + + // Create a canvas for holding the tiles which will be exported + core::BitmapCanvasPipeline(transfer_canvas_, transfer_blockset_bmp_, + 0x100, (8192 * 2), 0x20, + transfer_blockset_loaded_, true, 3); + } + ImGui::EndTable(); + } + + ImGui::EndTabItem(); + } + + ImGui::EndTabBar(); + } + return absl::OkStatus(); } + +absl::Status Tile16Editor::InitBlockset(gfx::Bitmap tile16_blockset_bmp) { + tile16_blockset_bmp_ = tile16_blockset_bmp; + map_blockset_loaded_ = true; + return absl::OkStatus(); +} + +} // namespace editor +} // namespace app +} // namespace yaze \ No newline at end of file diff --git a/src/app/editor/modules/tile16_editor.h b/src/app/editor/modules/tile16_editor.h index a079e9eb..75809397 100644 --- a/src/app/editor/modules/tile16_editor.h +++ b/src/app/editor/modules/tile16_editor.h @@ -18,9 +18,54 @@ #include "app/rom.h" #include "app/zelda3/overworld.h" -class Tile16Editor { +namespace yaze { +namespace app { +namespace editor { + +class Tile16Editor : public SharedROM { public: absl::Status Update(); + + absl::Status InitBlockset(gfx::Bitmap tile16_blockset_bmp); + + private: + bool map_blockset_loaded_ = false; + bool transfer_started_ = false; + bool transfer_blockset_loaded_ = false; + + // Canvas dimensions + int canvas_width; + int canvas_height; + + // Texture ID for the canvas + int texture_id; + + // Various options for the Tile16 Editor + bool x_flip; + bool y_flip; + bool priority_tile; + int tile_size; + + gui::Canvas blockset_canvas_; + gfx::Bitmap tile16_blockset_bmp_; + + gui::Canvas transfer_canvas_; + gfx::Bitmap transfer_blockset_bmp_; + gfx::Bitmap transfer_current_bmp_; + + PaletteEditor palette_editor_; + + gfx::SNESPalette palette_; + zelda3::Overworld transfer_overworld_; + std::vector tile16_individual_data_; + std::vector tile16_individual_; + gfx::BitmapTable graphics_bin_; + + ROM transfer_rom_; + absl::Status transfer_status_; }; +} // namespace editor +} // namespace app +} // namespace yaze #endif // YAZE_APP_EDITOR_TILE16EDITOR_H \ No newline at end of file