yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
usage_statistics_card.cc
Go to the documentation of this file.
2
3#include <algorithm>
4
5#include "absl/strings/str_format.h"
9#include "imgui/imgui.h"
11
12namespace yaze::editor {
13
15 : overworld_(overworld) {}
16
17void UsageStatisticsCard::Draw(bool* p_open) {
18 if (!overworld_ || !overworld_->is_loaded()) {
19 ImGui::TextDisabled("Overworld not loaded");
20 return;
21 }
22
23 if (ImGui::Begin("Usage Statistics", p_open)) {
24 if (gui::BeginThemedTabBar("UsageTabs")) {
25 if (ImGui::BeginTabItem("Grid View")) {
27 ImGui::EndTabItem();
28 }
29 if (ImGui::BeginTabItem("States")) {
31 ImGui::EndTabItem();
32 }
34 }
35 }
36 ImGui::End();
37}
38
40 const int world = std::clamp(overworld_->current_world(), 0, 2);
41 const int world_start = (world == 0) ? 0 : ((world == 1) ? 0x40 : 0x80);
42 const int world_count = (world == 2) ? 32 : 64;
43
44 ImGui::Text("Map Usage Grid (World %d)", world);
45 ImGui::Separator();
46
47 if (ImGui::BeginTable(
48 "UsageGrid", 8,
49 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit)) {
50 for (int y = 0; y < 8; y++) {
51 ImGui::TableNextRow();
52 for (int x = 0; x < 8; x++) {
53 ImGui::TableNextColumn();
54 const int local_id = y * 8 + x;
55 if (local_id >= world_count) {
56 ImGui::TextDisabled("--");
57 continue;
58 }
59
60 const int map_id = world_start + local_id;
61 const auto* map = overworld_->overworld_map(map_id);
62 if (!map) {
63 ImGui::TextDisabled("??");
64 continue;
65 }
66
67 ImVec4 area_color = ImVec4(0.35f, 0.55f, 0.35f, 1.0f); // Small
68 const char* area_label = "Small";
69 switch (map->area_size()) {
71 area_color = ImVec4(0.65f, 0.52f, 0.28f, 1.0f);
72 area_label = "Large";
73 break;
75 area_color = ImVec4(0.30f, 0.50f, 0.72f, 1.0f);
76 area_label = "Wide";
77 break;
79 area_color = ImVec4(0.55f, 0.40f, 0.72f, 1.0f);
80 area_label = "Tall";
81 break;
83 default:
84 break;
85 }
86
87 ImGui::PushStyleColor(ImGuiCol_Button, area_color);
88 ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
89 ImVec4(area_color.x + 0.1f, area_color.y + 0.1f,
90 area_color.z + 0.1f, 1.0f));
91 ImGui::PushStyleColor(ImGuiCol_ButtonActive, area_color);
92 const std::string button_id =
93 absl::StrFormat("%02X##usage_map_%d", map_id, map_id);
94 ImGui::Button(button_id.c_str(), ImVec2(34.0f, 0.0f));
95 ImGui::PopStyleColor(3);
96
97 if (ImGui::IsItemHovered()) {
98 ImGui::BeginTooltip();
99 ImGui::Text("Map %02X (%s)", map_id, area_label);
100 ImGui::Text("Parent: %02X", map->parent());
101 ImGui::Text("Quadrant: %d", map->large_index());
102 ImGui::EndTooltip();
103 }
104 }
105 }
106 ImGui::EndTable();
107 }
108}
109
111 const int world = std::clamp(overworld_->current_world(), 0, 2);
112 const int world_start = (world == 0) ? 0 : ((world == 1) ? 0x40 : 0x80);
113 const int world_count = (world == 2) ? 32 : 64;
114
115 int small_count = 0;
116 int large_count = 0;
117 int wide_count = 0;
118 int tall_count = 0;
119 int parent_count = 0;
120
121 for (int local_id = 0; local_id < world_count; ++local_id) {
122 const int map_id = world_start + local_id;
123 const auto* map = overworld_->overworld_map(map_id);
124 if (!map) {
125 continue;
126 }
127
128 if (map->parent() == map_id) {
129 parent_count++;
130 }
131
132 switch (map->area_size()) {
134 large_count++;
135 break;
137 wide_count++;
138 break;
140 tall_count++;
141 break;
143 default:
144 small_count++;
145 break;
146 }
147 }
148
149 ImGui::Text("Global Usage Statistics");
150 ImGui::Separator();
151 ImGui::Text("Current World: %d", world);
152 ImGui::Text("Total Maps: %d", world_count);
153 ImGui::Text("Small Maps: %d", small_count);
154 ImGui::Text("Large Maps: %d", large_count);
155 ImGui::Text("Wide Maps: %d", wide_count);
156 ImGui::Text("Tall Maps: %d", tall_count);
157 ImGui::Text("Parent Areas: %d", parent_count);
158}
159
160} // namespace yaze::editor
UsageStatisticsCard(zelda3::Overworld *overworld)
Represents the full Overworld data, light and dark world.
Definition overworld.h:261
int current_world() const
Definition overworld.h:602
auto is_loaded() const
Definition overworld.h:597
auto overworld_map(int i) const
Definition overworld.h:531
Editors are the view controllers for the application.
bool BeginThemedTabBar(const char *id, ImGuiTabBarFlags flags)
A stylized tab bar with "Mission Control" branding.
void EndThemedTabBar()