add controller selection, auto-search

- fix bug in master volume control where the text input doesn't work
- fix bug in the Fan Club minigame where the player wouldn't jump when they were supposed to
This commit is contained in:
minenice55
2022-07-23 22:24:07 -04:00
parent ecbe84074f
commit 06fe482f3d
8 changed files with 144 additions and 35 deletions

View File

@ -122,6 +122,7 @@ namespace HeavenStudio.Games.Scripts_FanClub
{
animator.Play("FanFree", -1, 0);
stopBeat = false;
clappingStartTime = Single.MinValue;
}
}
}
@ -204,6 +205,7 @@ namespace HeavenStudio.Games.Scripts_FanClub
animator.Play("FanJump", -1, 0);
Jukebox.PlayOneShotGame("fanClub/play_jump");
jumpStartTime = cond.songPositionInBeats;
clappingStartTime = Single.MinValue;
stopCharge = false;
}

View File

@ -123,17 +123,17 @@ namespace HeavenStudio.InputSystem
public override bool GetButton(int button)
{
return BitwiseUtils.WantCurrent(joyBtStateCurrent.buttons, mappings[button]);
return BitwiseUtils.WantCurrent(joyBtStateCurrent.buttons, 1 << mappings[button]);
}
public override bool GetButtonDown(int button)
{
return BitwiseUtils.WantCurrentAndNotLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, mappings[button]);
return BitwiseUtils.WantCurrentAndNotLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, 1 << mappings[button]);
}
public override bool GetButtonUp(int button)
{
return BitwiseUtils.WantNotCurrentAndLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, mappings[button]);
return BitwiseUtils.WantNotCurrentAndLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, 1 << mappings[button]);
}
public override float GetAxis(InputAxis axis)
@ -164,74 +164,93 @@ namespace HeavenStudio.InputSystem
public override bool GetHatDirection(InputDirection direction)
{
//todo: check analogue stick hat direction too
int bt;
switch (direction)
{
case InputDirection.Up:
return BitwiseUtils.WantCurrent(joyBtStateCurrent.buttons, ButtonMaskUp);
bt = mappings[0];
break;
case InputDirection.Down:
return BitwiseUtils.WantCurrent(joyBtStateCurrent.buttons, ButtonMaskDown);
bt = mappings[1];
break;
case InputDirection.Left:
return BitwiseUtils.WantCurrent(joyBtStateCurrent.buttons, ButtonMaskLeft);
bt = mappings[2];
break;
case InputDirection.Right:
return BitwiseUtils.WantCurrent(joyBtStateCurrent.buttons, ButtonMaskRight);
bt = mappings[3];
break;
default:
return false;
}
return BitwiseUtils.WantCurrent(joyBtStateCurrent.buttons, 1 << bt);
}
public override bool GetHatDirectionDown(InputDirection direction)
{
//todo: check analogue stick hat direction too
int bt;
switch (direction)
{
case InputDirection.Up:
return BitwiseUtils.WantCurrentAndNotLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, ButtonMaskUp);
bt = mappings[0];
break;
case InputDirection.Down:
return BitwiseUtils.WantCurrentAndNotLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, ButtonMaskDown);
bt = mappings[1];
break;
case InputDirection.Left:
return BitwiseUtils.WantCurrentAndNotLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, ButtonMaskLeft);
bt = mappings[2];
break;
case InputDirection.Right:
return BitwiseUtils.WantCurrentAndNotLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, ButtonMaskRight);
bt = mappings[3];
break;
default:
return false;
}
return BitwiseUtils.WantCurrentAndNotLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, 1 << bt);
}
public override bool GetHatDirectionUp(InputDirection direction)
{
//todo: check analogue stick hat direction too
int bt;
switch (direction)
{
case InputDirection.Up:
return BitwiseUtils.WantNotCurrentAndLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, ButtonMaskUp);
bt = mappings[0];
break;
case InputDirection.Down:
return BitwiseUtils.WantNotCurrentAndLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, ButtonMaskDown);
bt = mappings[1];
break;
case InputDirection.Left:
return BitwiseUtils.WantNotCurrentAndLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, ButtonMaskLeft);
bt = mappings[2];
break;
case InputDirection.Right:
return BitwiseUtils.WantNotCurrentAndLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, ButtonMaskRight);
bt = mappings[3];
break;
default:
return false;
}
return BitwiseUtils.WantNotCurrentAndLast(joyBtStateCurrent.buttons, joyBtStateLast.buttons, 1 << bt);
}
public override void SetPlayer(int playerNum)
public override void SetPlayer(int? playerNum)
{
if (playerNum == -1)
if (playerNum == -1 || playerNum == null)
{
this.playerNum = null;
JslSetPlayerNumber(joyshockHandle, 0);
return;
}
this.playerNum = playerNum;
int ledMask = (int) this.playerNum;
if (type == TypeDualSense)
{
if (playerNum <= 4)
{
playerNum = DualSensePlayerMask[playerNum];
ledMask = DualSensePlayerMask[(int) this.playerNum];
}
}
JslSetPlayerNumber(joyshockHandle, playerNum);
this.playerNum = playerNum;
JslSetPlayerNumber(joyshockHandle, ledMask);
}
public override int? GetPlayer()

View File

@ -136,14 +136,14 @@ namespace HeavenStudio.InputSystem
}
}
public override void SetPlayer(int playerNum)
public override void SetPlayer(int? playerNum)
{
if (playerNum == -1)
if (playerNum == -1 || playerNum == null)
{
this.playerNum = null;
return;
}
this.playerNum = playerNum;
this.playerNum = (int) playerNum;
}
public override int? GetPlayer()

View File

