145 void Draw(
bool* p_open)
override {
156 constexpr float kRoomWidth = 64.0f;
157 constexpr float kRoomHeight = 64.0f;
158 constexpr float kRoomSpacing = 8.0f;
161 float max_x = 0, max_y = 0;
163 max_x = std::max(max_x, pos.x);
164 max_y = std::max(max_y, pos.y);
166 float canvas_width = (max_x + 1) * (kRoomWidth + kRoomSpacing) + kRoomSpacing;
167 float canvas_height = (max_y + 1) * (kRoomHeight + kRoomSpacing) + kRoomSpacing;
170 canvas_width = std::max(canvas_width, 200.0f);
171 canvas_height = std::max(canvas_height, 200.0f);
173 ImVec2 available = ImGui::GetContentRegionAvail();
174 ImVec2 canvas_size(std::min(available.x, canvas_width),
175 std::min(available.y - 40, canvas_height));
178 ImVec2 canvas_pos = ImGui::GetCursorScreenPos();
179 ImDrawList* draw_list = ImGui::GetWindowDrawList();
182 ImU32 bg_color = ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker);
183 draw_list->AddRectFilled(canvas_pos,
184 ImVec2(canvas_pos.x + canvas_size.x,
185 canvas_pos.y + canvas_size.y),
189 auto RoomCenter = [&](
int room_id) -> ImVec2 {
192 ImVec2 pos = it->second;
194 canvas_pos.x + kRoomSpacing +
195 pos.x * (kRoomWidth + kRoomSpacing) + kRoomWidth * 0.5f,
196 canvas_pos.y + kRoomSpacing +
197 pos.y * (kRoomHeight + kRoomSpacing) + kRoomHeight * 0.5f);
201 ImVec4 connection_color = theme.dungeon_room_border_dark;
202 connection_color.w = 0.45f;
208 bool adjacent =
false;
209 if (std::abs(room_a - room_b) == 16) {
211 }
else if (std::abs(room_a - room_b) == 1) {
212 int col_a = room_a % 16;
213 int col_b = room_b % 16;
214 if (std::abs(col_a - col_b) == 1) {
220 draw_list->AddLine(RoomCenter(room_a), RoomCenter(room_b),
221 ImGui::ColorConvertFloat4ToU32(connection_color),
231 ImVec2 from = RoomCenter(conn.from_room);
232 ImVec2 to = RoomCenter(conn.to_room);
234 IM_COL32(100, 149, 237, 200), 1.5f, 6.0f);
242 ImVec2 from = RoomCenter(conn.from_room);
243 ImVec2 to = RoomCenter(conn.to_room);
244 ImU32 red = IM_COL32(220, 60, 60, 200);
245 draw_list->AddLine(from, to, red, 2.0f);
256 ImVec2 grid_pos = pos_it->second;
258 canvas_pos.x + kRoomSpacing + grid_pos.x * (kRoomWidth + kRoomSpacing),
259 canvas_pos.y + kRoomSpacing + grid_pos.y * (kRoomHeight + kRoomSpacing));
260 ImVec2 room_max(room_min.x + kRoomWidth, room_min.y + kRoomHeight);
263 if (room_id < 0 || room_id >= 0x128)
continue;
266 bool is_open =
false;
276 auto& bg1_bitmap = (*rooms_)[room_id].bg1_buffer().bitmap();
277 if (bg1_bitmap.is_active() && bg1_bitmap.texture() != 0) {
280 (ImTextureID)(intptr_t)bg1_bitmap.texture(),
284 draw_list->AddRectFilled(
286 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_color));
290 draw_list->AddRectFilled(
292 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker));
296 snprintf(label,
sizeof(label),
"%02X", room_id);
297 ImVec2 text_size = ImGui::CalcTextSize(label);
298 ImVec2 text_pos(room_min.x + (kRoomWidth - text_size.x) * 0.5f,
299 room_min.y + (kRoomHeight - text_size.y) * 0.5f);
302 ImGui::ColorConvertFloat4ToU32(theme.text_secondary_gray), label);
308 ImVec4 glow = theme.dungeon_selection_primary;
310 ImVec2 glow_min(room_min.x - 2, room_min.y - 2);
311 ImVec2 glow_max(room_max.x + 2, room_max.y + 2);
312 draw_list->AddRect(glow_min, glow_max,
313 ImGui::ColorConvertFloat4ToU32(glow), 0.0f, 0, 4.0f);
315 draw_list->AddRect(room_min, room_max,
316 ImGui::ColorConvertFloat4ToU32(
317 theme.dungeon_selection_primary),
319 }
else if (is_open) {
320 draw_list->AddRect(room_min, room_max,
321 ImGui::ColorConvertFloat4ToU32(
322 theme.dungeon_grid_cell_selected),
325 draw_list->AddRect(room_min, room_max,
326 ImGui::ColorConvertFloat4ToU32(
327 theme.dungeon_grid_cell_border),
334 ImU32 badge_color = 0;
335 if (type_it->second ==
"entrance") {
336 badge_color = IM_COL32(76, 175, 80, 220);
337 }
else if (type_it->second ==
"boss") {
338 badge_color = IM_COL32(244, 67, 54, 220);
339 }
else if (type_it->second ==
"mini_boss") {
340 badge_color = IM_COL32(255, 152, 0, 220);
342 if (badge_color != 0) {
343 ImVec2 badge_center(room_min.x + 6.0f, room_min.y + 6.0f);
344 draw_list->AddCircleFilled(badge_center, 4.0f, badge_color);
349 ImGui::SetCursorScreenPos(room_min);
351 snprintf(btn_id,
sizeof(btn_id),
"##map_room%d", room_id);
352 ImGui::InvisibleButton(btn_id, ImVec2(kRoomWidth, kRoomHeight));
354 if (ImGui::IsItemClicked()) {
355 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
367 if (ImGui::IsItemHovered()) {
368 ImGui::BeginTooltip();
369 ImGui::Text(
"[%03X] %s", room_id,
372 ImGui::TextDisabled(
"Palette: %d", (*
rooms_)[room_id].palette());
374 ImGui::TextDisabled(
"Click to select");
380 ImGui::Dummy(canvas_size);