111 ImGui::TextDisabled(
"No usage data. Load rooms and click Refresh.");
115 ImGui::Text(
"Blockset Usage Grid");
117 ImGui::TextDisabled(
"(?)");
118 if (ImGui::IsItemHovered()) {
120 "Color intensity indicates room count.\n"
121 "Green = few rooms, Red = many rooms.\n"
122 "Click a cell to select that blockset.");
127 std::vector<uint16_t> blockset_ids;
130 blockset_ids.push_back(
id);
132 std::sort(blockset_ids.begin(), blockset_ids.end());
139 constexpr int kGridCols = 8;
140 if (ImGui::BeginTable(
141 "BlocksetGrid", kGridCols,
142 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit)) {
143 for (
size_t i = 0; i < blockset_ids.size(); ++i) {
144 if (i % kGridCols == 0)
145 ImGui::TableNextRow();
146 ImGui::TableNextColumn();
148 uint16_t bs_id = blockset_ids[i];
150 float t =
static_cast<float>(count) /
static_cast<float>(max_val);
152 ImU32 bg_color = HeatColor(t);
156 ImVec2 cell_min = ImGui::GetCursorScreenPos();
157 ImVec2 cell_size(48.0f, 36.0f);
158 ImVec2 cell_max(cell_min.x + cell_size.x, cell_min.y + cell_size.y);
159 ImDrawList* draw_list = ImGui::GetWindowDrawList();
160 draw_list->AddRectFilled(cell_min, cell_max, bg_color);
163 draw_list->AddRect(cell_min, cell_max, IM_COL32(255, 255, 255, 255),
169 snprintf(btn_id,
sizeof(btn_id),
"##bs%d", bs_id);
170 if (ImGui::InvisibleButton(btn_id, cell_size)) {
176 snprintf(label,
sizeof(label),
"%02X", bs_id);
177 ImVec2 text_pos(cell_min.x + 2.0f, cell_min.y + 2.0f);
178 draw_list->AddText(text_pos, IM_COL32(0, 0, 0, 255), label);
180 char count_label[16];
181 snprintf(count_label,
sizeof(count_label),
"%d", count);
182 ImVec2 count_pos(cell_min.x + 2.0f, cell_min.y + 18.0f);
183 draw_list->AddText(count_pos, IM_COL32(0, 0, 0, 200), count_label);
186 if (ImGui::IsItemHovered()) {
187 ImGui::BeginTooltip();
188 ImGui::Text(
"Blockset 0x%02X", bs_id);
189 ImGui::Text(
"Used by %d rooms", count);
197 if (ImGui::CollapsingHeader(
"Spriteset Usage Grid")) {
201 if (ImGui::CollapsingHeader(
"Palette Usage Grid")) {
207 const absl::flat_hash_map<uint16_t, int>& usage_map, uint16_t& selected_set,
208 int spriteset_offset) {
209 if (usage_map.empty()) {
210 ImGui::TextDisabled(
"No data available.");
215 std::vector<uint16_t> ids;
216 ids.reserve(usage_map.size());
217 for (
const auto& [
id, count] : usage_map) {
220 std::sort(ids.begin(), ids.end());
222 int max_val = MaxCount(usage_map);
227 ImGui::Text(
"%zu unique sets, max usage: %d rooms", ids.size(), max_val);
233 ImGui::PushID(
static_cast<const void*
>(&usage_map));
234 if (ImGui::BeginTable(
"SetUsageTable", 3,
235 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg |
236 ImGuiTableFlags_ScrollY | ImGuiTableFlags_Resizable,
237 ImVec2(0, 200.0f))) {
238 ImGui::TableSetupColumn(
"ID", ImGuiTableColumnFlags_WidthFixed, 50.0f);
239 ImGui::TableSetupColumn(
"Rooms", ImGuiTableColumnFlags_WidthFixed, 50.0f);
240 ImGui::TableSetupColumn(
"Usage", ImGuiTableColumnFlags_WidthStretch);
241 ImGui::TableHeadersRow();
243 ImGuiListClipper clipper;
244 clipper.Begin(
static_cast<int>(ids.size()));
246 while (clipper.Step()) {
247 for (
int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row) {
248 uint16_t set_id = ids[row];
249 auto it = usage_map.find(set_id);
250 int count = (it != usage_map.end()) ? it->second : 0;
252 ImGui::TableNextRow();
253 ImGui::TableNextColumn();
256 uint16_t display_id =
static_cast<uint16_t
>(set_id + spriteset_offset);
258 snprintf(id_label,
sizeof(id_label),
"0x%02X##set%d", display_id,
260 if (ImGui::Selectable(id_label, selected_set == set_id,
261 ImGuiSelectableFlags_SpanAllColumns)) {
262 selected_set = set_id;
265 ImGui::TableNextColumn();
266 ImGui::Text(
"%d", count);
268 ImGui::TableNextColumn();
271 static_cast<float>(count) /
static_cast<float>(max_val);
272 ImU32 bar_color = HeatColor(fraction);
274 ImVec2 bar_pos = ImGui::GetCursorScreenPos();
275 float bar_width = ImGui::GetContentRegionAvail().x;
276 float bar_height = ImGui::GetTextLineHeight();
277 ImVec2 bar_end(bar_pos.x + bar_width * fraction,
278 bar_pos.y + bar_height);
279 ImVec2 bar_bg_end(bar_pos.x + bar_width, bar_pos.y + bar_height);
281 ImDrawList* draw_list = ImGui::GetWindowDrawList();
282 draw_list->AddRectFilled(bar_pos, bar_bg_end,
283 IM_COL32(40, 40, 40, 100));
284 draw_list->AddRectFilled(bar_pos, bar_end, bar_color);
287 ImGui::Dummy(ImVec2(bar_width, bar_height));