3#include "absl/container/flat_hash_map.h"
12#include "imgui/imgui.h"
21using ImGui::BeginChild;
22using ImGui::BeginTabBar;
23using ImGui::BeginTabItem;
24using ImGui::BeginTable;
27using ImGui::EndTabBar;
28using ImGui::EndTabItem;
29using ImGui::RadioButton;
31using ImGui::TableHeadersRow;
32using ImGui::TableNextColumn;
33using ImGui::TableNextRow;
34using ImGui::TableSetupColumn;
38 ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable |
39 ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersOuter |
40 ImGuiTableFlags_BordersV;
53 if (ImGui::BeginTabBar(
"##DungeonEditorTabBar")) {
59 static bool calc_stats =
false;
70 return absl::OkStatus();
74 auto dungeon_man_pal_group =
rom()->palette_group().dungeon_main;
75 for (
int i = 0; i < 0x100 + 40; i++) {
78 rooms_[i].LoadRoomFromROM();
79 if (
flags()->kDrawDungeonRoomGraphics) {
80 rooms_[i].LoadRoomGraphics();
84 if (
rooms_[i].room_size_ptr() != 0x0A8000) {
88 auto dungeon_palette_ptr =
rom()->paletteset_ids[
rooms_[i].palette][0];
90 rom()->ReadWord(0xDEC4B + dungeon_palette_ptr));
91 int p_id = palette_id / 180;
92 auto color = dungeon_man_pal_group[p_id][3];
98 for (
int i = 0; i < 0x07; ++i) {
102 for (
int i = 0; i < 0x85; ++i) {
116 return absl::OkStatus();
120 for (
int i = 0; i < 8; i++) {
126 auto sprites_aux1_pal_group =
rom()->palette_group().sprites_aux1;
127 for (
int i = 9; i < 16; i++) {
133 return absl::OkStatus();
137 std::map<int, std::vector<int>> rooms_by_bank;
139 int bank = room.second >> 16;
140 rooms_by_bank[bank].push_back(room.second);
144 for (
auto& bank_rooms : rooms_by_bank) {
146 std::sort(bank_rooms.second.begin(), bank_rooms.second.end());
148 for (
size_t i = 0; i < bank_rooms.second.size(); ++i) {
149 int room_ptr = bank_rooms.second[i];
154 [room_ptr](
const auto& entry) {
155 return entry.second == room_ptr;
159 if (room_ptr != 0x0A8000) {
160 if (i < bank_rooms.second.size() - 1) {
163 rooms_[room_id].set_room_size(bank_rooms.second[i + 1] - room_ptr);
166 int bank_end_address = (bank_rooms.first << 16) | 0xFFFF;
167 rooms_[room_id].set_room_size(bank_end_address - room_ptr + 1);
172 rooms_[room_id].set_room_size(0x00);
183 auto dungeon_main_pal_group =
rom()->palette_group().dungeon_main;
191 TableSetupColumn(
"Room Selector");
192 TableSetupColumn(
"Canvas", ImGuiTableColumnFlags_WidthStretch,
193 ImGui::GetContentRegionAvail().x);
194 TableSetupColumn(
"Object Selector");
199 if (ImGui::BeginTabBar(
"##DungeonRoomTabBar")) {
216 return absl::OkStatus();
220 if (BeginTable(
"DWToolset", 13, ImGuiTableFlags_SizingFixedFit,
222 TableSetupColumn(
"#undoTool");
223 TableSetupColumn(
"#redoTool");
224 TableSetupColumn(
"#separator");
225 TableSetupColumn(
"#anyTool");
227 TableSetupColumn(
"#bg1Tool");
228 TableSetupColumn(
"#bg2Tool");
229 TableSetupColumn(
"#bg3Tool");
230 TableSetupColumn(
"#separator");
231 TableSetupColumn(
"#spriteTool");
232 TableSetupColumn(
"#itemTool");
233 TableSetupColumn(
"#doorTool");
234 TableSetupColumn(
"#blockTool");
276 if (ImGui::IsItemHovered()) {
277 ImGui::SetTooltip(
"Sprites");
284 if (ImGui::IsItemHovered()) {
285 ImGui::SetTooltip(
"Items");
292 if (ImGui::IsItemHovered()) {
293 ImGui::SetTooltip(
"Doors");
300 if (ImGui::IsItemHovered()) {
301 ImGui::SetTooltip(
"Blocks");
314 if (
rom()->is_loaded()) {
318 if (ImGuiID child_id = ImGui::GetID((
void*)(intptr_t)9);
319 BeginChild(child_id, ImGui::GetContentRegionAvail(),
true,
320 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
323 rom()->resource_label()->SelectableLabelWithNameEdit(
326 if (ImGui::IsItemClicked()) {
340using ImGui::Separator;
343 if (
rom()->is_loaded()) {
373 Text(
"Camera Boundaries");
375 Text(
"\t\t\t\t\tNorth East South West");
394 if (BeginChild(
"EntranceSelector", ImVec2(0, 0),
true,
395 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
396 for (
int i = 0; i < 0x85 + 7; i++) {
397 rom()->resource_label()->SelectableLabelWithNameEdit(
402 if (ImGui::IsItemClicked()) {
415 static int next_tab_id = 0;
437 &open, ImGuiTabItemFlags_None)) {
488 const auto height = 0x40;
489 const int num_sheets = 0x10;
495 int current_block = 0;
496 for (
int block : blocks) {
497 int offset = height * (current_block + 1);
499 if (current_block >= 1) {
515 if (BeginTabBar(
"##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
516 if (BeginTabItem(
"Room Graphics")) {
517 if (ImGuiID child_id = ImGui::GetID((
void*)(intptr_t)3);
518 BeginChild(child_id, ImGui::GetContentRegionAvail(),
true,
519 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
526 if (BeginTabItem(
"Object Renderer")) {
537 TableSetupColumn(
"Dungeon Objects", ImGuiTableColumnFlags_WidthStretch,
538 ImGui::GetContentRegionAvail().x);
539 TableSetupColumn(
"Canvas");
542 BeginChild(
"DungeonObjectButtons", ImVec2(250, 0),
true);
544 int selected_object = 0;
546 for (
const auto object_name : zelda3::dungeon::Type1RoomObjectNames) {
547 if (ImGui::Selectable(object_name.data(), selected_object == i)) {
562 BeginChild(
"DungeonObjectCanvas", ImVec2(276, 0x10 * 0x40 + 1),
true);
579 static MemoryEditor mem_edit;
589 for (
const auto& room :
rooms_) {
611 const absl::flat_hash_map<uint16_t, int>& usage_map, uint16_t& selected_set,
612 int spriteset_offset) {
614 std::vector<std::pair<uint16_t, int>> sorted_usage(usage_map.begin(),
616 std::sort(sorted_usage.begin(), sorted_usage.end(),
617 [](
const auto& a,
const auto& b) { return a.first < b.first; });
619 for (
const auto& [set, count] : sorted_usage) {
620 std::string display_str;
621 if (spriteset_offset != 0x00) {
622 display_str = absl::StrFormat(
"%#02x, %#02x: %d", set,
623 (set + spriteset_offset), count);
626 absl::StrFormat(
"%#02x: %d", (set + spriteset_offset), count);
628 if (ImGui::Selectable(display_str.c_str(), selected_set == set)) {
641 int spriteset_offset = 0x00) {
642 std::vector<int> unused_sets;
643 for (
int i = 0; i < max_set; i++) {
644 if (usage_map.find(i) == usage_map.end()) {
645 unused_sets.push_back(i);
648 for (
const auto& set : unused_sets) {
649 if (spriteset_offset != 0x00) {
650 Text(
"%#02x, %#02x", set, (set + spriteset_offset));
659 if (Button(
"Refresh")) {
669 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
670 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
671 if (BeginTable(
"DungeonUsageStatsTable", 8,
673 ImGui::GetContentRegionAvail())) {
674 TableSetupColumn(
"Blockset Usage");
675 TableSetupColumn(
"Unused Blockset");
676 TableSetupColumn(
"Palette Usage");
677 TableSetupColumn(
"Unused Palette");
678 TableSetupColumn(
"Spriteset Usage");
679 TableSetupColumn(
"Unused Spriteset");
680 TableSetupColumn(
"Usage Grid");
681 TableSetupColumn(
"Group Preview");
683 ImGui::PopStyleVar(2);
686 BeginChild(
"BlocksetUsageScroll", ImVec2(0, 0),
true,
687 ImGuiWindowFlags_HorizontalScrollbar);
692 BeginChild(
"UnusedBlocksetScroll", ImVec2(0, 0),
true,
693 ImGuiWindowFlags_HorizontalScrollbar);
698 BeginChild(
"PaletteUsageScroll", ImVec2(0, 0),
true,
699 ImGuiWindowFlags_HorizontalScrollbar);
704 BeginChild(
"UnusedPaletteScroll", ImVec2(0, 0),
true,
705 ImGuiWindowFlags_HorizontalScrollbar);
711 BeginChild(
"SpritesetUsageScroll", ImVec2(0, 0),
true,
712 ImGuiWindowFlags_HorizontalScrollbar);
717 BeginChild(
"UnusedSpritesetScroll", ImVec2(0, 0),
true,
718 ImGuiWindowFlags_HorizontalScrollbar);
723 BeginChild(
"UsageGrid", ImVec2(0, 0),
true,
724 ImGuiWindowFlags_HorizontalScrollbar);
725 Text(
"%s", absl::StrFormat(
"Total size of all rooms: %d hex format: %#06x",
744 int totalSquares = 296;
745 int squaresWide = 16;
746 int squaresTall = (totalSquares + squaresWide - 1) /
749 for (
int row = 0; row < squaresTall; ++row) {
752 for (
int col = 0; col < squaresWide; ++col) {
754 if (row * squaresWide + col >= totalSquares) {
758 const auto& room =
rooms_[row * squaresWide + col];
763 color.x = color.x / 255;
764 color.y = color.y / 255;
765 color.z = color.z / 255;
767 if (
rooms_[row * squaresWide + col].room_size() > 0xFFFF) {
768 color = ImVec4(1.0f, 0.0f, 0.0f, 1.0f);
770 if (
rooms_[row * squaresWide + col].room_size() == 0) {
771 color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
773 ImGui::PushStyleColor(ImGuiCol_Button, color);
775 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
783 ImGui::PushStyleColor(
785 ImVec4(1.0f, 0.5f, 0.0f, 1.0f));
787 if (Button(absl::StrFormat(
"%#x",
788 rooms_[row * squaresWide + col].room_size())
795 if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
797 absl::StrFormat(
"RoomContextMenu%d", row * squaresWide + col)
800 ImGui::PopStyleColor(2);
805 ImGui::PopStyleColor();
809 if (ImGui::IsItemHovered()) {
811 ImGui::BeginTooltip();
812 Text(
"Room ID: %d", row * squaresWide + col);
813 Text(
"Blockset: %#02x", room.blockset);
814 Text(
"Spriteset: %#02x", room.spriteset);
815 Text(
"Palette: %#02x", room.palette);
816 Text(
"Floor1: %#02x", room.floor1);
817 Text(
"Floor2: %#02x", room.floor2);
818 Text(
"Message ID: %#04x", room.message_id_);
819 Text(
"Size: %#016llx", room.room_size());
820 Text(
"Size Pointer: %#016llx", room.room_size_ptr());
void UpdateBitmap(gfx::Bitmap *bitmap)
Used to update a bitmap on the screen.
static Renderer & GetInstance()
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
uint16_t current_room_id_
uint16_t selected_blockset_
std::unordered_map< int, int > room_size_addresses_
absl::flat_hash_map< uint16_t, int > blockset_usage_
void DrawDungeonTabView()
absl::Status Redo() override
uint64_t current_palette_group_id_
std::vector< zelda3::dungeon::Room > rooms_
uint16_t current_entrance_id_
void LoadDungeonRoomSize()
void DrawDungeonCanvas(int room_id)
std::array< gfx::Bitmap, kNumGfxSheets > graphics_bin_
gfx::SnesPalette current_palette_
absl::Status Undo() override
gui::Canvas object_canvas_
gui::Canvas room_gfx_canvas_
ImVector< int > active_rooms_
absl::flat_hash_map< uint16_t, int > palette_usage_
gfx::PaletteGroup current_palette_group_
std::vector< zelda3::dungeon::RoomEntrance > entrances_
std::vector< gfx::Bitmap * > room_gfx_sheets_
uint16_t selected_palette_
void CalculateUsageStats()
uint64_t total_room_size_
gfx::SnesPalette full_palette_
absl::Status Update() override
std::unordered_map< int, ImVec4 > room_palette_
absl::Status RefreshGraphics()
uint16_t selected_spriteset_
void DrawObjectRenderer()
zelda3::dungeon::DungeonObjectRenderer object_renderer_
uint64_t current_palette_id_
absl::Status UpdateDungeonRoomView()
absl::Status Initialize()
std::vector< int64_t > room_size_pointers_
absl::flat_hash_map< uint16_t, int > spriteset_usage_
void DrawEntranceSelector()
GfxGroupEditor gfx_group_editor_
void RenderSetUsage(const absl::flat_hash_map< uint16_t, int > &usage_map, uint16_t &selected_set, int spriteset_offset=0x00)
void SetSelectedBlockset(uint8_t blockset)
void DrawSpritesetViewer(bool sheet_only=false)
void DrawBlocksetViewer(bool sheet_only=false)
void SetSelectedSpriteset(uint8_t spriteset)
bool DrawTileSelector(int size)
void DrawBackground(ImVec2 canvas_size=ImVec2(0, 0), bool drag=false)
void DrawGrid(float grid_step=64.0f, int tile_id_offset=8)
void DrawBitmap(const Bitmap &bitmap, int border_offset=0, bool ready=true)
void DrawContextMenu(gfx::Bitmap *bitmap=nullptr)
void LoadObject(uint32_t routine_ptr, std::array< uint8_t, 16 > &sheet_ids)
Dungeon Room Entrance or Spawn Point.
#define PRINT_IF_ERROR(expression)
#define RETURN_IF_ERROR(expression)
#define ASSIGN_OR_RETURN(type_variable_name, expression)
#define ICON_MD_MORE_VERT
#define ICON_MD_FILTER_NONE
#define ICON_MD_SENSOR_DOOR
#define ICON_MD_PEST_CONTROL
std::string UppercaseHexByte(uint8_t byte, bool leading)
void RenderUnusedSets(const absl::flat_hash_map< T, int > &usage_map, int max_set, int spriteset_offset=0x00)
constexpr ImGuiTableFlags kDungeonTableFlags
constexpr ImGuiTableFlags kDungeonObjectTableFlags
constexpr ImGuiTabBarFlags kDungeonTabBarFlags
constexpr ImGuiTabItemFlags kDungeonTabFlags
absl::StatusOr< PaletteGroup > CreatePaletteGroupFromLargePalette(SnesPalette &palette, int num_colors)
Take a SNESPalette, divide it into palettes of 8 colors.
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
bool InputHex(const char *label, uint64_t *data)
void SelectablePalettePipeline(uint64_t &palette_id, bool &refresh_graphics, gfx::SnesPalette &palette)
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
constexpr std::string_view kEntranceNames[]
constexpr std::string_view kRoomNames[]