Fixes #520 and #840 - locks cursor to screen when menu is not open

Rather than lock the cursor to the middle of the screen, the cursor will
move to it's last known coordinates when a menu or the minimap is not
open.
This commit is contained in:
Hunter Parks 2021-03-27 11:55:26 -07:00 committed by Marcel Märtens
parent 88079cfd30
commit 7df0413be4
2 changed files with 12 additions and 1 deletions

View File

@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Server kicks old client when a user is trying to log in again (often the case when a user's original connection gets dropped) - Server kicks old client when a user is trying to log in again (often the case when a user's original connection gets dropped)
- Added a raycast check to beams to prevent their effect applying through walls - Added a raycast check to beams to prevent their effect applying through walls
- Flying agents raycast more angles to check for obstacles. - Flying agents raycast more angles to check for obstacles.
- Mouse Cursor now stays in the same position when menu is not open
## [0.9.0] - 2021-03-20 ## [0.9.0] - 2021-03-20

View File

@ -1036,7 +1036,17 @@ impl Window {
self.events.push(Event::Focused(state)); self.events.push(Event::Focused(state));
}, },
WindowEvent::CursorMoved { position, .. } => { WindowEvent::CursorMoved { position, .. } => {
if self.cursor_grabbed {
if let Err(err) = self
.window
.window()
.set_cursor_position(self.cursor_position)
{
error!("Error setting cursor position: {:?}", err);
}
} else {
self.cursor_position = position; self.cursor_position = position;
}
}, },
WindowEvent::MouseWheel { delta, .. } if self.cursor_grabbed && self.focused => { WindowEvent::MouseWheel { delta, .. } if self.cursor_grabbed && self.focused => {
const DIFFERENCE_FROM_DEVICE_EVENT_ON_X11: f32 = -15.0; const DIFFERENCE_FROM_DEVICE_EVENT_ON_X11: f32 = -15.0;