148 void Draw(
bool* p_open)
override {
160 constexpr float kRoomWidth = 64.0f;
161 constexpr float kRoomHeight = 64.0f;
162 constexpr float kRoomSpacing = 8.0f;
165 float max_x = 0, max_y = 0;
167 max_x = std::max(max_x, pos.x);
168 max_y = std::max(max_y, pos.y);
171 (max_x + 1) * (kRoomWidth + kRoomSpacing) + kRoomSpacing;
172 float canvas_height =
173 (max_y + 1) * (kRoomHeight + kRoomSpacing) + kRoomSpacing;
176 canvas_width = std::max(canvas_width, 200.0f);
177 canvas_height = std::max(canvas_height, 200.0f);
179 ImVec2 available = ImGui::GetContentRegionAvail();
180 ImVec2 canvas_size(std::min(available.x, canvas_width),
181 std::min(available.y - 40, canvas_height));
184 ImVec2 canvas_pos = ImGui::GetCursorScreenPos();
185 ImDrawList* draw_list = ImGui::GetWindowDrawList();
188 ImU32 bg_color = ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker);
189 draw_list->AddRectFilled(
191 ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
195 auto RoomCenter = [&](
int room_id) -> ImVec2 {
199 ImVec2 pos = it->second;
200 return ImVec2(canvas_pos.x + kRoomSpacing +
201 pos.x * (kRoomWidth + kRoomSpacing) + kRoomWidth * 0.5f,
202 canvas_pos.y + kRoomSpacing +
203 pos.y * (kRoomHeight + kRoomSpacing) +
208 ImVec4 connection_color = theme.dungeon_room_border_dark;
209 connection_color.w = 0.45f;
215 bool adjacent =
false;
216 if (std::abs(room_a - room_b) == 16) {
218 }
else if (std::abs(room_a - room_b) == 1) {
219 int col_a = room_a % 16;
220 int col_b = room_b % 16;
221 if (std::abs(col_a - col_b) == 1) {
227 draw_list->AddLine(RoomCenter(room_a), RoomCenter(room_b),
228 ImGui::ColorConvertFloat4ToU32(connection_color),
238 ImVec2 from = RoomCenter(conn.from_room);
239 ImVec2 to = RoomCenter(conn.to_room);
240 DrawDashedLine(draw_list, from, to, IM_COL32(100, 149, 237, 200), 1.5f,
249 ImVec2 from = RoomCenter(conn.from_room);
250 ImVec2 to = RoomCenter(conn.to_room);
251 ImU32 red = IM_COL32(220, 60, 60, 200);
252 draw_list->AddLine(from, to, red, 2.0f);
264 ImVec2 grid_pos = pos_it->second;
265 ImVec2 room_min(canvas_pos.x + kRoomSpacing +
266 grid_pos.x * (kRoomWidth + kRoomSpacing),
267 canvas_pos.y + kRoomSpacing +
268 grid_pos.y * (kRoomHeight + kRoomSpacing));
269 ImVec2 room_max(room_min.x + kRoomWidth, room_min.y + kRoomHeight);
272 if (room_id < 0 || room_id >= 0x128)
276 bool is_open =
false;
287 if (loaded_room !=
nullptr) {
290 auto& preview_bitmap = loaded_room->GetCompositeBitmap(layer_mgr);
291 if (preview_bitmap.is_active() && preview_bitmap.width() > 0) {
292 if (!preview_bitmap.texture()) {
296 }
else if (preview_bitmap.modified()) {
300 preview_bitmap.set_modified(
false);
303 if (preview_bitmap.is_active() && preview_bitmap.texture() != 0) {
305 draw_list->AddImage((ImTextureID)(intptr_t)preview_bitmap.texture(),
309 draw_list->AddRectFilled(
311 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_color));
315 draw_list->AddRectFilled(
317 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker));
321 snprintf(label,
sizeof(label),
"%02X", room_id);
322 ImVec2 text_size = ImGui::CalcTextSize(label);
323 ImVec2 text_pos(room_min.x + (kRoomWidth - text_size.x) * 0.5f,
324 room_min.y + (kRoomHeight - text_size.y) * 0.5f);
327 ImGui::ColorConvertFloat4ToU32(theme.text_secondary_gray), label);
331 draw_list->AddRectFilled(
333 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker));
337 snprintf(label,
sizeof(label),
"%02X", room_id);
338 ImVec2 text_size = ImGui::CalcTextSize(label);
339 ImVec2 text_pos(room_min.x + (kRoomWidth - text_size.x) * 0.5f,
340 room_min.y + (kRoomHeight - text_size.y) * 0.5f);
342 text_pos, ImGui::ColorConvertFloat4ToU32(theme.text_secondary_gray),
349 ImVec4 glow = theme.dungeon_selection_primary;
351 ImVec2 glow_min(room_min.x - 2, room_min.y - 2);
352 ImVec2 glow_max(room_max.x + 2, room_max.y + 2);
353 draw_list->AddRect(glow_min, glow_max,
354 ImGui::ColorConvertFloat4ToU32(glow), 0.0f, 0, 4.0f);
358 ImGui::ColorConvertFloat4ToU32(theme.dungeon_selection_primary),
360 }
else if (is_open) {
363 ImGui::ColorConvertFloat4ToU32(theme.dungeon_grid_cell_selected),
368 ImGui::ColorConvertFloat4ToU32(theme.dungeon_grid_cell_border),
375 ImU32 badge_color = 0;
376 if (type_it->second ==
"entrance") {
377 badge_color = IM_COL32(76, 175, 80, 220);
378 }
else if (type_it->second ==
"boss") {
379 badge_color = IM_COL32(244, 67, 54, 220);
380 }
else if (type_it->second ==
"mini_boss") {
381 badge_color = IM_COL32(255, 152, 0, 220);
383 if (badge_color != 0) {
384 ImVec2 badge_center(room_min.x + 6.0f, room_min.y + 6.0f);
385 draw_list->AddCircleFilled(badge_center, 4.0f, badge_color);
390 ImGui::SetCursorScreenPos(room_min);
392 snprintf(btn_id,
sizeof(btn_id),
"##map_room%d", room_id);
393 ImGui::InvisibleButton(btn_id, ImVec2(kRoomWidth, kRoomHeight));
395 if (ImGui::IsItemClicked()) {
396 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
408 if (ImGui::IsItemHovered()) {
409 ImGui::BeginTooltip();
410 ImGui::Text(
"[%03X] %s", room_id,
414 ImGui::TextDisabled(
"Palette: %d", loaded_room->palette());
417 ImGui::TextDisabled(
"Click to select");
423 ImGui::Dummy(canvas_size);