From 74c1e4a15da13a8f049156b99e2a8453273a9090 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 27 Feb 2024 19:57:53 -0700 Subject: [PATCH] Added input device confirmation. --- .../Controls/Games/InputDeviceSelector.cs | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/Engines/Forms/FlatRedBall.Forms/FlatRedBall.Forms.Shared/Controls/Games/InputDeviceSelector.cs b/Engines/Forms/FlatRedBall.Forms/FlatRedBall.Forms.Shared/Controls/Games/InputDeviceSelector.cs index 0ac011afa..cdc17da7e 100644 --- a/Engines/Forms/FlatRedBall.Forms/FlatRedBall.Forms.Shared/Controls/Games/InputDeviceSelector.cs +++ b/Engines/Forms/FlatRedBall.Forms/FlatRedBall.Forms.Shared/Controls/Games/InputDeviceSelector.cs @@ -9,6 +9,23 @@ namespace FlatRedBall.Forms.Controls.Games { + public enum ConfirmJoinedResult + { + Succeeded, + NotEnoughPlayers, + InputDeviceNotJoined + } + + public class ConfirmJoinedEventArgs : EventArgs + { + public ConfirmJoinedResult Result { get; private set; } + + public ConfirmJoinedEventArgs(ConfirmJoinedResult result) + { + Result = result; + } + } + public class InputDeviceSelector : FrameworkElement { #region Fields/Properties @@ -35,7 +52,8 @@ public int MaxPlayers List InputDeviceSelectionItemsInternal = new List(); - public event EventHandler ConfirmedJoinedInput; + public event Action ConfirmedJoinedInput; + #endregion @@ -221,15 +239,23 @@ bool DidUnjoin(IInputDevice inputDevice) => } } - if(joinedInputDeviceCount >= MinPlayers) + for(int i = 0; i < AllConnectedInputDevices.Count; i++) { - for(int i = 0; i < JoinedInputDevices.Length; i++) + // In this context, "Join" means to confirm the selection and advance + if(AllConnectedInputDevices[i].DefaultJoinInput.WasJustPressed) { - if (JoinedInputDevices[i] != null && JoinedInputDevices[i].DefaultJoinInput.WasJustPressed) + ConfirmJoinedResult result = ConfirmJoinedResult.Succeeded; + if (JoinedInputDevices.Contains(AllConnectedInputDevices[i]) == false) + { + result = ConfirmJoinedResult.InputDeviceNotJoined; + } + else if(joinedInputDeviceCount < MinPlayers) { - ConfirmedJoinedInput?.Invoke(this, null); - break; + result = ConfirmJoinedResult.NotEnoughPlayers; } + var args = new ConfirmJoinedEventArgs(result); + ConfirmedJoinedInput?.Invoke(this, args); + break; } } @@ -294,6 +320,11 @@ public T this[int index] } } + public bool Contains(T item) + { + return _array.Contains(item); + } + void OnIndexChanged(T oldItem, int index) { CollectionChanged?.Invoke(this, new ObservableArrayIndexChangeArgs(index));