From f28e33b5d0fe0131a327c943682f17302b59d52d Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 6 Apr 2024 10:29:28 -0400 Subject: [PATCH] Tile16 Editor and Transfer cleanup --- src/app/editor/modules/tile16_editor.cc | 157 ++++++++++++------------ src/app/editor/modules/tile16_editor.h | 8 +- 2 files changed, 86 insertions(+), 79 deletions(-) diff --git a/src/app/editor/modules/tile16_editor.cc b/src/app/editor/modules/tile16_editor.cc index 22690f93..f7ac1c37 100644 --- a/src/app/editor/modules/tile16_editor.cc +++ b/src/app/editor/modules/tile16_editor.cc @@ -63,7 +63,7 @@ absl::Status Tile16Editor::DrawTile16Editor() { if (BeginTabItem("Tile16 Editing")) { if (BeginTable("#Tile16EditorTable", 2, TABLE_BORDERS_RESIZABLE, ImVec2(0, 0))) { - TableSetupColumn("Tiles", ImGuiTableColumnFlags_WidthFixed, + TableSetupColumn("Blockset", ImGuiTableColumnFlags_WidthFixed, ImGui::GetContentRegionAvail().x); TableSetupColumn("Properties", ImGuiTableColumnFlags_WidthStretch, ImGui::GetContentRegionAvail().x); @@ -83,42 +83,19 @@ absl::Status Tile16Editor::DrawTile16Editor() { return absl::OkStatus(); } -absl::Status Tile16Editor::UpdateTile16Transfer() { - if (BeginTabItem("Tile16 Transfer")) { - if (BeginTable("#Tile16TransferTable", 2, TABLE_BORDERS_RESIZABLE, - ImVec2(0, 0))) { - TableSetupColumn("Current ROM Tiles", ImGuiTableColumnFlags_WidthFixed, - ImGui::GetContentRegionAvail().x / 2); - TableSetupColumn("Transfer ROM Tiles", ImGuiTableColumnFlags_WidthFixed, - ImGui::GetContentRegionAvail().x / 2); - TableHeadersRow(); - TableNextRow(); - - TableNextColumn(); - RETURN_IF_ERROR(UpdateBlockset()); - - TableNextColumn(); - RETURN_IF_ERROR(UpdateTransferTileCanvas()); - - ImGui::EndTable(); - } - - ImGui::EndTabItem(); - } - return absl::OkStatus(); -} - absl::Status Tile16Editor::UpdateBlockset() { gui::BeginPadding(2); gui::BeginChildWithScrollbar("##Tile16EditorBlocksetScrollRegion"); blockset_canvas_.DrawBackground(); gui::EndPadding(); - blockset_canvas_.DrawContextMenu(); - blockset_canvas_.DrawTileSelector(32); - blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, 0, map_blockset_loaded_); - blockset_canvas_.DrawGrid(); - blockset_canvas_.DrawOverlay(); - ImGui::EndChild(); + { + blockset_canvas_.DrawContextMenu(); + blockset_canvas_.DrawTileSelector(32); + blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, 0, map_blockset_loaded_); + blockset_canvas_.DrawGrid(); + blockset_canvas_.DrawOverlay(); + ImGui::EndChild(); + } if (!blockset_canvas_.points().empty()) { uint16_t x = blockset_canvas_.points().front().x / 32; @@ -176,8 +153,7 @@ absl::Status Tile16Editor::UpdateTile16Edit() { if (ImGui::BeginChild("Tile8 Selector", ImVec2(ImGui::GetContentRegionAvail().x, 0x175), true)) { - tile8_source_canvas_.DrawBackground( - ImVec2(core::kTilesheetWidth * 4, core::kTilesheetHeight * 0x10 * 4)); + tile8_source_canvas_.DrawBackground(); tile8_source_canvas_.DrawContextMenu(); if (tile8_source_canvas_.DrawTileSelector(32)) { current_gfx_individual_[current_tile8_].ApplyPaletteWithTransparent( @@ -185,11 +161,12 @@ absl::Status Tile16Editor::UpdateTile16Edit() { rom()->UpdateBitmap(¤t_gfx_individual_[current_tile8_]); } tile8_source_canvas_.DrawBitmap(current_gfx_bmp_, 0, 0, 4.0f); - tile8_source_canvas_.DrawGrid(32.0f); + tile8_source_canvas_.DrawGrid(); tile8_source_canvas_.DrawOverlay(); } ImGui::EndChild(); + // The user selected a tile8 if (!tile8_source_canvas_.points().empty()) { uint16_t x = tile8_source_canvas_.points().front().x / 16; uint16_t y = tile8_source_canvas_.points().front().y / 16; @@ -205,7 +182,7 @@ absl::Status Tile16Editor::UpdateTile16Edit() { if (ImGui::BeginChild("Tile16 Editor Options", ImVec2(ImGui::GetContentRegionAvail().x, 0x50), true)) { - tile16_edit_canvas_.DrawBackground(ImVec2(0x40, 0x40)); + tile16_edit_canvas_.DrawBackground(); tile16_edit_canvas_.DrawContextMenu(); tile16_edit_canvas_.DrawBitmap(current_tile16_bmp_, 0, 0, 4.0f); if (!tile8_source_canvas_.points().empty()) { @@ -216,7 +193,7 @@ absl::Status Tile16Editor::UpdateTile16Edit() { rom()->UpdateBitmap(¤t_tile16_bmp_); } } - tile16_edit_canvas_.DrawGrid(64.0f); + tile16_edit_canvas_.DrawGrid(); tile16_edit_canvas_.DrawOverlay(); } ImGui::EndChild(); @@ -254,45 +231,6 @@ void Tile16Editor::DrawTileEditControls() { ImGui::Checkbox("Priority Tile", &priority_tile); } -absl::Status Tile16Editor::UpdateTransferTileCanvas() { - // Create a button for loading another ROM - if (ImGui::Button("Load ROM")) { - ImGuiFileDialog::Instance()->OpenDialog( - "ChooseTransferFileDlgKey", "Open Transfer ROM", ".sfc,.smc", "."); - } - gui::FileDialogPipeline( - "ChooseTransferFileDlgKey", ".sfc,.smc", std::nullopt, [&]() { - std::string filePathName = - ImGuiFileDialog::Instance()->GetFilePathName(); - transfer_status_ = transfer_rom_.LoadFromFile(filePathName); - transfer_started_ = true; - }); - - // TODO: Implement tile16 transfer - if (transfer_started_ && !transfer_blockset_loaded_) { - PRINT_IF_ERROR(transfer_rom_.LoadAllGraphicsData()) - graphics_bin_ = transfer_rom_.graphics_bin(); - - // Load the Link to the Past overworld. - PRINT_IF_ERROR(transfer_overworld_.Load(transfer_rom_)) - transfer_overworld_.set_current_map(0); - palette_ = transfer_overworld_.AreaPalette(); - - // Create the tile16 blockset image - gui::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 - gui::BitmapCanvasPipeline(transfer_canvas_, transfer_blockset_bmp_, 0x100, - (8192 * 2), 0x20, transfer_blockset_loaded_, true, - 3); - - return absl::OkStatus(); -} - absl::Status Tile16Editor::InitBlockset( const gfx::Bitmap& tile16_blockset_bmp, gfx::Bitmap current_gfx_bmp, const std::vector& tile16_individual, @@ -349,6 +287,73 @@ absl::Status Tile16Editor::LoadTile8() { return absl::OkStatus(); } +// ============================================================================ +// Tile16 Transfer + +absl::Status Tile16Editor::UpdateTile16Transfer() { + if (BeginTabItem("Tile16 Transfer")) { + if (BeginTable("#Tile16TransferTable", 2, TABLE_BORDERS_RESIZABLE, + ImVec2(0, 0))) { + TableSetupColumn("Current ROM Tiles", ImGuiTableColumnFlags_WidthFixed, + ImGui::GetContentRegionAvail().x / 2); + TableSetupColumn("Transfer ROM Tiles", ImGuiTableColumnFlags_WidthFixed, + ImGui::GetContentRegionAvail().x / 2); + TableHeadersRow(); + TableNextRow(); + + TableNextColumn(); + RETURN_IF_ERROR(UpdateBlockset()); + + TableNextColumn(); + RETURN_IF_ERROR(UpdateTransferTileCanvas()); + + ImGui::EndTable(); + } + + ImGui::EndTabItem(); + } + return absl::OkStatus(); +} + +absl::Status Tile16Editor::UpdateTransferTileCanvas() { + // Create a button for loading another ROM + if (ImGui::Button("Load ROM")) { + ImGuiFileDialog::Instance()->OpenDialog( + "ChooseTransferFileDlgKey", "Open Transfer ROM", ".sfc,.smc", "."); + } + gui::FileDialogPipeline( + "ChooseTransferFileDlgKey", ".sfc,.smc", std::nullopt, [&]() { + std::string filePathName = + ImGuiFileDialog::Instance()->GetFilePathName(); + transfer_status_ = transfer_rom_.LoadFromFile(filePathName); + transfer_started_ = true; + }); + + // TODO: Implement tile16 transfer + if (transfer_started_ && !transfer_blockset_loaded_) { + PRINT_IF_ERROR(transfer_rom_.LoadAllGraphicsData()) + graphics_bin_ = transfer_rom_.graphics_bin(); + + // Load the Link to the Past overworld. + PRINT_IF_ERROR(transfer_overworld_.Load(transfer_rom_)) + transfer_overworld_.set_current_map(0); + palette_ = transfer_overworld_.AreaPalette(); + + // Create the tile16 blockset image + gui::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 + gui::BitmapCanvasPipeline(transfer_canvas_, transfer_blockset_bmp_, 0x100, + (8192 * 2), 0x20, transfer_blockset_loaded_, true, + 3); + + 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 e616ba2a..ec5c5640 100644 --- a/src/app/editor/modules/tile16_editor.h +++ b/src/app/editor/modules/tile16_editor.h @@ -78,7 +78,7 @@ class Tile16Editor : public GfxContext, public SharedROM { bool priority_tile; int tile_size; - uint8_t *all_tiles_types_; + uint8_t* all_tiles_types_; // Tile16 blockset for selecting the tile to edit gui::Canvas blockset_canvas_{ImVec2(0x100, 0x4000), @@ -86,12 +86,14 @@ class Tile16Editor : public GfxContext, public SharedROM { gfx::Bitmap tile16_blockset_bmp_; // Canvas for editing the selected tile - gui::Canvas tile16_edit_canvas_; + gui::Canvas tile16_edit_canvas_{ImVec2(0x40, 0x40), gui::CanvasGridSize::k64x64}; gfx::Bitmap current_tile16_bmp_; gfx::Bitmap current_tile8_bmp_; // Tile8 canvas to get the tile to drawing in the tile16_edit_canvas_ - gui::Canvas tile8_source_canvas_; + gui::Canvas tile8_source_canvas_{ + ImVec2(core::kTilesheetWidth * 4, core::kTilesheetHeight * 0x10 * 4), + gui::CanvasGridSize::k32x32}; gfx::Bitmap current_gfx_bmp_; gui::Canvas transfer_canvas_;