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 4b8b28728..0ac011afa 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 @@ -31,8 +31,12 @@ public int MaxPlayers } } + public int MinPlayers { get; set; } = 1; + List InputDeviceSelectionItemsInternal = new List(); + public event EventHandler ConfirmedJoinedInput; + #endregion #region Initialize @@ -195,7 +199,10 @@ bool DidUnjoin(IInputDevice inputDevice) => foreach(var inputDevice in AllConnectedInputDevices) { - if(inputDevice.DefaultJoinInput.WasJustPressed) + // We use the primary action (such as A or Space) to join, + // then the Join input (such as Enter or Start) as the "hard" + // proceed input. + if(inputDevice.DefaultPrimaryActionInput.WasJustPressed) { HandleJoin(inputDevice); } @@ -205,31 +212,49 @@ bool DidUnjoin(IInputDevice inputDevice) => } } + int joinedInputDeviceCount = 0; + for(int i = 0; i < JoinedInputDevices.Length; i++) + { + if (JoinedInputDevices[i] != null ) + { + joinedInputDeviceCount++; + } + } + + if(joinedInputDeviceCount >= MinPlayers) + { + for(int i = 0; i < JoinedInputDevices.Length; i++) + { + if (JoinedInputDevices[i] != null && JoinedInputDevices[i].DefaultJoinInput.WasJustPressed) + { + ConfirmedJoinedInput?.Invoke(this, null); + break; + } + } + } base.Activity(); } private void HandleJoin(IInputDevice inputDevice) { - var isInputDeviceAlreadyShownInItem = false; - foreach(var item in InputDeviceSelectionItemsInternal) + int? firstEmpty = null; + for(int i = 0; i < JoinedInputDevices.Length; i++) { - if(item.InputDevice == inputDevice) + if (JoinedInputDevices[i] == inputDevice) { - // user just pressed join, no biggie - isInputDeviceAlreadyShownInItem = true; + return; + } + else if(firstEmpty == null && JoinedInputDevices[i] == null) + { + firstEmpty = i; } } - if(!isInputDeviceAlreadyShownInItem) + // If we got here, it's not already joined: + if(firstEmpty != null) { - // find the first empty - var firstEmpty = InputDeviceSelectionItemsInternal.Find(item => item.InputDevice == null); - - if(firstEmpty != null) - { - firstEmpty.InputDevice = inputDevice; - } + JoinedInputDevices[firstEmpty.Value] = inputDevice; } } } diff --git a/FRBDK/Glue/GumPlugin/GumPlugin/Embedded/GumDefaults2/Components/Controls/InputDeviceSelectionItem.gucx b/FRBDK/Glue/GumPlugin/GumPlugin/Embedded/GumDefaults2/Components/Controls/InputDeviceSelectionItem.gucx index d7389bd71..a446fcab8 100644 --- a/FRBDK/Glue/GumPlugin/GumPlugin/Embedded/GumDefaults2/Components/Controls/InputDeviceSelectionItem.gucx +++ b/FRBDK/Glue/GumPlugin/GumPlugin/Embedded/GumDefaults2/Components/Controls/InputDeviceSelectionItem.gucx @@ -80,24 +80,6 @@ JoinedCategoryState false - - float - MinSizeContainer.Height - 44 - true - - - float - MinSizeContainer.X - 0 - true - - - float - MinSizeContainer.Y - 40 - true - float RemoveDeviceButtonInstance.Height @@ -321,11 +303,6 @@ Text false - - MinSizeContainer - Container - false - RemoveDeviceButtonInstance Controls/ButtonClose