149 void Draw(
bool* p_open)
override {
161 constexpr float kRoomWidth = 64.0f;
162 constexpr float kRoomHeight = 64.0f;
163 constexpr float kRoomSpacing = 8.0f;
166 float max_x = 0, max_y = 0;
168 max_x = std::max(max_x, pos.x);
169 max_y = std::max(max_y, pos.y);
172 (max_x + 1) * (kRoomWidth + kRoomSpacing) + kRoomSpacing;
173 float canvas_height =
174 (max_y + 1) * (kRoomHeight + kRoomSpacing) + kRoomSpacing;
177 canvas_width = std::max(canvas_width, 200.0f);
178 canvas_height = std::max(canvas_height, 200.0f);
180 ImVec2 available = ImGui::GetContentRegionAvail();
181 const float available_width = std::max(160.0f, available.x);
182 const float available_height = std::max(160.0f, available.y - 40.0f);
183 ImVec2 canvas_size(std::min(available_width, canvas_width),
184 std::min(available_height, canvas_height));
187 ImVec2 canvas_pos = ImGui::GetCursorScreenPos();
188 ImDrawList* draw_list = ImGui::GetWindowDrawList();
191 ImU32 bg_color = ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker);
192 draw_list->AddRectFilled(
194 ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y),
198 auto RoomCenter = [&](
int room_id) -> ImVec2 {
202 ImVec2 pos = it->second;
203 return ImVec2(canvas_pos.x + kRoomSpacing +
204 pos.x * (kRoomWidth + kRoomSpacing) + kRoomWidth * 0.5f,
205 canvas_pos.y + kRoomSpacing +
206 pos.y * (kRoomHeight + kRoomSpacing) +
211 ImVec4 connection_color = theme.dungeon_room_border_dark;
212 connection_color.w = 0.45f;
218 bool adjacent =
false;
219 if (std::abs(room_a - room_b) == 16) {
221 }
else if (std::abs(room_a - room_b) == 1) {
222 int col_a = room_a % 16;
223 int col_b = room_b % 16;
224 if (std::abs(col_a - col_b) == 1) {
230 draw_list->AddLine(RoomCenter(room_a), RoomCenter(room_b),
231 ImGui::ColorConvertFloat4ToU32(connection_color),
241 ImVec2 from = RoomCenter(conn.from_room);
242 ImVec2 to = RoomCenter(conn.to_room);
243 DrawDashedLine(draw_list, from, to, IM_COL32(100, 149, 237, 200), 1.5f,
252 ImVec2 from = RoomCenter(conn.from_room);
253 ImVec2 to = RoomCenter(conn.to_room);
254 ImU32 red = IM_COL32(220, 60, 60, 200);
255 draw_list->AddLine(from, to, red, 2.0f);
267 ImVec2 grid_pos = pos_it->second;
268 ImVec2 room_min(canvas_pos.x + kRoomSpacing +
269 grid_pos.x * (kRoomWidth + kRoomSpacing),
270 canvas_pos.y + kRoomSpacing +
271 grid_pos.y * (kRoomHeight + kRoomSpacing));
272 ImVec2 room_max(room_min.x + kRoomWidth, room_min.y + kRoomHeight);
275 if (room_id < 0 || room_id >= 0x128)
279 bool is_open =
false;
290 if (loaded_room !=
nullptr) {
293 auto& preview_bitmap = loaded_room->GetCompositeBitmap(layer_mgr);
294 if (preview_bitmap.is_active() && preview_bitmap.width() > 0) {
295 if (!preview_bitmap.texture()) {
299 }
else if (preview_bitmap.modified()) {
303 preview_bitmap.set_modified(
false);
306 if (preview_bitmap.is_active() && preview_bitmap.texture() != 0) {
308 draw_list->AddImage((ImTextureID)(intptr_t)preview_bitmap.texture(),
312 draw_list->AddRectFilled(
314 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_color));
318 draw_list->AddRectFilled(
320 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker));
324 snprintf(label,
sizeof(label),
"%02X", room_id);
325 ImVec2 text_size = ImGui::CalcTextSize(label);
326 ImVec2 text_pos(room_min.x + (kRoomWidth - text_size.x) * 0.5f,
327 room_min.y + (kRoomHeight - text_size.y) * 0.5f);
330 ImGui::ColorConvertFloat4ToU32(theme.text_secondary_gray), label);
334 draw_list->AddRectFilled(
336 ImGui::ColorConvertFloat4ToU32(theme.panel_bg_darker));
340 snprintf(label,
sizeof(label),
"%02X", room_id);
341 ImVec2 text_size = ImGui::CalcTextSize(label);
342 ImVec2 text_pos(room_min.x + (kRoomWidth - text_size.x) * 0.5f,
343 room_min.y + (kRoomHeight - text_size.y) * 0.5f);
345 text_pos, ImGui::ColorConvertFloat4ToU32(theme.text_secondary_gray),
352 ImVec4 glow = theme.dungeon_selection_primary;
354 ImVec2 glow_min(room_min.x - 2, room_min.y - 2);
355 ImVec2 glow_max(room_max.x + 2, room_max.y + 2);
356 draw_list->AddRect(glow_min, glow_max,
357 ImGui::ColorConvertFloat4ToU32(glow), 0.0f, 0, 4.0f);
361 ImGui::ColorConvertFloat4ToU32(theme.dungeon_selection_primary),
363 }
else if (is_open) {
366 ImGui::ColorConvertFloat4ToU32(theme.dungeon_grid_cell_selected),
371 ImGui::ColorConvertFloat4ToU32(theme.dungeon_grid_cell_border),
378 ImU32 badge_color = 0;
379 if (type_it->second ==
"entrance") {
380 badge_color = IM_COL32(76, 175, 80, 220);
381 }
else if (type_it->second ==
"boss") {
382 badge_color = IM_COL32(244, 67, 54, 220);
383 }
else if (type_it->second ==
"mini_boss") {
384 badge_color = IM_COL32(255, 152, 0, 220);
386 if (badge_color != 0) {
387 ImVec2 badge_center(room_min.x + 6.0f, room_min.y + 6.0f);
388 draw_list->AddCircleFilled(badge_center, 4.0f, badge_color);
393 ImGui::SetCursorScreenPos(room_min);
395 snprintf(btn_id,
sizeof(btn_id),
"##map_room%d", room_id);
396 ImGui::InvisibleButton(btn_id, ImVec2(kRoomWidth, kRoomHeight));
398 if (ImGui::IsItemClicked()) {
399 if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
411 if (ImGui::IsItemHovered()) {
412 ImGui::BeginTooltip();
413 ImGui::Text(
"[%03X] %s", room_id,
417 ImGui::TextDisabled(tr(
"Palette: %d"), loaded_room->palette());
420 ImGui::TextDisabled(tr(
"Click to select"));
426 ImGui::Dummy(canvas_size);