Skip to content

Commit

Permalink
Don't move events when the mouse is not hovering over them
Browse files Browse the repository at this point in the history
  • Loading branch information
white-axe committed Sep 17, 2023
1 parent bec1a79 commit bce08f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -83,6 +88,8 @@ impl MapView {

hover_tile: None,

selected_event_is_hovered: false,

scale: 100.,
})
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tabs/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bce08f2

Please sign in to comment.