163 void Draw(
bool* p_open)
override {
175 constexpr float kRoomWidth = 64.0f;
176 constexpr float kRoomHeight = 64.0f;
177 constexpr float kRoomSpacing = 8.0f;
180 float max_x = 0, max_y = 0;
182 max_x = std::max(max_x, pos.x);
183 max_y = std::max(max_y, pos.y);
186 (max_x + 1) * (kRoomWidth + kRoomSpacing) + kRoomSpacing;
187 float canvas_height =
188 (max_y + 1) * (kRoomHeight + kRoomSpacing) + kRoomSpacing;
191 canvas_width = std::max(canvas_width, 200.0f);
192 canvas_height = std::max(canvas_height, 200.0f);
194 ImVec2 available = ImGui::GetContentRegionAvail();
195 const float available_width = std::max(160.0f, available.x);
196 const float available_height = std::max(160.0f, available.y - 40.0f);
197 ImVec2 canvas_size(std::min(available_width, canvas_width),
198 std::min(available_height, canvas_height));
201 ImVec2 canvas_pos = ImGui::GetCursorScreenPos();
202 ImDrawList* draw_list = ImGui::GetWindowDrawList();
205 ImU32 bg_color = ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker);
206 draw_list->AddRectFilled(
208 ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
212 auto RoomCenter = [&](
int room_id) -> ImVec2 {
216 ImVec2 pos = it->second;
217 return ImVec2(canvas_pos.x + kRoomSpacing +
218 pos.x * (kRoomWidth + kRoomSpacing) + kRoomWidth * 0.5f,
219 canvas_pos.y + kRoomSpacing +
220 pos.y * (kRoomHeight + kRoomSpacing) +
225 ImVec4 connection_color = theme.dungeon_room_border_dark;
226 connection_color.w = 0.45f;
232 bool adjacent =
false;
233 if (std::abs(room_a - room_b) == 16) {
235 }
else if (std::abs(room_a - room_b) == 1) {
236 int col_a = room_a % 16;
237 int col_b = room_b % 16;
238 if (std::abs(col_a - col_b) == 1) {
244 draw_list->AddLine(RoomCenter(room_a), RoomCenter(room_b),
245 ImGui::ColorConvertFloat4ToU32(connection_color),
255 ImVec2 from = RoomCenter(conn.from_room);
256 ImVec2 to = RoomCenter(conn.to_room);
257 DrawDashedLine(draw_list, from, to, IM_COL32(100, 149, 237, 200), 1.5f,
266 ImVec2 from = RoomCenter(conn.from_room);
267 ImVec2 to = RoomCenter(conn.to_room);
268 ImU32 red = IM_COL32(220, 60, 60, 200);
269 draw_list->AddLine(from, to, red, 2.0f);
281 ImVec2 grid_pos = pos_it->second;
282 ImVec2 room_min(canvas_pos.x + kRoomSpacing +
283 grid_pos.x * (kRoomWidth + kRoomSpacing),
284 canvas_pos.y + kRoomSpacing +
285 grid_pos.y * (kRoomHeight + kRoomSpacing));
286 ImVec2 room_max(room_min.x + kRoomWidth, room_min.y + kRoomHeight);
289 if (room_id < 0 || room_id >= 0x128)
293 bool is_open =
false;
304 if (loaded_room !=
nullptr) {
307 output = std::make_unique<RoomCompositeOutput>();
309 auto& preview_bitmap =
313 if (preview_bitmap.is_active() && preview_bitmap.texture() != 0) {
315 draw_list->AddImage((ImTextureID)(intptr_t)preview_bitmap.texture(),
319 draw_list->AddRectFilled(
321 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_color));
325 draw_list->AddRectFilled(
327 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker));
331 snprintf(label,
sizeof(label),
"%02X", room_id);
332 ImVec2 text_size = ImGui::CalcTextSize(label);
333 ImVec2 text_pos(room_min.x + (kRoomWidth - text_size.x) * 0.5f,
334 room_min.y + (kRoomHeight - text_size.y) * 0.5f);
337 ImGui::ColorConvertFloat4ToU32(theme.text_secondary_gray), label);
341 draw_list->AddRectFilled(
343 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker));
347 snprintf(label,
sizeof(label),
"%02X", room_id);
348 ImVec2 text_size = ImGui::CalcTextSize(label);
349 ImVec2 text_pos(room_min.x + (kRoomWidth - text_size.x) * 0.5f,
350 room_min.y + (kRoomHeight - text_size.y) * 0.5f);
352 text_pos, ImGui::ColorConvertFloat4ToU32(theme.text_secondary_gray),
359 ImVec4 glow = theme.dungeon_selection_primary;
361 ImVec2 glow_min(room_min.x - 2, room_min.y - 2);
362 ImVec2 glow_max(room_max.x + 2, room_max.y + 2);
363 draw_list->AddRect(glow_min, glow_max,
364 ImGui::ColorConvertFloat4ToU32(glow), 0.0f, 0, 4.0f);
368 ImGui::ColorConvertFloat4ToU32(theme.dungeon_selection_primary),
370 }
else if (is_open) {
373 ImGui::ColorConvertFloat4ToU32(theme.dungeon_grid_cell_selected),
378 ImGui::ColorConvertFloat4ToU32(theme.dungeon_grid_cell_border),
385 ImU32 badge_color = 0;
386 if (type_it->second ==
"entrance") {
387 badge_color = IM_COL32(76, 175, 80, 220);
388 }
else if (type_it->second ==
"boss") {
389 badge_color = IM_COL32(244, 67, 54, 220);
390 }
else if (type_it->second ==
"mini_boss") {
391 badge_color = IM_COL32(255, 152, 0, 220);
393 if (badge_color != 0) {
394 ImVec2 badge_center(room_min.x + 6.0f, room_min.y + 6.0f);
395 draw_list->AddCircleFilled(badge_center, 4.0f, badge_color);
400 ImGui::SetCursorScreenPos(room_min);
402 snprintf(btn_id,
sizeof(btn_id),
"##map_room%d", room_id);
403 ImGui::InvisibleButton(btn_id, ImVec2(kRoomWidth, kRoomHeight));
405 if (ImGui::IsItemClicked()) {
406 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
418 if (ImGui::IsItemHovered()) {
419 ImGui::BeginTooltip();
420 ImGui::Text(
"[%03X] %s", room_id,
424 ImGui::TextDisabled(tr(
"Palette: %d"), loaded_room->palette());
427 ImGui::TextDisabled(tr(
"Click to select"));
433 ImGui::Dummy(canvas_size);