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#include "util/i18n/tr.h"
3
4#include <algorithm>
5
6#include "absl/strings/str_format.h"
11#include "imgui/imgui.h"
13
14namespace yaze::editor {
15
17 : overworld_(overworld) {}
18
19void UsageStatisticsCard::Draw(bool* p_open) {
20 if (!overworld_ || !overworld_->is_loaded()) {
21 ImGui::TextDisabled(tr("Overworld not loaded"));
22 return;
23 }
24
25 if (ImGui::Begin("Usage Statistics", p_open)) {
26 if (gui::BeginThemedTabBar("UsageTabs")) {
27 if (ImGui::BeginTabItem(tr("Grid View"))) {
29 ImGui::EndTabItem();
30 }
31 if (ImGui::BeginTabItem(tr("States"))) {
33 ImGui::EndTabItem();
34 }
36 }
37 }
38 ImGui::End();
39}
40
42 const int world = std::clamp(overworld_->current_world(), 0, 2);
43 const int world_start = (world == 0) ? 0 : ((world == 1) ? 0x40 : 0x80);
44 const int world_count = (world == 2) ? 32 : 64;
45
46 ImGui::Text(tr("Map Usage Grid (World %d)"), world);
47 ImGui::Separator();
48
49 if (ImGui::BeginTable(
50 "UsageGrid", 8,
51 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit)) {
52 for (int y = 0; y < 8; y++) {
53 ImGui::TableNextRow();
54 for (int x = 0; x < 8; x++) {
55 ImGui::TableNextColumn();
56 const int local_id = y * 8 + x;
57 if (local_id >= world_count) {
58 ImGui::TextDisabled("--");
59 continue;
60 }
61
62 const int map_id = world_start + local_id;
63 const auto* map = overworld_->overworld_map(map_id);
64 if (!map) {
65 ImGui::TextDisabled("??");
66 continue;
67 }
68
69 ImVec4 area_color = ImVec4(0.35f, 0.55f, 0.35f, 1.0f); // Small
70 const char* area_label = "Small";
71 switch (map->area_size()) {
73 area_color = ImVec4(0.65f, 0.52f, 0.28f, 1.0f);
74 area_label = "Large";
75 break;
77 area_color = ImVec4(0.30f, 0.50f, 0.72f, 1.0f);
78 area_label = "Wide";
79 break;
81 area_color = ImVec4(0.55f, 0.40f, 0.72f, 1.0f);
82 area_label = "Tall";
83 break;
85 default:
86 break;
87 }
88
89 const ImVec4 area_hover(area_color.x + 0.1f, area_color.y + 0.1f,
90 area_color.z + 0.1f, 1.0f);
91 const std::string button_id =
92 absl::StrFormat("%02X##usage_map_%d", map_id, map_id);
93 {
94 gui::StyleColorGuard area_colors(
95 {{ImGuiCol_Button, area_color},
96 {ImGuiCol_ButtonHovered, area_hover},
97 {ImGuiCol_ButtonActive, area_color}});
98 ImGui::Button(button_id.c_str(), ImVec2(34.0f, 0.0f));
99 }
100
101 if (ImGui::IsItemHovered()) {
102 ImGui::BeginTooltip();
103 ImGui::Text(tr("Map %02X (%s)"), map_id, area_label);
104 ImGui::Text(tr("Parent: %02X"), map->parent());
105 ImGui::Text(tr("Quadrant: %d"), map->large_index());
106 ImGui::EndTooltip();
107 }
108 }
109 }
110 ImGui::EndTable();
111 }
112}
113
115 const int world = std::clamp(overworld_->current_world(), 0, 2);
116 const int world_start = (world == 0) ? 0 : ((world == 1) ? 0x40 : 0x80);
117 const int world_count = (world == 2) ? 32 : 64;
118
119 int small_count = 0;
120 int large_count = 0;
121 int wide_count = 0;
122 int tall_count = 0;
123 int parent_count = 0;
124
125 for (int local_id = 0; local_id < world_count; ++local_id) {
126 const int map_id = world_start + local_id;
127 const auto* map = overworld_->overworld_map(map_id);
128 if (!map) {
129 continue;
130 }
131
132 if (map->parent() == map_id) {
133 parent_count++;
134 }
135
136 switch (map->area_size()) {
138 large_count++;
139 break;
141 wide_count++;
142 break;
144 tall_count++;
145 break;
147 default:
148 small_count++;
149 break;
150 }
151 }
152
153 ImGui::Text(tr("Global Usage Statistics"));
154 ImGui::Separator();
155 ImGui::Text(tr("Current World: %d"), world);
156 ImGui::Text(tr("Total Maps: %d"), world_count);
157 ImGui::Text(tr("Small Maps: %d"), small_count);
158 ImGui::Text(tr("Large Maps: %d"), large_count);
159 ImGui::Text(tr("Wide Maps: %d"), wide_count);
160 ImGui::Text(tr("Tall Maps: %d"), tall_count);
161 ImGui::Text(tr("Parent Areas: %d"), parent_count);
162}
163
164} // namespace yaze::editor
UsageStatisticsCard(zelda3::Overworld *overworld)
RAII guard for ImGui style colors.
Definition style_guard.h:27
int current_world() const
Definition overworld.h:808
auto is_loaded() const
Definition overworld.h:803
auto overworld_map(int i) const
Definition overworld.h:737
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()