diff --git a/src/components/map_view.rs b/src/components/map_view.rs index 3f045403..1b93b6dc 100644 --- a/src/components/map_view.rs +++ b/src/components/map_view.rs @@ -38,6 +38,11 @@ pub struct MapView { /// The map coordinates of the tile being hovered over pub hover_tile: Option<egui::Pos2>, + /// True if selected_event_id is being hovered over by the mouse + /// (as opposed to the map cursor) + /// and false otherwise + pub selected_event_is_hovered: bool, + pub darken_unselected_layers: bool, pub scale: f32, @@ -83,6 +88,8 @@ impl MapView { hover_tile: None, + selected_event_is_hovered: false, + scale: 100., }) } @@ -201,14 +208,12 @@ impl MapView { if !self.event_enabled || !matches!(self.selected_layer, SelectedLayer::Events) { self.selected_event_id = None; } + self.selected_event_is_hovered = false; if self.event_enabled { let mut selected_event = None; let mut selected_event_rects = None; - // True if an event is being hovered over by the mouse, false otherwise - let mut selected_event_is_hovered = false; - for (_, event) in map.events.iter() { let sprite = self.events.get(event.id); let event_size = sprite @@ -258,7 +263,7 @@ impl MapView { // If the mouse is not hovering over an event, then we will handle the selected // tile based on where the map cursor is - if !selected_event_is_hovered && !dragging_event { + if !self.selected_event_is_hovered && !dragging_event { selected_event = match selected_event { // If the map cursor is on the exact tile of an event, then that is the // selected event @@ -337,7 +342,7 @@ impl MapView { }; if let Some(e) = selected_event { if e.id == event.id { - selected_event_is_hovered = true; + self.selected_event_is_hovered = true; selected_event_rects = Some((tile_rect, box_rect)); } } diff --git a/src/tabs/map.rs b/src/tabs/map.rs index 187e4935..5922ec37 100644 --- a/src/tabs/map.rs +++ b/src/tabs/map.rs @@ -412,6 +412,7 @@ impl tab::Tab for Tab { } // Allow drag and drop to move events else if !self.dragging_event + && self.view.selected_event_is_hovered && response.drag_started_by(egui::PointerButton::Primary) { self.dragging_event = true;