112 ImGui::TextDisabled(tr(
"No usage data. Load rooms and click Refresh."));
116 ImGui::Text(tr(
"Blockset Usage Grid"));
118 ImGui::TextDisabled(
"(?)");
119 if (ImGui::IsItemHovered()) {
121 tr(
"Color intensity indicates room count.\n"
122 "Green = few rooms, Red = many rooms.\n"
123 "Click a cell to select that blockset."));
128 std::vector<uint16_t> blockset_ids;
131 blockset_ids.push_back(
id);
133 std::sort(blockset_ids.begin(), blockset_ids.end());
140 constexpr int kGridCols = 8;
141 if (ImGui::BeginTable(
142 "BlocksetGrid", kGridCols,
143 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit)) {
144 for (
size_t i = 0; i < blockset_ids.size(); ++i) {
145 if (i % kGridCols == 0)
146 ImGui::TableNextRow();
147 ImGui::TableNextColumn();
149 uint16_t bs_id = blockset_ids[i];
151 float t =
static_cast<float>(count) /
static_cast<float>(max_val);
153 ImU32 bg_color = HeatColor(t);
157 ImVec2 cell_min = ImGui::GetCursorScreenPos();
158 ImVec2 cell_size(48.0f, 36.0f);
159 ImVec2 cell_max(cell_min.x + cell_size.x, cell_min.y + cell_size.y);
160 ImDrawList* draw_list = ImGui::GetWindowDrawList();
161 draw_list->AddRectFilled(cell_min, cell_max, bg_color);
164 draw_list->AddRect(cell_min, cell_max, IM_COL32(255, 255, 255, 255),
170 snprintf(btn_id,
sizeof(btn_id),
"##bs%d", bs_id);
171 if (ImGui::InvisibleButton(btn_id, cell_size)) {
177 snprintf(label,
sizeof(label),
"%02X", bs_id);
178 ImVec2 text_pos(cell_min.x + 2.0f, cell_min.y + 2.0f);
179 draw_list->AddText(text_pos, IM_COL32(0, 0, 0, 255), label);
181 char count_label[16];
182 snprintf(count_label,
sizeof(count_label),
"%d", count);
183 ImVec2 count_pos(cell_min.x + 2.0f, cell_min.y + 18.0f);
184 draw_list->AddText(count_pos, IM_COL32(0, 0, 0, 200), count_label);
187 if (ImGui::IsItemHovered()) {
188 ImGui::BeginTooltip();
189 ImGui::Text(tr(
"Blockset 0x%02X"), bs_id);
190 ImGui::Text(tr(
"Used by %d rooms"), count);
198 if (ImGui::CollapsingHeader(tr(
"Spriteset Usage Grid"))) {
202 if (ImGui::CollapsingHeader(tr(
"Palette Usage Grid"))) {
208 const absl::flat_hash_map<uint16_t, int>& usage_map, uint16_t& selected_set,
209 int spriteset_offset) {
210 if (usage_map.empty()) {
211 ImGui::TextDisabled(tr(
"No data available."));
216 std::vector<uint16_t> ids;
217 ids.reserve(usage_map.size());
218 for (
const auto& [
id, count] : usage_map) {
221 std::sort(ids.begin(), ids.end());
223 int max_val = MaxCount(usage_map);
228 ImGui::Text(tr(
"%zu unique sets, max usage: %d rooms"), ids.size(), max_val);
234 ImGui::PushID(
static_cast<const void*
>(&usage_map));
235 if (ImGui::BeginTable(
"SetUsageTable", 3,
236 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg |
237 ImGuiTableFlags_ScrollY | ImGuiTableFlags_Resizable,
238 ImVec2(0, 200.0f))) {
239 ImGui::TableSetupColumn(
"ID", ImGuiTableColumnFlags_WidthFixed, 50.0f);
240 ImGui::TableSetupColumn(
"Rooms", ImGuiTableColumnFlags_WidthFixed, 50.0f);
241 ImGui::TableSetupColumn(
"Usage", ImGuiTableColumnFlags_WidthStretch);
242 ImGui::TableHeadersRow();
244 ImGuiListClipper clipper;
245 clipper.Begin(
static_cast<int>(ids.size()));
247 while (clipper.Step()) {
248 for (
int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row) {
249 uint16_t set_id = ids[row];
250 auto it = usage_map.find(set_id);
251 int count = (it != usage_map.end()) ? it->second : 0;
253 ImGui::TableNextRow();
254 ImGui::TableNextColumn();
257 uint16_t display_id =
static_cast<uint16_t
>(set_id + spriteset_offset);
259 snprintf(id_label,
sizeof(id_label),
"0x%02X##set%d", display_id,
261 if (ImGui::Selectable(id_label, selected_set == set_id,
262 ImGuiSelectableFlags_SpanAllColumns)) {
263 selected_set = set_id;
266 ImGui::TableNextColumn();
267 ImGui::Text(
"%d", count);
269 ImGui::TableNextColumn();
272 static_cast<float>(count) /
static_cast<float>(max_val);
273 ImU32 bar_color = HeatColor(fraction);
275 ImVec2 bar_pos = ImGui::GetCursorScreenPos();
276 float bar_width = ImGui::GetContentRegionAvail().x;
277 float bar_height = ImGui::GetTextLineHeight();
278 ImVec2 bar_end(bar_pos.x + bar_width * fraction,
279 bar_pos.y + bar_height);
280 ImVec2 bar_bg_end(bar_pos.x + bar_width, bar_pos.y + bar_height);
282 ImDrawList* draw_list = ImGui::GetWindowDrawList();
283 draw_list->AddRectFilled(bar_pos, bar_bg_end,
284 IM_COL32(40, 40, 40, 100));
285 draw_list->AddRectFilled(bar_pos, bar_end, bar_color);
288 ImGui::Dummy(ImVec2(bar_width, bar_height));