64 void Draw(
bool* p_open)
override {
70 constexpr int kRoomsPerRow = 16;
71 constexpr int kRoomsPerCol = 19;
72 constexpr int kTotalRooms = 0x128;
73 constexpr float kCellSpacing = 1.0f;
76 float panel_width = ImGui::GetContentRegionAvail().x;
78 float cell_size = std::max(12.0f, std::min(24.0f,
79 (panel_width - kCellSpacing * (kRoomsPerRow - 1)) / kRoomsPerRow));
81 ImDrawList* draw_list = ImGui::GetWindowDrawList();
82 ImVec2 canvas_pos = ImGui::GetCursorScreenPos();
85 for (
int row = 0; row < kRoomsPerCol; row++) {
86 for (
int col = 0; col < kRoomsPerRow; col++) {
87 int room_id = room_index;
88 bool is_valid_room = (room_id < kTotalRooms);
91 ImVec2(canvas_pos.x + col * (cell_size + kCellSpacing),
92 canvas_pos.y + row * (cell_size + kCellSpacing));
94 ImVec2(cell_min.x + cell_size, cell_min.y + cell_size);
101 bool is_open =
false;
110 draw_list->AddRectFilled(cell_min, cell_max, bg_color);
114 ImU32 sel_color = ImGui::ColorConvertFloat4ToU32(
115 theme.dungeon_selection_primary);
116 draw_list->AddRect(cell_min, cell_max, sel_color, 0.0f, 0, 2.5f);
117 }
else if (is_open) {
118 ImU32 open_color = ImGui::ColorConvertFloat4ToU32(
119 theme.dungeon_grid_cell_selected);
120 draw_list->AddRect(cell_min, cell_max, open_color, 0.0f, 0, 2.0f);
122 ImU32 border_color = ImGui::ColorConvertFloat4ToU32(
123 theme.dungeon_grid_cell_border);
124 draw_list->AddRect(cell_min, cell_max, border_color, 0.0f, 0, 1.0f);
128 if (cell_size >= 18.0f) {
130 snprintf(label,
sizeof(label),
"%02X", room_id);
131 ImVec2 text_size = ImGui::CalcTextSize(label);
133 ImVec2(cell_min.x + (cell_size - text_size.x) * 0.5f,
134 cell_min.y + (cell_size - text_size.y) * 0.5f);
135 ImU32 text_color = ImGui::ColorConvertFloat4ToU32(
136 theme.dungeon_grid_text);
137 draw_list->AddText(text_pos, text_color, label);
141 ImGui::SetCursorScreenPos(cell_min);
143 snprintf(btn_id,
sizeof(btn_id),
"##room%d", room_id);
144 ImGui::InvisibleButton(btn_id, ImVec2(cell_size, cell_size));
151 if (ImGui::IsItemHovered()) {
152 ImGui::BeginTooltip();
157 ImGui::TextDisabled(
"Palette: %d", (*
rooms_)[room_id].palette);
159 ImGui::Text(
"Click to %s", is_open ?
"focus" :
"open");
164 draw_list->AddRectFilled(cell_min, cell_max, IM_COL32(40, 40, 40, 255));
172 ImGui::Dummy(ImVec2(kRoomsPerRow * (cell_size + kCellSpacing),
173 kRoomsPerCol * (cell_size + kCellSpacing)));
189 int palette = (*rooms_)[room_id].palette;
192 float hue = (palette * 15.0f);
193 float saturation = 0.4f + (palette % 3) * 0.1f;
194 float value = 0.5f + (palette % 5) * 0.08f;
197 float h = fmodf(hue, 360.0f) / 60.0f;
198 int i =
static_cast<int>(h);
200 float p = value * (1 - saturation);
201 float q = value * (1 - saturation * f);
202 float t = value * (1 - saturation * (1 - f));
206 case 0: r = value; g = t; b = p;
break;
207 case 1: r = q; g = value; b = p;
break;
208 case 2: r = p; g = value; b = t;
break;
209 case 3: r = p; g = q; b = value;
break;
210 case 4: r = t; g = p; b = value;
break;
211 case 5: r = value; g = p; b = q;
break;
212 default: r = g = b = 0.3f;
break;
214 return IM_COL32(
static_cast<int>(r * 255),
215 static_cast<int>(g * 255),
216 static_cast<int>(b * 255), 255);
221 int dungeon_group = room_id / 0x20;
222 float hue = (dungeon_group * 45.0f) + (room_id % 8) * 5.0f;
223 float saturation = 0.35f + (room_id % 3) * 0.1f;
224 float value = 0.45f + (room_id % 5) * 0.08f;
226 float h = fmodf(hue, 360.0f) / 60.0f;
227 int i =
static_cast<int>(h);
229 float p = value * (1 - saturation);
230 float q = value * (1 - saturation * f);
231 float t = value * (1 - saturation * (1 - f));
235 case 0: r = value; g = t; b = p;
break;
236 case 1: r = q; g = value; b = p;
break;
237 case 2: r = p; g = value; b = t;
break;
238 case 3: r = p; g = q; b = value;
break;
239 case 4: r = t; g = p; b = value;
break;
240 case 5: r = value; g = p; b = q;
break;
241 default: r = g = b = 0.3f;
break;
243 return IM_COL32(
static_cast<int>(r * 255),
244 static_cast<int>(g * 255),
245 static_cast<int>(b * 255), 255);