Skip to content

Commit

Permalink
Added input device confirmation.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Feb 28, 2024
1 parent 71facf5 commit 74c1e4a
Showing 1 changed file with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +52,8 @@ public int MaxPlayers

List<InputDeviceSelectionItem> InputDeviceSelectionItemsInternal = new List<InputDeviceSelectionItem>();

public event EventHandler ConfirmedJoinedInput;
public event Action<object, ConfirmJoinedEventArgs> ConfirmedJoinedInput;


#endregion

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 74c1e4a

Please sign in to comment.