From 9d7f0aa0b40ca0a4fce83911338c31792d481e71 Mon Sep 17 00:00:00 2001 From: Justin Scofield Date: Sun, 12 Jun 2022 13:17:59 -0400 Subject: [PATCH] Moving tiles related stuff into the project window --- src/Application/Core/Constants.h | 6 +++ src/Application/Core/Controller.h | 1 - src/Application/Editor/Editor.cc | 48 ++++++++++++++--- src/Application/Editor/OverworldEditor.cc | 64 ----------------------- src/Application/Utils/ROM.cc | 2 +- 5 files changed, 47 insertions(+), 74 deletions(-) diff --git a/src/Application/Core/Constants.h b/src/Application/Core/Constants.h index 68ab0e92..fe7bcf42 100644 --- a/src/Application/Core/Constants.h +++ b/src/Application/Core/Constants.h @@ -4,6 +4,12 @@ #include #include +#define TAB_BAR(w) if (ImGui::BeginTabBar(w)) { +#define END_TAB_BAR() ImGui::EndTabBar(); } + +#define MENU_BAR() if (ImGui::BeginMenuBar()) { +#define END_MENU_BAR() ImGui::EndMenuBar(); } + namespace yaze { namespace Application { namespace Core { diff --git a/src/Application/Core/Controller.h b/src/Application/Core/Controller.h index 8475edf0..198226b3 100644 --- a/src/Application/Core/Controller.h +++ b/src/Application/Core/Controller.h @@ -7,7 +7,6 @@ #include #include "Editor/Editor.h" -#include "Events/Event.h" #include "Renderer.h" #include "Window.h" #include "imgui/backends/imgui_impl_sdl.h" diff --git a/src/Application/Editor/Editor.cc b/src/Application/Editor/Editor.cc index 9f32ae5d..bb7aa90e 100644 --- a/src/Application/Editor/Editor.cc +++ b/src/Application/Editor/Editor.cc @@ -82,6 +82,14 @@ Editor::Editor() { } asm_editor_.SetLanguageDefinition(language65816Def); asm_editor_.SetPalette(TextEditor::GetDarkPalette()); + + current_set_.bpp = 3; + current_set_.pcTilesLocation = 0x8000; + current_set_.SNESTilesLocation = 0; + current_set_.length = 1000; + current_set_.pcPaletteLocation = 0; + current_set_.SNESPaletteLocation = 0; + current_set_.compression = "zelda3"; } void Editor::UpdateScreen() { @@ -102,28 +110,25 @@ void Editor::UpdateScreen() { DrawYazeMenu(); - if (ImGui::BeginTabBar("##TabBar")) { + TAB_BAR("##TabBar"); DrawProjectEditor(); DrawOverworldEditor(); DrawDungeonEditor(); DrawGraphicsEditor(); DrawSpriteEditor(); DrawScreenEditor(); - ImGui::EndTabBar(); - } + END_TAB_BAR(); ImGui::End(); } void Editor::DrawYazeMenu() { - if (ImGui::BeginMenuBar()) { + MENU_BAR(); DrawFileMenu(); DrawEditMenu(); DrawViewMenu(); DrawHelpMenu(); - - ImGui::EndMenuBar(); - } + END_MENU_BAR(); // display if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) { @@ -283,13 +288,40 @@ void Editor::DrawHelpMenu() const { } void Editor::DrawProjectEditor() { + static bool inited = false; + if (ImGui::BeginTabItem("Project")) { - if (rom.isLoaded()) { + ImGui::InputInt("PC Tile Location", ¤t_set_.pcTilesLocation); + ImGui::InputScalar("SNES Tile Location", ImGuiDataType_U32, (void*)¤t_set_.SNESTilesLocation); + ImGui::InputScalar("Tile Preset Length", ImGuiDataType_U32, (void*)¤t_set_.length); + ImGui::InputScalar("Bits per Pixel", ImGuiDataType_U32, (void*)¤t_set_.bpp); + ImGui::InputScalar("PC Palette Location", ImGuiDataType_U32, (void*)¤t_set_.pcPaletteLocation); + ImGui::InputScalar("SNES Palette Location", ImGuiDataType_U32, (void*)¤t_set_.SNESPaletteLocation); + + if (rom.isLoaded()) { + ImGui::Text("Title: %s", rom.getTitle()); ImGui::Text("Version: %d", rom.getVersion()); ImGui::Text("ROM Size: %ld", rom.getSize()); + + if (!inited) { + current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.0f, 1.0f)); + current_palette_.colors.push_back(ImVec4(0.0f, 0.5f, 0.0f, 1.0f)); + current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.4f, 1.0f)); + current_palette_.colors.push_back(ImVec4(0.3f, 0.0f, 0.0f, 1.0f)); + current_palette_.colors.push_back(ImVec4(0.3f, 0.7f, 0.9f, 1.0f)); + current_palette_.colors.push_back(ImVec4(0.5f, 0.5f, 0.5f, 1.0f)); + + current_scene_.buildSurface(rom.ExtractTiles(current_set_), current_palette_, current_set_.tilesPattern); + inited = true; + } + + for (const auto & [key, value] : current_scene_.imagesCache) { + ImGui::Image((void *)(SDL_Texture*)value, ImVec2(8, 8)); + } } + ImGui::EndTabItem(); } } diff --git a/src/Application/Editor/OverworldEditor.cc b/src/Application/Editor/OverworldEditor.cc index 66f8969b..22c6c0a5 100644 --- a/src/Application/Editor/OverworldEditor.cc +++ b/src/Application/Editor/OverworldEditor.cc @@ -33,65 +33,6 @@ void OverworldEditor::Update() { if (rom_.isLoaded()) { if (!doneLoaded) { //overworld.Load(rom_); - // name=The Legend of Zelda - Link Sprites - - // [rom] - // name= - // type=LoROM - - // [tiles] - // pc_location=80000 - // snes_location=0 - // length=28672 - // bpp=4 - // compression=None - // pattern=normal - - // [tiles_arrangement] - // tiles_per_row=16 - - // [palette] - // pc_location=dd308 - // snes_location=0 - // nozerocolor=true - - // name="The Legend of Zelda - Action Sprites, shields, shovel and book" - - // [rom] - // name= - // type=LoROM - - // [tiles] - // pc_location=c0d64 - // snes_location=0 - // length=1081 - // bpp=3 - // compression=zelda3 - - // [tiles_arrangement] - // tiles_per_row=16 - - // [palette] - // pc_location=0 - // snes_location=0 - // nozerocolor=true - - current_set_.pcTilesLocation = 0x8000; - current_set_.SNESTilesLocation = 0; - current_set_.length = 1000; - current_set_.bpp = 3; - current_set_.compression = "zelda3"; - current_set_.pcPaletteLocation = 0; - current_set_.SNESPaletteLocation = 0; - - palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.0f, 1.0f)); - palette_.colors.push_back(ImVec4(0.0f, 0.5f, 0.0f, 1.0f)); - palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.4f, 1.0f)); - palette_.colors.push_back(ImVec4(0.3f, 0.0f, 0.0f, 1.0f)); - palette_.colors.push_back(ImVec4(0.3f, 0.7f, 0.9f, 1.0f)); - palette_.colors.push_back(ImVec4(0.5f, 0.5f, 0.5f, 1.0f)); - - current_scene_.buildSurface(rom_.ExtractTiles(current_set_), palette_, current_set_.tilesPattern); doneLoaded = true; } } @@ -325,11 +266,6 @@ void OverworldEditor::DrawOverworldCanvas() { void OverworldEditor::DrawTileSelector() { if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) { if (ImGui::BeginTabItem("Tile8")) { - if (rom_.isLoaded()) { - for (const auto & [key, value] : current_scene_.imagesCache) { - ImGui::Image((void *)(SDL_Texture*)value, ImVec2(8, 8)); - } - } ImGui::EndTabItem(); } diff --git a/src/Application/Utils/ROM.cc b/src/Application/Utils/ROM.cc index 09853289..0ca27497 100644 --- a/src/Application/Utils/ROM.cc +++ b/src/Application/Utils/ROM.cc @@ -25,7 +25,7 @@ void ROM::LoadFromFile(const std::string &path) { int bytes_read = fread(current_rom_, sizeof(unsigned char), size, file); fclose(file); - memcpy(title, current_rom_ + 32704, 21); + memcpy(title, rom_data_ + 32704, 21); type = LoROM; version = current_rom_[27]; loaded = true;