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