From 45ed4739ae5485e10a43b249db0a4c4f82d02d9c Mon Sep 17 00:00:00 2001 From: Martin Indra Date: Mon, 24 Jul 2023 22:37:23 +0200 Subject: [PATCH] Rename events --- crates/controller/src/commands/handlers.rs | 14 ++++----- crates/controller/src/mouse/input.rs | 36 +++++++++++----------- crates/controller/src/mouse/mod.rs | 3 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/crates/controller/src/commands/handlers.rs b/crates/controller/src/commands/handlers.rs index fe5800cd..05714011 100644 --- a/crates/controller/src/commands/handlers.rs +++ b/crates/controller/src/commands/handlers.rs @@ -34,8 +34,8 @@ use crate::{ draft::{DiscardDraftsEvent, DraftSet, NewDraftEvent, SpawnDraftsEvent}, hud::{GameMenuSet, ToggleGameMenu, UpdateSelectionBoxEvent}, mouse::{ - DragUpdateType, MouseClicked, MouseDoubleClicked, MouseDragged, MouseSet, Pointer, - PointerSet, + DragUpdateType, MouseClickedEvent, MouseDoubleClickedEvent, MouseDraggedEvent, MouseSet, + Pointer, PointerSet, }, selection::{ AreaSelectSet, SelectEvent, SelectInRectEvent, Selected, SelectionMode, SelectionSet, @@ -172,16 +172,16 @@ pub(crate) enum HandlersSet { LeftClick, } -fn on_click(button: MouseButton) -> impl Fn(EventReader) -> bool { - move |mut events: EventReader| { +fn on_click(button: MouseButton) -> impl Fn(EventReader) -> bool { + move |mut events: EventReader| { // It is desirable to exhaust the iterator, thus .filter().count() is // used instead of .any() events.iter().filter(|e| e.button() == button).count() > 0 } } -fn on_double_click(button: MouseButton) -> impl Fn(EventReader) -> bool { - move |mut events: EventReader| { +fn on_double_click(button: MouseButton) -> impl Fn(EventReader) -> bool { + move |mut events: EventReader| { // It is desirable to exhaust the iterator, thus .filter().count() is // used instead of .any() events.iter().filter(|e| e.button() == button).count() > 0 @@ -425,7 +425,7 @@ fn select_all_visible(mut events: EventWriter) { fn update_drags( keys: Res>, - mut drag_events: EventReader, + mut drag_events: EventReader, mut ui_events: EventWriter, mut select_events: EventWriter, ) { diff --git a/crates/controller/src/mouse/input.rs b/crates/controller/src/mouse/input.rs index f72f9d0e..267b2f5a 100644 --- a/crates/controller/src/mouse/input.rs +++ b/crates/controller/src/mouse/input.rs @@ -15,9 +15,9 @@ pub(super) struct InputPlugin; impl Plugin for InputPlugin { fn build(&self, app: &mut App) { - app.add_event::() - .add_event::() - .add_event::() + app.add_event::() + .add_event::() + .add_event::() .add_system(setup.in_schedule(OnEnter(AppState::InGame))) .add_system(cleanup.in_schedule(OnExit(AppState::InGame))) .add_system( @@ -59,12 +59,12 @@ pub(crate) enum MouseSet { Buttons, } -pub(crate) struct MouseClicked { +pub(crate) struct MouseClickedEvent { button: MouseButton, position: Vec2, } -impl MouseClicked { +impl MouseClickedEvent { fn new(button: MouseButton, position: Vec2) -> Self { Self { button, position } } @@ -78,11 +78,11 @@ impl MouseClicked { } } -pub(crate) struct MouseDoubleClicked { +pub(crate) struct MouseDoubleClickedEvent { button: MouseButton, } -impl MouseDoubleClicked { +impl MouseDoubleClickedEvent { fn new(button: MouseButton) -> Self { Self { button } } @@ -92,13 +92,13 @@ impl MouseDoubleClicked { } } -pub(crate) struct MouseDragged { +pub(crate) struct MouseDraggedEvent { button: MouseButton, rect: Option, update_type: DragUpdateType, } -impl MouseDragged { +impl MouseDraggedEvent { fn new(button: MouseButton, rect: Option, update_type: DragUpdateType) -> Self { Self { button, @@ -263,11 +263,11 @@ fn update_position( fn update_drags( mouse_position: Res, mut mouse_state: ResMut, - mut drags: EventWriter, + mut drags: EventWriter, ) { let resolutions = mouse_state.update(mouse_position.ndc()); for (&button, &rect) in resolutions.iter() { - drags.send(MouseDragged::new(button, rect, DragUpdateType::Moved)); + drags.send(MouseDraggedEvent::new(button, rect, DragUpdateType::Moved)); } } @@ -275,8 +275,8 @@ fn update_buttons( mouse_position: Res, mut mouse_state: ResMut, mut input_events: EventReader, - mut clicks: EventWriter, - mut drags: EventWriter, + mut clicks: EventWriter, + mut drags: EventWriter, ) { for event in input_events.iter() { match event.state { @@ -284,10 +284,10 @@ fn update_buttons( if let Some(drag_resolution) = mouse_state.resolve(event.button) { match drag_resolution { DragResolution::Point(position) => { - clicks.send(MouseClicked::new(event.button, position)); + clicks.send(MouseClickedEvent::new(event.button, position)); } DragResolution::Rect(rect) => { - drags.send(MouseDragged::new( + drags.send(MouseDraggedEvent::new( event.button, rect, DragUpdateType::Released, @@ -304,8 +304,8 @@ fn update_buttons( } fn check_double_click( - mut clicks: EventReader, - mut double_clicks: EventWriter, + mut clicks: EventReader, + mut double_clicks: EventWriter, mut last_click_position: Local>, mut last_click_time: Local, time: Res