diff --git a/src/app/editor/graphics_editor.cc b/src/app/editor/graphics_editor.cc index 7b7e8b98..7141cc79 100644 --- a/src/app/editor/graphics_editor.cc +++ b/src/app/editor/graphics_editor.cc @@ -8,6 +8,7 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "app/gfx/bitmap.h" +#include "app/gfx/snes_tile.h" #include "app/gui/canvas.h" #include "app/gui/input.h" #include "app/rom.h" @@ -17,22 +18,35 @@ namespace app { namespace editor { absl::Status GraphicsEditor::Update() { - DrawImport(); + if (ImGui::BeginTable("#gfxEditTable", 2, gfx_edit_flags, ImVec2(0, 0))) { + ImGui::TableSetupColumn("Bin Importer", ImGuiTableColumnFlags_WidthStretch, + ImGui::GetContentRegionAvail().x); + ImGui::TableSetupColumn("Graphics Manager"); + ImGui::TableHeadersRow(); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + RETURN_IF_ERROR(DrawImport()) + + ImGui::TableNextColumn(); + + ImGui::EndTable(); + } return absl::OkStatus(); } absl::Status GraphicsEditor::DrawImport() { - static int offset = 0; static int size = 0; static char filePath[256] = ""; + static bool open = false; + ImGui::SetNextItemWidth(350.f); ImGui::InputText("File", filePath, sizeof(filePath)); // Open the file dialog when the user clicks the "Browse" button if (ImGui::Button("Browse")) { ImGuiFileDialog::Instance()->OpenDialog("ImportDlgKey", "Choose File", - ".bin\0", "."); + ".bin\0.hex\0", "."); } // Draw the file dialog @@ -41,42 +55,60 @@ absl::Status GraphicsEditor::DrawImport() { if (ImGuiFileDialog::Instance()->IsOk()) { strncpy(filePath, ImGuiFileDialog::Instance()->GetFilePathName().c_str(), sizeof(filePath)); + RETURN_IF_ERROR(temp_rom_.LoadFromFile(filePath)) + open = true; } // Close the modal ImGuiFileDialog::Instance()->Close(); } - gui::InputHex("Offset", &offset); + if (open) { + static MemoryEditor mem_edit; + mem_edit.DrawWindow(filePath, (void *)&temp_rom_, temp_rom_.size()); + } + + gui::InputHex("Offset", ¤t_offset_); gui::InputHex("Size ", &size); + if (ImGui::Button("Super Donkey")) { + current_offset_ = 0x98219; + size = 0x30000; + } + if (ImGui::Button("Import")) { if (strlen(filePath) > 0) { // Add your importing code here, using filePath and offset as parameters - RETURN_IF_ERROR(DecompressImportData(filePath, offset, size)) + RETURN_IF_ERROR(DecompressImportData(size)) } else { // Show an error message if no file has been selected ImGui::Text("Please select a file before importing."); } } - import_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1)); - import_canvas_.DrawContextMenu(); - import_canvas_.DrawBitmap(bitmap_, 2, gfx_loaded_); - import_canvas_.DrawTileSelector(32); - import_canvas_.DrawGrid(32.0f); - import_canvas_.DrawOverlay(); + if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)2); + ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, + ImGuiWindowFlags_AlwaysVerticalScrollbar)) { + import_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1)); + import_canvas_.DrawContextMenu(); + import_canvas_.DrawBitmap(bitmap_, 2, gfx_loaded_); + import_canvas_.DrawTileSelector(32); + import_canvas_.DrawGrid(32.0f); + import_canvas_.DrawOverlay(); + } + ImGui::EndChild(); return absl::OkStatus(); } -absl::Status GraphicsEditor::DecompressImportData(char *filePath, int offset, - int size) { - RETURN_IF_ERROR(temp_rom.LoadFromFile(filePath)) - ASSIGN_OR_RETURN(import_data_, temp_rom.DecompressGraphics(offset, size)) +absl::Status GraphicsEditor::DecompressImportData(int size) { + ASSIGN_OR_RETURN(import_data_, temp_rom_.Decompress(current_offset_, size)) + std::cout << "Size of import data" << import_data_.size() << std::endl; - bitmap_.Create(core::kTilesheetWidth, core::kTilesheetHeight * 0x10, - core::kTilesheetDepth, import_data_.data()); + Bytes new_sheet; + + bitmap_.Create(core::kTilesheetWidth, core::kTilesheetHeight, + core::kTilesheetDepth, import_data_); rom_.RenderBitmap(&bitmap_); gfx_loaded_ = true; diff --git a/src/app/editor/graphics_editor.h b/src/app/editor/graphics_editor.h index 2a531a84..3755fc84 100644 --- a/src/app/editor/graphics_editor.h +++ b/src/app/editor/graphics_editor.h @@ -9,6 +9,7 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "app/gfx/bitmap.h" +#include "app/gfx/snes_tile.h" #include "app/gui/canvas.h" #include "app/gui/input.h" #include "app/rom.h" @@ -17,6 +18,27 @@ namespace yaze { namespace app { namespace editor { +const std::string kSuperDonkeyTiles[] = { + "97C05", "98219", "9871E", "98C00", "99084", "995AF", "99973", + "99DE0", "9A27E", "9A741", "9AC31", "9B07E", "9B55C", "9B963", + "9BB99", "9C009", "9C4B4", "9C92B", "9CDD6", "9D2C2", "9E037", + "9E527", "9EA56", "9EF65", "9FCD1", "A0193", "A059E", "A0B17", + "A0FB6", "A14A5", "A1988", "A1E66", "A232B", "A27F0", "A2B6E", + "A302C", "A3453", "A38CA", "A3D80", "A42BB", "A470C", "A4BA9", + "A5089", "A5385", "A5742", "A5BCC", "A6017", "A6361", "A66F8"}; + +const std::string kSuperDonkeySprites[] = { + "A8E5D", "A9435", "A9934", "A9D83", "AA2F1", "AA6D4", "AABE4", "AB127", + "AB65A", "ABBDD", "AC38D", "AC797", "ACCC8", "AD0AE", "AD245", "AD554", + "ADAAC", "ADECC", "AE453", "AE9D2", "AEF40", "AF3C9", "AF92E", "AFE9D", + "B03D2", "B09AC", "B0F0C", "B1430", "B1859", "B1E01", "B229A", "B2854", + "B2D27", "B31D7", "B3B58", "B40B5", "B45A5", "B4D64", "B5031", "B555F", + "B5F30", "B6858", "B70DD", "B7526", "B79EC", "B7C83", "B80F7", "B85CC", + "B8A3F", "B8F97", "B94F2", "B9A20", "B9E9A", "BA3A2", "BA8F6", "BACDC", + "BB1F9", "BB781", "BBCCA", "BC26D", "BC7D4", "BCBB0", "BD082", "BD5FC", + "BE115", "BE5C2", "BEB63", "BF0CB", "BF607", "BFA55", "BFD71", "C017D", + "C0567", "C0981", "C0BA7", "C116D", "C166A", "C1FE0", "C24CE", "C2B19"}; + class GraphicsEditor { public: absl::Status Update(); @@ -24,18 +46,23 @@ class GraphicsEditor { private: absl::Status DrawImport(); - absl::Status DecompressImportData(char *filePath, int offset, int size); + absl::Status DecompressImportData(int size); + + int current_offset_ = 0; + int current_size_ = 0; + bool gfx_loaded_ = false; ROM rom_; - ROM temp_rom; - - gfx::Bitmap bitmap_; - - gui::Canvas import_canvas_; - + ROM temp_rom_; Bytes import_data_; - bool gfx_loaded_ = false; + gfx::Bitmap bitmap_; + gui::Canvas import_canvas_; + gfx::BitmapTable bitmap_table_; + + ImGuiTableFlags gfx_edit_flags = ImGuiTableFlags_Reorderable | + ImGuiTableFlags_Resizable | + ImGuiTableFlags_SizingStretchSame; }; } // namespace editor