mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
Fixed InputHandler and UiControls maintaining old input states when input types are toggled off
This commit is contained in:
parent
d6309ce9c1
commit
560c797b87
3 changed files with 37 additions and 15 deletions
|
@ -27,6 +27,7 @@ Improvements
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed TokenizedString handling trailing spaces incorrectly in the last line of non-left aligned text
|
- Fixed TokenizedString handling trailing spaces incorrectly in the last line of non-left aligned text
|
||||||
- Fixed some TokenizedString tokens starting with a line break not being split correctly
|
- Fixed some TokenizedString tokens starting with a line break not being split correctly
|
||||||
|
- Fixed InputHandler maintaining old input states when input types are toggled off
|
||||||
|
|
||||||
### MLEM.Ui
|
### MLEM.Ui
|
||||||
Additions
|
Additions
|
||||||
|
@ -50,6 +51,7 @@ Fixes
|
||||||
- Fixed Element.OnChildAdded and Element.OnChildRemoved being called for grandchildren when a child is added
|
- Fixed Element.OnChildAdded and Element.OnChildRemoved being called for grandchildren when a child is added
|
||||||
- Fixed an exception when trying to force-update the area of an element without a ui system
|
- Fixed an exception when trying to force-update the area of an element without a ui system
|
||||||
- Fixed the scroll bar of an empty panel being positioned incorrectly
|
- Fixed the scroll bar of an empty panel being positioned incorrectly
|
||||||
|
- Fixed UiControls maintaining old input states when input types are toggled off
|
||||||
|
|
||||||
### MLEM.Data
|
### MLEM.Data
|
||||||
Additions
|
Additions
|
||||||
|
|
|
@ -161,7 +161,6 @@ namespace MLEM.Ui {
|
||||||
this.Input.Update();
|
this.Input.Update();
|
||||||
this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanBeActive);
|
this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanBeActive);
|
||||||
|
|
||||||
// MOUSE INPUT
|
|
||||||
if (this.HandleMouse) {
|
if (this.HandleMouse) {
|
||||||
var mousedNow = this.GetElementUnderPos(new Vector2(this.Input.ViewportMousePosition.X, this.Input.ViewportMousePosition.Y));
|
var mousedNow = this.GetElementUnderPos(new Vector2(this.Input.ViewportMousePosition.X, this.Input.ViewportMousePosition.Y));
|
||||||
this.SetMousedElement(mousedNow);
|
this.SetMousedElement(mousedNow);
|
||||||
|
@ -181,9 +180,10 @@ namespace MLEM.Ui {
|
||||||
this.Input.TryConsumeMouseButtonPressed(MouseButton.Right);
|
this.Input.TryConsumeMouseButtonPressed(MouseButton.Right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.SetMousedElement(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// KEYBOARD INPUT
|
|
||||||
if (this.HandleKeyboard) {
|
if (this.HandleKeyboard) {
|
||||||
if (this.KeyboardButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
if (this.KeyboardButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
||||||
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
|
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
|
||||||
|
@ -210,7 +210,6 @@ namespace MLEM.Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOUCH INPUT
|
|
||||||
if (this.HandleTouch) {
|
if (this.HandleTouch) {
|
||||||
if (this.Input.GetViewportGesture(GestureType.Tap, out var tap)) {
|
if (this.Input.GetViewportGesture(GestureType.Tap, out var tap)) {
|
||||||
this.IsAutoNavMode = false;
|
this.IsAutoNavMode = false;
|
||||||
|
@ -238,9 +237,10 @@ namespace MLEM.Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.SetTouchedElement(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GAMEPAD INPUT
|
|
||||||
if (this.HandleGamepad) {
|
if (this.HandleGamepad) {
|
||||||
if (this.GamepadButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
if (this.GamepadButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
||||||
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
|
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
|
||||||
|
|
|
@ -108,8 +108,8 @@ namespace MLEM.Input {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IList<TouchLocation> ViewportTouchState { get; private set; }
|
public IList<TouchLocation> ViewportTouchState { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains the amount of gamepads that are currently connected.
|
/// Contains the amount of gamepads that are currently connected. Note that this value will be set to 0 if <see cref="HandleGamepads"/> is false.
|
||||||
/// This field is automatically updated in <see cref="Update()"/>
|
/// This field is automatically updated in <see cref="Update()"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ConnectedGamepads { get; private set; }
|
public int ConnectedGamepads { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -196,15 +196,15 @@ namespace MLEM.Input {
|
||||||
|
|
||||||
this.consumedPresses.Clear();
|
this.consumedPresses.Clear();
|
||||||
|
|
||||||
|
this.LastKeyboardState = this.KeyboardState;
|
||||||
if (this.HandleKeyboard) {
|
if (this.HandleKeyboard) {
|
||||||
this.LastKeyboardState = this.KeyboardState;
|
|
||||||
this.KeyboardState = active ? Keyboard.GetState() : default;
|
this.KeyboardState = active ? Keyboard.GetState() : default;
|
||||||
var pressedKeys = this.KeyboardState.GetPressedKeys();
|
var pressedKeys = this.KeyboardState.GetPressedKeys();
|
||||||
foreach (var pressed in pressedKeys)
|
foreach (var pressed in pressedKeys)
|
||||||
this.AccumulateDown(pressed, -1);
|
this.AccumulateDown(pressed, -1);
|
||||||
|
|
||||||
|
this.triggerKeyRepeat = false;
|
||||||
if (this.HandleKeyboardRepeats) {
|
if (this.HandleKeyboardRepeats) {
|
||||||
this.triggerKeyRepeat = false;
|
|
||||||
// the key that started being held most recently should be the one being repeated
|
// the key that started being held most recently should be the one being repeated
|
||||||
this.heldKey = pressedKeys.OrderBy(k => this.GetDownTime(k)).FirstOrDefault();
|
this.heldKey = pressedKeys.OrderBy(k => this.GetDownTime(k)).FirstOrDefault();
|
||||||
if (this.TryGetDownTime(this.heldKey, out var heldTime)) {
|
if (this.TryGetDownTime(this.heldKey, out var heldTime)) {
|
||||||
|
@ -219,11 +219,17 @@ namespace MLEM.Input {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.heldKey = Keys.None;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.KeyboardState = default;
|
||||||
|
this.triggerKeyRepeat = false;
|
||||||
|
this.heldKey = Keys.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.LastMouseState = this.MouseState;
|
||||||
if (this.HandleMouse) {
|
if (this.HandleMouse) {
|
||||||
this.LastMouseState = this.MouseState;
|
|
||||||
var state = Mouse.GetState();
|
var state = Mouse.GetState();
|
||||||
if (active && this.Game.GraphicsDevice.Viewport.Bounds.Contains(state.X, state.Y)) {
|
if (active && this.Game.GraphicsDevice.Viewport.Bounds.Contains(state.X, state.Y)) {
|
||||||
this.MouseState = state;
|
this.MouseState = state;
|
||||||
|
@ -239,6 +245,8 @@ namespace MLEM.Input {
|
||||||
this.MouseState = new MouseState(state.X, state.Y, state.ScrollWheelValue, 0, 0, 0, 0, 0, state.HorizontalScrollWheelValue);
|
this.MouseState = new MouseState(state.X, state.Y, state.ScrollWheelValue, 0, 0, 0, 0, 0, state.HorizontalScrollWheelValue);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.MouseState = default;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.HandleGamepads) {
|
if (this.HandleGamepads) {
|
||||||
|
@ -259,9 +267,9 @@ namespace MLEM.Input {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.HandleGamepadRepeats) {
|
for (var i = 0; i < this.ConnectedGamepads; i++) {
|
||||||
for (var i = 0; i < this.ConnectedGamepads; i++) {
|
this.triggerGamepadButtonRepeat[i] = false;
|
||||||
this.triggerGamepadButtonRepeat[i] = false;
|
if (this.HandleGamepadRepeats) {
|
||||||
this.heldGamepadButtons[i] = EnumHelper.Buttons
|
this.heldGamepadButtons[i] = EnumHelper.Buttons
|
||||||
.Where(b => this.IsGamepadButtonDown(b, i))
|
.Where(b => this.IsGamepadButtonDown(b, i))
|
||||||
.OrderBy(b => this.GetDownTime(b, i))
|
.OrderBy(b => this.GetDownTime(b, i))
|
||||||
|
@ -275,14 +283,23 @@ namespace MLEM.Input {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.heldGamepadButtons[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.ConnectedGamepads = 0;
|
||||||
|
for (var i = 0; i < InputHandler.MaximumGamePadCount; i++) {
|
||||||
|
this.lastGamepads[i] = this.gamepads[i];
|
||||||
|
this.gamepads[i] = default;
|
||||||
|
this.triggerGamepadButtonRepeat[i] = false;
|
||||||
|
this.heldGamepadButtons[i] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.LastTouchState = this.TouchState;
|
||||||
|
this.LastViewportTouchState = this.ViewportTouchState;
|
||||||
if (this.HandleTouch) {
|
if (this.HandleTouch) {
|
||||||
this.LastTouchState = this.TouchState;
|
|
||||||
this.LastViewportTouchState = this.ViewportTouchState;
|
|
||||||
|
|
||||||
this.TouchState = active ? TouchPanel.GetState() : new TouchCollection(InputHandler.EmptyTouchLocations);
|
this.TouchState = active ? TouchPanel.GetState() : new TouchCollection(InputHandler.EmptyTouchLocations);
|
||||||
if (this.TouchState.Count > 0 && this.ViewportOffset != Point.Zero) {
|
if (this.TouchState.Count > 0 && this.ViewportOffset != Point.Zero) {
|
||||||
this.ViewportTouchState = new List<TouchLocation>();
|
this.ViewportTouchState = new List<TouchLocation>();
|
||||||
|
@ -301,6 +318,9 @@ namespace MLEM.Input {
|
||||||
while (TouchPanel.IsGestureAvailable)
|
while (TouchPanel.IsGestureAvailable)
|
||||||
this.gestures.Add(TouchPanel.ReadGesture());
|
this.gestures.Add(TouchPanel.ReadGesture());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.TouchState = new TouchCollection(InputHandler.EmptyTouchLocations);
|
||||||
|
this.gestures.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.inputsDownAccum.Count <= 0 && this.inputsDown.Count <= 0) {
|
if (this.inputsDownAccum.Count <= 0 && this.inputsDown.Count <= 0) {
|
||||||
|
|
Loading…
Reference in a new issue