Skip to content

Commit

Permalink
housekeeping, accessors, gui, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
scawful committed Nov 21, 2023
1 parent 4ef2540 commit bbe76ac
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 84 deletions.
25 changes: 15 additions & 10 deletions src/app/editor/dungeon_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ namespace yaze {
namespace app {
namespace editor {

using ImGui::TableHeadersRow;
using ImGui::TableNextColumn;
using ImGui::TableNextRow;
using ImGui::TableSetupColumn;

absl::Status DungeonEditor::Update() {
if (!is_loaded_ && rom()->isLoaded()) {
for (int i = 0; i < 0x100; i++) {
Expand All @@ -29,14 +34,14 @@ absl::Status DungeonEditor::Update() {
ImGui::Separator();
if (ImGui::BeginTable("#DungeonEditTable", 3, toolset_table_flags_,
ImVec2(0, 0))) {
ImGui::TableSetupColumn("Room Selector");

ImGui::TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
ImGui::GetContentRegionAvail().x);
ImGui::TableSetupColumn("Object Selector");
ImGui::TableHeadersRow();
ImGui::TableNextRow();
ImGui::TableNextColumn();
TableSetupColumn("Room Selector");

TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
ImGui::GetContentRegionAvail().x);
TableSetupColumn("Object Selector");
TableHeadersRow();
TableNextRow();
TableNextColumn();
if (rom()->isLoaded()) {
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)9);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
Expand All @@ -53,9 +58,9 @@ absl::Status DungeonEditor::Update() {
ImGui::EndChild();
}

ImGui::TableNextColumn();
TableNextColumn();
DrawDungeonTabView();
ImGui::TableNextColumn();
TableNextColumn();
DrawTileSelector();
ImGui::EndTable();
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/editor/modules/gfx_group_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ absl::Status GfxGroupEditor::Update() {
ImGui::BeginGroup();
for (int i = 0; i < 8; i++) {
int sheet_id = rom()->main_blockset_ids[selected_blockset_][i];
auto &sheet = *rom()->BitmapManager()[sheet_id];
auto &sheet = *rom()->bitmap_manager()[sheet_id];
if (sheet_id != last_sheet_id_) {
last_sheet_id_ = sheet_id;
auto palette_group = rom()->GetPaletteGroup("ow_main");
Expand Down Expand Up @@ -109,7 +109,7 @@ absl::Status GfxGroupEditor::Update() {
ImGui::BeginGroup();
for (int i = 0; i < 4; i++) {
int sheet_id = rom()->room_blockset_ids[selected_roomset_][i];
auto &sheet = *rom()->BitmapManager()[sheet_id];
auto &sheet = *rom()->bitmap_manager()[sheet_id];
core::BitmapCanvasPipeline(roomset_canvas_, sheet, 256, 0x10 * 0x04,
0x20, true, false, 23);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ absl::Status GfxGroupEditor::Update() {
ImGui::BeginGroup();
for (int i = 0; i < 4; i++) {
int sheet_id = rom()->spriteset_ids[selected_spriteset_][i];
auto sheet = *rom()->BitmapManager()[sheet_id];
auto sheet = *rom()->bitmap_manager()[sheet_id];
core::BitmapCanvasPipeline(spriteset_canvas_, sheet, 256,
0x10 * 0x04, 0x20, true, false, 24);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/editor/modules/tile16_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ absl::Status Tile16Editor::Update() {

if (transfer_started_ && !transfer_blockset_loaded_) {
PRINT_IF_ERROR(transfer_rom_.LoadAllGraphicsData())
graphics_bin_ = transfer_rom_.GetGraphicsBin();
graphics_bin_ = transfer_rom_.graphics_bin();

// Load the Link to the Past overworld.
PRINT_IF_ERROR(transfer_overworld_.Load(transfer_rom_))
Expand Down
74 changes: 40 additions & 34 deletions src/app/editor/overworld_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ namespace app {
namespace editor {

using ImGui::Separator;
using ImGui::TableHeadersRow;
using ImGui::TableNextColumn;
using ImGui::TableNextRow;
using ImGui::TableSetupColumn;
using ImGui::Text;

absl::Status OverworldEditor::Update() {
// Initialize overworld graphics, maps, and palettes
Expand All @@ -43,14 +48,14 @@ absl::Status OverworldEditor::Update() {

Separator();
if (ImGui::BeginTable(kOWEditTable.data(), 2, kOWEditFlags, ImVec2(0, 0))) {
ImGui::TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
ImGui::GetContentRegionAvail().x);
ImGui::TableSetupColumn("Tile Selector");
ImGui::TableHeadersRow();
ImGui::TableNextRow();
ImGui::TableNextColumn();
TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
ImGui::GetContentRegionAvail().x);
TableSetupColumn("Tile Selector");
TableHeadersRow();
TableNextRow();
TableNextColumn();
DrawOverworldCanvas();
ImGui::TableNextColumn();
TableNextColumn();
DrawTileSelector();
ImGui::EndTable();
}
Expand Down Expand Up @@ -103,22 +108,22 @@ absl::Status OverworldEditor::DrawToolset() {
BUTTON_COLUMN(ICON_MD_ADD_LOCATION) // Transports
BUTTON_COLUMN(ICON_MD_MUSIC_NOTE) // Music

ImGui::TableNextColumn();
TableNextColumn();
if (ImGui::Button(ICON_MD_GRID_VIEW)) {
show_tile16 = !show_tile16;
}

ImGui::TableNextColumn();
TableNextColumn();
if (ImGui::Button(ICON_MD_TABLE_CHART)) {
show_gfx_group = !show_gfx_group;
}

TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator

ImGui::TableNextColumn(); // Palette
TableNextColumn(); // Palette
palette_editor_.DisplayPalette(palette_, overworld_.isLoaded());
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
ImGui::TableNextColumn(); // Experimental
TableNextColumn(); // Experimental
ImGui::Checkbox("Experimental", &show_experimental);

ImGui::EndTable();
Expand Down Expand Up @@ -150,45 +155,46 @@ void OverworldEditor::DrawOverworldMapSettings() {
for (const auto &name : kOverworldSettingsColumnNames)
ImGui::TableSetupColumn(name.data());

ImGui::TableNextColumn();
TableNextColumn();
ImGui::SetNextItemWidth(100.f);
ImGui::Combo("##world", &current_world_, kWorldList.data(), 3);

ImGui::TableNextColumn();
ImGui::Text("GFX");
TableNextColumn();
Text("GFX");
ImGui::SameLine();
ImGui::SetNextItemWidth(kInputFieldSize);
ImGui::InputText("##mapGFX", map_gfx_, kByteSize);

ImGui::TableNextColumn();
ImGui::Text("Palette");
TableNextColumn();
Text("Palette");
ImGui::SameLine();
ImGui::SetNextItemWidth(kInputFieldSize);
ImGui::InputText("##mapPal", map_palette_, kByteSize);

ImGui::TableNextColumn();
ImGui::Text("Spr GFX");
TableNextColumn();
Text("Spr GFX");
ImGui::SameLine();
ImGui::SetNextItemWidth(kInputFieldSize);
ImGui::InputText("##sprGFX", spr_gfx_, kByteSize);

ImGui::TableNextColumn();
ImGui::Text("Spr Palette");
TableNextColumn();
Text("Spr Palette");
ImGui::SameLine();
ImGui::SetNextItemWidth(kInputFieldSize);
ImGui::InputText("##sprPal", spr_palette_, kByteSize);

ImGui::TableNextColumn();
ImGui::Text("Msg ID");
TableNextColumn();
Text("Msg ID");
ImGui::SameLine();
ImGui::SetNextItemWidth(50.f);
ImGui::InputText("##msgid", spr_palette_, kMessageIdSize);

ImGui::TableNextColumn();
TableNextColumn();
ImGui::SetNextItemWidth(100.f);
ImGui::Combo("##world", &game_state_, "Part 0\0Part 1\0Part 2\0", 3);
// ImGui::Combo("##world", &game_state_, "Part 0\0Part 1\0Part 2\0", 3);
ImGui::Combo("##World", &game_state_, kGamePartComboString, 3);

ImGui::TableNextColumn();
TableNextColumn();
ImGui::Checkbox("Show grid", &opt_enable_grid); // TODO
ImGui::EndTable();
}
Expand All @@ -214,7 +220,7 @@ void OverworldEditor::DrawOverworldEntrances(ImVec2 canvas_p0,
if (ImGui::BeginDragDropSource()) {
ImGui::SetDragDropPayload("ENTRANCE_PAYLOAD", &each,
sizeof(zelda3::OverworldEntrance));
ImGui::Text("Moving Entrance ID: %s", str.c_str());
Text("Moving Entrance ID: %s", str.c_str());
ImGui::EndDragDropSource();
}
} else if (is_dragging_entrance_ && dragged_entrance_ == &each &&
Expand Down Expand Up @@ -412,7 +418,7 @@ void OverworldEditor::DrawTile8Selector() {
graphics_bin_canvas_.DrawContextMenu();
if (all_gfx_loaded_) {
// for (const auto &[key, value] : graphics_bin_) {
for (auto &[key, value] : rom()->BitmapManager()) {
for (auto &[key, value] : rom()->bitmap_manager()) {
int offset = 0x40 * (key + 1);
int top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 2;
if (key >= 1) {
Expand Down Expand Up @@ -465,7 +471,7 @@ void OverworldEditor::DrawTileSelector() {
absl::Status OverworldEditor::LoadGraphics() {
// Load all of the graphics data from the game.
PRINT_IF_ERROR(rom()->LoadAllGraphicsData())
graphics_bin_ = rom()->GetGraphicsBin();
graphics_bin_ = rom()->graphics_bin();

// Load the Link to the Past overworld.
RETURN_IF_ERROR(overworld_.Load(*rom()))
Expand Down Expand Up @@ -549,12 +555,12 @@ absl::Status OverworldEditor::DrawExperimentalModal() {
ImGui::Begin("Experimental", &show_experimental);

gui::TextWithSeparators("PROTOTYPE OVERWORLD TILEMAP LOADER");
ImGui::Text("Please provide two files:");
ImGui::Text("One based on MAPn.DAT, which represents the overworld tilemap");
ImGui::Text("One based on MAPDATn.DAT, which is the tile32 configurations.");
ImGui::Text("Currently, loading CGX for this component is NOT supported. ");
ImGui::Text("Please load a US ROM of LTTP (JP ROM support coming soon).");
ImGui::Text(
Text("Please provide two files:");
Text("One based on MAPn.DAT, which represents the overworld tilemap");
Text("One based on MAPDATn.DAT, which is the tile32 configurations.");
Text("Currently, loading CGX for this component is NOT supported. ");
Text("Please load a US ROM of LTTP (JP ROM support coming soon).");
Text(
"Once you've loaded the files, you can click the button below to load "
"the tilemap into the editor");

Expand Down
5 changes: 4 additions & 1 deletion src/app/editor/overworld_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ constexpr ImGuiTableFlags kOWEditFlags = ImGuiTableFlags_Reorderable |
ImGuiTableFlags_Resizable |
ImGuiTableFlags_SizingStretchSame;

constexpr absl::string_view kWorldList = "Light World\0Dark World\0Extra World";
constexpr absl::string_view kWorldList =
"Light World\0Dark World\0Extra World\0";

constexpr char *const kGamePartComboString[] = {"Part 0", "Part 1", "Part 2"};

constexpr absl::string_view kTileSelectorTab = "##TileSelectorTabBar";
constexpr absl::string_view kOWEditTable = "##OWEditTable";
Expand Down
26 changes: 13 additions & 13 deletions src/app/rom.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,23 +399,25 @@ class ROM : public core::ExperimentFlags {
changes_.push(function);
}

VersionConstants GetVersionConstants() const {
VersionConstants version_constants() const {
return kVersionConstantsMap.at(version_);
}

int GetGraphicsAddress(const uchar* data, uint8_t addr) const {
auto part_one = data[GetVersionConstants().kOverworldGfxPtr1 + addr] << 16;
auto part_two = data[GetVersionConstants().kOverworldGfxPtr2 + addr] << 8;
auto part_three = data[GetVersionConstants().kOverworldGfxPtr3 + addr];
auto part_one = data[version_constants().kOverworldGfxPtr1 + addr] << 16;
auto part_two = data[version_constants().kOverworldGfxPtr2 + addr] << 8;
auto part_three = data[version_constants().kOverworldGfxPtr3 + addr];
auto snes_addr = (part_one | part_two | part_three);
return core::SnesToPc(snes_addr);
}

gfx::PaletteGroup GetPaletteGroup(const std::string& group) {
return palette_groups_[group];
}
Bytes GetGraphicsBuffer() const { return graphics_buffer_; }
gfx::BitmapTable GetGraphicsBin() const { return graphics_bin_; }

Bytes graphics_buffer() const { return graphics_buffer_; }

gfx::BitmapTable graphics_bin() const { return graphics_bin_; }

auto title() const { return title_; }
auto size() const { return size_; }
Expand Down Expand Up @@ -477,7 +479,7 @@ class ROM : public core::ExperimentFlags {
bitmap->UpdateTexture(renderer_);
}

auto BitmapManager() { return graphics_manager_; }
auto bitmap_manager() { return graphics_manager_; }

std::vector<std::vector<uint8_t>> main_blockset_ids;
std::vector<std::vector<uint8_t>> room_blockset_ids;
Expand Down Expand Up @@ -510,16 +512,14 @@ class ROM : public core::ExperimentFlags {
for (int i = 0; i < 144; i++) {
for (int j = 0; j < 4; j++) {
spriteset_ids[i][j] =
rom_data_[GetVersionConstants().kSpriteBlocksetPointer + (i * 4) +
j];
rom_data_[version_constants().kSpriteBlocksetPointer + (i * 4) + j];
}
}

for (int i = 0; i < 72; i++) {
for (int j = 0; j < 4; j++) {
paletteset_ids[i][j] =
rom_data_[GetVersionConstants().kDungeonPalettesGroups + (i * 4) +
j];
rom_data_[version_constants().kDungeonPalettesGroups + (i * 4) + j];
}
}
}
Expand All @@ -544,14 +544,14 @@ class ROM : public core::ExperimentFlags {

for (int i = 0; i < 144; i++) {
for (int j = 0; j < 4; j++) {
rom_data_[GetVersionConstants().kSpriteBlocksetPointer + (i * 4) + j] =
rom_data_[version_constants().kSpriteBlocksetPointer + (i * 4) + j] =
spriteset_ids[i][j];
}
}

for (int i = 0; i < 72; i++) {
for (int j = 0; j < 4; j++) {
rom_data_[GetVersionConstants().kDungeonPalettesGroups + (i * 4) + j] =
rom_data_[version_constants().kDungeonPalettesGroups + (i * 4) + j] =
paletteset_ids[i][j];
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/app/zelda3/dungeon/room.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,14 @@ void Room::LoadRoomGraphics(uchar entrance_blockset) {
blocks[12 + i] = (uchar)(spriteGfx[SpriteTileset + 64][i] + 115);
} // 12-16 sprites

auto gfx_buffer_data = rom()->GetGraphicsBuffer();
auto gfx_buffer_data = rom()->graphics_buffer();

// Into "room gfx16" 16 of them
int sheetPos = 0;
for (int i = 0; i < 16; i++) {
int d = 0;
int ioff = blocks[i] * 2048;
while (d < 2048) {
// NOTE LOAD BLOCKSETS SOMEWHERE FIRST
uchar mapByte = gfx_buffer_data[d + ioff];
if (i < 4) {
mapByte += 0x88;
Expand All @@ -191,9 +190,9 @@ void Room::LoadRoomGraphics(uchar entrance_blockset) {

void Room::LoadAnimatedGraphics() {
int gfx_ptr =
core::SnesToPc(rom()->GetVersionConstants().kGfxAnimatedPointer);
core::SnesToPc(rom()->version_constants().kGfxAnimatedPointer);

auto gfx_buffer_data = rom()->GetGraphicsBuffer();
auto gfx_buffer_data = rom()->graphics_buffer();
auto rom_data = rom()->vector();
int data = 0;
while (data < 512) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/zelda3/dungeon/room_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DungeonObjectRenderer {
};

void CreateVramFromRoomBlockset() {
// auto bitmap_manager = rom()->BitmapManager();
// auto bitmap_manager = rom()->bitmap_manager();
// uint16_t room_id = 0;
// auto room_blockset = rom()->room_blockset_ids[room_id];

Expand Down
Loading

0 comments on commit bbe76ac

Please sign in to comment.