From 79e5986b0b6fcfe55925960a19994e1620d46e12 Mon Sep 17 00:00:00 2001 From: scawful Date: Tue, 13 Aug 2024 21:47:13 -0400 Subject: [PATCH] chore: Update asset_browser to use std::array for gfx sheets --- src/app/editor/graphics/graphics_editor.cc | 59 +++++++++++----------- src/app/editor/graphics/graphics_editor.h | 13 +++-- src/app/gui/asset_browser.cc | 10 ++-- src/app/gui/asset_browser.h | 11 ++-- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/app/editor/graphics/graphics_editor.cc b/src/app/editor/graphics/graphics_editor.cc index e007425d..efefa065 100644 --- a/src/app/editor/graphics/graphics_editor.cc +++ b/src/app/editor/graphics/graphics_editor.cc @@ -58,9 +58,9 @@ absl::Status GraphicsEditor::Update() { status_ = UpdateGfxEdit(); TAB_ITEM("Sheet Browser") if (asset_browser_.Initialized == false) { - asset_browser_.Initialize(rom()->mutable_bitmap_manager()); + asset_browser_.Initialize(rom()->gfx_sheets()); } - asset_browser_.Draw(rom()->mutable_bitmap_manager()); + asset_browser_.Draw(rom()->gfx_sheets()); END_TAB_ITEM() status_ = UpdateScadView(); @@ -194,21 +194,21 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() { static ImGuiSelectionBasicStorage selection; ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d; - ImGuiMultiSelectIO* ms_io = ImGui::BeginMultiSelect( - flags, selection.Size, rom()->bitmap_manager().size()); + ImGuiMultiSelectIO* ms_io = + ImGui::BeginMultiSelect(flags, selection.Size, kNumGfxSheets); selection.ApplyRequests(ms_io); ImGuiListClipper clipper; - clipper.Begin(rom()->bitmap_manager().size()); + clipper.Begin(kNumGfxSheets); if (ms_io->RangeSrcItem != -1) clipper.IncludeItemByIndex( (int)ms_io->RangeSrcItem); // Ensure RangeSrc item is not clipped. - for (auto& [key, value] : rom()->bitmap_manager()) { + int key = 0; + for (auto& value : rom()->gfx_sheets()) { ImGui::BeginChild(absl::StrFormat("##GfxSheet%02X", key).c_str(), ImVec2(0x100 + 1, 0x40 + 1), true, ImGuiWindowFlags_NoDecoration); ImGui::PopStyleVar(); - gui::Canvas graphics_bin_canvas_; graphics_bin_canvas_.DrawBackground(ImVec2(0x100 + 1, 0x40 + 1)); graphics_bin_canvas_.DrawContextMenu(); @@ -242,6 +242,8 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() { graphics_bin_canvas_.draw_list()->AddText( text_pos, IM_COL32(125, 255, 125, 255), absl::StrFormat("%02X", key).c_str()); + + key++; } graphics_bin_canvas_.DrawGrid(16.0f); graphics_bin_canvas_.DrawOverlay(); @@ -460,17 +462,18 @@ absl::Status GraphicsEditor::UpdateScadView() { NEXT_COLUMN() if (super_donkey_) { - if (refresh_graphics_) { - for (int i = 0; i < graphics_bin_.size(); i++) { - status_ = graphics_bin_[i].ApplyPalette( - col_file_palette_group_[current_palette_index_]); - Renderer::GetInstance().UpdateBitmap(&graphics_bin_[i]); - } - refresh_graphics_ = false; - } + // TODO: Implement the Super Donkey 1 graphics decompression + // if (refresh_graphics_) { + // for (int i = 0; i < kNumGfxSheets; i++) { + // status_ = graphics_bin_[i].ApplyPalette( + // col_file_palette_group_[current_palette_index_]); + // Renderer::GetInstance().UpdateBitmap(&graphics_bin_[i]); + // } + // refresh_graphics_ = false; + // } // Load the full graphics space from `super_donkey_1.bin` - gui::GraphicsBinCanvasPipeline(0x100, 0x40, 0x20, num_sheets_to_load_, 3, - super_donkey_, graphics_bin_); + // gui::GraphicsBinCanvasPipeline(0x100, 0x40, 0x20, num_sheets_to_load_, 3, + // super_donkey_, graphics_bin_); } else if (cgx_loaded_ && col_file_) { // Load the CGX graphics gui::BitmapCanvasPipeline(import_canvas_, cgx_bitmap_, 0x100, 16384, 0x20, @@ -792,11 +795,10 @@ absl::Status GraphicsEditor::DecompressSuperDonkey() { auto decompressed_data, gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000)) auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3); - graphics_bin_[i] = - gfx::Bitmap(core::kTilesheetWidth, core::kTilesheetHeight, - core::kTilesheetDepth, converted_sheet); + gfx_sheets_[i] = gfx::Bitmap(core::kTilesheetWidth, core::kTilesheetHeight, + core::kTilesheetDepth, converted_sheet); if (col_file_) { - status_ = graphics_bin_[i].ApplyPalette( + status_ = gfx_sheets_[i].ApplyPalette( col_file_palette_group_[current_palette_index_]); } else { // ROM palette @@ -804,10 +806,10 @@ absl::Status GraphicsEditor::DecompressSuperDonkey() { auto palette_group = rom()->palette_group().get_group( kPaletteGroupAddressesKeys[current_palette_]); z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_); - status_ = graphics_bin_[i].ApplyPalette(z3_rom_palette_); + status_ = gfx_sheets_[i].ApplyPalette(z3_rom_palette_); } - Renderer::GetInstance().RenderBitmap(&graphics_bin_[i]); + Renderer::GetInstance().RenderBitmap(&gfx_sheets_[i]); i++; } @@ -818,21 +820,20 @@ absl::Status GraphicsEditor::DecompressSuperDonkey() { auto decompressed_data, gfx::lc_lz2::DecompressV2(temp_rom_.data(), offset_value, 0x1000)) auto converted_sheet = gfx::SnesTo8bppSheet(decompressed_data, 3); - graphics_bin_[i] = - gfx::Bitmap(core::kTilesheetWidth, core::kTilesheetHeight, - core::kTilesheetDepth, converted_sheet); + gfx_sheets_[i] = gfx::Bitmap(core::kTilesheetWidth, core::kTilesheetHeight, + core::kTilesheetDepth, converted_sheet); if (col_file_) { - status_ = graphics_bin_[i].ApplyPalette( + status_ = gfx_sheets_[i].ApplyPalette( col_file_palette_group_[current_palette_index_]); } else { // ROM palette auto palette_group = rom()->palette_group().get_group( kPaletteGroupAddressesKeys[current_palette_]); z3_rom_palette_ = *palette_group->mutable_palette(current_palette_index_); - status_ = graphics_bin_[i].ApplyPalette(z3_rom_palette_); + status_ = gfx_sheets_[i].ApplyPalette(z3_rom_palette_); } - Renderer::GetInstance().RenderBitmap(&graphics_bin_[i]); + Renderer::GetInstance().RenderBitmap(&gfx_sheets_[i]); i++; } super_donkey_ = true; diff --git a/src/app/editor/graphics/graphics_editor.h b/src/app/editor/graphics/graphics_editor.h index 99974792..88d4501d 100644 --- a/src/app/editor/graphics/graphics_editor.h +++ b/src/app/editor/graphics/graphics_editor.h @@ -2,10 +2,6 @@ #define YAZE_APP_EDITOR_GRAPHICS_EDITOR_H #include "ImGuiFileDialog/ImGuiFileDialog.h" -#include "imgui/imgui.h" -#include "imgui/misc/cpp/imgui_stdlib.h" -#include "imgui_memory_editor.h" - #include "absl/status/status.h" #include "absl/status/statusor.h" #include "app/editor/graphics/palette_editor.h" @@ -17,6 +13,9 @@ #include "app/gui/input.h" #include "app/rom.h" #include "app/zelda3/overworld/overworld.h" +#include "imgui/imgui.h" +#include "imgui/misc/cpp/imgui_stdlib.h" +#include "imgui_memory_editor.h" namespace yaze { namespace app { @@ -179,9 +178,8 @@ class GraphicsEditor : public SharedRom, public Editor { gfx::Bitmap scr_bitmap_; gfx::Bitmap bin_bitmap_; gfx::Bitmap link_full_sheet_; - gfx::BitmapTable graphics_bin_; - gfx::BitmapTable clipboard_graphics_bin_; - gfx::BitmapTable link_graphics_; + std::array gfx_sheets_; + gfx::PaletteGroup col_file_palette_group_; gfx::SnesPalette z3_rom_palette_; gfx::SnesPalette col_file_palette_; @@ -189,6 +187,7 @@ class GraphicsEditor : public SharedRom, public Editor { gui::Canvas import_canvas_; gui::Canvas scr_canvas_; gui::Canvas super_donkey_canvas_; + gui::Canvas graphics_bin_canvas_; gui::Canvas current_sheet_canvas_{"CurrentSheetCanvas", ImVec2(0x80, 0x20), gui::CanvasGridSize::k8x8}; gui::Canvas link_canvas_{ diff --git a/src/app/gui/asset_browser.cc b/src/app/gui/asset_browser.cc index fe6979e7..22c7cff6 100644 --- a/src/app/gui/asset_browser.cc +++ b/src/app/gui/asset_browser.cc @@ -10,7 +10,8 @@ using namespace ImGui; const ImGuiTableSortSpecs* AssetObject::s_current_sort_specs = NULL; -void GfxSheetAssetBrowser::Draw(gfx::BitmapManager* bmp_manager) { +void GfxSheetAssetBrowser::Draw( + const std::array& bmp_manager) { PushItemWidth(GetFontSize() * 10); SeparatorText("Contents"); Checkbox("Show Type Overlay", &ShowTypeOverlay); @@ -228,10 +229,9 @@ void GfxSheetAssetBrowser::Draw(gfx::BitmapManager* bmp_manager) { if (display_label) { ImU32 label_col = GetColorU32( item_is_selected ? ImGuiCol_Text : ImGuiCol_TextDisabled); - draw_list->AddImage( - (void*)bmp_manager->mutable_bitmap(item_data->ID)->texture(), - box_min, box_max, ImVec2(0, 0), ImVec2(1, 1), - GetColorU32(ImVec4(1, 1, 1, 1))); + draw_list->AddImage((void*)bmp_manager[item_data->ID].texture(), + box_min, box_max, ImVec2(0, 0), ImVec2(1, 1), + GetColorU32(ImVec4(1, 1, 1, 1))); draw_list->AddText(ImVec2(box_min.x, box_max.y - GetFontSize()), label_col, absl::StrFormat("%X", item_data->ID).c_str()); diff --git a/src/app/gui/asset_browser.h b/src/app/gui/asset_browser.h index 3575b95f..46f57c58 100644 --- a/src/app/gui/asset_browser.h +++ b/src/app/gui/asset_browser.h @@ -1,11 +1,12 @@ #ifndef YAZE_APP_GUI_ASSET_BROWSER_H #define YAZE_APP_GUI_ASSET_BROWSER_H -#include "imgui/imgui.h" - +#include #include #include "app/gfx/bitmap.h" +#include "app/rom.h" +#include "imgui/imgui.h" #define IM_MIN(A, B) (((A) < (B)) ? (A) : (B)) #define IM_MAX(A, B) (((A) >= (B)) ? (A) : (B)) @@ -187,9 +188,9 @@ struct GfxSheetAssetBrowser { int LayoutLineCount = 0; bool Initialized = false; - void Initialize(gfx::BitmapManager* bmp_manager) { + void Initialize(const std::array& bmp_manager) { // Load the assets - for (int i = 0; i < bmp_manager->size(); i++) { + for (int i = 0; i < kNumGfxSheets; i++) { Items.push_back(UnsortedAsset(i)); } Initialized = true; @@ -238,7 +239,7 @@ struct GfxSheetAssetBrowser { LayoutOuterPadding = floorf(LayoutItemSpacing * 0.5f); } - void Draw(gfx::BitmapManager* bmp_manager); + void Draw(const std::array& bmp_manager); }; } // namespace gui