2026-03-06 11:42:20 -06:00
|
|
|
mod exporter;
|
2026-03-06 08:41:39 -06:00
|
|
|
mod layout;
|
2026-04-20 10:23:49 -05:00
|
|
|
mod saveandload;
|
2026-03-06 09:40:22 -06:00
|
|
|
mod seed;
|
2026-03-06 09:56:26 -06:00
|
|
|
mod settings;
|
2026-04-14 11:21:49 -05:00
|
|
|
mod startend;
|
2026-03-06 09:24:24 -06:00
|
|
|
mod ui;
|
2026-03-06 08:41:39 -06:00
|
|
|
|
2026-03-06 09:19:03 -06:00
|
|
|
use std::collections::HashSet;
|
2026-03-12 08:59:28 -05:00
|
|
|
use std::sync::mpsc;
|
|
|
|
|
use std::thread;
|
2026-03-06 09:19:03 -06:00
|
|
|
|
2026-03-05 19:17:01 -06:00
|
|
|
use eframe::egui;
|
|
|
|
|
use egui::{Color32, Stroke};
|
2026-03-20 10:52:44 -05:00
|
|
|
use layout::{
|
2026-03-23 12:22:03 -05:00
|
|
|
DoorSettings, DungeonLayout, WindowSettings, blocked_room_cells, corridor_cells,
|
|
|
|
|
shortest_path_cells,
|
2026-03-20 10:52:44 -05:00
|
|
|
};
|
2026-04-20 09:59:25 -05:00
|
|
|
use startend::{
|
|
|
|
|
manual_marker_size, manual_monster_marker_size, manual_trap_marker_size,
|
|
|
|
|
populate_random_markers,
|
|
|
|
|
};
|
2026-03-12 09:58:08 -05:00
|
|
|
use ui::{AddTool, UiSettings, draw_side_panel};
|
2026-03-05 19:17:01 -06:00
|
|
|
|
2026-03-23 12:43:33 -05:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
enum ManualDoorKind {
|
2026-04-07 11:28:34 -05:00
|
|
|
Archway,
|
2026-03-23 12:43:33 -05:00
|
|
|
Regular,
|
|
|
|
|
Locked,
|
|
|
|
|
Secret,
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:06:48 -05:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
struct AppSnapshot {
|
|
|
|
|
settings: UiSettings,
|
2026-04-23 10:30:49 -05:00
|
|
|
levels: Vec<DungeonLayout>,
|
2026-03-24 09:06:48 -05:00
|
|
|
suppressed_auto_door_edges: HashSet<((usize, usize), (usize, usize))>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Boot the native app and start the egui event loop.
|
2026-03-05 19:17:01 -06:00
|
|
|
fn main() -> eframe::Result<()> {
|
|
|
|
|
let options = eframe::NativeOptions::default();
|
|
|
|
|
|
|
|
|
|
eframe::run_native(
|
|
|
|
|
"Desktop Dungeon Generator",
|
|
|
|
|
options,
|
|
|
|
|
Box::new(|_cc| Ok(Box::new(DungeonApp::default()))),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct DungeonApp {
|
2026-03-06 09:24:24 -06:00
|
|
|
settings: UiSettings,
|
2026-04-23 10:30:49 -05:00
|
|
|
levels: Vec<DungeonLayout>,
|
2026-03-23 12:49:00 -05:00
|
|
|
suppressed_auto_door_edges: HashSet<((usize, usize), (usize, usize))>,
|
2026-03-24 09:06:48 -05:00
|
|
|
undo_stack: Vec<AppSnapshot>,
|
|
|
|
|
redo_stack: Vec<AppSnapshot>,
|
2026-03-06 10:26:23 -06:00
|
|
|
drag_state: Option<DragState>,
|
2026-03-12 08:59:28 -05:00
|
|
|
export_rx: Option<mpsc::Receiver<Result<std::path::PathBuf, String>>>,
|
2026-03-12 09:58:08 -05:00
|
|
|
pending_delete: bool,
|
|
|
|
|
add_corridor_drag: Option<AddCorridorDrag>,
|
2026-03-24 09:25:44 -05:00
|
|
|
resize_state: Option<ResizeState>,
|
2026-03-12 10:42:12 -05:00
|
|
|
hover_room_idx: Option<usize>,
|
2026-03-12 11:12:50 -05:00
|
|
|
hover_corridor_idx: Option<usize>,
|
2026-03-12 11:36:36 -05:00
|
|
|
hover_door_idx: Option<usize>,
|
2026-03-24 09:25:44 -05:00
|
|
|
hover_text_idx: Option<usize>,
|
2026-04-14 11:03:58 -05:00
|
|
|
hover_marker: Option<HoverMarker>,
|
2026-03-05 19:17:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for DungeonApp {
|
2026-03-19 13:49:42 -05:00
|
|
|
// Build the app with persisted settings and a generated layout.
|
2026-03-05 19:17:01 -06:00
|
|
|
fn default() -> Self {
|
2026-03-06 09:56:26 -06:00
|
|
|
let settings = settings::load_settings().unwrap_or_default();
|
2026-04-23 10:30:49 -05:00
|
|
|
let levels = generate_all_levels(&settings);
|
2026-03-06 09:56:26 -06:00
|
|
|
Self {
|
|
|
|
|
settings,
|
2026-04-23 10:30:49 -05:00
|
|
|
levels,
|
2026-03-23 12:49:00 -05:00
|
|
|
suppressed_auto_door_edges: HashSet::new(),
|
2026-03-24 09:06:48 -05:00
|
|
|
undo_stack: Vec::new(),
|
|
|
|
|
redo_stack: Vec::new(),
|
2026-03-06 10:26:23 -06:00
|
|
|
drag_state: None,
|
2026-03-12 08:59:28 -05:00
|
|
|
export_rx: None,
|
2026-03-12 09:58:08 -05:00
|
|
|
pending_delete: false,
|
|
|
|
|
add_corridor_drag: None,
|
2026-03-12 10:42:12 -05:00
|
|
|
resize_state: None,
|
|
|
|
|
hover_room_idx: None,
|
2026-03-12 11:12:50 -05:00
|
|
|
hover_corridor_idx: None,
|
2026-03-12 11:36:36 -05:00
|
|
|
hover_door_idx: None,
|
2026-03-24 09:25:44 -05:00
|
|
|
hover_text_idx: None,
|
2026-04-14 11:03:58 -05:00
|
|
|
hover_marker: None,
|
2026-03-06 09:56:26 -06:00
|
|
|
}
|
2026-03-05 19:17:01 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 09:42:57 -06:00
|
|
|
impl Drop for DungeonApp {
|
2026-03-19 13:49:42 -05:00
|
|
|
// Persist settings when the app is being dropped.
|
2026-03-06 09:42:57 -06:00
|
|
|
fn drop(&mut self) {
|
2026-03-06 09:56:26 -06:00
|
|
|
if let Err(err) = settings::save_settings(&self.settings) {
|
2026-03-06 09:42:57 -06:00
|
|
|
eprintln!("Failed to save settings: {err}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 19:17:01 -06:00
|
|
|
impl eframe::App for DungeonApp {
|
2026-03-19 13:49:42 -05:00
|
|
|
// Render UI, handle input, and update app state each frame.
|
2026-03-05 19:17:01 -06:00
|
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
2026-03-12 08:59:28 -05:00
|
|
|
let panel_result = draw_side_panel(ctx, &mut self.settings, self.export_rx.is_some());
|
2026-03-24 09:06:48 -05:00
|
|
|
let undo_requested = ctx.input(|i| i.modifiers.command && i.key_pressed(egui::Key::Z));
|
|
|
|
|
let redo_requested = ctx.input(|i| {
|
|
|
|
|
(i.modifiers.command && i.key_pressed(egui::Key::Y))
|
|
|
|
|
|| (i.modifiers.command && i.modifiers.shift && i.key_pressed(egui::Key::Z))
|
|
|
|
|
});
|
2026-04-20 11:23:36 -05:00
|
|
|
let escape_pressed = ctx.input(|i| i.key_pressed(egui::Key::Escape));
|
|
|
|
|
|
|
|
|
|
if escape_pressed || panel_result.settings_changed {
|
|
|
|
|
self.settings.add_tool = AddTool::None;
|
|
|
|
|
}
|
2026-03-06 08:41:39 -06:00
|
|
|
|
2026-04-14 11:47:31 -05:00
|
|
|
clamp_dependent_settings(&mut self.settings);
|
2026-03-06 08:52:56 -06:00
|
|
|
|
2026-03-24 09:06:48 -05:00
|
|
|
if undo_requested {
|
|
|
|
|
self.undo();
|
|
|
|
|
} else if redo_requested {
|
|
|
|
|
self.redo();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 11:49:24 -05:00
|
|
|
if panel_result.clear_clicked {
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-03-23 11:49:24 -05:00
|
|
|
self.clear_layout();
|
|
|
|
|
} else if panel_result.reset_clicked || panel_result.settings_changed {
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-03-06 09:24:24 -06:00
|
|
|
self.regenerate_layout();
|
2026-04-20 10:23:49 -05:00
|
|
|
} else if panel_result.save_clicked {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index < self.levels.len() {
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
let svg = exporter::build_svg(layout, &self.settings);
|
|
|
|
|
if let Err(err) = saveandload::save_dungeon(&self.settings, layout, svg) {
|
|
|
|
|
eprintln!("{err}");
|
|
|
|
|
}
|
2026-04-20 10:23:49 -05:00
|
|
|
}
|
|
|
|
|
} else if panel_result.load_clicked {
|
|
|
|
|
match saveandload::load_dungeon() {
|
|
|
|
|
Ok(data) => {
|
|
|
|
|
self.push_undo_snapshot();
|
|
|
|
|
self.settings = data.settings;
|
2026-04-23 10:30:49 -05:00
|
|
|
self.levels = vec![data.layout];
|
|
|
|
|
self.settings.active_level_index = 0;
|
2026-04-20 10:23:49 -05:00
|
|
|
// Don't regenerate_layout() here to preserve the exact loaded state.
|
|
|
|
|
}
|
|
|
|
|
Err(err) => {
|
|
|
|
|
eprintln!("{err}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-06 08:41:39 -06:00
|
|
|
}
|
2026-03-12 09:58:08 -05:00
|
|
|
if ctx.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace)) {
|
|
|
|
|
self.pending_delete = true;
|
|
|
|
|
}
|
2026-03-12 08:59:28 -05:00
|
|
|
if panel_result.export_clicked && self.export_rx.is_none() {
|
|
|
|
|
let target = match exporter::select_export_target(&self.settings) {
|
|
|
|
|
Ok(target) => target,
|
|
|
|
|
Err(err) => {
|
|
|
|
|
eprintln!("{err}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-04-20 14:04:59 -05:00
|
|
|
|
|
|
|
|
// Update the last export path in settings to remember the directory.
|
|
|
|
|
match &target {
|
|
|
|
|
exporter::ExportTarget::File(path) => {
|
|
|
|
|
if let Some(parent) = path.parent() {
|
|
|
|
|
self.settings.last_export_path = Some(parent.to_string_lossy().to_string());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exporter::ExportTarget::Folder(path) => {
|
|
|
|
|
self.settings.last_export_path = Some(path.to_string_lossy().to_string());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index < self.levels.len() {
|
|
|
|
|
let layout = self.levels[self.settings.active_level_index].clone();
|
|
|
|
|
let settings = self.settings.clone();
|
|
|
|
|
let (tx, rx) = mpsc::channel();
|
|
|
|
|
thread::spawn(move || {
|
|
|
|
|
let result = exporter::export_to_target(&layout, &settings, target);
|
|
|
|
|
let _ = tx.send(result);
|
|
|
|
|
});
|
|
|
|
|
self.export_rx = Some(rx);
|
|
|
|
|
}
|
2026-03-12 08:59:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(rx) = &self.export_rx {
|
|
|
|
|
match rx.try_recv() {
|
|
|
|
|
Ok(Ok(_)) => {
|
|
|
|
|
self.export_rx = None;
|
|
|
|
|
}
|
|
|
|
|
Ok(Err(err)) => {
|
|
|
|
|
eprintln!("{err}");
|
|
|
|
|
self.export_rx = None;
|
|
|
|
|
}
|
|
|
|
|
Err(mpsc::TryRecvError::Empty) => {}
|
|
|
|
|
Err(mpsc::TryRecvError::Disconnected) => {
|
|
|
|
|
self.export_rx = None;
|
|
|
|
|
}
|
2026-03-06 11:42:20 -06:00
|
|
|
}
|
|
|
|
|
}
|
2026-03-06 08:41:39 -06:00
|
|
|
|
2026-03-06 10:58:21 -06:00
|
|
|
egui::SidePanel::right("legend_panel")
|
|
|
|
|
.resizable(false)
|
|
|
|
|
.min_width(180.0)
|
|
|
|
|
.default_width(200.0)
|
|
|
|
|
.show_separator_line(true)
|
|
|
|
|
.show(ctx, |ui| {
|
2026-03-06 11:16:17 -06:00
|
|
|
ui.heading("Accessibility");
|
|
|
|
|
ui.add_space(6.0);
|
|
|
|
|
ui.checkbox(&mut self.settings.colorblind_mode, "Colorblind Mode");
|
|
|
|
|
ui.add_space(10.0);
|
|
|
|
|
ui.separator();
|
|
|
|
|
ui.add_space(8.0);
|
2026-03-06 10:58:21 -06:00
|
|
|
ui.heading("Legend");
|
|
|
|
|
ui.add_space(8.0);
|
2026-03-06 11:16:17 -06:00
|
|
|
if self.settings.colorblind_mode {
|
|
|
|
|
draw_legend_entry_colorblind(ui, "Rooms", LegendStyle::Crosshatch);
|
|
|
|
|
draw_legend_entry_colorblind(ui, "Corridors", LegendStyle::Dots);
|
|
|
|
|
draw_legend_entry_colorblind(ui, "Walls", LegendStyle::SolidLine);
|
|
|
|
|
draw_legend_entry_colorblind(ui, "Doors", LegendStyle::LongDash);
|
|
|
|
|
draw_legend_entry_colorblind(ui, "Locked Doors", LegendStyle::ShortDash);
|
2026-03-23 12:43:33 -05:00
|
|
|
draw_legend_entry_colorblind(ui, "Secret Doors", LegendStyle::DashDotDotLine);
|
2026-03-06 11:16:17 -06:00
|
|
|
draw_legend_entry_colorblind(ui, "Archways", LegendStyle::DottedLine);
|
2026-03-23 12:22:03 -05:00
|
|
|
draw_legend_entry_colorblind(ui, "Windows", LegendStyle::DashDotLine);
|
2026-04-14 10:31:26 -05:00
|
|
|
draw_legend_entry_colorblind(ui, "Start Marker", LegendStyle::SolidLine);
|
|
|
|
|
draw_legend_entry_colorblind(ui, "End Marker", LegendStyle::SolidLine);
|
2026-04-20 09:59:25 -05:00
|
|
|
draw_legend_entry_colorblind(ui, "Trap", LegendStyle::SolidLine);
|
|
|
|
|
draw_legend_entry_colorblind(ui, "Monster", LegendStyle::SolidLine);
|
2026-03-06 11:16:17 -06:00
|
|
|
} else {
|
|
|
|
|
draw_legend_entry(ui, Color32::from_rgb(70, 120, 160), "Rooms");
|
|
|
|
|
draw_legend_entry(ui, Color32::from_rgb(210, 190, 120), "Corridors");
|
|
|
|
|
draw_legend_entry(ui, Color32::BLACK, "Walls");
|
2026-03-12 09:11:48 -05:00
|
|
|
draw_legend_entry(ui, Color32::from_rgb(80, 200, 120), "Doors");
|
|
|
|
|
draw_legend_entry(ui, Color32::from_rgb(220, 70, 70), "Locked Doors");
|
2026-03-23 12:43:33 -05:00
|
|
|
draw_legend_entry(ui, Color32::from_rgb(170, 80, 170), "Secret Doors");
|
2026-03-23 12:22:03 -05:00
|
|
|
draw_legend_entry(ui, Color32::from_rgb(230, 140, 60), "Archways");
|
|
|
|
|
draw_legend_entry(ui, Color32::from_rgb(70, 130, 220), "Windows");
|
2026-04-14 10:31:26 -05:00
|
|
|
draw_legend_entry(ui, Color32::from_rgb(60, 220, 200), "Start Marker");
|
|
|
|
|
draw_legend_entry(ui, Color32::from_rgb(240, 90, 90), "End Marker");
|
2026-04-20 09:59:25 -05:00
|
|
|
draw_legend_entry(ui, Color32::from_rgb(150, 80, 230), "Trap");
|
|
|
|
|
draw_legend_entry(ui, Color32::from_rgb(200, 50, 50), "Monster");
|
2026-03-06 11:16:17 -06:00
|
|
|
}
|
2026-03-12 09:58:08 -05:00
|
|
|
ui.add_space(10.0);
|
|
|
|
|
ui.separator();
|
|
|
|
|
ui.add_space(8.0);
|
|
|
|
|
ui.heading("Keybinds");
|
|
|
|
|
ui.add_space(6.0);
|
2026-04-20 09:59:25 -05:00
|
|
|
ui.label(
|
|
|
|
|
"• Delete / Backspace: Remove hovered room, corridor, door, text, or marker",
|
|
|
|
|
);
|
2026-03-24 09:25:44 -05:00
|
|
|
ui.label("• Ctrl+Z: Undo");
|
|
|
|
|
ui.label("• Ctrl+Y: Redo");
|
2026-04-07 10:53:55 -05:00
|
|
|
ui.label("• Left click + drag: Move hovered room");
|
2026-03-24 09:25:44 -05:00
|
|
|
ui.label("• Right click: Cancel add tool");
|
|
|
|
|
ui.label("• Right click + drag: Resize hovered room");
|
2026-03-06 10:58:21 -06:00
|
|
|
});
|
|
|
|
|
|
2026-03-05 19:17:01 -06:00
|
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
2026-04-23 10:30:49 -05:00
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
for i in 0..self.levels.len() {
|
|
|
|
|
let label = format!("Level {}", i + 1);
|
|
|
|
|
if ui
|
|
|
|
|
.selectable_label(self.settings.active_level_index == i, label)
|
|
|
|
|
.clicked()
|
|
|
|
|
{
|
|
|
|
|
self.settings.active_level_index = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ui.separator();
|
|
|
|
|
|
2026-03-05 19:17:01 -06:00
|
|
|
let available = ui.available_size_before_wrap();
|
2026-03-06 09:56:26 -06:00
|
|
|
let (response, painter) = ui.allocate_painter(available, egui::Sense::click_and_drag());
|
2026-03-05 19:17:01 -06:00
|
|
|
let canvas = response.rect.shrink(12.0);
|
2026-03-06 09:24:24 -06:00
|
|
|
let geometry = draw_grid(&painter, canvas, self.settings.cols, self.settings.rows);
|
2026-03-12 11:12:50 -05:00
|
|
|
self.update_hover_targets(ctx, &geometry);
|
2026-03-12 10:42:12 -05:00
|
|
|
let resizing = self.handle_resize(ctx, &response, &geometry);
|
|
|
|
|
if !resizing {
|
|
|
|
|
self.handle_drag(ctx, &response, &geometry);
|
|
|
|
|
}
|
2026-03-12 09:58:08 -05:00
|
|
|
self.handle_add_tool(&response, &geometry);
|
|
|
|
|
if self.pending_delete {
|
|
|
|
|
if let Some(pointer_pos) = ctx.pointer_interact_pos() {
|
|
|
|
|
self.delete_at_pointer(pointer_pos, &geometry);
|
|
|
|
|
}
|
|
|
|
|
self.pending_delete = false;
|
|
|
|
|
}
|
2026-04-23 10:30:49 -05:00
|
|
|
|
|
|
|
|
if self.settings.active_level_index < self.levels.len() {
|
|
|
|
|
draw_layout(
|
|
|
|
|
&painter,
|
|
|
|
|
&geometry,
|
|
|
|
|
&self.levels[self.settings.active_level_index],
|
|
|
|
|
self.settings.colorblind_mode,
|
|
|
|
|
self.hover_text_idx,
|
|
|
|
|
self.hover_marker,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-12 09:58:08 -05:00
|
|
|
self.draw_add_overlay(&painter, &geometry);
|
2026-03-12 10:42:12 -05:00
|
|
|
self.draw_resize_overlay(&painter, &geometry);
|
2026-03-12 11:12:50 -05:00
|
|
|
self.draw_corridor_hover_overlay(&painter, &geometry);
|
2026-03-12 11:36:36 -05:00
|
|
|
self.draw_door_hover_overlay(&painter, &geometry);
|
2026-03-05 19:17:01 -06:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
fn generate_all_levels(settings: &UiSettings) -> Vec<DungeonLayout> {
|
|
|
|
|
let level_count = if settings.min_levels == settings.max_levels {
|
|
|
|
|
settings.min_levels
|
|
|
|
|
} else {
|
|
|
|
|
let range_seed = seed::derive_seed(settings.seed, 0x1E_7E_1_u64);
|
|
|
|
|
(range_seed as usize % (settings.max_levels - settings.min_levels + 1))
|
|
|
|
|
+ settings.min_levels
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut levels = Vec::with_capacity(level_count);
|
|
|
|
|
for i in 0..level_count {
|
|
|
|
|
let level_seed = seed::derive_seed(settings.seed, i as u64);
|
|
|
|
|
let layout = layout::generate_layout(
|
|
|
|
|
settings.cols,
|
|
|
|
|
settings.rows,
|
|
|
|
|
settings.room_count,
|
|
|
|
|
level_seed,
|
|
|
|
|
settings.min_room_size,
|
|
|
|
|
settings.max_room_size,
|
|
|
|
|
settings.square_rooms_only,
|
|
|
|
|
settings.min_corridor_width,
|
|
|
|
|
settings.max_corridor_width,
|
|
|
|
|
settings.corridor_randomness,
|
|
|
|
|
settings.dead_end_rooms_percent,
|
|
|
|
|
settings.pack_rooms_without_corridors,
|
|
|
|
|
door_settings_from_ui(settings),
|
|
|
|
|
window_settings_from_ui(settings),
|
|
|
|
|
);
|
|
|
|
|
let layout = populate_random_markers(layout, settings);
|
|
|
|
|
levels.push(layout);
|
|
|
|
|
}
|
|
|
|
|
levels
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 11:47:31 -05:00
|
|
|
fn clamp_dependent_settings(settings: &mut UiSettings) {
|
|
|
|
|
if settings.min_room_size > settings.max_room_size {
|
|
|
|
|
settings.max_room_size = settings.min_room_size;
|
|
|
|
|
}
|
|
|
|
|
if settings.min_corridor_width == 0 {
|
|
|
|
|
settings.min_corridor_width = 1;
|
|
|
|
|
}
|
|
|
|
|
if settings.min_corridor_width > settings.max_corridor_width {
|
|
|
|
|
settings.max_corridor_width = settings.min_corridor_width;
|
|
|
|
|
}
|
|
|
|
|
if settings.min_window_width > settings.max_window_width {
|
|
|
|
|
settings.max_window_width = settings.min_window_width;
|
|
|
|
|
}
|
|
|
|
|
if settings.min_start_marker_size > settings.max_start_marker_size {
|
|
|
|
|
settings.max_start_marker_size = settings.min_start_marker_size;
|
|
|
|
|
}
|
|
|
|
|
if settings.min_end_marker_size > settings.max_end_marker_size {
|
|
|
|
|
settings.max_end_marker_size = settings.min_end_marker_size;
|
|
|
|
|
}
|
|
|
|
|
if settings.min_start_marker_count > settings.max_start_marker_count {
|
|
|
|
|
settings.max_start_marker_count = settings.min_start_marker_count;
|
|
|
|
|
}
|
|
|
|
|
if settings.min_end_marker_count > settings.max_end_marker_count {
|
|
|
|
|
settings.max_end_marker_count = settings.min_end_marker_count;
|
|
|
|
|
}
|
2026-04-20 09:59:25 -05:00
|
|
|
if settings.min_traps_per_area > settings.max_traps_per_area {
|
|
|
|
|
settings.max_traps_per_area = settings.min_traps_per_area;
|
|
|
|
|
}
|
|
|
|
|
if settings.min_monsters_per_area > settings.max_monsters_per_area {
|
|
|
|
|
settings.max_monsters_per_area = settings.min_monsters_per_area;
|
|
|
|
|
}
|
2026-04-23 10:30:49 -05:00
|
|
|
if settings.min_levels == 0 {
|
|
|
|
|
settings.min_levels = 1;
|
|
|
|
|
}
|
|
|
|
|
if settings.min_levels > settings.max_levels {
|
|
|
|
|
settings.max_levels = settings.min_levels;
|
|
|
|
|
}
|
2026-04-14 11:47:31 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 09:24:24 -06:00
|
|
|
impl DungeonApp {
|
2026-04-14 12:02:24 -05:00
|
|
|
fn clear_hover_targets(&mut self) {
|
|
|
|
|
self.hover_room_idx = None;
|
|
|
|
|
self.hover_corridor_idx = None;
|
|
|
|
|
self.hover_door_idx = None;
|
|
|
|
|
self.hover_text_idx = None;
|
|
|
|
|
self.hover_marker = None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn reset_transient_state(&mut self) {
|
|
|
|
|
self.drag_state = None;
|
|
|
|
|
self.add_corridor_drag = None;
|
|
|
|
|
self.resize_state = None;
|
|
|
|
|
self.clear_hover_targets();
|
|
|
|
|
self.pending_delete = false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:06:48 -05:00
|
|
|
fn snapshot(&self) -> AppSnapshot {
|
|
|
|
|
AppSnapshot {
|
|
|
|
|
settings: self.settings.clone(),
|
2026-04-23 10:30:49 -05:00
|
|
|
levels: self.levels.clone(),
|
2026-03-24 09:06:48 -05:00
|
|
|
suppressed_auto_door_edges: self.suppressed_auto_door_edges.clone(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn push_undo_snapshot(&mut self) {
|
|
|
|
|
let snapshot = self.snapshot();
|
|
|
|
|
if self.undo_stack.last() == Some(&snapshot) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.undo_stack.push(snapshot);
|
|
|
|
|
if self.undo_stack.len() > 100 {
|
|
|
|
|
self.undo_stack.remove(0);
|
|
|
|
|
}
|
|
|
|
|
self.redo_stack.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn restore_snapshot(&mut self, snapshot: AppSnapshot) {
|
|
|
|
|
self.settings = snapshot.settings;
|
2026-04-23 10:30:49 -05:00
|
|
|
self.levels = snapshot.levels;
|
2026-03-24 09:06:48 -05:00
|
|
|
self.suppressed_auto_door_edges = snapshot.suppressed_auto_door_edges;
|
2026-04-14 12:02:24 -05:00
|
|
|
self.reset_transient_state();
|
2026-03-24 09:06:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn undo(&mut self) {
|
|
|
|
|
let Some(snapshot) = self.undo_stack.pop() else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
self.redo_stack.push(self.snapshot());
|
|
|
|
|
self.restore_snapshot(snapshot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn redo(&mut self) {
|
|
|
|
|
let Some(snapshot) = self.redo_stack.pop() else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
self.undo_stack.push(self.snapshot());
|
|
|
|
|
self.restore_snapshot(snapshot);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 11:49:24 -05:00
|
|
|
// Clear the current layout and reset transient interaction state.
|
|
|
|
|
fn clear_layout(&mut self) {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.levels[self.settings.active_level_index] = DungeonLayout {
|
2026-03-23 11:49:24 -05:00
|
|
|
packed_rooms: self.settings.pack_rooms_without_corridors,
|
|
|
|
|
..DungeonLayout::default()
|
|
|
|
|
};
|
2026-03-23 12:49:00 -05:00
|
|
|
self.suppressed_auto_door_edges.clear();
|
2026-04-14 12:02:24 -05:00
|
|
|
self.reset_transient_state();
|
2026-03-23 11:49:24 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Regenerate the dungeon layout from current settings and reset drag state.
|
2026-03-06 09:24:24 -06:00
|
|
|
fn regenerate_layout(&mut self) {
|
2026-03-06 10:26:23 -06:00
|
|
|
self.drag_state = None;
|
2026-03-23 12:49:00 -05:00
|
|
|
self.suppressed_auto_door_edges.clear();
|
2026-04-23 10:30:49 -05:00
|
|
|
self.levels = generate_all_levels(&self.settings);
|
|
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
self.settings.active_level_index = 0;
|
|
|
|
|
}
|
2026-03-06 09:24:24 -06:00
|
|
|
}
|
2026-03-06 09:56:26 -06:00
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Handle dragging rooms or corridors with the primary mouse button.
|
2026-03-12 10:42:12 -05:00
|
|
|
fn handle_drag(
|
|
|
|
|
&mut self,
|
|
|
|
|
ctx: &egui::Context,
|
|
|
|
|
response: &egui::Response,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) {
|
|
|
|
|
if !ctx.input(|i| i.pointer.primary_down()) && !response.drag_started() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-12 09:58:08 -05:00
|
|
|
if self.settings.add_tool != AddTool::None {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-06 09:56:26 -06:00
|
|
|
if response.drag_started()
|
2026-03-24 09:25:44 -05:00
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
&& let Some(text_idx) = self.text_at_pointer(pointer_pos, geometry)
|
|
|
|
|
{
|
|
|
|
|
self.push_undo_snapshot();
|
|
|
|
|
self.drag_state = Some(DragState::Text(TextDragState { text_idx }));
|
2026-04-14 11:03:58 -05:00
|
|
|
} else if response.drag_started()
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
&& let Some(marker_drag) = self.marker_drag_at_pointer(pointer_pos, geometry)
|
|
|
|
|
{
|
|
|
|
|
self.push_undo_snapshot();
|
|
|
|
|
self.drag_state = Some(DragState::Marker(marker_drag));
|
2026-03-24 09:25:44 -05:00
|
|
|
} else if response.drag_started()
|
2026-03-06 09:56:26 -06:00
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
&& let Some((room_idx, offset_x, offset_y)) =
|
|
|
|
|
self.room_at_pointer(pointer_pos, geometry)
|
|
|
|
|
{
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-03-06 10:26:23 -06:00
|
|
|
self.drag_state = Some(DragState::Room(RoomDragState {
|
2026-03-06 09:56:26 -06:00
|
|
|
room_idx,
|
|
|
|
|
offset_x,
|
|
|
|
|
offset_y,
|
2026-03-06 10:26:23 -06:00
|
|
|
}));
|
|
|
|
|
} else if response.drag_started()
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
&& let Some(corridor_drag) = self.corridor_drag_at_pointer(pointer_pos, geometry)
|
|
|
|
|
{
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-03-06 10:26:23 -06:00
|
|
|
self.drag_state = Some(DragState::Corridor(corridor_drag));
|
2026-03-06 09:56:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if response.dragged()
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
2026-03-06 10:26:23 -06:00
|
|
|
&& let Some(drag_state) = self.drag_state.clone()
|
2026-03-06 09:56:26 -06:00
|
|
|
{
|
2026-03-06 10:26:23 -06:00
|
|
|
match drag_state {
|
|
|
|
|
DragState::Room(drag) => self.drag_room_to_pointer(drag, pointer_pos, geometry),
|
2026-03-24 09:25:44 -05:00
|
|
|
DragState::Text(drag) => self.drag_text_to_pointer(drag, pointer_pos, geometry),
|
2026-04-14 11:03:58 -05:00
|
|
|
DragState::Marker(drag) => self.drag_marker_to_pointer(drag, pointer_pos, geometry),
|
2026-03-06 10:26:23 -06:00
|
|
|
DragState::Corridor(drag) => {
|
|
|
|
|
self.drag_corridor_to_pointer(drag, pointer_pos, geometry)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-06 09:56:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if response.drag_stopped() || !response.ctx.input(|i| i.pointer.primary_down()) {
|
2026-03-06 10:26:23 -06:00
|
|
|
self.drag_state = None;
|
2026-03-06 09:56:26 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Resolve the top-most room under the pointer and return its index and offset.
|
2026-03-06 09:56:26 -06:00
|
|
|
fn room_at_pointer(
|
|
|
|
|
&self,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) -> Option<(usize, f32, f32)> {
|
|
|
|
|
let (grid_x, grid_y) = pointer_to_grid(pointer_pos, geometry)?;
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
for (room_idx, room) in layout.rooms.iter().enumerate().rev() {
|
2026-03-06 09:56:26 -06:00
|
|
|
let room_x = room.x as f32;
|
|
|
|
|
let room_y = room.y as f32;
|
|
|
|
|
let room_right = room_x + room.width as f32;
|
|
|
|
|
let room_bottom = room_y + room.height as f32;
|
|
|
|
|
|
|
|
|
|
if grid_x >= room_x && grid_x < room_right && grid_y >= room_y && grid_y < room_bottom {
|
|
|
|
|
return Some((room_idx, grid_x - room_x, grid_y - room_y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Move a room to follow the pointer and reroute its corridors.
|
2026-03-06 09:56:26 -06:00
|
|
|
fn drag_room_to_pointer(
|
|
|
|
|
&mut self,
|
|
|
|
|
drag: RoomDragState,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) {
|
|
|
|
|
let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry) else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if drag.room_idx >= self.levels[self.settings.active_level_index].rooms.len() {
|
2026-03-06 10:26:23 -06:00
|
|
|
self.drag_state = None;
|
2026-03-06 09:56:26 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 10:26:23 -06:00
|
|
|
let (width, height, old_x, old_y) = {
|
2026-04-23 10:30:49 -05:00
|
|
|
let room = &self.levels[self.settings.active_level_index].rooms[drag.room_idx];
|
2026-03-06 10:26:23 -06:00
|
|
|
(room.width, room.height, room.x, room.y)
|
2026-03-06 09:56:26 -06:00
|
|
|
};
|
|
|
|
|
let max_x = self.settings.cols.saturating_sub(width);
|
|
|
|
|
let max_y = self.settings.rows.saturating_sub(height);
|
|
|
|
|
|
|
|
|
|
let target_x = (grid_x - drag.offset_x).floor().max(0.0) as usize;
|
|
|
|
|
let target_y = (grid_y - drag.offset_y).floor().max(0.0) as usize;
|
|
|
|
|
let new_x = target_x.min(max_x);
|
|
|
|
|
let new_y = target_y.min(max_y);
|
|
|
|
|
|
|
|
|
|
if new_x == old_x && new_y == old_y {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
self.levels[self.settings.active_level_index].rooms[drag.room_idx].x = new_x;
|
|
|
|
|
self.levels[self.settings.active_level_index].rooms[drag.room_idx].y = new_y;
|
2026-03-06 10:26:23 -06:00
|
|
|
self.reroute_corridors_for_room(drag.room_idx);
|
2026-03-06 10:53:46 -06:00
|
|
|
self.refresh_doors();
|
2026-03-06 09:56:26 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
fn drag_text_to_pointer(
|
|
|
|
|
&mut self,
|
|
|
|
|
drag: TextDragState,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) {
|
|
|
|
|
let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry) else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if drag.text_idx
|
|
|
|
|
>= self.levels[self.settings.active_level_index]
|
|
|
|
|
.text_labels
|
|
|
|
|
.len()
|
|
|
|
|
{
|
2026-03-24 09:25:44 -05:00
|
|
|
self.drag_state = None;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let target = (
|
|
|
|
|
(grid_x.floor().max(0.0) as usize).min(self.settings.cols.saturating_sub(1)),
|
|
|
|
|
(grid_y.floor().max(0.0) as usize).min(self.settings.rows.saturating_sub(1)),
|
|
|
|
|
);
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
self.levels[self.settings.active_level_index].text_labels[drag.text_idx].cell = target;
|
2026-03-24 09:25:44 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Recalculate corridor paths connected to a moved room.
|
2026-03-06 10:26:23 -06:00
|
|
|
fn reroute_corridors_for_room(&mut self, room_idx: usize) {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
if layout.packed_rooms {
|
2026-03-23 11:46:52 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
for corridor in &mut layout.corridors {
|
2026-03-06 10:26:23 -06:00
|
|
|
if corridor.start_room_id != room_idx && corridor.end_room_id != room_idx {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
let start = layout.rooms[corridor.start_room_id].center_cell();
|
|
|
|
|
let end = layout.rooms[corridor.end_room_id].center_cell();
|
2026-03-20 10:52:44 -05:00
|
|
|
let blocked = blocked_room_cells(
|
2026-04-23 10:30:49 -05:00
|
|
|
&layout.rooms,
|
2026-03-20 10:52:44 -05:00
|
|
|
&[corridor.start_room_id, corridor.end_room_id],
|
|
|
|
|
);
|
|
|
|
|
if let Some(path) =
|
|
|
|
|
shortest_path_cells(start, end, self.settings.cols, self.settings.rows, &blocked)
|
|
|
|
|
{
|
|
|
|
|
corridor.path = path;
|
|
|
|
|
}
|
2026-03-06 10:26:23 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Capture corridor drag state when the pointer is over a corridor cell.
|
2026-03-06 10:26:23 -06:00
|
|
|
fn corridor_drag_at_pointer(
|
|
|
|
|
&self,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) -> Option<CorridorDragState> {
|
|
|
|
|
let (grid_x, grid_y) = pointer_to_grid(pointer_pos, geometry)?;
|
|
|
|
|
let clicked = (grid_x.floor() as usize, grid_y.floor() as usize);
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
let corridor_index = layout
|
2026-03-06 10:26:23 -06:00
|
|
|
.corridors
|
|
|
|
|
.iter()
|
|
|
|
|
.position(|corridor| corridor.path.contains(&clicked))?;
|
|
|
|
|
|
|
|
|
|
Some(CorridorDragState {
|
|
|
|
|
corridor_index,
|
2026-04-23 10:30:49 -05:00
|
|
|
original_path: layout.corridors[corridor_index].path.clone(),
|
2026-03-06 10:26:23 -06:00
|
|
|
original_cell: clicked,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Reroute a corridor path through the current pointer cell.
|
2026-03-06 10:26:23 -06:00
|
|
|
fn drag_corridor_to_pointer(
|
2026-03-06 09:56:26 -06:00
|
|
|
&mut self,
|
2026-03-06 10:26:23 -06:00
|
|
|
drag: CorridorDragState,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
2026-03-06 09:56:26 -06:00
|
|
|
) {
|
2026-03-06 10:26:23 -06:00
|
|
|
let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry) else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
if drag.corridor_index >= layout.corridors.len() {
|
2026-03-06 10:26:23 -06:00
|
|
|
self.drag_state = None;
|
2026-03-06 09:56:26 -06:00
|
|
|
return;
|
|
|
|
|
}
|
2026-04-23 10:30:49 -05:00
|
|
|
let corridor = &layout.corridors[drag.corridor_index];
|
2026-03-06 09:56:26 -06:00
|
|
|
|
2026-03-06 10:26:23 -06:00
|
|
|
let target = (
|
|
|
|
|
(grid_x.floor().max(0.0) as usize).min(self.settings.cols.saturating_sub(1)),
|
|
|
|
|
(grid_y.floor().max(0.0) as usize).min(self.settings.rows.saturating_sub(1)),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let Some(new_path) = reroute_path_through_cell(
|
|
|
|
|
&drag.original_path,
|
|
|
|
|
drag.original_cell,
|
|
|
|
|
target,
|
|
|
|
|
self.settings.cols,
|
|
|
|
|
self.settings.rows,
|
2026-03-20 10:52:44 -05:00
|
|
|
&blocked_room_cells(
|
2026-04-23 10:30:49 -05:00
|
|
|
&layout.rooms,
|
2026-03-20 10:52:44 -05:00
|
|
|
&[corridor.start_room_id, corridor.end_room_id],
|
|
|
|
|
),
|
2026-03-06 10:26:23 -06:00
|
|
|
) else {
|
|
|
|
|
return;
|
2026-03-06 09:56:26 -06:00
|
|
|
};
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
layout.corridors[drag.corridor_index].path = new_path;
|
2026-03-06 10:53:46 -06:00
|
|
|
self.refresh_doors();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Rebuild doors based on the current layout and settings.
|
2026-03-06 10:53:46 -06:00
|
|
|
fn refresh_doors(&mut self) {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-03-06 10:53:46 -06:00
|
|
|
layout::apply_doors(
|
2026-04-23 10:30:49 -05:00
|
|
|
layout,
|
2026-03-06 10:53:46 -06:00
|
|
|
self.settings.seed,
|
|
|
|
|
door_settings_from_ui(&self.settings),
|
2026-03-12 08:25:37 -05:00
|
|
|
self.settings.cols,
|
|
|
|
|
self.settings.rows,
|
2026-03-06 10:53:46 -06:00
|
|
|
);
|
2026-04-23 10:30:49 -05:00
|
|
|
layout.doors.retain(|door| {
|
2026-03-23 12:49:00 -05:00
|
|
|
!door_edges_for(door, self.settings.cols, self.settings.rows)
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|edge| self.suppressed_auto_door_edges.contains(edge))
|
|
|
|
|
});
|
2026-03-23 12:22:03 -05:00
|
|
|
layout::apply_windows(
|
2026-04-23 10:30:49 -05:00
|
|
|
layout,
|
2026-03-23 12:22:03 -05:00
|
|
|
self.settings.seed,
|
|
|
|
|
window_settings_from_ui(&self.settings),
|
|
|
|
|
self.settings.cols,
|
|
|
|
|
self.settings.rows,
|
|
|
|
|
);
|
2026-03-06 09:56:26 -06:00
|
|
|
}
|
2026-03-12 09:58:08 -05:00
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Handle add-tool interactions for rooms, corridors, and doors.
|
2026-03-12 09:58:08 -05:00
|
|
|
fn handle_add_tool(&mut self, response: &egui::Response, geometry: &GridGeometry) {
|
2026-03-12 10:42:12 -05:00
|
|
|
if self.settings.add_tool != AddTool::None && response.secondary_clicked() {
|
2026-03-12 09:58:08 -05:00
|
|
|
self.settings.add_tool = AddTool::None;
|
|
|
|
|
self.add_corridor_drag = None;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
match self.settings.add_tool {
|
|
|
|
|
AddTool::Room => {
|
|
|
|
|
self.add_corridor_drag = None;
|
|
|
|
|
if response.clicked()
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
&& let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry)
|
|
|
|
|
{
|
|
|
|
|
let cell = (grid_x.floor() as usize, grid_y.floor() as usize);
|
|
|
|
|
self.add_room_at_cell(cell);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AddTool::Corridor => {
|
|
|
|
|
if response.drag_started()
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
&& let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry)
|
|
|
|
|
{
|
|
|
|
|
let cell = (grid_x.floor() as usize, grid_y.floor() as usize);
|
|
|
|
|
self.add_corridor_drag = Some(AddCorridorDrag {
|
|
|
|
|
start_cell: cell,
|
|
|
|
|
current_cell: cell,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if response.dragged()
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
&& let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry)
|
|
|
|
|
&& let Some(drag) = &mut self.add_corridor_drag
|
|
|
|
|
{
|
|
|
|
|
drag.current_cell = (grid_x.floor() as usize, grid_y.floor() as usize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if response.drag_stopped() {
|
|
|
|
|
if let Some(drag) = self.add_corridor_drag.take() {
|
|
|
|
|
self.add_corridor_between(drag.start_cell, drag.current_cell);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-07 11:28:34 -05:00
|
|
|
AddTool::Archway | AddTool::Door | AddTool::LockedDoor | AddTool::SecretDoor => {
|
2026-03-12 11:36:36 -05:00
|
|
|
self.add_corridor_drag = None;
|
|
|
|
|
if response.clicked()
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
{
|
2026-03-23 12:43:33 -05:00
|
|
|
let kind = match self.settings.add_tool {
|
2026-04-07 11:28:34 -05:00
|
|
|
AddTool::Archway => ManualDoorKind::Archway,
|
2026-03-23 12:43:33 -05:00
|
|
|
AddTool::Door => ManualDoorKind::Regular,
|
|
|
|
|
AddTool::LockedDoor => ManualDoorKind::Locked,
|
|
|
|
|
AddTool::SecretDoor => ManualDoorKind::Secret,
|
|
|
|
|
_ => unreachable!(),
|
|
|
|
|
};
|
|
|
|
|
self.add_door_at_pointer(pointer_pos, geometry, kind);
|
2026-03-12 11:36:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
2026-03-24 09:25:44 -05:00
|
|
|
AddTool::Text => {
|
|
|
|
|
self.add_corridor_drag = None;
|
|
|
|
|
if response.clicked()
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
&& let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry)
|
|
|
|
|
{
|
|
|
|
|
let cell = (grid_x.floor() as usize, grid_y.floor() as usize);
|
|
|
|
|
self.add_text_at_cell(cell);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-20 09:59:25 -05:00
|
|
|
AddTool::StartMarker | AddTool::EndMarker | AddTool::TrapMarker => {
|
2026-04-14 10:31:26 -05:00
|
|
|
self.add_corridor_drag = None;
|
|
|
|
|
if response.clicked()
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
&& let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry)
|
|
|
|
|
{
|
|
|
|
|
let cell = (grid_x.floor() as usize, grid_y.floor() as usize);
|
|
|
|
|
let kind = match self.settings.add_tool {
|
|
|
|
|
AddTool::StartMarker => MarkerKind::Start,
|
|
|
|
|
AddTool::EndMarker => MarkerKind::End,
|
2026-04-20 09:59:25 -05:00
|
|
|
AddTool::TrapMarker => MarkerKind::Trap,
|
2026-04-14 10:31:26 -05:00
|
|
|
_ => unreachable!(),
|
|
|
|
|
};
|
|
|
|
|
self.add_marker_at_cell(cell, kind);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-12 09:58:08 -05:00
|
|
|
AddTool::None => {
|
|
|
|
|
self.add_corridor_drag = None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw the overlay showing the corridor add drag preview.
|
2026-03-12 09:58:08 -05:00
|
|
|
fn draw_add_overlay(&self, painter: &egui::Painter, geometry: &GridGeometry) {
|
|
|
|
|
if self.settings.add_tool != AddTool::Corridor {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let Some(drag) = &self.add_corridor_drag else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let start = cell_center(geometry, drag.start_cell.0, drag.start_cell.1);
|
|
|
|
|
let end = cell_center(geometry, drag.current_cell.0, drag.current_cell.1);
|
|
|
|
|
let stroke = Stroke::new(2.0, Color32::WHITE);
|
|
|
|
|
painter.circle_filled(start, 3.0, Color32::WHITE);
|
|
|
|
|
draw_dashed_line(painter, start, end, stroke, 8.0, 6.0);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Add a room anchored to the given grid cell if space allows.
|
2026-03-12 09:58:08 -05:00
|
|
|
fn add_room_at_cell(&mut self, cell: (usize, usize)) {
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-03-12 09:58:08 -05:00
|
|
|
let width = self.settings.min_room_size.max(1);
|
|
|
|
|
let height = self.settings.min_room_size.max(1);
|
|
|
|
|
if cell.0 >= self.settings.cols || cell.1 >= self.settings.rows {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let max_w = self.settings.cols.saturating_sub(cell.0);
|
|
|
|
|
let max_h = self.settings.rows.saturating_sub(cell.1);
|
|
|
|
|
let width = width.min(max_w);
|
|
|
|
|
let height = height.min(max_h);
|
|
|
|
|
if width == 0 || height == 0 {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let new_room = layout::Room {
|
|
|
|
|
x: cell.0,
|
|
|
|
|
y: cell.1,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if layout
|
2026-03-12 09:58:08 -05:00
|
|
|
.rooms
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|room| rooms_overlap(&new_room, room))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
layout.rooms.push(new_room);
|
2026-03-12 09:58:08 -05:00
|
|
|
self.refresh_doors();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Add a corridor between two room cells using a shortest path.
|
2026-03-12 09:58:08 -05:00
|
|
|
fn add_corridor_between(&mut self, start: (usize, usize), end: (usize, usize)) {
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-03-12 09:58:08 -05:00
|
|
|
if start == end {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
let start_room = room_index_at_cell(&layout.rooms, start);
|
|
|
|
|
let end_room = room_index_at_cell(&layout.rooms, end);
|
2026-03-12 09:58:08 -05:00
|
|
|
let (Some(start_room), Some(end_room)) = (start_room, end_room) else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
let blocked = blocked_room_cells(&layout.rooms, &[start_room, end_room]);
|
2026-03-12 09:58:08 -05:00
|
|
|
|
|
|
|
|
let Some(path) =
|
|
|
|
|
shortest_path_cells(start, end, self.settings.cols, self.settings.rows, &blocked)
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
let next_id = layout
|
2026-03-12 09:58:08 -05:00
|
|
|
.corridors
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|c| c.id)
|
|
|
|
|
.max()
|
|
|
|
|
.unwrap_or(0)
|
|
|
|
|
.wrapping_add(1);
|
|
|
|
|
let width = self.settings.min_corridor_width.max(1);
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
layout.corridors.push(layout::Corridor {
|
2026-03-12 09:58:08 -05:00
|
|
|
id: next_id,
|
|
|
|
|
start_room_id: start_room,
|
|
|
|
|
end_room_id: end_room,
|
|
|
|
|
path,
|
|
|
|
|
width,
|
|
|
|
|
});
|
|
|
|
|
self.refresh_doors();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
fn add_text_at_cell(&mut self, cell: (usize, usize)) {
|
2026-04-23 10:30:49 -05:00
|
|
|
self.push_undo_snapshot();
|
|
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
if cell.0 >= self.settings.cols || cell.1 >= self.settings.rows {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let text = self.settings.add_text_value.trim().to_string();
|
|
|
|
|
if text.is_empty() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if let Some(existing) = layout
|
2026-03-24 09:25:44 -05:00
|
|
|
.text_labels
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.find(|label| label.cell == cell)
|
|
|
|
|
{
|
|
|
|
|
existing.text = text;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
layout.text_labels.push(layout::TextLabel {
|
2026-03-24 09:25:44 -05:00
|
|
|
cell,
|
|
|
|
|
text,
|
|
|
|
|
font_size: 18,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 10:31:26 -05:00
|
|
|
fn add_marker_at_cell(&mut self, cell: (usize, usize), kind: MarkerKind) {
|
2026-04-23 10:30:49 -05:00
|
|
|
self.push_undo_snapshot();
|
|
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-04-14 10:31:26 -05:00
|
|
|
if cell.0 >= self.settings.cols || cell.1 >= self.settings.rows {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 09:59:25 -05:00
|
|
|
let size = match kind {
|
|
|
|
|
MarkerKind::Start => manual_marker_size(&self.settings, true),
|
|
|
|
|
MarkerKind::End => manual_marker_size(&self.settings, false),
|
|
|
|
|
MarkerKind::Trap => manual_trap_marker_size(&self.settings),
|
|
|
|
|
MarkerKind::Monster => manual_monster_marker_size(&self.settings),
|
|
|
|
|
};
|
2026-04-14 10:31:26 -05:00
|
|
|
let origin = centered_marker_origin(cell, size, self.settings.cols, self.settings.rows);
|
|
|
|
|
let marker = layout::AreaMarker { cell: origin, size };
|
|
|
|
|
|
|
|
|
|
match kind {
|
2026-04-23 10:30:49 -05:00
|
|
|
MarkerKind::Start => layout.start_markers.push(marker),
|
|
|
|
|
MarkerKind::End => layout.end_markers.push(marker),
|
|
|
|
|
MarkerKind::Trap => layout.trap_markers.push(marker),
|
|
|
|
|
MarkerKind::Monster => layout.monster_markers.push(marker),
|
2026-04-14 10:31:26 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Update which room/corridor/door is currently hovered.
|
2026-03-12 11:12:50 -05:00
|
|
|
fn update_hover_targets(&mut self, ctx: &egui::Context, geometry: &GridGeometry) {
|
2026-03-12 10:42:12 -05:00
|
|
|
let Some(pointer_pos) = ctx.pointer_hover_pos() else {
|
2026-04-14 12:02:24 -05:00
|
|
|
self.clear_hover_targets();
|
2026-03-12 10:42:12 -05:00
|
|
|
return;
|
|
|
|
|
};
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-03-12 11:36:36 -05:00
|
|
|
if let Some(edge) = self.door_edge_at_pointer(pointer_pos, geometry) {
|
|
|
|
|
let target = normalized_edge(edge.0, edge.1);
|
2026-04-23 10:30:49 -05:00
|
|
|
self.hover_door_idx = layout.doors.iter().position(|d| {
|
2026-03-12 11:36:36 -05:00
|
|
|
door_edges_for(d, self.settings.cols, self.settings.rows)
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|e| normalized_edge(e.0, e.1) == target)
|
|
|
|
|
});
|
|
|
|
|
if self.hover_door_idx.is_some() {
|
|
|
|
|
self.hover_room_idx = None;
|
|
|
|
|
self.hover_corridor_idx = None;
|
2026-03-24 09:25:44 -05:00
|
|
|
self.hover_text_idx = None;
|
2026-04-14 11:03:58 -05:00
|
|
|
self.hover_marker = None;
|
2026-03-12 11:36:36 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
self.hover_text_idx = self.text_at_pointer(pointer_pos, geometry);
|
|
|
|
|
if self.hover_text_idx.is_some() {
|
2026-04-14 10:31:26 -05:00
|
|
|
self.hover_room_idx = None;
|
|
|
|
|
self.hover_corridor_idx = None;
|
|
|
|
|
self.hover_door_idx = None;
|
2026-04-14 11:03:58 -05:00
|
|
|
self.hover_marker = None;
|
2026-04-14 10:31:26 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 11:03:58 -05:00
|
|
|
self.hover_marker = self.marker_at_pointer(pointer_pos, geometry);
|
|
|
|
|
if self.hover_marker.is_some() {
|
2026-03-24 09:25:44 -05:00
|
|
|
self.hover_room_idx = None;
|
|
|
|
|
self.hover_corridor_idx = None;
|
|
|
|
|
self.hover_door_idx = None;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 10:42:12 -05:00
|
|
|
if let Some((room_idx, _, _)) = self.room_at_pointer(pointer_pos, geometry) {
|
|
|
|
|
self.hover_room_idx = Some(room_idx);
|
2026-03-12 11:12:50 -05:00
|
|
|
self.hover_corridor_idx = None;
|
2026-03-12 11:36:36 -05:00
|
|
|
self.hover_door_idx = None;
|
2026-04-14 11:03:58 -05:00
|
|
|
self.hover_marker = None;
|
2026-03-12 10:42:12 -05:00
|
|
|
} else {
|
|
|
|
|
self.hover_room_idx = None;
|
2026-03-12 11:12:50 -05:00
|
|
|
if let Some(corridor_drag) = self.corridor_drag_at_pointer(pointer_pos, geometry) {
|
|
|
|
|
self.hover_corridor_idx = Some(corridor_drag.corridor_index);
|
2026-03-12 11:36:36 -05:00
|
|
|
self.hover_door_idx = None;
|
2026-04-14 11:03:58 -05:00
|
|
|
self.hover_marker = None;
|
2026-03-12 11:12:50 -05:00
|
|
|
} else {
|
|
|
|
|
self.hover_corridor_idx = None;
|
2026-03-12 11:36:36 -05:00
|
|
|
self.hover_door_idx = None;
|
2026-04-14 11:03:58 -05:00
|
|
|
self.hover_marker = None;
|
2026-03-12 11:12:50 -05:00
|
|
|
}
|
2026-03-12 10:42:12 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
fn text_at_pointer(&self, pointer_pos: egui::Pos2, geometry: &GridGeometry) -> Option<usize> {
|
|
|
|
|
let (grid_x, grid_y) = pointer_to_grid(pointer_pos, geometry)?;
|
|
|
|
|
let clicked = (grid_x.floor() as usize, grid_y.floor() as usize);
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
layout
|
2026-03-24 09:25:44 -05:00
|
|
|
.text_labels
|
|
|
|
|
.iter()
|
|
|
|
|
.position(|label| label.cell == clicked)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 10:31:26 -05:00
|
|
|
fn marker_at_pointer(
|
|
|
|
|
&self,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
2026-04-14 11:03:58 -05:00
|
|
|
) -> Option<HoverMarker> {
|
2026-04-14 10:31:26 -05:00
|
|
|
let (grid_x, grid_y) = pointer_to_grid(pointer_pos, geometry)?;
|
|
|
|
|
let clicked = (grid_x.floor() as usize, grid_y.floor() as usize);
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
layout
|
2026-04-14 11:03:58 -05:00
|
|
|
.start_markers
|
|
|
|
|
.iter()
|
|
|
|
|
.enumerate()
|
|
|
|
|
.find(|(_, marker)| marker_contains_cell(Some(marker), clicked))
|
|
|
|
|
.map(|(idx, _)| HoverMarker::Start(idx))
|
2026-04-14 10:31:26 -05:00
|
|
|
.or_else(|| {
|
2026-04-23 10:30:49 -05:00
|
|
|
layout
|
2026-04-14 11:03:58 -05:00
|
|
|
.end_markers
|
|
|
|
|
.iter()
|
|
|
|
|
.enumerate()
|
|
|
|
|
.find(|(_, marker)| marker_contains_cell(Some(marker), clicked))
|
|
|
|
|
.map(|(idx, _)| HoverMarker::End(idx))
|
2026-04-14 10:31:26 -05:00
|
|
|
})
|
2026-04-20 09:59:25 -05:00
|
|
|
.or_else(|| {
|
2026-04-23 10:30:49 -05:00
|
|
|
layout
|
2026-04-20 09:59:25 -05:00
|
|
|
.trap_markers
|
|
|
|
|
.iter()
|
|
|
|
|
.enumerate()
|
|
|
|
|
.find(|(_, marker)| marker_contains_cell(Some(marker), clicked))
|
|
|
|
|
.map(|(idx, _)| HoverMarker::Trap(idx))
|
|
|
|
|
})
|
|
|
|
|
.or_else(|| {
|
2026-04-23 10:30:49 -05:00
|
|
|
layout
|
2026-04-20 09:59:25 -05:00
|
|
|
.monster_markers
|
|
|
|
|
.iter()
|
|
|
|
|
.enumerate()
|
|
|
|
|
.find(|(_, marker)| marker_contains_cell(Some(marker), clicked))
|
|
|
|
|
.map(|(idx, _)| HoverMarker::Monster(idx))
|
|
|
|
|
})
|
2026-04-14 10:31:26 -05:00
|
|
|
}
|
|
|
|
|
|
2026-04-14 11:03:58 -05:00
|
|
|
fn marker_drag_at_pointer(
|
|
|
|
|
&self,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) -> Option<MarkerDragState> {
|
|
|
|
|
let (grid_x, grid_y) = pointer_to_grid(pointer_pos, geometry)?;
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-04-14 11:03:58 -05:00
|
|
|
match self.marker_at_pointer(pointer_pos, geometry)? {
|
|
|
|
|
HoverMarker::Start(marker_idx) => {
|
2026-04-23 10:30:49 -05:00
|
|
|
let marker = layout.start_markers.get(marker_idx)?;
|
2026-04-14 11:03:58 -05:00
|
|
|
Some(MarkerDragState {
|
|
|
|
|
kind: MarkerKind::Start,
|
|
|
|
|
marker_idx,
|
|
|
|
|
offset_x: grid_x - marker.cell.0 as f32,
|
|
|
|
|
offset_y: grid_y - marker.cell.1 as f32,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
HoverMarker::End(marker_idx) => {
|
2026-04-23 10:30:49 -05:00
|
|
|
let marker = layout.end_markers.get(marker_idx)?;
|
2026-04-14 11:03:58 -05:00
|
|
|
Some(MarkerDragState {
|
|
|
|
|
kind: MarkerKind::End,
|
|
|
|
|
marker_idx,
|
|
|
|
|
offset_x: grid_x - marker.cell.0 as f32,
|
|
|
|
|
offset_y: grid_y - marker.cell.1 as f32,
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-04-20 09:59:25 -05:00
|
|
|
HoverMarker::Trap(marker_idx) => {
|
2026-04-23 10:30:49 -05:00
|
|
|
let marker = layout.trap_markers.get(marker_idx)?;
|
2026-04-20 09:59:25 -05:00
|
|
|
Some(MarkerDragState {
|
|
|
|
|
kind: MarkerKind::Trap,
|
|
|
|
|
marker_idx,
|
|
|
|
|
offset_x: grid_x - marker.cell.0 as f32,
|
|
|
|
|
offset_y: grid_y - marker.cell.1 as f32,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
HoverMarker::Monster(marker_idx) => {
|
2026-04-23 10:30:49 -05:00
|
|
|
let marker = layout.monster_markers.get(marker_idx)?;
|
2026-04-20 09:59:25 -05:00
|
|
|
Some(MarkerDragState {
|
|
|
|
|
kind: MarkerKind::Monster,
|
|
|
|
|
marker_idx,
|
|
|
|
|
offset_x: grid_x - marker.cell.0 as f32,
|
|
|
|
|
offset_y: grid_y - marker.cell.1 as f32,
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-04-14 11:03:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn drag_marker_to_pointer(
|
|
|
|
|
&mut self,
|
|
|
|
|
drag: MarkerDragState,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) {
|
|
|
|
|
let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry) else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-04-14 11:03:58 -05:00
|
|
|
let markers = match drag.kind {
|
2026-04-23 10:30:49 -05:00
|
|
|
MarkerKind::Start => &mut layout.start_markers,
|
|
|
|
|
MarkerKind::End => &mut layout.end_markers,
|
|
|
|
|
MarkerKind::Trap => &mut layout.trap_markers,
|
|
|
|
|
MarkerKind::Monster => &mut layout.monster_markers,
|
2026-04-14 11:03:58 -05:00
|
|
|
};
|
|
|
|
|
let Some(marker) = markers.get_mut(drag.marker_idx) else {
|
|
|
|
|
self.drag_state = None;
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let max_x = self.settings.cols.saturating_sub(marker.size);
|
|
|
|
|
let max_y = self.settings.rows.saturating_sub(marker.size);
|
|
|
|
|
let target_x = (grid_x - drag.offset_x).floor().max(0.0) as usize;
|
|
|
|
|
let target_y = (grid_y - drag.offset_y).floor().max(0.0) as usize;
|
|
|
|
|
marker.cell = (target_x.min(max_x), target_y.min(max_y));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Handle right-click resizing of rooms and return whether resizing is active.
|
2026-03-12 10:42:12 -05:00
|
|
|
fn handle_resize(
|
|
|
|
|
&mut self,
|
|
|
|
|
ctx: &egui::Context,
|
|
|
|
|
response: &egui::Response,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) -> bool {
|
|
|
|
|
if self.settings.add_tool != AddTool::None {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 10:53:55 -05:00
|
|
|
if ctx.input(|i| i.pointer.secondary_pressed()) && self.resize_state.is_none() {
|
2026-03-12 10:42:12 -05:00
|
|
|
if let Some(pointer_pos) = response.interact_pointer_pos() {
|
2026-03-24 09:25:44 -05:00
|
|
|
if let Some(text_idx) = self.text_at_pointer(pointer_pos, geometry) {
|
|
|
|
|
if let Some(state) = self.start_text_resize(text_idx) {
|
|
|
|
|
self.push_undo_snapshot();
|
|
|
|
|
self.resize_state = Some(ResizeState::Text(state));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else if let Some(room_idx) = self.resize_room_at_pointer(pointer_pos, geometry) {
|
2026-03-12 10:42:12 -05:00
|
|
|
if let Some(state) = self.start_resize(room_idx, pointer_pos, geometry) {
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-03-24 09:25:44 -05:00
|
|
|
self.resize_state = Some(ResizeState::Room(state));
|
2026-03-12 10:42:12 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(state) = self.resize_state.clone() {
|
2026-04-07 10:53:55 -05:00
|
|
|
if response.dragged_by(egui::PointerButton::Secondary)
|
|
|
|
|
&& ctx.input(|i| i.pointer.secondary_down())
|
|
|
|
|
&& let Some(pointer_pos) = response.interact_pointer_pos()
|
|
|
|
|
{
|
2026-03-12 10:42:12 -05:00
|
|
|
if let Some((grid_x, grid_y)) = pointer_to_grid(pointer_pos, geometry) {
|
|
|
|
|
let cell = (grid_x.floor() as usize, grid_y.floor() as usize);
|
2026-03-24 09:25:44 -05:00
|
|
|
match state {
|
|
|
|
|
ResizeState::Room(state) => self.resize_room(&state, cell),
|
|
|
|
|
ResizeState::Text(state) => self.resize_text(&state, cell),
|
|
|
|
|
}
|
2026-03-12 10:42:12 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ctx.input(|i| i.pointer.button_released(egui::PointerButton::Secondary)) {
|
|
|
|
|
self.resize_state = None;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
fn start_text_resize(&self, text_idx: usize) -> Option<TextResizeState> {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
let label = layout.text_labels.get(text_idx)?;
|
2026-03-24 09:25:44 -05:00
|
|
|
Some(TextResizeState {
|
|
|
|
|
text_idx,
|
|
|
|
|
origin_cell: label.cell,
|
|
|
|
|
original_font_size: label.font_size,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:54:49 -05:00
|
|
|
// Resolve the room that should respond to a resize click, including outer corner targets.
|
|
|
|
|
fn resize_room_at_pointer(
|
|
|
|
|
&self,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) -> Option<usize> {
|
|
|
|
|
if let Some((room_idx, _, _)) = self.room_at_pointer(pointer_pos, geometry) {
|
|
|
|
|
return Some(room_idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let (grid_x, grid_y) = pointer_to_grid(pointer_pos, geometry)?;
|
|
|
|
|
let clicked = (
|
|
|
|
|
grid_x.floor().max(0.0) as usize,
|
|
|
|
|
grid_y.floor().max(0.0) as usize,
|
|
|
|
|
);
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
for (room_idx, room) in layout.rooms.iter().enumerate().rev() {
|
|
|
|
|
if resize_hit_cells(room, room_idx, &layout.rooms, geometry.cols, geometry.rows)
|
|
|
|
|
.contains(&clicked)
|
2026-03-23 12:54:49 -05:00
|
|
|
{
|
|
|
|
|
return Some(room_idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 10:53:55 -05:00
|
|
|
// Pick the resize corner from the initial click quadrant and keep the opposite corner fixed.
|
2026-03-12 10:42:12 -05:00
|
|
|
fn start_resize(
|
|
|
|
|
&self,
|
|
|
|
|
room_idx: usize,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) -> Option<RoomResizeState> {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
let original_room = layout.rooms.get(room_idx)?.clone();
|
2026-03-12 10:42:12 -05:00
|
|
|
let (grid_x, grid_y) = pointer_to_grid(pointer_pos, geometry)?;
|
2026-04-07 10:53:55 -05:00
|
|
|
let center_x = original_room.x as f32 + original_room.width as f32 * 0.5;
|
|
|
|
|
let center_y = original_room.y as f32 + original_room.height as f32 * 0.5;
|
|
|
|
|
let pointer_x = grid_x;
|
|
|
|
|
let pointer_y = grid_y;
|
2026-03-12 10:42:12 -05:00
|
|
|
|
2026-04-07 10:53:55 -05:00
|
|
|
let resize_corner = match (pointer_x >= center_x, pointer_y >= center_y) {
|
|
|
|
|
(false, false) => ResizeCorner::TopLeft,
|
|
|
|
|
(true, false) => ResizeCorner::TopRight,
|
|
|
|
|
(false, true) => ResizeCorner::BottomLeft,
|
|
|
|
|
(true, true) => ResizeCorner::BottomRight,
|
2026-03-12 10:42:12 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Some(RoomResizeState {
|
|
|
|
|
room_idx,
|
2026-04-07 10:53:55 -05:00
|
|
|
original_room,
|
|
|
|
|
resize_corner,
|
2026-03-12 10:42:12 -05:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 10:53:55 -05:00
|
|
|
// Resize only the corner chosen at drag start while keeping the opposite corner fixed.
|
2026-03-12 10:42:12 -05:00
|
|
|
fn resize_room(&mut self, state: &RoomResizeState, target_cell: (usize, usize)) {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-03-12 10:42:12 -05:00
|
|
|
let cols = self.settings.cols.max(1);
|
|
|
|
|
let rows = self.settings.rows.max(1);
|
|
|
|
|
|
|
|
|
|
let tx = target_cell.0.min(cols - 1) as isize;
|
|
|
|
|
let ty = target_cell.1.min(rows - 1) as isize;
|
2026-04-07 10:53:55 -05:00
|
|
|
let original = &state.original_room;
|
2026-03-12 10:42:12 -05:00
|
|
|
|
2026-04-07 10:53:55 -05:00
|
|
|
let left = original.x as isize;
|
|
|
|
|
let top = original.y as isize;
|
|
|
|
|
let right = (original.x + original.width - 1) as isize;
|
|
|
|
|
let bottom = (original.y + original.height - 1) as isize;
|
|
|
|
|
let (x0, x1, y0, y1) = match state.resize_corner {
|
|
|
|
|
ResizeCorner::TopLeft => (tx.min(right), right, ty.min(bottom), bottom),
|
|
|
|
|
ResizeCorner::TopRight => (left, tx.max(left), ty.min(bottom), bottom),
|
|
|
|
|
ResizeCorner::BottomLeft => (tx.min(right), right, top, ty.max(top)),
|
|
|
|
|
ResizeCorner::BottomRight => (left, tx.max(left), top, ty.max(top)),
|
|
|
|
|
};
|
2026-03-12 10:42:12 -05:00
|
|
|
|
|
|
|
|
let new_room = layout::Room {
|
|
|
|
|
x: x0 as usize,
|
|
|
|
|
y: y0 as usize,
|
|
|
|
|
width: (x1 - x0 + 1) as usize,
|
|
|
|
|
height: (y1 - y0 + 1) as usize,
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-23 12:54:49 -05:00
|
|
|
if new_room.width == 0 || new_room.height == 0 {
|
2026-03-12 10:42:12 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if new_room.x + new_room.width > cols || new_room.y + new_room.height > rows {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if layout
|
2026-03-12 10:42:12 -05:00
|
|
|
.rooms
|
|
|
|
|
.iter()
|
|
|
|
|
.enumerate()
|
|
|
|
|
.any(|(idx, room)| idx != state.room_idx && rooms_overlap(&new_room, room))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
if let Some(room) = layout.rooms.get_mut(state.room_idx) {
|
2026-03-12 10:42:12 -05:00
|
|
|
room.x = new_room.x;
|
|
|
|
|
room.y = new_room.y;
|
|
|
|
|
room.width = new_room.width;
|
|
|
|
|
room.height = new_room.height;
|
|
|
|
|
self.reroute_corridors_for_room(state.room_idx);
|
|
|
|
|
self.refresh_doors();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
fn resize_text(&mut self, state: &TextResizeState, target_cell: (usize, usize)) {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
let Some(label) = layout.text_labels.get_mut(state.text_idx) else {
|
2026-03-24 09:25:44 -05:00
|
|
|
self.resize_state = None;
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let dx = target_cell.0 as isize - state.origin_cell.0 as isize;
|
|
|
|
|
let dy = target_cell.1 as isize - state.origin_cell.1 as isize;
|
|
|
|
|
let delta_cells = if dx.abs() >= dy.abs() { dx } else { -dy };
|
|
|
|
|
let new_size = (state.original_font_size as isize + (delta_cells * 4)).clamp(8, 96);
|
|
|
|
|
label.font_size = new_size as u16;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw dashed overlays for room resizing interactions.
|
2026-03-12 10:42:12 -05:00
|
|
|
fn draw_resize_overlay(&self, painter: &egui::Painter, geometry: &GridGeometry) {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
if let Some(text_idx) = self
|
|
|
|
|
.resize_state
|
|
|
|
|
.as_ref()
|
|
|
|
|
.and_then(|s| match s {
|
|
|
|
|
ResizeState::Text(state) => Some(state.text_idx),
|
|
|
|
|
ResizeState::Room(_) => None,
|
|
|
|
|
})
|
|
|
|
|
.or(self.hover_text_idx)
|
|
|
|
|
{
|
2026-04-23 10:30:49 -05:00
|
|
|
if let Some(label) = layout.text_labels.get(text_idx) {
|
2026-03-24 09:25:44 -05:00
|
|
|
let rect = text_label_rect(geometry, label).expand(3.0);
|
|
|
|
|
painter.rect_stroke(
|
|
|
|
|
rect,
|
|
|
|
|
0.0,
|
|
|
|
|
Stroke::new(2.0, Color32::from_gray(180)),
|
|
|
|
|
egui::StrokeKind::Middle,
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 10:42:12 -05:00
|
|
|
let room_idx = self
|
|
|
|
|
.resize_state
|
|
|
|
|
.as_ref()
|
2026-03-24 09:25:44 -05:00
|
|
|
.and_then(|s| match s {
|
|
|
|
|
ResizeState::Room(state) => Some(state.room_idx),
|
|
|
|
|
ResizeState::Text(_) => None,
|
|
|
|
|
})
|
2026-03-12 10:42:12 -05:00
|
|
|
.or(self.hover_room_idx);
|
|
|
|
|
let Some(room_idx) = room_idx else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
2026-04-23 10:30:49 -05:00
|
|
|
let Some(room) = layout.rooms.get(room_idx) else {
|
2026-03-12 10:42:12 -05:00
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
let color = Color32::from_gray(170);
|
|
|
|
|
let stroke = Stroke::new(1.5, color);
|
|
|
|
|
|
|
|
|
|
let left = geometry.rect.left() + room.x as f32 * geometry.cell_size;
|
|
|
|
|
let top = geometry.rect.top() + room.y as f32 * geometry.cell_size;
|
|
|
|
|
let right = left + room.width as f32 * geometry.cell_size;
|
|
|
|
|
let bottom = top + room.height as f32 * geometry.cell_size;
|
|
|
|
|
|
|
|
|
|
let tl = egui::pos2(left, top);
|
|
|
|
|
let tr = egui::pos2(right, top);
|
|
|
|
|
let br = egui::pos2(right, bottom);
|
|
|
|
|
let bl = egui::pos2(left, bottom);
|
|
|
|
|
|
|
|
|
|
draw_dashed_line(painter, tl, tr, stroke, 6.0, 6.0);
|
|
|
|
|
draw_dashed_line(painter, tr, br, stroke, 6.0, 6.0);
|
|
|
|
|
draw_dashed_line(painter, br, bl, stroke, 6.0, 6.0);
|
|
|
|
|
draw_dashed_line(painter, bl, tl, stroke, 6.0, 6.0);
|
|
|
|
|
|
|
|
|
|
let font = egui::FontId::proportional(12.0);
|
|
|
|
|
let center_top = egui::pos2((left + right) * 0.5, top - 10.0);
|
|
|
|
|
let center_left = egui::pos2(left - 12.0, (top + bottom) * 0.5);
|
|
|
|
|
painter.text(
|
|
|
|
|
center_top,
|
|
|
|
|
egui::Align2::CENTER_CENTER,
|
|
|
|
|
"<->",
|
|
|
|
|
font.clone(),
|
|
|
|
|
color,
|
|
|
|
|
);
|
|
|
|
|
painter.text(center_left, egui::Align2::CENTER_CENTER, "^v", font, color);
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
if matches!(self.resize_state, Some(ResizeState::Room(_))) {
|
2026-03-12 10:42:12 -05:00
|
|
|
draw_resize_handle(painter, tl, ResizeCorner::TopLeft, color);
|
|
|
|
|
draw_resize_handle(painter, tr, ResizeCorner::TopRight, color);
|
|
|
|
|
draw_resize_handle(painter, br, ResizeCorner::BottomRight, color);
|
|
|
|
|
draw_resize_handle(painter, bl, ResizeCorner::BottomLeft, color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a dashed overlay along the hovered corridor path.
|
2026-03-12 11:12:50 -05:00
|
|
|
fn draw_corridor_hover_overlay(&self, painter: &egui::Painter, geometry: &GridGeometry) {
|
|
|
|
|
let Some(idx) = self.hover_corridor_idx else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
let Some(corridor) = layout.corridors.get(idx) else {
|
2026-03-12 11:12:50 -05:00
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let color = Color32::from_gray(170);
|
|
|
|
|
let stroke = Stroke::new(2.0, color);
|
|
|
|
|
for pair in corridor.path.windows(2) {
|
|
|
|
|
let a = cell_center(geometry, pair[0].0, pair[0].1);
|
|
|
|
|
let b = cell_center(geometry, pair[1].0, pair[1].1);
|
|
|
|
|
draw_dashed_line(painter, a, b, stroke, 6.0, 6.0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a dashed overlay along the hovered door.
|
2026-03-12 11:36:36 -05:00
|
|
|
fn draw_door_hover_overlay(&self, painter: &egui::Painter, geometry: &GridGeometry) {
|
|
|
|
|
let Some(idx) = self.hover_door_idx else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let layout = &self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
let Some(door) = layout.doors.get(idx) else {
|
2026-03-12 11:36:36 -05:00
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
let color = Color32::from_gray(200);
|
|
|
|
|
let stroke = Stroke::new(2.0, color);
|
|
|
|
|
draw_door_line(
|
|
|
|
|
painter,
|
|
|
|
|
geometry,
|
|
|
|
|
door.from,
|
|
|
|
|
door.to,
|
|
|
|
|
door_render_width(door),
|
|
|
|
|
stroke,
|
|
|
|
|
DoorLineStyle::LongDash,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Delete the door, room, or corridor at the pointer position.
|
2026-03-12 09:58:08 -05:00
|
|
|
fn delete_at_pointer(&mut self, pointer_pos: egui::Pos2, geometry: &GridGeometry) {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
if let Some(idx) = self.text_at_pointer(pointer_pos, geometry) {
|
|
|
|
|
self.push_undo_snapshot();
|
2026-04-23 10:30:49 -05:00
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
if idx < layout.text_labels.len() {
|
|
|
|
|
layout.text_labels.remove(idx);
|
2026-03-24 09:25:44 -05:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 11:03:58 -05:00
|
|
|
if let Some(marker) = self.marker_at_pointer(pointer_pos, geometry) {
|
2026-04-14 10:31:26 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-04-23 10:30:49 -05:00
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
2026-04-14 11:03:58 -05:00
|
|
|
match marker {
|
|
|
|
|
HoverMarker::Start(idx) => {
|
2026-04-23 10:30:49 -05:00
|
|
|
if idx < layout.start_markers.len() {
|
|
|
|
|
layout.start_markers.remove(idx);
|
2026-04-14 11:03:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HoverMarker::End(idx) => {
|
2026-04-23 10:30:49 -05:00
|
|
|
if idx < layout.end_markers.len() {
|
|
|
|
|
layout.end_markers.remove(idx);
|
2026-04-14 11:03:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-20 09:59:25 -05:00
|
|
|
HoverMarker::Trap(idx) => {
|
2026-04-23 10:30:49 -05:00
|
|
|
if idx < layout.trap_markers.len() {
|
|
|
|
|
layout.trap_markers.remove(idx);
|
2026-04-20 09:59:25 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HoverMarker::Monster(idx) => {
|
2026-04-23 10:30:49 -05:00
|
|
|
if idx < layout.monster_markers.len() {
|
|
|
|
|
layout.monster_markers.remove(idx);
|
2026-04-20 09:59:25 -05:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-14 10:31:26 -05:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 11:36:36 -05:00
|
|
|
if let Some(edge) = self.door_edge_at_pointer(pointer_pos, geometry) {
|
|
|
|
|
let target = normalized_edge(edge.0, edge.1);
|
2026-04-23 10:30:49 -05:00
|
|
|
let active_index = self.settings.active_level_index;
|
|
|
|
|
if let Some(idx) = self.levels[active_index].doors.iter().position(|d| {
|
2026-03-12 11:36:36 -05:00
|
|
|
door_edges_for(d, self.settings.cols, self.settings.rows)
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|e| normalized_edge(e.0, e.1) == target)
|
|
|
|
|
}) {
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-04-23 10:30:49 -05:00
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
if !layout.doors[idx].manual {
|
|
|
|
|
for edge in
|
|
|
|
|
door_edges_for(&layout.doors[idx], self.settings.cols, self.settings.rows)
|
|
|
|
|
{
|
2026-03-23 12:49:00 -05:00
|
|
|
self.suppressed_auto_door_edges.insert(edge);
|
|
|
|
|
}
|
2026-04-23 10:30:49 -05:00
|
|
|
layout.doors.remove(idx);
|
2026-03-23 12:49:00 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
layout.doors.remove(idx);
|
2026-03-12 11:36:36 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 09:58:08 -05:00
|
|
|
if let Some((room_idx, _, _)) = self.room_at_pointer(pointer_pos, geometry) {
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-03-12 09:58:08 -05:00
|
|
|
self.delete_room(room_idx);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(corridor_drag) = self.corridor_drag_at_pointer(pointer_pos, geometry) {
|
2026-04-23 10:30:49 -05:00
|
|
|
let active_index = self.settings.active_level_index;
|
|
|
|
|
if corridor_drag.corridor_index < self.levels[active_index].corridors.len() {
|
2026-03-24 09:06:48 -05:00
|
|
|
self.push_undo_snapshot();
|
2026-04-23 10:30:49 -05:00
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
layout.corridors.remove(corridor_drag.corridor_index);
|
2026-03-12 09:58:08 -05:00
|
|
|
self.drag_state = None;
|
|
|
|
|
self.refresh_doors();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Remove a room and update corridors/doors to match.
|
2026-03-12 09:58:08 -05:00
|
|
|
fn delete_room(&mut self, room_idx: usize) {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
2026-03-12 09:58:08 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2026-04-23 10:30:49 -05:00
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
|
|
|
|
if room_idx >= layout.rooms.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
layout.rooms.remove(room_idx);
|
|
|
|
|
layout
|
2026-03-12 09:58:08 -05:00
|
|
|
.corridors
|
|
|
|
|
.retain(|c| c.start_room_id != room_idx && c.end_room_id != room_idx);
|
2026-04-23 10:30:49 -05:00
|
|
|
for corridor in &mut layout.corridors {
|
2026-03-12 09:58:08 -05:00
|
|
|
if corridor.start_room_id > room_idx {
|
|
|
|
|
corridor.start_room_id -= 1;
|
|
|
|
|
}
|
|
|
|
|
if corridor.end_room_id > room_idx {
|
|
|
|
|
corridor.end_room_id -= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.drag_state = None;
|
|
|
|
|
self.refresh_doors();
|
|
|
|
|
}
|
2026-03-12 11:36:36 -05:00
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Add or update a door at the pointer edge.
|
2026-03-12 11:36:36 -05:00
|
|
|
fn add_door_at_pointer(
|
|
|
|
|
&mut self,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
2026-03-23 12:43:33 -05:00
|
|
|
kind: ManualDoorKind,
|
2026-03-12 11:36:36 -05:00
|
|
|
) {
|
2026-04-23 10:30:49 -05:00
|
|
|
if self.settings.active_level_index >= self.levels.len() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 11:36:36 -05:00
|
|
|
let Some(edge) = self.door_edge_at_pointer(pointer_pos, geometry) else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
2026-04-23 10:30:49 -05:00
|
|
|
|
|
|
|
|
self.push_undo_snapshot();
|
|
|
|
|
let layout = &mut self.levels[self.settings.active_level_index];
|
|
|
|
|
|
2026-03-12 11:36:36 -05:00
|
|
|
let target = normalized_edge(edge.0, edge.1);
|
2026-04-23 10:30:49 -05:00
|
|
|
if let Some(idx) = layout.doors.iter().position(|d| {
|
2026-03-12 11:36:36 -05:00
|
|
|
door_edges_for(d, self.settings.cols, self.settings.rows)
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|e| normalized_edge(e.0, e.1) == target)
|
|
|
|
|
}) {
|
2026-04-23 10:30:49 -05:00
|
|
|
let edges = door_edges_for(&layout.doors[idx], self.settings.cols, self.settings.rows);
|
2026-03-12 11:36:36 -05:00
|
|
|
let mut spawned = Vec::new();
|
|
|
|
|
for edge in edges {
|
|
|
|
|
if normalized_edge(edge.0, edge.1) == target {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-04-23 10:30:49 -05:00
|
|
|
if layout
|
2026-03-12 11:36:36 -05:00
|
|
|
.doors
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|d| normalized_edge(d.from, d.to) == normalized_edge(edge.0, edge.1))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
spawned.push(layout::Door {
|
|
|
|
|
from: edge.0,
|
|
|
|
|
to: edge.1,
|
|
|
|
|
width: 1,
|
|
|
|
|
span_width: false,
|
|
|
|
|
locked: false,
|
|
|
|
|
archway: true,
|
2026-03-23 12:43:33 -05:00
|
|
|
secret: false,
|
2026-03-23 12:49:00 -05:00
|
|
|
manual: true,
|
2026-03-12 11:36:36 -05:00
|
|
|
});
|
|
|
|
|
}
|
2026-04-23 10:30:49 -05:00
|
|
|
let door = &mut layout.doors[idx];
|
2026-03-23 12:43:33 -05:00
|
|
|
door.locked = kind == ManualDoorKind::Locked;
|
2026-04-07 11:28:34 -05:00
|
|
|
door.archway = kind == ManualDoorKind::Archway;
|
2026-03-23 12:43:33 -05:00
|
|
|
door.secret = kind == ManualDoorKind::Secret;
|
2026-03-12 11:36:36 -05:00
|
|
|
door.width = 1;
|
|
|
|
|
door.span_width = false;
|
2026-03-23 12:49:00 -05:00
|
|
|
door.manual = true;
|
|
|
|
|
for edge in door_edges_for(door, self.settings.cols, self.settings.rows) {
|
|
|
|
|
self.suppressed_auto_door_edges.remove(&edge);
|
|
|
|
|
}
|
2026-04-23 10:30:49 -05:00
|
|
|
layout.doors.extend(spawned);
|
2026-03-12 11:36:36 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
let corridor_cells = corridor_cells(layout, self.settings.cols, self.settings.rows);
|
|
|
|
|
let a_room = room_index_at_cell(&layout.rooms, edge.0);
|
|
|
|
|
let b_room = room_index_at_cell(&layout.rooms, edge.1);
|
2026-03-12 11:36:36 -05:00
|
|
|
let a_in_corridor = corridor_cells.contains(&edge.0);
|
|
|
|
|
let b_in_corridor = corridor_cells.contains(&edge.1);
|
|
|
|
|
|
2026-04-07 11:28:34 -05:00
|
|
|
if !manual_door_edge_allowed(a_room, b_room, a_in_corridor, b_in_corridor) {
|
2026-03-12 11:36:36 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 10:30:49 -05:00
|
|
|
layout.doors.push(layout::Door {
|
2026-03-12 11:36:36 -05:00
|
|
|
from: edge.0,
|
|
|
|
|
to: edge.1,
|
|
|
|
|
width: 1,
|
|
|
|
|
span_width: false,
|
2026-03-23 12:43:33 -05:00
|
|
|
locked: kind == ManualDoorKind::Locked,
|
2026-04-07 11:28:34 -05:00
|
|
|
archway: kind == ManualDoorKind::Archway,
|
2026-03-23 12:43:33 -05:00
|
|
|
secret: kind == ManualDoorKind::Secret,
|
2026-03-23 12:49:00 -05:00
|
|
|
manual: true,
|
2026-03-12 11:36:36 -05:00
|
|
|
});
|
2026-03-23 12:49:00 -05:00
|
|
|
self.suppressed_auto_door_edges.remove(&target);
|
2026-03-12 11:36:36 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Find the nearest cell edge under the pointer for door placement.
|
2026-03-12 11:36:36 -05:00
|
|
|
fn door_edge_at_pointer(
|
|
|
|
|
&self,
|
|
|
|
|
pointer_pos: egui::Pos2,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
) -> Option<((usize, usize), (usize, usize))> {
|
|
|
|
|
let (grid_x, grid_y) = pointer_to_grid(pointer_pos, geometry)?;
|
|
|
|
|
let cell_x = grid_x.floor() as isize;
|
|
|
|
|
let cell_y = grid_y.floor() as isize;
|
|
|
|
|
if cell_x < 0
|
|
|
|
|
|| cell_y < 0
|
|
|
|
|
|| cell_x >= self.settings.cols as isize
|
|
|
|
|
|| cell_y >= self.settings.rows as isize
|
|
|
|
|
{
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let fx = grid_x - grid_x.floor();
|
|
|
|
|
let fy = grid_y - grid_y.floor();
|
|
|
|
|
let left = fx;
|
|
|
|
|
let right = 1.0 - fx;
|
|
|
|
|
let top = fy;
|
|
|
|
|
let bottom = 1.0 - fy;
|
|
|
|
|
|
|
|
|
|
let mut candidates = [
|
|
|
|
|
(left, (cell_x - 1, cell_y), (cell_x, cell_y)),
|
|
|
|
|
(right, (cell_x + 1, cell_y), (cell_x, cell_y)),
|
|
|
|
|
(top, (cell_x, cell_y - 1), (cell_x, cell_y)),
|
|
|
|
|
(bottom, (cell_x, cell_y + 1), (cell_x, cell_y)),
|
|
|
|
|
];
|
|
|
|
|
candidates.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap());
|
|
|
|
|
let (dist, a, b) = candidates[0];
|
|
|
|
|
if dist > 0.2 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let (ax, ay) = a;
|
|
|
|
|
let (bx, by) = b;
|
|
|
|
|
if ax < 0
|
|
|
|
|
|| ay < 0
|
|
|
|
|
|| bx < 0
|
|
|
|
|
|| by < 0
|
|
|
|
|
|| ax >= self.settings.cols as isize
|
|
|
|
|
|| bx >= self.settings.cols as isize
|
|
|
|
|
|| ay >= self.settings.rows as isize
|
|
|
|
|
|| by >= self.settings.rows as isize
|
|
|
|
|
{
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Some(((ax as usize, ay as usize), (bx as usize, by as usize)))
|
|
|
|
|
}
|
2026-03-06 09:56:26 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 10:26:23 -06:00
|
|
|
#[derive(Debug, Clone)]
|
2026-03-06 09:56:26 -06:00
|
|
|
struct RoomDragState {
|
|
|
|
|
room_idx: usize,
|
|
|
|
|
offset_x: f32,
|
|
|
|
|
offset_y: f32,
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
struct TextDragState {
|
|
|
|
|
text_idx: usize,
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 11:03:58 -05:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
struct MarkerDragState {
|
|
|
|
|
kind: MarkerKind,
|
|
|
|
|
marker_idx: usize,
|
|
|
|
|
offset_x: f32,
|
|
|
|
|
offset_y: f32,
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 10:26:23 -06:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
struct CorridorDragState {
|
|
|
|
|
corridor_index: usize,
|
|
|
|
|
original_path: Vec<(usize, usize)>,
|
|
|
|
|
original_cell: (usize, usize),
|
2026-03-06 09:56:26 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 09:58:08 -05:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
struct AddCorridorDrag {
|
|
|
|
|
start_cell: (usize, usize),
|
|
|
|
|
current_cell: (usize, usize),
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 10:42:12 -05:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
|
enum ResizeCorner {
|
|
|
|
|
TopLeft,
|
|
|
|
|
TopRight,
|
|
|
|
|
BottomLeft,
|
|
|
|
|
BottomRight,
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 10:31:26 -05:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
enum MarkerKind {
|
|
|
|
|
Start,
|
|
|
|
|
End,
|
2026-04-20 09:59:25 -05:00
|
|
|
Trap,
|
|
|
|
|
Monster,
|
2026-04-14 10:31:26 -05:00
|
|
|
}
|
|
|
|
|
|
2026-04-14 11:03:58 -05:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
enum HoverMarker {
|
|
|
|
|
Start(usize),
|
|
|
|
|
End(usize),
|
2026-04-20 09:59:25 -05:00
|
|
|
Trap(usize),
|
|
|
|
|
Monster(usize),
|
2026-04-14 11:03:58 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 10:42:12 -05:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
struct RoomResizeState {
|
|
|
|
|
room_idx: usize,
|
2026-04-07 10:53:55 -05:00
|
|
|
original_room: layout::Room,
|
|
|
|
|
resize_corner: ResizeCorner,
|
2026-03-12 10:42:12 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 10:26:23 -06:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
enum DragState {
|
|
|
|
|
Room(RoomDragState),
|
2026-03-24 09:25:44 -05:00
|
|
|
Text(TextDragState),
|
2026-04-14 11:03:58 -05:00
|
|
|
Marker(MarkerDragState),
|
2026-03-06 10:26:23 -06:00
|
|
|
Corridor(CorridorDragState),
|
2026-03-06 09:24:24 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
struct TextResizeState {
|
|
|
|
|
text_idx: usize,
|
|
|
|
|
origin_cell: (usize, usize),
|
|
|
|
|
original_font_size: u16,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
enum ResizeState {
|
|
|
|
|
Room(RoomResizeState),
|
|
|
|
|
Text(TextResizeState),
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 08:41:39 -06:00
|
|
|
struct GridGeometry {
|
|
|
|
|
rect: egui::Rect,
|
|
|
|
|
cell_size: f32,
|
2026-03-12 08:25:37 -05:00
|
|
|
cols: usize,
|
|
|
|
|
rows: usize,
|
2026-03-06 08:41:39 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw the grid and return geometry metrics for hit testing.
|
2026-03-06 08:41:39 -06:00
|
|
|
fn draw_grid(painter: &egui::Painter, area: egui::Rect, cols: usize, rows: usize) -> GridGeometry {
|
2026-03-05 19:17:01 -06:00
|
|
|
let cols = cols.max(1);
|
|
|
|
|
let rows = rows.max(1);
|
|
|
|
|
|
|
|
|
|
let cell_size = (area.width() / cols as f32).min(area.height() / rows as f32);
|
|
|
|
|
let grid_width = cell_size * cols as f32;
|
|
|
|
|
let grid_height = cell_size * rows as f32;
|
|
|
|
|
|
|
|
|
|
let grid_rect = egui::Rect::from_min_size(
|
|
|
|
|
egui::pos2(
|
|
|
|
|
area.center().x - (grid_width * 0.5),
|
|
|
|
|
area.center().y - (grid_height * 0.5),
|
|
|
|
|
),
|
|
|
|
|
egui::vec2(grid_width, grid_height),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let stroke = Stroke::new(1.0, Color32::from_gray(160));
|
|
|
|
|
painter.rect_stroke(grid_rect, 0.0, stroke, egui::StrokeKind::Middle);
|
|
|
|
|
|
|
|
|
|
for col in 1..cols {
|
|
|
|
|
let x = grid_rect.left() + (col as f32 * cell_size);
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[
|
|
|
|
|
egui::pos2(x, grid_rect.top()),
|
|
|
|
|
egui::pos2(x, grid_rect.bottom()),
|
|
|
|
|
],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for row in 1..rows {
|
|
|
|
|
let y = grid_rect.top() + (row as f32 * cell_size);
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[
|
|
|
|
|
egui::pos2(grid_rect.left(), y),
|
|
|
|
|
egui::pos2(grid_rect.right(), y),
|
|
|
|
|
],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-06 08:41:39 -06:00
|
|
|
|
|
|
|
|
GridGeometry {
|
|
|
|
|
rect: grid_rect,
|
|
|
|
|
cell_size,
|
2026-03-12 08:25:37 -05:00
|
|
|
cols,
|
|
|
|
|
rows,
|
2026-03-06 08:41:39 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Render rooms, corridors, walls, and doors in the main canvas.
|
2026-03-06 11:16:17 -06:00
|
|
|
fn draw_layout(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
layout: &DungeonLayout,
|
|
|
|
|
colorblind_mode: bool,
|
2026-03-24 09:25:44 -05:00
|
|
|
hover_text_idx: Option<usize>,
|
2026-04-14 11:03:58 -05:00
|
|
|
hover_marker: Option<HoverMarker>,
|
2026-03-06 11:16:17 -06:00
|
|
|
) {
|
2026-04-20 14:09:55 -05:00
|
|
|
let wall_width_px = (geometry.cell_size / 2.5).max(1.0);
|
2026-03-06 11:25:51 -06:00
|
|
|
let door_width_px = (geometry.cell_size / 10.0).max(1.0);
|
|
|
|
|
|
2026-03-06 08:41:39 -06:00
|
|
|
let room_fill = Color32::from_rgb(70, 120, 160);
|
|
|
|
|
let corridor_fill = Color32::from_rgb(210, 190, 120);
|
2026-03-06 14:42:08 -06:00
|
|
|
let wall_color = Color32::BLACK;
|
2026-03-12 08:25:37 -05:00
|
|
|
let corridor_cells_set = corridor_cells(layout, geometry.cols, geometry.rows);
|
|
|
|
|
let corridor_edges_set = corridor_edges_from_cells(&corridor_cells_set);
|
2026-03-06 11:16:17 -06:00
|
|
|
let mut room_cells_set = HashSet::new();
|
2026-03-12 08:25:37 -05:00
|
|
|
let room_edges_set = room_edges_from_rooms(&layout.rooms);
|
2026-03-06 11:16:17 -06:00
|
|
|
let mut door_edges_set = HashSet::new();
|
|
|
|
|
|
|
|
|
|
for door in &layout.doors {
|
2026-03-12 08:25:37 -05:00
|
|
|
for edge in door_edges_for(door, geometry.cols, geometry.rows) {
|
|
|
|
|
door_edges_set.insert(edge);
|
2026-03-06 09:19:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for &(col, row) in &corridor_cells_set {
|
|
|
|
|
painter.rect_filled(cell_rect(geometry, col, row), 0.0, corridor_fill);
|
2026-03-06 11:16:17 -06:00
|
|
|
if colorblind_mode {
|
|
|
|
|
painter.circle_filled(
|
|
|
|
|
cell_center(geometry, col, row),
|
|
|
|
|
geometry.cell_size * 0.14,
|
|
|
|
|
Color32::BLACK,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-06 09:19:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for &(col, row) in &corridor_cells_set {
|
|
|
|
|
let rect = cell_rect(geometry, col, row);
|
|
|
|
|
let right = (col + 1, row);
|
|
|
|
|
let bottom = (col, row + 1);
|
2026-03-06 11:16:17 -06:00
|
|
|
let left = col.checked_sub(1).map(|x| (x, row));
|
|
|
|
|
let top = row.checked_sub(1).map(|y| (col, y));
|
2026-03-06 09:19:03 -06:00
|
|
|
|
2026-03-06 11:16:17 -06:00
|
|
|
if col == 0
|
|
|
|
|
|| (!corridor_cells_set.contains(&(col - 1, row))
|
|
|
|
|
&& left
|
|
|
|
|
.map(|n| !door_edges_set.contains(&normalized_edge((col, row), n)))
|
|
|
|
|
.unwrap_or(true))
|
|
|
|
|
{
|
2026-03-06 14:42:08 -06:00
|
|
|
draw_wall_segment(
|
|
|
|
|
painter,
|
|
|
|
|
egui::pos2(rect.left(), rect.top()),
|
|
|
|
|
egui::pos2(rect.left(), rect.bottom()),
|
|
|
|
|
wall_width_px,
|
|
|
|
|
wall_color,
|
2026-03-06 09:19:03 -06:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-06 11:16:17 -06:00
|
|
|
if (!corridor_cells_set.contains(&right)
|
|
|
|
|
|| !corridor_edges_set.contains(&normalized_edge((col, row), right)))
|
|
|
|
|
&& !door_edges_set.contains(&normalized_edge((col, row), right))
|
2026-03-06 09:19:03 -06:00
|
|
|
{
|
2026-03-06 14:42:08 -06:00
|
|
|
draw_wall_segment(
|
|
|
|
|
painter,
|
|
|
|
|
egui::pos2(rect.right(), rect.top()),
|
|
|
|
|
egui::pos2(rect.right(), rect.bottom()),
|
|
|
|
|
wall_width_px,
|
|
|
|
|
wall_color,
|
2026-03-06 09:19:03 -06:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-06 11:16:17 -06:00
|
|
|
if row == 0
|
|
|
|
|
|| (!corridor_cells_set.contains(&(col, row - 1))
|
|
|
|
|
&& top
|
|
|
|
|
.map(|n| !door_edges_set.contains(&normalized_edge((col, row), n)))
|
|
|
|
|
.unwrap_or(true))
|
|
|
|
|
{
|
2026-03-06 14:42:08 -06:00
|
|
|
draw_wall_segment(
|
|
|
|
|
painter,
|
|
|
|
|
egui::pos2(rect.left(), rect.top()),
|
|
|
|
|
egui::pos2(rect.right(), rect.top()),
|
|
|
|
|
wall_width_px,
|
|
|
|
|
wall_color,
|
2026-03-06 09:19:03 -06:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-06 11:16:17 -06:00
|
|
|
if (!corridor_cells_set.contains(&bottom)
|
|
|
|
|
|| !corridor_edges_set.contains(&normalized_edge((col, row), bottom)))
|
|
|
|
|
&& !door_edges_set.contains(&normalized_edge((col, row), bottom))
|
2026-03-06 09:19:03 -06:00
|
|
|
{
|
2026-03-06 14:42:08 -06:00
|
|
|
draw_wall_segment(
|
|
|
|
|
painter,
|
|
|
|
|
egui::pos2(rect.left(), rect.bottom()),
|
|
|
|
|
egui::pos2(rect.right(), rect.bottom()),
|
|
|
|
|
wall_width_px,
|
|
|
|
|
wall_color,
|
2026-03-06 09:19:03 -06:00
|
|
|
);
|
2026-03-06 08:41:39 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for room in &layout.rooms {
|
2026-03-06 11:16:17 -06:00
|
|
|
for x in room.x..(room.x + room.width) {
|
|
|
|
|
for y in room.y..(room.y + room.height) {
|
|
|
|
|
room_cells_set.insert((x, y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 08:41:39 -06:00
|
|
|
let left = geometry.rect.left() + room.x as f32 * geometry.cell_size;
|
|
|
|
|
let top = geometry.rect.top() + room.y as f32 * geometry.cell_size;
|
|
|
|
|
let right = left + room.width as f32 * geometry.cell_size;
|
|
|
|
|
let bottom = top + room.height as f32 * geometry.cell_size;
|
|
|
|
|
let room_rect = egui::Rect::from_min_max(egui::pos2(left, top), egui::pos2(right, bottom));
|
|
|
|
|
|
|
|
|
|
painter.rect_filled(room_rect, 0.0, room_fill);
|
2026-03-06 11:16:17 -06:00
|
|
|
if colorblind_mode {
|
|
|
|
|
draw_room_crosshatch(painter, geometry, room, Stroke::new(1.5, Color32::BLACK));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for &(col, row) in &room_cells_set {
|
|
|
|
|
let rect = cell_rect(geometry, col, row);
|
|
|
|
|
let right = (col + 1, row);
|
|
|
|
|
let bottom = (col, row + 1);
|
|
|
|
|
let left = col.checked_sub(1).map(|x| (x, row));
|
|
|
|
|
let top = row.checked_sub(1).map(|y| (col, y));
|
|
|
|
|
|
2026-03-12 08:25:37 -05:00
|
|
|
let left_edge = col == 0
|
2026-03-06 11:16:17 -06:00
|
|
|
|| (!room_cells_set.contains(&(col - 1, row))
|
2026-03-12 08:25:37 -05:00
|
|
|
|| left
|
|
|
|
|
.map(|n| !room_edges_set.contains(&normalized_edge((col, row), n)))
|
|
|
|
|
.unwrap_or(true))
|
2026-03-06 11:16:17 -06:00
|
|
|
&& left
|
|
|
|
|
.map(|n| !door_edges_set.contains(&normalized_edge((col, row), n)))
|
2026-03-12 08:25:37 -05:00
|
|
|
.unwrap_or(true);
|
|
|
|
|
if left_edge {
|
2026-03-06 14:42:08 -06:00
|
|
|
draw_wall_segment(
|
|
|
|
|
painter,
|
|
|
|
|
egui::pos2(rect.left(), rect.top()),
|
|
|
|
|
egui::pos2(rect.left(), rect.bottom()),
|
|
|
|
|
wall_width_px,
|
|
|
|
|
wall_color,
|
2026-03-06 11:16:17 -06:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-12 08:25:37 -05:00
|
|
|
if (!room_cells_set.contains(&right)
|
|
|
|
|
|| !room_edges_set.contains(&normalized_edge((col, row), right)))
|
2026-03-06 11:16:17 -06:00
|
|
|
&& !door_edges_set.contains(&normalized_edge((col, row), right))
|
|
|
|
|
{
|
2026-03-06 14:42:08 -06:00
|
|
|
draw_wall_segment(
|
|
|
|
|
painter,
|
|
|
|
|
egui::pos2(rect.right(), rect.top()),
|
|
|
|
|
egui::pos2(rect.right(), rect.bottom()),
|
|
|
|
|
wall_width_px,
|
|
|
|
|
wall_color,
|
2026-03-06 11:16:17 -06:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-12 08:25:37 -05:00
|
|
|
let top_edge = row == 0
|
2026-03-06 11:16:17 -06:00
|
|
|
|| (!room_cells_set.contains(&(col, row - 1))
|
2026-03-12 08:25:37 -05:00
|
|
|
|| top
|
|
|
|
|
.map(|n| !room_edges_set.contains(&normalized_edge((col, row), n)))
|
|
|
|
|
.unwrap_or(true))
|
2026-03-06 11:16:17 -06:00
|
|
|
&& top
|
|
|
|
|
.map(|n| !door_edges_set.contains(&normalized_edge((col, row), n)))
|
2026-03-12 08:25:37 -05:00
|
|
|
.unwrap_or(true);
|
|
|
|
|
if top_edge {
|
2026-03-06 14:42:08 -06:00
|
|
|
draw_wall_segment(
|
|
|
|
|
painter,
|
|
|
|
|
egui::pos2(rect.left(), rect.top()),
|
|
|
|
|
egui::pos2(rect.right(), rect.top()),
|
|
|
|
|
wall_width_px,
|
|
|
|
|
wall_color,
|
2026-03-06 11:16:17 -06:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-12 08:25:37 -05:00
|
|
|
if (!room_cells_set.contains(&bottom)
|
|
|
|
|
|| !room_edges_set.contains(&normalized_edge((col, row), bottom)))
|
2026-03-06 11:16:17 -06:00
|
|
|
&& !door_edges_set.contains(&normalized_edge((col, row), bottom))
|
|
|
|
|
{
|
2026-03-06 14:42:08 -06:00
|
|
|
draw_wall_segment(
|
|
|
|
|
painter,
|
|
|
|
|
egui::pos2(rect.left(), rect.bottom()),
|
|
|
|
|
egui::pos2(rect.right(), rect.bottom()),
|
|
|
|
|
wall_width_px,
|
|
|
|
|
wall_color,
|
2026-03-06 11:16:17 -06:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-06 08:41:39 -06:00
|
|
|
}
|
2026-03-06 10:53:46 -06:00
|
|
|
|
|
|
|
|
for door in &layout.doors {
|
2026-03-06 11:16:17 -06:00
|
|
|
let color = if colorblind_mode {
|
|
|
|
|
Color32::BLACK
|
2026-03-23 12:43:33 -05:00
|
|
|
} else if door.secret {
|
|
|
|
|
Color32::from_rgb(170, 80, 170)
|
2026-03-06 11:16:17 -06:00
|
|
|
} else if door.archway {
|
2026-03-23 12:22:03 -05:00
|
|
|
Color32::from_rgb(230, 140, 60)
|
2026-03-06 10:53:46 -06:00
|
|
|
} else if door.locked {
|
|
|
|
|
Color32::from_rgb(220, 70, 70)
|
2026-03-12 09:11:48 -05:00
|
|
|
} else {
|
|
|
|
|
Color32::from_rgb(80, 200, 120)
|
2026-03-06 10:53:46 -06:00
|
|
|
};
|
2026-03-06 11:16:17 -06:00
|
|
|
let style = if colorblind_mode {
|
2026-03-23 12:43:33 -05:00
|
|
|
if door.secret {
|
|
|
|
|
DoorLineStyle::DashDotDot
|
|
|
|
|
} else if door.archway {
|
2026-03-06 11:16:17 -06:00
|
|
|
DoorLineStyle::Dotted
|
|
|
|
|
} else if door.locked {
|
|
|
|
|
DoorLineStyle::ShortDash
|
|
|
|
|
} else {
|
|
|
|
|
DoorLineStyle::LongDash
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
DoorLineStyle::Solid
|
|
|
|
|
};
|
2026-03-06 10:53:46 -06:00
|
|
|
draw_door_line(
|
|
|
|
|
painter,
|
|
|
|
|
geometry,
|
|
|
|
|
door.from,
|
|
|
|
|
door.to,
|
2026-03-12 11:36:36 -05:00
|
|
|
door_render_width(door),
|
2026-03-06 11:25:51 -06:00
|
|
|
Stroke::new(door_width_px, color),
|
2026-03-06 11:16:17 -06:00
|
|
|
style,
|
2026-03-06 10:53:46 -06:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-23 12:22:03 -05:00
|
|
|
|
|
|
|
|
for window in &layout.windows {
|
|
|
|
|
let style = if colorblind_mode {
|
|
|
|
|
DoorLineStyle::DashDot
|
|
|
|
|
} else {
|
|
|
|
|
DoorLineStyle::Solid
|
|
|
|
|
};
|
|
|
|
|
draw_window_line(
|
|
|
|
|
painter,
|
|
|
|
|
geometry,
|
|
|
|
|
window,
|
|
|
|
|
Stroke::new(door_width_px, Color32::from_rgb(70, 130, 220)),
|
|
|
|
|
style,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-24 09:25:44 -05:00
|
|
|
|
|
|
|
|
for (idx, label) in layout.text_labels.iter().enumerate() {
|
|
|
|
|
if hover_text_idx == Some(idx) {
|
|
|
|
|
painter.rect_stroke(
|
|
|
|
|
text_label_rect(geometry, label).expand(2.0),
|
|
|
|
|
0.0,
|
|
|
|
|
Stroke::new(2.0, Color32::from_rgb(255, 220, 120)),
|
|
|
|
|
egui::StrokeKind::Middle,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
let pos = cell_center(geometry, label.cell.0, label.cell.1);
|
|
|
|
|
let color = if colorblind_mode {
|
|
|
|
|
Color32::BLACK
|
|
|
|
|
} else {
|
|
|
|
|
Color32::WHITE
|
|
|
|
|
};
|
|
|
|
|
painter.text(
|
|
|
|
|
pos,
|
|
|
|
|
egui::Align2::CENTER_CENTER,
|
|
|
|
|
&label.text,
|
|
|
|
|
egui::FontId::proportional(label.font_size as f32),
|
|
|
|
|
color,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-14 10:31:26 -05:00
|
|
|
|
2026-04-14 12:02:24 -05:00
|
|
|
draw_area_marker_group(
|
|
|
|
|
painter,
|
|
|
|
|
geometry,
|
|
|
|
|
&layout.start_markers,
|
|
|
|
|
"S",
|
|
|
|
|
Color32::from_rgb(60, 220, 200),
|
|
|
|
|
colorblind_mode,
|
|
|
|
|
hover_marker,
|
|
|
|
|
MarkerKind::Start,
|
|
|
|
|
);
|
|
|
|
|
draw_area_marker_group(
|
|
|
|
|
painter,
|
|
|
|
|
geometry,
|
|
|
|
|
&layout.end_markers,
|
|
|
|
|
"E",
|
|
|
|
|
Color32::from_rgb(240, 90, 90),
|
|
|
|
|
colorblind_mode,
|
|
|
|
|
hover_marker,
|
|
|
|
|
MarkerKind::End,
|
|
|
|
|
);
|
2026-04-20 09:59:25 -05:00
|
|
|
draw_area_marker_group(
|
|
|
|
|
painter,
|
|
|
|
|
geometry,
|
|
|
|
|
&layout.trap_markers,
|
|
|
|
|
"T",
|
|
|
|
|
Color32::from_rgb(150, 80, 230), // Purple
|
|
|
|
|
colorblind_mode,
|
|
|
|
|
hover_marker,
|
|
|
|
|
MarkerKind::Trap,
|
|
|
|
|
);
|
|
|
|
|
draw_area_marker_group(
|
|
|
|
|
painter,
|
|
|
|
|
geometry,
|
|
|
|
|
&layout.monster_markers,
|
|
|
|
|
"M",
|
|
|
|
|
Color32::from_rgb(200, 50, 50), // Red
|
|
|
|
|
colorblind_mode,
|
|
|
|
|
hover_marker,
|
|
|
|
|
MarkerKind::Monster,
|
|
|
|
|
);
|
2026-03-06 08:41:39 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Compute the rectangle for a given grid cell.
|
2026-03-06 08:41:39 -06:00
|
|
|
fn cell_rect(geometry: &GridGeometry, col: usize, row: usize) -> egui::Rect {
|
|
|
|
|
let left = geometry.rect.left() + col as f32 * geometry.cell_size;
|
|
|
|
|
let top = geometry.rect.top() + row as f32 * geometry.cell_size;
|
|
|
|
|
egui::Rect::from_min_size(
|
|
|
|
|
egui::pos2(left, top),
|
|
|
|
|
egui::vec2(geometry.cell_size, geometry.cell_size),
|
|
|
|
|
)
|
2026-03-05 19:17:01 -06:00
|
|
|
}
|
2026-03-06 09:19:03 -06:00
|
|
|
|
2026-04-14 10:31:26 -05:00
|
|
|
fn marker_rect(marker: &layout::AreaMarker, geometry: &GridGeometry) -> egui::Rect {
|
|
|
|
|
let left = geometry.rect.left() + marker.cell.0 as f32 * geometry.cell_size;
|
|
|
|
|
let top = geometry.rect.top() + marker.cell.1 as f32 * geometry.cell_size;
|
|
|
|
|
egui::Rect::from_min_size(
|
|
|
|
|
egui::pos2(left, top),
|
|
|
|
|
egui::vec2(
|
|
|
|
|
marker.size as f32 * geometry.cell_size,
|
|
|
|
|
marker.size as f32 * geometry.cell_size,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn marker_contains_cell(marker: Option<&layout::AreaMarker>, cell: (usize, usize)) -> bool {
|
|
|
|
|
let Some(marker) = marker else {
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
cell.0 >= marker.cell.0
|
|
|
|
|
&& cell.0 < marker.cell.0 + marker.size
|
|
|
|
|
&& cell.1 >= marker.cell.1
|
|
|
|
|
&& cell.1 < marker.cell.1 + marker.size
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn centered_marker_origin(
|
|
|
|
|
cell: (usize, usize),
|
|
|
|
|
size: usize,
|
|
|
|
|
cols: usize,
|
|
|
|
|
rows: usize,
|
|
|
|
|
) -> (usize, usize) {
|
|
|
|
|
let size = size.clamp(1, 10).min(cols.max(1)).min(rows.max(1));
|
|
|
|
|
let half = size / 2;
|
|
|
|
|
let max_x = cols.saturating_sub(size);
|
|
|
|
|
let max_y = rows.saturating_sub(size);
|
2026-04-20 09:59:25 -05:00
|
|
|
(
|
|
|
|
|
cell.0.saturating_sub(half).min(max_x),
|
|
|
|
|
cell.1.saturating_sub(half).min(max_y),
|
|
|
|
|
)
|
2026-04-14 10:31:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw_area_marker(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
marker: &layout::AreaMarker,
|
|
|
|
|
label: &str,
|
|
|
|
|
base_color: Color32,
|
|
|
|
|
colorblind_mode: bool,
|
|
|
|
|
hovered: bool,
|
|
|
|
|
) {
|
|
|
|
|
let rect = marker_rect(marker, geometry);
|
|
|
|
|
let fill = base_color.gamma_multiply(if colorblind_mode { 0.22 } else { 0.35 });
|
|
|
|
|
let stroke_color = if hovered {
|
|
|
|
|
Color32::from_rgb(255, 220, 120)
|
|
|
|
|
} else if colorblind_mode {
|
|
|
|
|
Color32::BLACK
|
|
|
|
|
} else {
|
|
|
|
|
base_color
|
|
|
|
|
};
|
|
|
|
|
let text_color = if colorblind_mode {
|
|
|
|
|
Color32::BLACK
|
|
|
|
|
} else {
|
|
|
|
|
Color32::WHITE
|
|
|
|
|
};
|
|
|
|
|
let font_size = (geometry.cell_size * marker.size as f32 * 0.5).clamp(14.0, 72.0);
|
|
|
|
|
|
|
|
|
|
painter.rect_filled(rect, 4.0, fill);
|
|
|
|
|
painter.rect_stroke(
|
|
|
|
|
rect,
|
|
|
|
|
4.0,
|
|
|
|
|
Stroke::new(if hovered { 3.0 } else { 2.0 }, stroke_color),
|
|
|
|
|
egui::StrokeKind::Middle,
|
|
|
|
|
);
|
|
|
|
|
painter.text(
|
|
|
|
|
rect.center(),
|
|
|
|
|
egui::Align2::CENTER_CENTER,
|
|
|
|
|
label,
|
|
|
|
|
egui::FontId::proportional(font_size),
|
|
|
|
|
text_color,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 12:02:24 -05:00
|
|
|
fn draw_area_marker_group(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
markers: &[layout::AreaMarker],
|
|
|
|
|
label: &str,
|
|
|
|
|
base_color: Color32,
|
|
|
|
|
colorblind_mode: bool,
|
|
|
|
|
hover_marker: Option<HoverMarker>,
|
|
|
|
|
kind: MarkerKind,
|
|
|
|
|
) {
|
|
|
|
|
for (idx, marker) in markers.iter().enumerate() {
|
|
|
|
|
let hovered = match (kind, hover_marker) {
|
|
|
|
|
(MarkerKind::Start, Some(HoverMarker::Start(hover_idx))) => hover_idx == idx,
|
|
|
|
|
(MarkerKind::End, Some(HoverMarker::End(hover_idx))) => hover_idx == idx,
|
2026-04-20 09:59:25 -05:00
|
|
|
(MarkerKind::Trap, Some(HoverMarker::Trap(hover_idx))) => hover_idx == idx,
|
|
|
|
|
(MarkerKind::Monster, Some(HoverMarker::Monster(hover_idx))) => hover_idx == idx,
|
2026-04-14 12:02:24 -05:00
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
draw_area_marker(
|
|
|
|
|
painter,
|
|
|
|
|
geometry,
|
|
|
|
|
marker,
|
|
|
|
|
label,
|
|
|
|
|
base_color,
|
|
|
|
|
colorblind_mode,
|
|
|
|
|
hovered,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a rectangular wall segment between two points.
|
2026-03-06 14:42:08 -06:00
|
|
|
fn draw_wall_segment(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
from: egui::Pos2,
|
|
|
|
|
to: egui::Pos2,
|
|
|
|
|
width: f32,
|
|
|
|
|
color: Color32,
|
|
|
|
|
) {
|
|
|
|
|
let half = width * 0.5;
|
|
|
|
|
if (from.x - to.x).abs() <= f32::EPSILON {
|
|
|
|
|
let x = from.x.min(to.x);
|
|
|
|
|
let y0 = from.y.min(to.y);
|
|
|
|
|
let y1 = from.y.max(to.y);
|
|
|
|
|
let rect = egui::Rect::from_min_max(
|
|
|
|
|
egui::pos2(x - half, y0 - half),
|
|
|
|
|
egui::pos2(x + half, y1 + half),
|
|
|
|
|
);
|
|
|
|
|
painter.rect_filled(rect, 0.0, color);
|
|
|
|
|
} else {
|
|
|
|
|
let y = from.y.min(to.y);
|
|
|
|
|
let x0 = from.x.min(to.x);
|
|
|
|
|
let x1 = from.x.max(to.x);
|
|
|
|
|
let rect = egui::Rect::from_min_max(
|
|
|
|
|
egui::pos2(x0 - half, y - half),
|
|
|
|
|
egui::pos2(x1 + half, y + half),
|
|
|
|
|
);
|
|
|
|
|
painter.rect_filled(rect, 0.0, color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Normalize an edge tuple to a stable ordering.
|
2026-03-06 09:19:03 -06:00
|
|
|
fn normalized_edge(a: (usize, usize), b: (usize, usize)) -> ((usize, usize), (usize, usize)) {
|
|
|
|
|
if a <= b { (a, b) } else { (b, a) }
|
|
|
|
|
}
|
2026-03-06 09:56:26 -06:00
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Build a set of corridor-adjacent edges from corridor cells.
|
2026-03-12 08:25:37 -05:00
|
|
|
fn corridor_edges_from_cells(
|
|
|
|
|
corridor_cells: &HashSet<(usize, usize)>,
|
|
|
|
|
) -> HashSet<((usize, usize), (usize, usize))> {
|
|
|
|
|
let mut edges = HashSet::new();
|
|
|
|
|
for &(col, row) in corridor_cells {
|
|
|
|
|
let right = (col + 1, row);
|
|
|
|
|
let bottom = (col, row + 1);
|
|
|
|
|
if corridor_cells.contains(&right) {
|
|
|
|
|
edges.insert(normalized_edge((col, row), right));
|
|
|
|
|
}
|
|
|
|
|
if corridor_cells.contains(&bottom) {
|
|
|
|
|
edges.insert(normalized_edge((col, row), bottom));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
edges
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Build a set of internal room edges from room rectangles.
|
2026-03-12 08:25:37 -05:00
|
|
|
fn room_edges_from_rooms(rooms: &[layout::Room]) -> HashSet<((usize, usize), (usize, usize))> {
|
|
|
|
|
let mut edges = HashSet::new();
|
|
|
|
|
for room in rooms {
|
|
|
|
|
let x_end = room.x + room.width;
|
|
|
|
|
let y_end = room.y + room.height;
|
|
|
|
|
for x in room.x..x_end {
|
|
|
|
|
for y in room.y..y_end {
|
|
|
|
|
if x + 1 < x_end {
|
|
|
|
|
edges.insert(normalized_edge((x, y), (x + 1, y)));
|
|
|
|
|
}
|
|
|
|
|
if y + 1 < y_end {
|
|
|
|
|
edges.insert(normalized_edge((x, y), (x, y + 1)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
edges
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Find the index of the room containing a specific cell.
|
2026-03-12 09:58:08 -05:00
|
|
|
fn room_index_at_cell(rooms: &[layout::Room], cell: (usize, usize)) -> Option<usize> {
|
|
|
|
|
rooms.iter().position(|room| {
|
|
|
|
|
cell.0 >= room.x
|
|
|
|
|
&& cell.0 < room.x + room.width
|
|
|
|
|
&& cell.1 >= room.y
|
|
|
|
|
&& cell.1 < room.y + room.height
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Check whether two rooms overlap by area.
|
2026-03-12 09:58:08 -05:00
|
|
|
fn rooms_overlap(a: &layout::Room, b: &layout::Room) -> bool {
|
|
|
|
|
let a_right = a.x + a.width;
|
|
|
|
|
let a_bottom = a.y + a.height;
|
|
|
|
|
let b_right = b.x + b.width;
|
|
|
|
|
let b_bottom = b.y + b.height;
|
|
|
|
|
a.x < b_right && a_right > b.x && a.y < b_bottom && a_bottom > b.y
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 11:28:34 -05:00
|
|
|
fn manual_door_edge_allowed(
|
|
|
|
|
a_room: Option<usize>,
|
|
|
|
|
b_room: Option<usize>,
|
|
|
|
|
a_in_corridor: bool,
|
|
|
|
|
b_in_corridor: bool,
|
|
|
|
|
) -> bool {
|
|
|
|
|
if matches!((a_room, b_room), (Some(a), Some(b)) if a == b) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let a_is_feature = a_room.is_some() || a_in_corridor;
|
|
|
|
|
let b_is_feature = b_room.is_some() || b_in_corridor;
|
|
|
|
|
a_is_feature || b_is_feature
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:54:49 -05:00
|
|
|
fn resize_hit_cells(
|
|
|
|
|
room: &layout::Room,
|
|
|
|
|
room_idx: usize,
|
|
|
|
|
rooms: &[layout::Room],
|
|
|
|
|
cols: usize,
|
|
|
|
|
rows: usize,
|
|
|
|
|
) -> HashSet<(usize, usize)> {
|
|
|
|
|
let mut cells = HashSet::new();
|
|
|
|
|
let corners = [
|
|
|
|
|
(room.x as isize, room.y as isize, -1isize, -1isize),
|
|
|
|
|
(
|
|
|
|
|
(room.x + room.width - 1) as isize,
|
|
|
|
|
room.y as isize,
|
|
|
|
|
1isize,
|
|
|
|
|
-1isize,
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
room.x as isize,
|
|
|
|
|
(room.y + room.height - 1) as isize,
|
|
|
|
|
-1isize,
|
|
|
|
|
1isize,
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
(room.x + room.width - 1) as isize,
|
|
|
|
|
(room.y + room.height - 1) as isize,
|
|
|
|
|
1isize,
|
|
|
|
|
1isize,
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (cx, cy, ox, oy) in corners {
|
|
|
|
|
let candidates = [
|
|
|
|
|
(cx, cy),
|
|
|
|
|
(cx - ox, cy),
|
|
|
|
|
(cx, cy - oy),
|
|
|
|
|
(cx - ox, cy - oy),
|
|
|
|
|
(cx + ox, cy),
|
|
|
|
|
(cx, cy + oy),
|
|
|
|
|
(cx + ox, cy + oy),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (x, y) in candidates {
|
|
|
|
|
if x < 0 || y < 0 || x >= cols as isize || y >= rows as isize {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let cell = (x as usize, y as usize);
|
|
|
|
|
let in_other_room = rooms.iter().enumerate().any(|(idx, other_room)| {
|
|
|
|
|
idx != room_idx
|
|
|
|
|
&& cell.0 >= other_room.x
|
|
|
|
|
&& cell.0 < other_room.x + other_room.width
|
|
|
|
|
&& cell.1 >= other_room.y
|
|
|
|
|
&& cell.1 < other_room.y + other_room.height
|
|
|
|
|
});
|
|
|
|
|
if !in_other_room {
|
|
|
|
|
cells.insert(cell);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cells
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a single resize handle glyph at a corner.
|
2026-03-12 10:42:12 -05:00
|
|
|
fn draw_resize_handle(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
corner: egui::Pos2,
|
|
|
|
|
which: ResizeCorner,
|
|
|
|
|
color: Color32,
|
|
|
|
|
) {
|
|
|
|
|
let size = 10.0;
|
|
|
|
|
let half = size * 0.5;
|
|
|
|
|
let rect = egui::Rect::from_center_size(corner, egui::vec2(size, size));
|
|
|
|
|
painter.rect_filled(rect, 2.0, Color32::from_gray(30));
|
|
|
|
|
painter.rect_stroke(rect, 2.0, Stroke::new(1.0, color), egui::StrokeKind::Middle);
|
|
|
|
|
|
|
|
|
|
let center = corner;
|
|
|
|
|
let stroke = Stroke::new(1.0, color);
|
|
|
|
|
match which {
|
|
|
|
|
ResizeCorner::TopLeft => {
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[center, egui::pos2(center.x - half + 2.0, center.y)],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[center, egui::pos2(center.x, center.y - half + 2.0)],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
ResizeCorner::TopRight => {
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[center, egui::pos2(center.x + half - 2.0, center.y)],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[center, egui::pos2(center.x, center.y - half + 2.0)],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
ResizeCorner::BottomLeft => {
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[center, egui::pos2(center.x - half + 2.0, center.y)],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[center, egui::pos2(center.x, center.y + half - 2.0)],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
ResizeCorner::BottomRight => {
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[center, egui::pos2(center.x + half - 2.0, center.y)],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
painter.line_segment(
|
|
|
|
|
[center, egui::pos2(center.x, center.y + half - 2.0)],
|
|
|
|
|
stroke,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Expand a door into all grid edges it spans based on width.
|
2026-03-12 08:25:37 -05:00
|
|
|
fn door_edges_for(
|
|
|
|
|
door: &layout::Door,
|
|
|
|
|
cols: usize,
|
|
|
|
|
rows: usize,
|
|
|
|
|
) -> Vec<((usize, usize), (usize, usize))> {
|
|
|
|
|
let mut edges = Vec::new();
|
|
|
|
|
if door.from.0.abs_diff(door.to.0) + door.from.1.abs_diff(door.to.1) != 1 {
|
|
|
|
|
return edges;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 11:36:36 -05:00
|
|
|
let width = door_render_width(door).max(1) as isize;
|
2026-03-12 08:25:37 -05:00
|
|
|
let min_offset = -((width - 1) / 2);
|
|
|
|
|
let max_offset = width / 2;
|
|
|
|
|
|
|
|
|
|
if door.from.0 != door.to.0 {
|
|
|
|
|
let y = door.from.1 as isize;
|
|
|
|
|
for dy in min_offset..=max_offset {
|
|
|
|
|
let ny = y + dy;
|
|
|
|
|
if ny < 0 || ny >= rows as isize {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let a = (door.from.0, ny as usize);
|
|
|
|
|
let b = (door.to.0, ny as usize);
|
|
|
|
|
edges.push(normalized_edge(a, b));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let x = door.from.0 as isize;
|
|
|
|
|
for dx in min_offset..=max_offset {
|
|
|
|
|
let nx = x + dx;
|
|
|
|
|
if nx < 0 || nx >= cols as isize {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let a = (nx as usize, door.from.1);
|
|
|
|
|
let b = (nx as usize, door.to.1);
|
|
|
|
|
edges.push(normalized_edge(a, b));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
edges
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Determine the rendered door width in cells.
|
2026-03-12 11:36:36 -05:00
|
|
|
fn door_render_width(door: &layout::Door) -> usize {
|
|
|
|
|
if door.span_width {
|
|
|
|
|
door.width.max(1)
|
|
|
|
|
} else {
|
|
|
|
|
1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:22:03 -05:00
|
|
|
fn window_render_width(window: &layout::Window) -> usize {
|
|
|
|
|
if window.span_width {
|
|
|
|
|
window.width.max(1)
|
|
|
|
|
} else {
|
|
|
|
|
1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Convert a pointer position to grid coordinates if inside the grid.
|
2026-03-06 09:56:26 -06:00
|
|
|
fn pointer_to_grid(pointer_pos: egui::Pos2, geometry: &GridGeometry) -> Option<(f32, f32)> {
|
|
|
|
|
if !geometry.rect.contains(pointer_pos) {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let x = (pointer_pos.x - geometry.rect.left()) / geometry.cell_size;
|
|
|
|
|
let y = (pointer_pos.y - geometry.rect.top()) / geometry.cell_size;
|
|
|
|
|
Some((x, y))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Recompute a path that must pass through a target cell.
|
2026-03-06 10:26:23 -06:00
|
|
|
fn reroute_path_through_cell(
|
|
|
|
|
original_path: &[(usize, usize)],
|
|
|
|
|
original_cell: (usize, usize),
|
|
|
|
|
target_cell: (usize, usize),
|
2026-03-06 09:56:26 -06:00
|
|
|
cols: usize,
|
|
|
|
|
rows: usize,
|
2026-03-20 10:52:44 -05:00
|
|
|
blocked_room_cells_set: &HashSet<(usize, usize)>,
|
2026-03-06 10:26:23 -06:00
|
|
|
) -> Option<Vec<(usize, usize)>> {
|
|
|
|
|
let (&start, &end) = (original_path.first()?, original_path.last()?);
|
|
|
|
|
if start == end {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 10:52:44 -05:00
|
|
|
let mut blocked = blocked_room_cells_set.clone();
|
2026-03-06 10:26:23 -06:00
|
|
|
blocked.insert(original_cell);
|
|
|
|
|
blocked.remove(&start);
|
|
|
|
|
blocked.remove(&end);
|
|
|
|
|
blocked.remove(&target_cell);
|
|
|
|
|
|
|
|
|
|
let first_leg = shortest_path_cells(start, target_cell, cols, rows, &blocked)?;
|
|
|
|
|
|
|
|
|
|
let mut blocked_second = blocked.clone();
|
|
|
|
|
for &cell in first_leg
|
|
|
|
|
.iter()
|
|
|
|
|
.skip(1)
|
|
|
|
|
.take(first_leg.len().saturating_sub(2))
|
|
|
|
|
{
|
|
|
|
|
if cell != target_cell && cell != end {
|
|
|
|
|
blocked_second.insert(cell);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let second_leg = shortest_path_cells(target_cell, end, cols, rows, &blocked_second)
|
|
|
|
|
.or_else(|| shortest_path_cells(target_cell, end, cols, rows, &blocked))?;
|
|
|
|
|
|
|
|
|
|
let mut full_path = first_leg;
|
|
|
|
|
for cell in second_leg.into_iter().skip(1) {
|
|
|
|
|
if full_path.last().copied() != Some(cell) {
|
|
|
|
|
full_path.push(cell);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
simplify_path_loops(&mut full_path);
|
|
|
|
|
|
|
|
|
|
if full_path.len() < 2 || !full_path.contains(&target_cell) {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if original_cell != start && original_cell != end && full_path.contains(&original_cell) {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Some(full_path)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Remove loops in a path by truncating back to repeated cells.
|
2026-03-06 10:26:23 -06:00
|
|
|
fn simplify_path_loops(path: &mut Vec<(usize, usize)>) {
|
|
|
|
|
let mut out = Vec::new();
|
|
|
|
|
for &cell in path.iter() {
|
|
|
|
|
if let Some(pos) = out.iter().position(|&c| c == cell) {
|
|
|
|
|
out.truncate(pos + 1);
|
|
|
|
|
} else {
|
|
|
|
|
out.push(cell);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*path = out;
|
2026-03-06 09:56:26 -06:00
|
|
|
}
|
2026-03-06 10:53:46 -06:00
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Convert UI door settings into layout door settings.
|
2026-03-06 10:53:46 -06:00
|
|
|
fn door_settings_from_ui(settings: &UiSettings) -> DoorSettings {
|
|
|
|
|
DoorSettings {
|
|
|
|
|
frequency_percent: settings.door_frequency_percent,
|
|
|
|
|
room_hallway_percent: settings.room_hallway_door_percent,
|
|
|
|
|
locked_percent: settings.locked_door_percent,
|
2026-03-23 12:43:33 -05:00
|
|
|
secret_percent: settings.secret_door_percent,
|
2026-03-06 10:53:46 -06:00
|
|
|
allow_middle_corridor_doors: settings.allow_middle_corridor_doors,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:22:03 -05:00
|
|
|
fn window_settings_from_ui(settings: &UiSettings) -> WindowSettings {
|
|
|
|
|
WindowSettings {
|
|
|
|
|
enabled: settings.windows_enabled,
|
|
|
|
|
min_width: settings.min_window_width,
|
|
|
|
|
max_width: settings.max_window_width,
|
|
|
|
|
frequency_percent: settings.window_frequency_percent,
|
|
|
|
|
room_hallway_percent: settings.room_hallway_window_percent,
|
|
|
|
|
allow_internal_windows: settings.allow_internal_windows,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a door line segment with a selected style.
|
2026-03-06 10:53:46 -06:00
|
|
|
fn draw_door_line(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
a: (usize, usize),
|
|
|
|
|
b: (usize, usize),
|
2026-03-12 08:25:37 -05:00
|
|
|
width_cells: usize,
|
2026-03-06 10:53:46 -06:00
|
|
|
stroke: Stroke,
|
2026-03-06 11:16:17 -06:00
|
|
|
style: DoorLineStyle,
|
2026-03-06 10:53:46 -06:00
|
|
|
) {
|
|
|
|
|
if a.0.abs_diff(b.0) + a.1.abs_diff(b.1) != 1 {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 08:25:37 -05:00
|
|
|
let width_cells = width_cells.max(1);
|
|
|
|
|
let min_offset = -((width_cells as isize - 1) / 2);
|
|
|
|
|
let max_offset = width_cells as isize / 2;
|
|
|
|
|
|
2026-03-06 10:53:46 -06:00
|
|
|
if a.0 != b.0 {
|
|
|
|
|
let x = geometry.rect.left() + (a.0.max(b.0) as f32) * geometry.cell_size;
|
2026-03-12 08:25:37 -05:00
|
|
|
let row = a.1 as isize;
|
|
|
|
|
let y0_cell = (row + min_offset).clamp(0, geometry.rows.saturating_sub(1) as isize);
|
|
|
|
|
let y1_cell = (row + max_offset).clamp(0, geometry.rows.saturating_sub(1) as isize);
|
|
|
|
|
let y0 = geometry.rect.top() + y0_cell as f32 * geometry.cell_size;
|
|
|
|
|
let y1 = geometry.rect.top() + (y1_cell as f32 + 1.0) * geometry.cell_size;
|
2026-03-06 11:16:17 -06:00
|
|
|
draw_styled_line(painter, egui::pos2(x, y0), egui::pos2(x, y1), stroke, style);
|
2026-03-06 10:53:46 -06:00
|
|
|
} else {
|
|
|
|
|
let y = geometry.rect.top() + (a.1.max(b.1) as f32) * geometry.cell_size;
|
2026-03-12 08:25:37 -05:00
|
|
|
let col = a.0 as isize;
|
|
|
|
|
let x0_cell = (col + min_offset).clamp(0, geometry.cols.saturating_sub(1) as isize);
|
|
|
|
|
let x1_cell = (col + max_offset).clamp(0, geometry.cols.saturating_sub(1) as isize);
|
|
|
|
|
let x0 = geometry.rect.left() + x0_cell as f32 * geometry.cell_size;
|
|
|
|
|
let x1 = geometry.rect.left() + (x1_cell as f32 + 1.0) * geometry.cell_size;
|
2026-03-06 11:16:17 -06:00
|
|
|
draw_styled_line(painter, egui::pos2(x0, y), egui::pos2(x1, y), stroke, style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:22:03 -05:00
|
|
|
fn draw_window_line(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
window: &layout::Window,
|
|
|
|
|
stroke: Stroke,
|
|
|
|
|
style: DoorLineStyle,
|
|
|
|
|
) {
|
|
|
|
|
let width_cells = window_render_width(window).max(1) as isize;
|
|
|
|
|
let min_offset = -((width_cells - 1) / 2);
|
|
|
|
|
let max_offset = width_cells / 2;
|
|
|
|
|
|
|
|
|
|
match window.side {
|
|
|
|
|
layout::WindowSide::Left => {
|
|
|
|
|
let x = geometry.rect.left() + window.cell.0 as f32 * geometry.cell_size;
|
|
|
|
|
let row = window.cell.1 as isize;
|
|
|
|
|
let y0_cell = (row + min_offset).clamp(0, geometry.rows.saturating_sub(1) as isize);
|
|
|
|
|
let y1_cell = (row + max_offset).clamp(0, geometry.rows.saturating_sub(1) as isize);
|
|
|
|
|
let y0 = geometry.rect.top() + y0_cell as f32 * geometry.cell_size;
|
|
|
|
|
let y1 = geometry.rect.top() + (y1_cell as f32 + 1.0) * geometry.cell_size;
|
|
|
|
|
draw_styled_line(painter, egui::pos2(x, y0), egui::pos2(x, y1), stroke, style);
|
|
|
|
|
}
|
|
|
|
|
layout::WindowSide::Right => {
|
|
|
|
|
let x = geometry.rect.left() + (window.cell.0 as f32 + 1.0) * geometry.cell_size;
|
|
|
|
|
let row = window.cell.1 as isize;
|
|
|
|
|
let y0_cell = (row + min_offset).clamp(0, geometry.rows.saturating_sub(1) as isize);
|
|
|
|
|
let y1_cell = (row + max_offset).clamp(0, geometry.rows.saturating_sub(1) as isize);
|
|
|
|
|
let y0 = geometry.rect.top() + y0_cell as f32 * geometry.cell_size;
|
|
|
|
|
let y1 = geometry.rect.top() + (y1_cell as f32 + 1.0) * geometry.cell_size;
|
|
|
|
|
draw_styled_line(painter, egui::pos2(x, y0), egui::pos2(x, y1), stroke, style);
|
|
|
|
|
}
|
|
|
|
|
layout::WindowSide::Top => {
|
|
|
|
|
let y = geometry.rect.top() + window.cell.1 as f32 * geometry.cell_size;
|
|
|
|
|
let col = window.cell.0 as isize;
|
|
|
|
|
let x0_cell = (col + min_offset).clamp(0, geometry.cols.saturating_sub(1) as isize);
|
|
|
|
|
let x1_cell = (col + max_offset).clamp(0, geometry.cols.saturating_sub(1) as isize);
|
|
|
|
|
let x0 = geometry.rect.left() + x0_cell as f32 * geometry.cell_size;
|
|
|
|
|
let x1 = geometry.rect.left() + (x1_cell as f32 + 1.0) * geometry.cell_size;
|
|
|
|
|
draw_styled_line(painter, egui::pos2(x0, y), egui::pos2(x1, y), stroke, style);
|
|
|
|
|
}
|
|
|
|
|
layout::WindowSide::Bottom => {
|
|
|
|
|
let y = geometry.rect.top() + (window.cell.1 as f32 + 1.0) * geometry.cell_size;
|
|
|
|
|
let col = window.cell.0 as isize;
|
|
|
|
|
let x0_cell = (col + min_offset).clamp(0, geometry.cols.saturating_sub(1) as isize);
|
|
|
|
|
let x1_cell = (col + max_offset).clamp(0, geometry.cols.saturating_sub(1) as isize);
|
|
|
|
|
let x0 = geometry.rect.left() + x0_cell as f32 * geometry.cell_size;
|
|
|
|
|
let x1 = geometry.rect.left() + (x1_cell as f32 + 1.0) * geometry.cell_size;
|
|
|
|
|
draw_styled_line(painter, egui::pos2(x0, y), egui::pos2(x1, y), stroke, style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 11:16:17 -06:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
|
enum DoorLineStyle {
|
|
|
|
|
Solid,
|
|
|
|
|
LongDash,
|
|
|
|
|
ShortDash,
|
|
|
|
|
Dotted,
|
2026-03-23 12:22:03 -05:00
|
|
|
DashDot,
|
2026-03-23 12:43:33 -05:00
|
|
|
DashDotDot,
|
2026-03-06 11:16:17 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a line with solid, dashed, or dotted styling.
|
2026-03-06 11:16:17 -06:00
|
|
|
fn draw_styled_line(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
from: egui::Pos2,
|
|
|
|
|
to: egui::Pos2,
|
|
|
|
|
stroke: Stroke,
|
|
|
|
|
style: DoorLineStyle,
|
|
|
|
|
) {
|
|
|
|
|
match style {
|
|
|
|
|
DoorLineStyle::Solid => {
|
|
|
|
|
painter.line_segment([from, to], stroke);
|
|
|
|
|
}
|
|
|
|
|
DoorLineStyle::LongDash => draw_dashed_line(painter, from, to, stroke, 14.0, 7.0),
|
|
|
|
|
DoorLineStyle::ShortDash => draw_dashed_line(painter, from, to, stroke, 6.0, 4.0),
|
|
|
|
|
DoorLineStyle::Dotted => draw_dotted_line(painter, from, to, stroke),
|
2026-03-23 12:22:03 -05:00
|
|
|
DoorLineStyle::DashDot => draw_dash_dot_line(painter, from, to, stroke),
|
2026-03-23 12:43:33 -05:00
|
|
|
DoorLineStyle::DashDotDot => draw_dash_dot_dot_line(painter, from, to, stroke),
|
2026-03-06 11:16:17 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a dashed line between two points.
|
2026-03-06 11:16:17 -06:00
|
|
|
fn draw_dashed_line(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
from: egui::Pos2,
|
|
|
|
|
to: egui::Pos2,
|
|
|
|
|
stroke: Stroke,
|
|
|
|
|
dash_len: f32,
|
|
|
|
|
gap_len: f32,
|
|
|
|
|
) {
|
|
|
|
|
let dx = to.x - from.x;
|
|
|
|
|
let dy = to.y - from.y;
|
|
|
|
|
let len = (dx * dx + dy * dy).sqrt();
|
|
|
|
|
if len <= 0.0 {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let ux = dx / len;
|
|
|
|
|
let uy = dy / len;
|
|
|
|
|
|
|
|
|
|
let mut dist = 0.0_f32;
|
|
|
|
|
while dist < len {
|
|
|
|
|
let seg_start = dist;
|
|
|
|
|
let seg_end = (dist + dash_len).min(len);
|
|
|
|
|
let p0 = egui::pos2(from.x + ux * seg_start, from.y + uy * seg_start);
|
|
|
|
|
let p1 = egui::pos2(from.x + ux * seg_end, from.y + uy * seg_end);
|
|
|
|
|
painter.line_segment([p0, p1], stroke);
|
|
|
|
|
dist += dash_len + gap_len;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a dotted line between two points.
|
2026-03-06 11:16:17 -06:00
|
|
|
fn draw_dotted_line(painter: &egui::Painter, from: egui::Pos2, to: egui::Pos2, stroke: Stroke) {
|
|
|
|
|
let dx = to.x - from.x;
|
|
|
|
|
let dy = to.y - from.y;
|
|
|
|
|
let len = (dx * dx + dy * dy).sqrt();
|
|
|
|
|
if len <= 0.0 {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let ux = dx / len;
|
|
|
|
|
let uy = dy / len;
|
|
|
|
|
let step = 5.0_f32;
|
|
|
|
|
let radius = (stroke.width * 0.35).max(1.0);
|
|
|
|
|
|
|
|
|
|
let mut dist = 0.0_f32;
|
|
|
|
|
while dist <= len {
|
|
|
|
|
let p = egui::pos2(from.x + ux * dist, from.y + uy * dist);
|
|
|
|
|
painter.circle_filled(p, radius, stroke.color);
|
|
|
|
|
dist += step;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:22:03 -05:00
|
|
|
fn draw_dash_dot_line(painter: &egui::Painter, from: egui::Pos2, to: egui::Pos2, stroke: Stroke) {
|
|
|
|
|
let dx = to.x - from.x;
|
|
|
|
|
let dy = to.y - from.y;
|
|
|
|
|
let len = (dx * dx + dy * dy).sqrt();
|
|
|
|
|
if len <= 0.0 {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let ux = dx / len;
|
|
|
|
|
let uy = dy / len;
|
|
|
|
|
let mut dist = 0.0_f32;
|
|
|
|
|
while dist < len {
|
|
|
|
|
let dash_end = (dist + 7.0).min(len);
|
|
|
|
|
let p0 = egui::pos2(from.x + ux * dist, from.y + uy * dist);
|
|
|
|
|
let p1 = egui::pos2(from.x + ux * dash_end, from.y + uy * dash_end);
|
|
|
|
|
painter.line_segment([p0, p1], stroke);
|
|
|
|
|
dist = dash_end + 3.0;
|
|
|
|
|
if dist >= len {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
let dot = egui::pos2(from.x + ux * dist, from.y + uy * dist);
|
|
|
|
|
painter.circle_filled(dot, (stroke.width * 0.35).max(1.0), stroke.color);
|
|
|
|
|
dist += 4.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:43:33 -05:00
|
|
|
fn draw_dash_dot_dot_line(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
from: egui::Pos2,
|
|
|
|
|
to: egui::Pos2,
|
|
|
|
|
stroke: Stroke,
|
|
|
|
|
) {
|
|
|
|
|
let dx = to.x - from.x;
|
|
|
|
|
let dy = to.y - from.y;
|
|
|
|
|
let len = (dx * dx + dy * dy).sqrt();
|
|
|
|
|
if len <= 0.0 {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let ux = dx / len;
|
|
|
|
|
let uy = dy / len;
|
|
|
|
|
let radius = (stroke.width * 0.35).max(1.0);
|
|
|
|
|
let mut dist = 0.0_f32;
|
|
|
|
|
while dist < len {
|
|
|
|
|
let dash_end = (dist + 7.0).min(len);
|
|
|
|
|
let p0 = egui::pos2(from.x + ux * dist, from.y + uy * dist);
|
|
|
|
|
let p1 = egui::pos2(from.x + ux * dash_end, from.y + uy * dash_end);
|
|
|
|
|
painter.line_segment([p0, p1], stroke);
|
|
|
|
|
dist = dash_end + 3.0;
|
|
|
|
|
if dist >= len {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
let dot1 = egui::pos2(from.x + ux * dist, from.y + uy * dist);
|
|
|
|
|
painter.circle_filled(dot1, radius, stroke.color);
|
|
|
|
|
dist += 3.0;
|
|
|
|
|
if dist >= len {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
let dot2 = egui::pos2(from.x + ux * dist, from.y + uy * dist);
|
|
|
|
|
painter.circle_filled(dot2, radius, stroke.color);
|
|
|
|
|
dist += 4.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Compute the center position of a grid cell.
|
2026-03-06 11:16:17 -06:00
|
|
|
fn cell_center(geometry: &GridGeometry, col: usize, row: usize) -> egui::Pos2 {
|
|
|
|
|
egui::pos2(
|
|
|
|
|
geometry.rect.left() + (col as f32 + 0.5) * geometry.cell_size,
|
|
|
|
|
geometry.rect.top() + (row as f32 + 0.5) * geometry.cell_size,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 09:25:44 -05:00
|
|
|
fn text_label_rect(geometry: &GridGeometry, label: &layout::TextLabel) -> egui::Rect {
|
|
|
|
|
let center = cell_center(geometry, label.cell.0, label.cell.1);
|
|
|
|
|
let font_size = label.font_size as f32;
|
|
|
|
|
let width =
|
|
|
|
|
(label.text.chars().count().max(1) as f32 * font_size * 0.6).max(geometry.cell_size * 0.5);
|
|
|
|
|
let height = font_size.max(geometry.cell_size * 0.35);
|
|
|
|
|
egui::Rect::from_center_size(center, egui::vec2(width, height))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a crosshatch pattern inside a room for colorblind mode.
|
2026-03-06 11:16:17 -06:00
|
|
|
fn draw_room_crosshatch(
|
|
|
|
|
painter: &egui::Painter,
|
|
|
|
|
geometry: &GridGeometry,
|
|
|
|
|
room: &layout::Room,
|
|
|
|
|
stroke: Stroke,
|
|
|
|
|
) {
|
|
|
|
|
for x in room.x..(room.x + room.width) {
|
|
|
|
|
for y in room.y..(room.y + room.height) {
|
|
|
|
|
let rect = cell_rect(geometry, x, y).shrink(2.0);
|
|
|
|
|
painter.line_segment([rect.left_top(), rect.right_bottom()], stroke);
|
|
|
|
|
painter.line_segment([rect.right_top(), rect.left_bottom()], stroke);
|
|
|
|
|
}
|
2026-03-06 10:53:46 -06:00
|
|
|
}
|
|
|
|
|
}
|
2026-03-06 10:58:21 -06:00
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a colored legend entry in the sidebar.
|
2026-03-06 10:58:21 -06:00
|
|
|
fn draw_legend_entry(ui: &mut egui::Ui, color: Color32, label: &str) {
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
let (rect, _resp) = ui.allocate_exact_size(egui::vec2(16.0, 16.0), egui::Sense::hover());
|
|
|
|
|
ui.painter().rect_filled(rect, 0.0, color);
|
|
|
|
|
ui.painter().rect_stroke(
|
|
|
|
|
rect,
|
|
|
|
|
0.0,
|
|
|
|
|
Stroke::new(1.0, Color32::WHITE),
|
|
|
|
|
egui::StrokeKind::Middle,
|
|
|
|
|
);
|
|
|
|
|
ui.add_space(6.0);
|
|
|
|
|
ui.label(label);
|
|
|
|
|
});
|
|
|
|
|
ui.add_space(4.0);
|
|
|
|
|
}
|
2026-03-06 11:16:17 -06:00
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
|
enum LegendStyle {
|
|
|
|
|
Crosshatch,
|
|
|
|
|
Dots,
|
|
|
|
|
SolidLine,
|
|
|
|
|
LongDash,
|
|
|
|
|
ShortDash,
|
|
|
|
|
DottedLine,
|
2026-03-23 12:22:03 -05:00
|
|
|
DashDotLine,
|
2026-03-23 12:43:33 -05:00
|
|
|
DashDotDotLine,
|
2026-03-06 11:16:17 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 13:49:42 -05:00
|
|
|
// Draw a patterned legend entry for colorblind mode.
|
2026-03-06 11:16:17 -06:00
|
|
|
fn draw_legend_entry_colorblind(ui: &mut egui::Ui, label: &str, style: LegendStyle) {
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
let (rect, _resp) = ui.allocate_exact_size(egui::vec2(16.0, 16.0), egui::Sense::hover());
|
|
|
|
|
ui.painter().rect_filled(rect, 0.0, Color32::from_gray(220));
|
|
|
|
|
ui.painter().rect_stroke(
|
|
|
|
|
rect,
|
|
|
|
|
0.0,
|
|
|
|
|
Stroke::new(1.0, Color32::BLACK),
|
|
|
|
|
egui::StrokeKind::Middle,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
match style {
|
|
|
|
|
LegendStyle::Crosshatch => {
|
|
|
|
|
ui.painter().line_segment(
|
|
|
|
|
[rect.left_top(), rect.right_bottom()],
|
|
|
|
|
Stroke::new(1.2, Color32::BLACK),
|
|
|
|
|
);
|
|
|
|
|
ui.painter().line_segment(
|
|
|
|
|
[rect.right_top(), rect.left_bottom()],
|
|
|
|
|
Stroke::new(1.2, Color32::BLACK),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
LegendStyle::Dots => {
|
|
|
|
|
ui.painter()
|
|
|
|
|
.circle_filled(rect.center(), 2.0, Color32::BLACK);
|
|
|
|
|
ui.painter().circle_filled(
|
|
|
|
|
egui::pos2(rect.center().x - 4.0, rect.center().y),
|
|
|
|
|
1.4,
|
|
|
|
|
Color32::BLACK,
|
|
|
|
|
);
|
|
|
|
|
ui.painter().circle_filled(
|
|
|
|
|
egui::pos2(rect.center().x + 4.0, rect.center().y),
|
|
|
|
|
1.4,
|
|
|
|
|
Color32::BLACK,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
LegendStyle::SolidLine => {
|
|
|
|
|
ui.painter().line_segment(
|
|
|
|
|
[
|
|
|
|
|
egui::pos2(rect.left() + 1.0, rect.center().y),
|
|
|
|
|
egui::pos2(rect.right() - 1.0, rect.center().y),
|
|
|
|
|
],
|
|
|
|
|
Stroke::new(2.0, Color32::BLACK),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
LegendStyle::LongDash => draw_dashed_line(
|
|
|
|
|
ui.painter(),
|
|
|
|
|
egui::pos2(rect.left() + 1.0, rect.center().y),
|
|
|
|
|
egui::pos2(rect.right() - 1.0, rect.center().y),
|
|
|
|
|
Stroke::new(2.0, Color32::BLACK),
|
|
|
|
|
6.0,
|
|
|
|
|
3.0,
|
|
|
|
|
),
|
|
|
|
|
LegendStyle::ShortDash => draw_dashed_line(
|
|
|
|
|
ui.painter(),
|
|
|
|
|
egui::pos2(rect.left() + 1.0, rect.center().y),
|
|
|
|
|
egui::pos2(rect.right() - 1.0, rect.center().y),
|
|
|
|
|
Stroke::new(2.0, Color32::BLACK),
|
|
|
|
|
3.0,
|
|
|
|
|
2.0,
|
|
|
|
|
),
|
|
|
|
|
LegendStyle::DottedLine => draw_dotted_line(
|
|
|
|
|
ui.painter(),
|
|
|
|
|
egui::pos2(rect.left() + 1.0, rect.center().y),
|
|
|
|
|
egui::pos2(rect.right() - 1.0, rect.center().y),
|
|
|
|
|
Stroke::new(2.0, Color32::BLACK),
|
|
|
|
|
),
|
2026-03-23 12:22:03 -05:00
|
|
|
LegendStyle::DashDotLine => draw_dash_dot_line(
|
|
|
|
|
ui.painter(),
|
|
|
|
|
egui::pos2(rect.left() + 1.0, rect.center().y),
|
|
|
|
|
egui::pos2(rect.right() - 1.0, rect.center().y),
|
|
|
|
|
Stroke::new(2.0, Color32::BLACK),
|
|
|
|
|
),
|
2026-03-23 12:43:33 -05:00
|
|
|
LegendStyle::DashDotDotLine => draw_dash_dot_dot_line(
|
|
|
|
|
ui.painter(),
|
|
|
|
|
egui::pos2(rect.left() + 1.0, rect.center().y),
|
|
|
|
|
egui::pos2(rect.right() - 1.0, rect.center().y),
|
|
|
|
|
Stroke::new(2.0, Color32::BLACK),
|
|
|
|
|
),
|
2026-03-06 11:16:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.add_space(6.0);
|
|
|
|
|
ui.label(label);
|
|
|
|
|
});
|
|
|
|
|
ui.add_space(4.0);
|
|
|
|
|
}
|