From 8af096c1ae76363af613175b78cba4b46d3df077 Mon Sep 17 00:00:00 2001 From: Justin Scofield Date: Tue, 19 Jul 2022 20:22:17 -0400 Subject: [PATCH] Expand ScreenEditor and Screen class --- src/CMakeLists.txt | 2 + src/app/editor/screen_editor.cc | 76 ++++++++++++++++- src/app/editor/screen_editor.h | 72 ++++------------ src/app/zelda3/screen.cc | 141 +++++++++++++++++++++++++++++++- src/app/zelda3/screen.h | 72 +++++++++++++++- 5 files changed, 301 insertions(+), 62 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9718324..a2bd096c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,6 +44,7 @@ add_executable( app/editor/assembly_editor.cc app/editor/dungeon_editor.cc app/editor/overworld_editor.cc + app/editor/screen_editor.cc app/rom.cc app/core/common.cc app/core/constants.cc @@ -54,6 +55,7 @@ add_executable( app/gfx/snes_palette.cc app/zelda3/overworld.cc app/zelda3/overworld_map.cc + app/zelda3/screen.cc # GUI libraries ${IMGUI_PATH}/imgui.cpp ${IMGUI_PATH}/imgui_demo.cpp diff --git a/src/app/editor/screen_editor.cc b/src/app/editor/screen_editor.cc index 013159e5..7dfd72d0 100644 --- a/src/app/editor/screen_editor.cc +++ b/src/app/editor/screen_editor.cc @@ -1,9 +1,83 @@ #include "app/editor/screen_editor.h" +#include + +#include "app/core/common.h" +#include "app/core/constants.h" +#include "app/gfx/bitmap.h" +#include "app/gfx/snes_tile.h" +#include "gui/canvas.h" + namespace yaze { namespace app { namespace editor { -void ScreenEditor::Update() {} + +ScreenEditor::ScreenEditor() { screen_canvas_.SetCanvasSize(ImVec2(512, 512)); } + +void ScreenEditor::Update() { + TAB_BAR("##TabBar") + DrawTitleScreenEditor(); + DrawNamingScreenEditor(); + DrawOverworldMapEditor(); + DrawDungeonMapsEditor(); + DrawGameMenuEditor(); + DrawHUDEditor(); + END_TAB_BAR() +} + +void ScreenEditor::DrawTitleScreenEditor() { + TAB_ITEM("Title Screen") + END_TAB_ITEM() +} +void ScreenEditor::DrawNamingScreenEditor() { + TAB_ITEM("Naming Screen") + END_TAB_ITEM() +} +void ScreenEditor::DrawOverworldMapEditor() { + TAB_ITEM("Overworld Map") + END_TAB_ITEM() +} +void ScreenEditor::DrawDungeonMapsEditor() { + TAB_ITEM("Dungeon Maps") + END_TAB_ITEM() +} +void ScreenEditor::DrawGameMenuEditor() { + TAB_ITEM("Game Menu") + END_TAB_ITEM() +} +void ScreenEditor::DrawHUDEditor() { + TAB_ITEM("Heads-up Display") + END_TAB_ITEM() +} + +void ScreenEditor::DrawCanvas() { + screen_canvas_.DrawBackground(); + screen_canvas_.UpdateContext(); + + screen_canvas_.DrawGrid(); + screen_canvas_.DrawOverlay(); +} + +void ScreenEditor::DrawToolset() { + static bool show_bg1 = true; + static bool show_bg2 = true; + static bool show_bg3 = true; + + static bool drawing_bg1 = true; + static bool drawing_bg2 = false; + static bool drawing_bg3 = false; + + ImGui::Checkbox("Show BG1", &show_bg1); + ImGui::SameLine(); + ImGui::Checkbox("Show BG2", &show_bg2); + + ImGui::Checkbox("Draw BG1", &drawing_bg1); + ImGui::SameLine(); + ImGui::Checkbox("Draw BG2", &drawing_bg2); + ImGui::SameLine(); + ImGui::Checkbox("Draw BG3", &drawing_bg3); +} + } // namespace editor } // namespace app } // namespace yaze \ No newline at end of file diff --git a/src/app/editor/screen_editor.h b/src/app/editor/screen_editor.h index e34fdb93..23a56c4b 100644 --- a/src/app/editor/screen_editor.h +++ b/src/app/editor/screen_editor.h @@ -1,7 +1,12 @@ #ifndef YAZE_APP_EDITOR_SCREEN_EDITOR_H #define YAZE_APP_EDITOR_SCREEN_EDITOR_H +#include + +#include "app/gfx/bitmap.h" #include "app/gfx/snes_tile.h" +#include "app/zelda3/screen.h" +#include "gui/canvas.h" namespace yaze { namespace app { @@ -9,67 +14,22 @@ namespace editor { class ScreenEditor { public: + ScreenEditor(); void Update(); private: - int sword_x_ = 0; - int mx_click_ = 0; - int my_click_ = 0; - int mx_dist_ = 0; - int my_dist_ = 0; - int last_x_ = 0; - int last_y_ = 0; - int x_in_ = 0; - int y_in_ = 0; - int dungmap_selected_tile_ = 0; - int dungmap_selected_ = 0; - int selected_palette_ = 0; - int total_floors_ = 0; - int current_floor_ = 0; - int num_basement_ = 0; - int num_floor_ = 0; - int selected_map_tile = 0; - int current_floor_rooms; // [1][]; - int current_floor_gfx; // [1][]; - int copied_data_rooms; // 25 - int copied_data_gfx; // 25 - int addresses[] = {0x53de4, 0x53e2c, 0x53e08, 0x53e50, - 0x53e74, 0x53e98, 0x53ebc}; - int addressesgfx[] = {0x53ee0, 0x53f04, 0x53ef2, 0x53f16, - 0x53f28, 0x53f3a, 0x53f4c}; + void DrawTitleScreenEditor(); + void DrawNamingScreenEditor(); + void DrawOverworldMapEditor(); + void DrawDungeonMapsEditor(); + void DrawGameMenuEditor(); + void DrawHUDEditor(); - ushort bossRoom = 0x000F; - ushort selected_tile = 0; - ushort tilesBG1Buffer = new ushort[0x1000]; - ushort tilesBG2Buffer = new ushort[0x1000]; - uchar mapdata = new uchar[64 * 64]; - uchar dwmapdata = new uchar[64 * 64]; + void DrawCanvas(); + void DrawToolset(); - bool mDown = false; - bool swordSelected = false; - bool darkWorld = false; - bool currentDungeonChanged = false; - bool editedFromEditor = false; - bool mouseDown = false; - bool mdown = false; - - std::vector all_map_icons_; - - OAMTile oam_data[10]; - OAMTile selected_oam_tile = nullptr; - OAMTile last_selected_oam_tile = nullptr; - - gfx::Bitmap tilesBG1Bitmap; // 0x80000 - gfx::Bitmap tilesBG2Bitmap; // 0x80000 - gfx::Bitmap oamBGBitmap; // 0x80000 - - gfx::Bitmap dungeon_map_tiles8_bmp; // 0x8000 - gfx::Bitmap dungmaptiles16Bitmap; // 0x20000 - gfx::Bitmap tiles8Bitmap; // 0x20000 - gfx::Bitmap floor_selector; - - // DungeonMap dungeon_maps_[14]; - // MapIcon selectedMapIcon; + zelda3::Screen current_screen_; + gui::Canvas screen_canvas_; }; } // namespace editor diff --git a/src/app/zelda3/screen.cc b/src/app/zelda3/screen.cc index ec8b5ff9..3df65f56 100644 --- a/src/app/zelda3/screen.cc +++ b/src/app/zelda3/screen.cc @@ -1 +1,140 @@ -#include "screen.h" \ No newline at end of file +#include "screen.h" + +#include + +#include "app/core/common.h" +#include "app/gfx/bitmap.h" +#include "app/gfx/snes_tile.h" +#include "app/rom.h" + +namespace yaze { +namespace app { +namespace zelda3 { + +void Screen::Create() { + tiles8Bitmap.Create(128, 512, 8, 0x20000); + tilesBG1Bitmap.Create(256, 256, 8, 0x80000); + tilesBG2Bitmap.Create(256, 256, 8, 0x80000); + oamBGBitmap.Create(256, 256, 8, 0x80000); + + BuildTileset(); + + LoadTitleScreen(); + LoadOverworldMap(); + LoadDungeonMaps(); + LoadAllMapIcons(); +} + +void Screen::BuildTileset() { + uchar staticgfx[16]; + + // Main Blocksets + + // TODO: get the gfx from the GFX class rather than the rom. + // for (int i = 0; i < 8; i++) { + // staticgfx[i] = GfxGroups.mainGfx[titleScreenTilesGFX][i]; + // } + + staticgfx[8] = 115 + 0; + // staticgfx[9] = (GfxGroups.spriteGfx[titleScreenSpritesGFX][3] + 115); + staticgfx[10] = 115 + 6; + staticgfx[11] = 115 + 7; + // staticgfx[12] = (GfxGroups.spriteGfx[titleScreenSpritesGFX][0] + 115); + staticgfx[13] = 112; + staticgfx[14] = 112; + staticgfx[15] = 112; + + // Loaded gfx for the current screen (empty at this point) + uchar* currentmapgfx8Data = tiles8Bitmap.GetData(); + + // All gfx of the game pack of 2048 bytes (4bpp) + uchar* allgfxData = rom_.GetMasterGraphicsBin(); + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 2048; j++) { + uchar mapByte = allgfxData[j + (staticgfx[i] * 2048)]; + switch (i) { + case 0: + case 3: + case 4: + case 5: + mapByte += 0x88; + break; + } + + currentmapgfx8Data[(i * 2048) + j] = mapByte; // Upload used gfx data + } + } +} + +void Screen::LoadTitleScreen() { + int pos = (rom_.data()[0x138C + 3] << 16) + (rom_.data()[0x1383 + 3] << 8) + + rom_.data()[0x137A + 3]; + + for (int i = 0; i < 1024; i++) { + tilesBG1Buffer[i] = 492; + tilesBG2Buffer[i] = 492; + } + + pos = core::SnesToPc(pos); + + while ((rom_.data()[pos] & 0x80) != 0x80) { + int dest_addr = pos; // $03 and $04 + pos += 2; + short length = pos; + bool increment64 = (length & 0x8000) == 0x8000; + bool fixsource = (length & 0x4000) == 0x4000; + pos += 2; + + length = (short)((length & 0x07FF)); + + int j = 0; + int jj = 0; + int posB = pos; + while (j < (length / 2) + 1) { + ushort tiledata = (ushort)pos; + if (dest_addr >= 0x1000) { + // destAddr -= 0x1000; + if (dest_addr < 0x2000) { + tilesBG1Buffer[dest_addr - 0x1000] = tiledata; + } + } else { + if (dest_addr < 0x1000) { + tilesBG2Buffer[dest_addr] = tiledata; + } + } + + if (increment64) { + dest_addr += 32; + } else { + dest_addr++; + } + + if (!fixsource) { + pos += 2; + } + + jj += 2; + j++; + } + + if (fixsource) { + pos += 2; + } else { + pos = posB + jj; + } + } + + pal_selected_ = 2; +} + +void Screen::LoadNamingScreen() {} + +void Screen::LoadOverworldMap() {} + +void Screen::LoadDungeonMaps() {} + +void Screen::LoadAllMapIcons() {} + +} // namespace zelda3 +} // namespace app +} // namespace yaze \ No newline at end of file diff --git a/src/app/zelda3/screen.h b/src/app/zelda3/screen.h index 5f549c4f..a8d92a0d 100644 --- a/src/app/zelda3/screen.h +++ b/src/app/zelda3/screen.h @@ -1,7 +1,12 @@ #ifndef YAZE_APP_ZELDA3_SCREEN_H #define YAZE_APP_ZELDA3_SCREEN_H +#include + +#include "app/core/common.h" #include "app/gfx/bitmap.h" +#include "app/gfx/snes_tile.h" +#include "app/rom.h" namespace yaze { namespace app { @@ -9,13 +14,72 @@ namespace zelda3 { class Screen { public: - Screen() = default; + void Create(); private: - gfx::Bitmap screen; - uchar *data = nullptr; + void BuildTileset(); + void LoadTitleScreen(); + void LoadNamingScreen(); + void LoadOverworldMap(); + void LoadDungeonMaps(); + void LoadAllMapIcons(); + + int sword_x_ = 0; + int mx_click_ = 0; + int my_click_ = 0; + int mx_dist_ = 0; + int my_dist_ = 0; + int last_x_ = 0; + int last_y_ = 0; + int x_in_ = 0; + int y_in_ = 0; + int dungmap_selected_tile_ = 0; + int dungmap_selected_ = 0; + int selected_palette_ = 0; + int total_floors_ = 0; + int current_floor_ = 0; + int num_basement_ = 0; + int num_floor_ = 0; + int selected_map_tile = 0; + int current_floor_rooms; // [1][]; + int current_floor_gfx; // [1][]; + int copied_data_rooms; // 25 + int copied_data_gfx; // 25 + int pal_selected_; + int addresses[7] = {0x53de4, 0x53e2c, 0x53e08, 0x53e50, + 0x53e74, 0x53e98, 0x53ebc}; + int addressesgfx[7] = {0x53ee0, 0x53f04, 0x53ef2, 0x53f16, + 0x53f28, 0x53f3a, 0x53f4c}; + + ushort bossRoom = 0x000F; + ushort selected_tile = 0; + ushort tilesBG1Buffer[0x1000]; // 0x1000 + ushort tilesBG2Buffer[0x1000]; // 0x1000 + uchar mapdata; // 64 * 64 + uchar dwmapdata; // 64 * 64 + + bool mDown = false; + bool swordSelected = false; + bool darkWorld = false; + bool currentDungeonChanged = false; + bool editedFromEditor = false; + bool mouseDown = false; + bool mdown = false; + + ROM rom_; + + gfx::OAMTile oam_data[10]; + gfx::OAMTile selected_oam_tile; + gfx::OAMTile last_selected_oam_tile; + + gfx::Bitmap tilesBG1Bitmap; // 0x80000 + gfx::Bitmap tilesBG2Bitmap; // 0x80000 + gfx::Bitmap oamBGBitmap; // 0x80000 + gfx::Bitmap tiles8Bitmap; // 0x20000 }; } // namespace zelda3 } // namespace app -} // namespace yaze \ No newline at end of file +} // namespace yaze + +#endif \ No newline at end of file