@ -159,7 +159,7 @@ namespace HeavenStudio.InputSystem
public abstract bool GetHatDirectionDown(InputDirection direction); // direction just became active?
public abstract bool GetHatDirectionUp(InputDirection direction); // direction just became inactive?
public abstract void SetPlayer(int playerNum); // Set the player number (starts at 1, set to -1 or null for no player)
public abstract void SetPlayer(int? playerNum); // Set the player number (starts at 1, set to -1 or null for no player)
public abstract int? GetPlayer(); // Get the player number (null if no player)
//public abstract Sprite GetDisplayIcon(); //"big icon" for the controller in the settings menu

View File

@ -60,6 +60,7 @@ namespace HeavenStudio
InputJoyshock joyshock = new InputJoyshock(i);
joyshock.InitializeController();
joyshock.SetPlayer(inputDevices.Count + 1);
inputDevices.Add(joyshock);
}
}
else
@ -99,6 +100,22 @@ namespace HeavenStudio
return null;
}
public static int GetInputControllerId(int player)
{
//select input controller id that has player field set to player
//this will return the first controller that has that player number in the case of controller pairs (eg. Joy-Cons)
//so such controllers should have a reference to the other controller in the pair
//controller IDs are determined by connection order (the Keyboard is always first)
for (int i = 0; i < inputDevices.Count; i++)
{
if (inputDevices[i].GetPlayer() == player)
{
return i;
}
}
return -1;
}
public static void UpdateInputControllers()
{
foreach (InputController i in inputDevices)

View File

@ -17,10 +17,53 @@ namespace HeavenStudio.Editor
[SerializeField] private TMP_Text currentControllerLabel;
[SerializeField] private TMP_Dropdown controllersDropdown;
[SerializeField] private TMP_Dropdown splitControllersDropdown;
[SerializeField] private GameObject autoSearchLabel;
private bool isAutoSearching = false;
private void Start() {
numConnectedLabel.text = "Connected: " + PlayerInput.GetNumControllersConnected();
currentControllerLabel.text = "Current Controller: " + PlayerInput.GetInputController(1).GetDeviceName();
PopulateControllersDropdown();
PopulateSplitControllersDropdown();
controllersDropdown.onValueChanged.AddListener(delegate
{
InputController lastController = PlayerInput.GetInputController(1);
InputController newController = PlayerInput.GetInputControllers()[controllersDropdown.value];
lastController.SetPlayer(newController.GetPlayer() != null ? (int) newController.GetPlayer() : -1);
newController.SetPlayer(1);
currentControllerLabel.text = "Current Controller: " + newController.GetDeviceName();
if (typeof(InputJoyshock) == newController.GetType()) {
StartCoroutine(SelectionVibrate((InputJoyshock) newController));
}
});
}
private void Update() {
if (isAutoSearching) {
var controllers = PlayerInput.GetInputControllers();
foreach (var controller in controllers) {
if (controller.GetLastButtonDown() > 0 || controller.GetLastKeyDown() > 0) {
PlayerInput.GetInputController(1).SetPlayer(controller.GetPlayer() != null ? (int) controller.GetPlayer() : -1);
controller.SetPlayer(1);
isAutoSearching = false;
autoSearchLabel.SetActive(false);
controllersDropdown.value = PlayerInput.GetInputControllerId(1);
currentControllerLabel.text = "Current Controller: " + controller.GetDeviceName();
if (typeof(InputJoyshock) == controller.GetType()) {
StartCoroutine(SelectionVibrate((InputJoyshock) controller));
}
}
}
}
}
public void StartAutoSearch() {
autoSearchLabel.SetActive(true);
isAutoSearching = true;
}
public void SearchAndConnectControllers()
@ -28,9 +71,11 @@ namespace HeavenStudio.Editor
int connected = PlayerInput.InitInputControllers();
numConnectedLabel.text = "Connected: " + connected;
currentControllerLabel.text = "Current Controller: " + PlayerInput.GetInputController(1).GetDeviceName();
PopulateControllersDropdown();
PopulateSplitControllersDropdown();
}
public void populateControllersDropdown()
public void PopulateControllersDropdown()
{
List<TMP_Dropdown.OptionData> dropDownData = new List<TMP_Dropdown.OptionData>();
var vals = PlayerInput.GetInputControllers();
@ -44,7 +89,7 @@ namespace HeavenStudio.Editor
controllersDropdown.value = 0;
}
public void populateSplitControllersDropdown()
public void PopulateSplitControllersDropdown()
{
List<TMP_Dropdown.OptionData> dropDownData = new List<TMP_Dropdown.OptionData>();
var vals = PlayerInput.GetInputControllers();
@ -62,5 +107,16 @@ namespace HeavenStudio.Editor
splitControllersDropdown.AddOptions(dropDownData);
splitControllersDropdown.value = 0;
}
IEnumerator SelectionVibrate(InputJoyshock controller)
{
JslSetRumbleFrequency(controller.GetHandle(), 0.2f, 0.25f, 80f, 160f);
yield return new WaitForSeconds(0.08f);
JslSetRumbleFrequency(controller.GetHandle(), 0f, 0f, 0f, 0f);
yield return new WaitForSeconds(0.04f);
JslSetRumbleFrequency(controller.GetHandle(), 0.25f, 0f, 640f, 0f);
yield return new WaitForSeconds(0.05f);
JslSetRumbleFrequency(controller.GetHandle(), 0f, 0f, 0f, 0f);
}
}
}

View File

@ -68,7 +68,7 @@ namespace HeavenStudio.Editor
public void OnVolLabelChanged()
{
volSlider.value = (float)System.Math.Round(System.Convert.ToSingle(volLabel.text), 2);
volSlider.value = (float)System.Math.Round(System.Convert.ToSingle(volLabel.text) / 100f, 2);
GlobalGameManager.ChangeMasterVolume(volSlider.value);
}
}