Implement dungeon map screen drawing functionality in ScreenEditor

- Added DrawDungeonMapScreen method to encapsulate the logic for rendering the dungeon map, improving code organization and readability.
- Refactored DrawDungeonMapsTabs to utilize the new DrawDungeonMapScreen method, reducing code duplication.
- Updated various drawing operations for better clarity and efficiency, including adjustments to tile rendering and grid display.
- Removed commented-out code to clean up the implementation.
This commit is contained in:
scawful
2025-09-23 21:38:54 -04:00
parent 0920fcc1fb
commit 8da8014170
3 changed files with 66 additions and 59 deletions

View File

@@ -38,6 +38,7 @@ absl::Status ScreenEditor::Load() {
sheets_.try_emplace(1, gfx::Arena::Get().gfx_sheets()[213]);
sheets_.try_emplace(2, gfx::Arena::Get().gfx_sheets()[214]);
sheets_.try_emplace(3, gfx::Arena::Get().gfx_sheets()[215]);
/**
int current_tile8 = 0;
int tile_data_offset = 0;
for (int i = 0; i < 4; ++i) {
@@ -53,6 +54,7 @@ absl::Status ScreenEditor::Load() {
}
tile_data_offset = 0;
}
*/
return absl::OkStatus();
}
@@ -157,20 +159,9 @@ void ScreenEditor::DrawInventoryToolset() {
}
}
void ScreenEditor::DrawDungeonMapsTabs() {
void ScreenEditor::DrawDungeonMapScreen(int i) {
auto &current_dungeon = dungeon_maps_[selected_dungeon];
if (ImGui::BeginTabBar("##DungeonMapTabs")) {
auto nbr_floors =
current_dungeon.nbr_of_floor + current_dungeon.nbr_of_basement;
for (int i = 0; i < nbr_floors; i++) {
int basement_num = current_dungeon.nbr_of_basement - i;
std::string tab_name = absl::StrFormat("Basement %d", basement_num);
if (i >= current_dungeon.nbr_of_basement) {
tab_name = absl::StrFormat("Floor %d",
i - current_dungeon.nbr_of_basement + 1);
}
if (ImGui::BeginTabItem(tab_name.c_str())) {
floor_number = i;
screen_canvas_.DrawBackground(ImVec2(325, 325));
screen_canvas_.DrawTileSelector(64.f);
@@ -187,8 +178,8 @@ void ScreenEditor::DrawDungeonMapsTabs() {
(posX * 2), (posY * 2), 4.0f);
if (current_dungeon.floor_rooms[floor_number][j] == boss_room) {
screen_canvas_.DrawOutlineWithColor((posX * 2), (posY * 2), 64,
64, kRedPen);
screen_canvas_.DrawOutlineWithColor((posX * 2), (posY * 2), 64, 64,
kRedPen);
}
std::string label =
@@ -207,6 +198,22 @@ void ScreenEditor::DrawDungeonMapsTabs() {
int y = screen_canvas_.points().front().y / 64;
selected_room = x + (y * 5);
}
}
void ScreenEditor::DrawDungeonMapsTabs() {
auto &current_dungeon = dungeon_maps_[selected_dungeon];
if (ImGui::BeginTabBar("##DungeonMapTabs")) {
auto nbr_floors =
current_dungeon.nbr_of_floor + current_dungeon.nbr_of_basement;
for (int i = 0; i < nbr_floors; i++) {
int basement_num = current_dungeon.nbr_of_basement - i;
std::string tab_name = absl::StrFormat("Basement %d", basement_num);
if (i >= current_dungeon.nbr_of_basement) {
tab_name = absl::StrFormat("Floor %d",
i - current_dungeon.nbr_of_basement + 1);
}
if (ImGui::BeginTabItem(tab_name.data())) {
DrawDungeonMapScreen(i);
ImGui::EndTabItem();
}
}
@@ -219,9 +226,8 @@ void ScreenEditor::DrawDungeonMapsTabs() {
gui::InputHexWord("Boss Room", &current_dungeon.boss_room);
const ImVec2 button_size = ImVec2(130, 0);
const auto button_size = ImVec2(130, 0);
// Add Floor Button
if (ImGui::Button("Add Floor", button_size) &&
current_dungeon.nbr_of_floor < 8) {
current_dungeon.nbr_of_floor++;
@@ -234,7 +240,6 @@ void ScreenEditor::DrawDungeonMapsTabs() {
dungeon_map_labels_[selected_dungeon].pop_back();
}
// Add Basement Button
if (ImGui::Button("Add Basement", button_size) &&
current_dungeon.nbr_of_basement < 8) {
current_dungeon.nbr_of_basement++;
@@ -264,30 +269,32 @@ void ScreenEditor::DrawDungeonMapsRoomGfx() {
selected_tile16_ = tilesheet_canvas_.points().front().x / 32 +
(tilesheet_canvas_.points().front().y / 32) * 16;
gfx::RenderTile16(tile16_blockset_, selected_tile16_);
std::copy(tile16_blockset_.tile_info[selected_tile16_].begin(),
tile16_blockset_.tile_info[selected_tile16_].end(),
std::ranges::copy(tile16_blockset_.tile_info[selected_tile16_],
current_tile16_info.begin());
}
tilesheet_canvas_.DrawBitmap(tile16_blockset_.atlas, 1, 1, 2.0f);
tilesheet_canvas_.DrawGrid(32.f);
tilesheet_canvas_.DrawOverlay();
if (!tilesheet_canvas_.points().empty()) {
if (!screen_canvas_.points().empty()) {
if (!tilesheet_canvas_.points().empty() &&
!screen_canvas_.points().empty()) {
dungeon_maps_[selected_dungeon].floor_gfx[floor_number][selected_room] =
selected_tile16_;
tilesheet_canvas_.mutable_points()->clear();
}
}
ImGui::Separator();
current_tile_canvas_.DrawBackground(); // ImVec2(64 * 2 + 2, 64 * 2 + 4));
current_tile_canvas_.DrawContextMenu();
// if
// (current_tile_canvas_.DrawTilePainter(tile8_individual_[selected_tile8_],
// 16)) {
if (current_tile_canvas_.DrawTilePainter(tile8_individual_[selected_tile8_],
16)) {
// Modify the tile16 based on the selected tile and current_tile16_info
// }
gfx::ModifyTile16(tile16_blockset_, rom()->graphics_buffer(),
current_tile16_info[0], current_tile16_info[1],
current_tile16_info[2], current_tile16_info[3], 212,
selected_tile16_);
gfx::UpdateTile16(tile16_blockset_, selected_tile16_);
}
current_tile_canvas_.DrawBitmap(
tile16_blockset_.tile_bitmaps[selected_tile16_], 2, 4.0f);
current_tile_canvas_.DrawGrid(16.f);
@@ -385,8 +392,8 @@ void ScreenEditor::LoadBinaryGfx() {
// Read the gfx data into a buffer
std::vector<uint8_t> bin_data((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
auto converted_bin = gfx::SnesTo8bppSheet(bin_data, 4, 4);
if (zelda3::LoadDungeonMapTile16(tile16_blockset_, *rom(), converted_bin,
if (auto converted_bin = gfx::SnesTo8bppSheet(bin_data, 4, 4);
zelda3::LoadDungeonMapTile16(tile16_blockset_, *rom(), converted_bin,
true)
.ok()) {
sheets_.clear();

View File

@@ -64,6 +64,7 @@ class ScreenEditor : public Editor {
bool bin_mode = false);
absl::Status SaveDungeonMapTile16();
void DrawDungeonMapScreen(int i);
void DrawDungeonMapsTabs();
void DrawDungeonMapsEditor();
void DrawDungeonMapsRoomGfx();
@@ -86,7 +87,6 @@ class ScreenEditor : public Editor {
bool copy_button_pressed = false;
bool paste_button_pressed = false;
std::unordered_map<int, gfx::Bitmap> tile16_individual_;
std::vector<gfx::Bitmap> tile8_individual_;
zelda3::DungeonMapLabels dungeon_map_labels_;

View File

@@ -111,7 +111,7 @@ void Canvas::DrawContextMenu() {
static bool show_bitmap_data = false;
if (show_bitmap_data && bitmap_ != nullptr) {
MemoryEditor mem_edit;
static MemoryEditor mem_edit;
mem_edit.DrawWindow("Bitmap Data", (void *)bitmap_->data(), bitmap_->size(),
0);
}