3#include "absl/container/flat_hash_map.h"
14#include "imgui/imgui.h"
15#include "imgui_memory_editor.h"
23using ImGui::BeginChild;
24using ImGui::BeginTabBar;
25using ImGui::BeginTabItem;
26using ImGui::BeginTable;
29using ImGui::EndTabBar;
30using ImGui::EndTabItem;
31using ImGui::RadioButton;
33using ImGui::TableHeadersRow;
34using ImGui::TableNextColumn;
35using ImGui::TableNextRow;
36using ImGui::TableSetupColumn;
40 ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable |
41 ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersOuter |
42 ImGuiTableFlags_BordersV;
55 if (ImGui::BeginTabBar(
"##DungeonEditorTabBar")) {
61 static bool calc_stats =
false;
72 return absl::OkStatus();
76 auto dungeon_man_pal_group =
rom()->palette_group().dungeon_main;
78 for (
int i = 0; i < 0x100 + 40; i++) {
81 rooms_[i].LoadRoomFromROM();
83 rooms_[i].LoadRoomGraphics();
87 if (
rooms_[i].room_size_ptr() != 0x0A8000) {
91 auto dungeon_palette_ptr =
rom()->paletteset_ids[
rooms_[i].palette][0];
93 rom()->ReadWord(0xDEC4B + dungeon_palette_ptr));
94 int p_id = palette_id / 180;
95 auto color = dungeon_man_pal_group[p_id][3];
101 for (
int i = 0; i < 0x07; ++i) {
105 for (
int i = 0; i < 0x85; ++i) {
119 return absl::OkStatus();
125 [
this](
int block) -> absl::Status {
129 return absl::OkStatus();
132 auto sprites_aux1_pal_group =
rom()->palette_group().sprites_aux1;
135 [
this, &sprites_aux1_pal_group](
int block) -> absl::Status {
139 return absl::OkStatus();
141 return absl::OkStatus();
145 std::map<int, std::vector<int>> rooms_by_bank;
147 int bank = room.second >> 16;
148 rooms_by_bank[bank].push_back(room.second);
152 for (
auto &bank_rooms : rooms_by_bank) {
154 std::sort(bank_rooms.second.begin(), bank_rooms.second.end());
156 for (
size_t i = 0; i < bank_rooms.second.size(); ++i) {
157 int room_ptr = bank_rooms.second[i];
162 [room_ptr](
const auto &entry) {
163 return entry.second == room_ptr;
167 if (room_ptr != 0x0A8000) {
168 if (i < bank_rooms.second.size() - 1) {
171 rooms_[room_id].set_room_size(bank_rooms.second[i + 1] - room_ptr);
174 int bank_end_address = (bank_rooms.first << 16) | 0xFFFF;
175 rooms_[room_id].set_room_size(bank_end_address - room_ptr + 1);
180 rooms_[room_id].set_room_size(0x00);
191 auto dungeon_main_pal_group =
rom()->palette_group().dungeon_main;
199 TableSetupColumn(
"Room Selector");
200 TableSetupColumn(
"Canvas", ImGuiTableColumnFlags_WidthStretch,
201 ImGui::GetContentRegionAvail().x);
202 TableSetupColumn(
"Object Selector");
207 if (ImGui::BeginTabBar(
"##DungeonRoomTabBar")) {
224 return absl::OkStatus();
228 if (BeginTable(
"DWToolset", 13, ImGuiTableFlags_SizingFixedFit,
230 TableSetupColumn(
"#undoTool");
231 TableSetupColumn(
"#redoTool");
232 TableSetupColumn(
"#separator");
233 TableSetupColumn(
"#anyTool");
235 TableSetupColumn(
"#bg1Tool");
236 TableSetupColumn(
"#bg2Tool");
237 TableSetupColumn(
"#bg3Tool");
238 TableSetupColumn(
"#separator");
239 TableSetupColumn(
"#spriteTool");
240 TableSetupColumn(
"#itemTool");
241 TableSetupColumn(
"#doorTool");
242 TableSetupColumn(
"#blockTool");
284 if (ImGui::IsItemHovered()) {
285 ImGui::SetTooltip(
"Sprites");
292 if (ImGui::IsItemHovered()) {
293 ImGui::SetTooltip(
"Items");
300 if (ImGui::IsItemHovered()) {
301 ImGui::SetTooltip(
"Doors");
308 if (ImGui::IsItemHovered()) {
309 ImGui::SetTooltip(
"Blocks");
322 if (
rom()->is_loaded()) {
326 if (ImGuiID child_id = ImGui::GetID((
void *)(intptr_t)9);
327 BeginChild(child_id, ImGui::GetContentRegionAvail(),
true,
328 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
331 rom()->resource_label()->SelectableLabelWithNameEdit(
333 each_room_name.data());
334 if (ImGui::IsItemClicked()) {
348using ImGui::Separator;
351 if (
rom()->is_loaded()) {
381 Text(
"Camera Boundaries");
383 Text(
"\t\t\t\t\tNorth East South West");
402 if (BeginChild(
"EntranceSelector", ImVec2(0, 0),
true,
403 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
404 for (
int i = 0; i < 0x85 + 7; i++) {
405 rom()->resource_label()->SelectableLabelWithNameEdit(
409 if (ImGui::IsItemClicked()) {
422 static int next_tab_id = 0;
444 ImGuiTabItemFlags_None)) {
485 canvas_.DrawBackground(ImVec2(0x200, 0x200));
495 const auto height = 0x40;
496 const int num_sheets = 0x10;
497 room_gfx_canvas_.DrawBackground(ImVec2(0x100 + 1, num_sheets * height + 1));
502 int current_block = 0;
503 for (
int block : blocks) {
504 int offset = height * (current_block + 1);
506 if (current_block >= 1) {
522 if (BeginTabBar(
"##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
523 if (BeginTabItem(
"Room Graphics")) {
524 if (ImGuiID child_id = ImGui::GetID((
void *)(intptr_t)3);
525 BeginChild(child_id, ImGui::GetContentRegionAvail(),
true,
526 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
533 if (BeginTabItem(
"Object Renderer")) {
544 TableSetupColumn(
"Dungeon Objects", ImGuiTableColumnFlags_WidthStretch,
545 ImGui::GetContentRegionAvail().x);
546 TableSetupColumn(
"Canvas");
549 BeginChild(
"DungeonObjectButtons", ImVec2(250, 0),
true);
551 int selected_object = 0;
553 for (
const auto object_name : zelda3::Type1RoomObjectNames) {
554 if (ImGui::Selectable(object_name.data(), selected_object == i)) {
569 BeginChild(
"DungeonObjectCanvas", ImVec2(276, 0x10 * 0x40 + 1),
true);
586 static MemoryEditor mem_edit;
594 for (
const auto &room :
rooms_) {
616 const absl::flat_hash_map<uint16_t, int> &usage_map, uint16_t &selected_set,
617 int spriteset_offset) {
619 std::vector<std::pair<uint16_t, int>> sorted_usage(usage_map.begin(),
621 std::sort(sorted_usage.begin(), sorted_usage.end(),
622 [](
const auto &a,
const auto &b) { return a.first < b.first; });
624 for (
const auto &[set, count] : sorted_usage) {
625 std::string display_str;
626 if (spriteset_offset != 0x00) {
627 display_str = absl::StrFormat(
"%#02x, %#02x: %d", set,
628 (set + spriteset_offset), count);
631 absl::StrFormat(
"%#02x: %d", (set + spriteset_offset), count);
633 if (ImGui::Selectable(display_str.c_str(), selected_set == set)) {
646 int spriteset_offset = 0x00) {
647 std::vector<int> unused_sets;
648 for (
int i = 0; i < max_set; i++) {
649 if (usage_map.find(i) == usage_map.end()) {
650 unused_sets.push_back(i);
653 for (
const auto &set : unused_sets) {
654 if (spriteset_offset != 0x00) {
655 Text(
"%#02x, %#02x", set, (set + spriteset_offset));
664 if (Button(
"Refresh")) {
674 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
675 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
676 if (BeginTable(
"DungeonUsageStatsTable", 8,
678 ImGui::GetContentRegionAvail())) {
679 TableSetupColumn(
"Blockset Usage");
680 TableSetupColumn(
"Unused Blockset");
681 TableSetupColumn(
"Palette Usage");
682 TableSetupColumn(
"Unused Palette");
683 TableSetupColumn(
"Spriteset Usage");
684 TableSetupColumn(
"Unused Spriteset");
685 TableSetupColumn(
"Usage Grid");
686 TableSetupColumn(
"Group Preview");
688 ImGui::PopStyleVar(2);
691 BeginChild(
"BlocksetUsageScroll", ImVec2(0, 0),
true,
692 ImGuiWindowFlags_HorizontalScrollbar);
697 BeginChild(
"UnusedBlocksetScroll", ImVec2(0, 0),
true,
698 ImGuiWindowFlags_HorizontalScrollbar);
703 BeginChild(
"PaletteUsageScroll", ImVec2(0, 0),
true,
704 ImGuiWindowFlags_HorizontalScrollbar);
709 BeginChild(
"UnusedPaletteScroll", ImVec2(0, 0),
true,
710 ImGuiWindowFlags_HorizontalScrollbar);
716 BeginChild(
"SpritesetUsageScroll", ImVec2(0, 0),
true,
717 ImGuiWindowFlags_HorizontalScrollbar);
722 BeginChild(
"UnusedSpritesetScroll", ImVec2(0, 0),
true,
723 ImGuiWindowFlags_HorizontalScrollbar);
728 BeginChild(
"UsageGrid", ImVec2(0, 0),
true,
729 ImGuiWindowFlags_HorizontalScrollbar);
730 Text(
"%s", absl::StrFormat(
"Total size of all rooms: %d hex format: %#06x",
749 int totalSquares = 296;
750 int squaresWide = 16;
751 int squaresTall = (totalSquares + squaresWide - 1) /
754 for (
int row = 0; row < squaresTall; ++row) {
757 for (
int col = 0; col < squaresWide; ++col) {
759 if (row * squaresWide + col >= totalSquares) {
763 const auto &room =
rooms_[row * squaresWide + col];
768 color.x = color.x / 255;
769 color.y = color.y / 255;
770 color.z = color.z / 255;
772 if (
rooms_[row * squaresWide + col].room_size() > 0xFFFF) {
773 color = ImVec4(1.0f, 0.0f, 0.0f, 1.0f);
775 if (
rooms_[row * squaresWide + col].room_size() == 0) {
776 color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
778 ImGui::PushStyleColor(ImGuiCol_Button, color);
780 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
788 ImGui::PushStyleColor(
790 ImVec4(1.0f, 0.5f, 0.0f, 1.0f));
792 if (Button(absl::StrFormat(
"%#x",
793 rooms_[row * squaresWide + col].room_size())
800 if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
802 absl::StrFormat(
"RoomContextMenu%d", row * squaresWide + col)
805 ImGui::PopStyleColor(2);
810 ImGui::PopStyleColor();
814 if (ImGui::IsItemHovered()) {
816 ImGui::BeginTooltip();
817 Text(
"Room ID: %d", row * squaresWide + col);
818 Text(
"Blockset: %#02x", room.blockset);
819 Text(
"Spriteset: %#02x", room.spriteset);
820 Text(
"Palette: %#02x", room.palette);
821 Text(
"Floor1: %#02x", room.floor1);
822 Text(
"Floor2: %#02x", room.floor2);
823 Text(
"Message ID: %#04x", room.message_id_);
824 Text(
"Size: %#016llx", room.room_size());
825 Text(
"Size Pointer: %#016llx", room.room_size_ptr());
static GraphicsSheetManager & GetInstance()
std::array< gfx::Bitmap, kNumGfxSheets > & gfx_sheets()
void UpdateBitmap(gfx::Bitmap *bitmap)
Used to update a bitmap on the screen.
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
absl::flat_hash_map< uint16_t, int > spriteset_usage_
void LoadDungeonRoomSize()
uint16_t selected_blockset_
absl::Status RefreshGraphics()
absl::Status Update() override
uint64_t current_palette_group_id_
void DrawEntranceSelector()
std::vector< zelda3::RoomEntrance > entrances_
std::unordered_map< int, ImVec4 > room_palette_
uint16_t current_room_id_
absl::flat_hash_map< uint16_t, int > blockset_usage_
uint64_t current_palette_id_
absl::flat_hash_map< uint16_t, int > palette_usage_
std::vector< zelda3::Room > rooms_
void RenderSetUsage(const absl::flat_hash_map< uint16_t, int > &usage_map, uint16_t &selected_set, int spriteset_offset=0x00)
uint16_t selected_spriteset_
std::vector< gfx::Bitmap * > room_gfx_sheets_
GfxGroupEditor gfx_group_editor_
uint16_t selected_palette_
uint64_t total_room_size_
absl::Status Initialize()
gfx::SnesPalette current_palette_
gfx::PaletteGroup current_palette_group_
void DrawDungeonCanvas(int room_id)
uint16_t current_entrance_id_
std::unordered_map< int, int > room_size_addresses_
absl::Status Redo() override
zelda3::DungeonObjectRenderer object_renderer_
gui::Canvas room_gfx_canvas_
gfx::SnesPalette full_palette_
gui::Canvas object_canvas_
void DrawDungeonTabView()
void CalculateUsageStats()
std::vector< int64_t > room_size_pointers_
std::array< gfx::Bitmap, kNumGfxSheets > graphics_bin_
void DrawObjectRenderer()
ImVector< int > active_rooms_
absl::Status UpdateDungeonRoomView()
absl::Status Undo() override
static Renderer & GetInstance()
Dungeon Room Entrance or Spawn Point.
#define ICON_MD_MORE_VERT
#define ICON_MD_FILTER_NONE
#define ICON_MD_SENSOR_DOOR
#define ICON_MD_PEST_CONTROL
#define PRINT_IF_ERROR(expression)
#define RETURN_IF_ERROR(expression)
#define ASSIGN_OR_RETURN(type_variable_name, expression)
void RenderUnusedSets(const absl::flat_hash_map< T, int > &usage_map, int max_set, int spriteset_offset=0x00)
Editors are the view controllers for the application.
constexpr ImGuiTableFlags kDungeonTableFlags
constexpr ImGuiTabItemFlags kDungeonTabFlags
constexpr ImGuiTabBarFlags kDungeonTabBarFlags
constexpr ImGuiTableFlags kDungeonObjectTableFlags
absl::StatusOr< PaletteGroup > CreatePaletteGroupFromLargePalette(SnesPalette &palette, int num_colors)
Take a SNESPalette, divide it into palettes of 8 colors.
bool InputHexWord(const char *label, uint16_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 InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
std::string HexByte(uint8_t byte, HexStringParams params)
constexpr std::string_view kEntranceNames[]
constexpr std::string_view kRoomNames[]
Main namespace for the application.