support different control styles in options

deprecate old input check methods
This commit is contained in:
minenice55 2023-09-17 22:55:06 -04:00
parent fed8c3f897
commit 4f264ef4cb
19 changed files with 2637 additions and 286 deletions

View file

@ -199,7 +199,7 @@ namespace HeavenStudio.Games
DogAnim.SetBool("needPrepare", true);
}
if (PlayerInput.Pressed(true) && !IsExpectingInputNow(InputType.STANDARD_DOWN))
if ((PlayerInput.Pressed() || PlayerInput.GetAnyDirectionDown()) && !IsExpectingInputNow(InputType.STANDARD_DOWN | InputType.DIRECTION_DOWN))
{
System.Random rd = new System.Random();
string slice;

View file

@ -299,7 +299,7 @@ namespace HeavenStudio.Games
lastReportedBeat = Math.Round(Conductor.instance.songPositionInBeatsAsDouble);
}
if (PlayerInput.Pressed(true) && !IsExpectingInputNow(InputType.STANDARD_DOWN | InputType.DIRECTION_DOWN))
if ((PlayerInput.Pressed() || PlayerInput.GetAnyDirectionDown()) && !IsExpectingInputNow(InputType.STANDARD_DOWN | InputType.DIRECTION_DOWN))
{
translator.DoScaledAnimationAsync("translator_eh", 0.5f);
if (isSpeaking)

View file

@ -22,11 +22,6 @@ namespace HeavenStudio.Games.Scripts_FirstContact
private void Update()
{
////IF YOU WANT TO PLAY NOTES ANYTIME W/O CONSTRAINTS
//if (PlayerInput.Pressed(true) && !game.isSpeaking)
//{
// successTranslation(true);
//}
}
public void SuccessTranslation(bool ace)

View file

@ -135,7 +135,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
}
}
if (PlayerInput.Pressed(true) && !inSpecial)
if ((PlayerInput.Pressed() || PlayerInput.GetAnyDirectionDown()) && !inSpecial)
{
if (!KarateMan.instance.IsExpectingInputNow(InputType.STANDARD_DOWN | InputType.DIRECTION_DOWN))
{
@ -164,7 +164,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
}
}
if ((!GameManager.instance.autoplay) && (PlayerInput.PressedUp(true) && !PlayerInput.Pressing(true)))
if ((!GameManager.instance.autoplay) && (PlayerInput.PressedUp() || PlayerInput.GetAnyDirectionUp()) && !(PlayerInput.Pressing() || PlayerInput.GetAnyDirection()))
{
if (wantKick)
{

View file

@ -312,12 +312,12 @@ namespace HeavenStudio.Games
CadetPlayer.DoScaledAnimationAsync("Halt", 0.5f);
}
if (PlayerInput.Pressed(true) && PlayerInput.GetSpecificDirection(PlayerInput.LEFT) && !IsExpectingInputNow(InputType.DIRECTION_LEFT_DOWN)) {
if (PlayerInput.GetSpecificDirectionDown((int) InputSystem.InputController.InputDirection.Left) && !IsExpectingInputNow(InputType.DIRECTION_LEFT_DOWN)) {
Miss();
CadetHeadPlayer.DoScaledAnimationAsync("FaceL", 0.5f);
}
if (PlayerInput.Pressed(true) && PlayerInput.GetSpecificDirection(PlayerInput.RIGHT) && !IsExpectingInputNow(InputType.DIRECTION_RIGHT_DOWN)) {
if (PlayerInput.GetSpecificDirectionDown((int) InputSystem.InputController.InputDirection.Right) && !IsExpectingInputNow(InputType.DIRECTION_RIGHT_DOWN)) {
Miss();
CadetHeadPlayer.DoScaledAnimationAsync("FaceR", 0.5f);
}

View file

@ -124,7 +124,7 @@ namespace HeavenStudio.Games
private void Update()
{
if (PlayerInput.Pressed(true) && (!IsExpectingInputNow(InputType.STANDARD_DOWN) || !IsExpectingInputNow(InputType.DIRECTION_DOWN))) {
if ((PlayerInput.Pressed() || PlayerInput.GetAnyDirectionDown()) && (!IsExpectingInputNow(InputType.STANDARD_DOWN) || !IsExpectingInputNow(InputType.DIRECTION_DOWN))) {
TackAnim.DoScaledAnimationAsync("TackEmptyHit", 0.5f);
TackAnim.SetBool("tackMeated", false);
SoundByte.PlayOneShotGame(sfxName+"whiff");

View file

@ -278,8 +278,8 @@ namespace HeavenStudio.Games
private void Update()
{
// input stuff
if (PlayerInput.Pressed(true) && !IsExpectingInputNow(InputType.STANDARD_DOWN)) {
Debug.Log("ooops" + PlayerInput.Pressed(true));
if (PlayerInput.Pressed() && !IsExpectingInputNow(InputType.STANDARD_DOWN)) {
Debug.Log("ooops" + PlayerInput.Pressed());
MonkArmsAnim.DoScaledAnimationAsync("WristSlap", 0.5f);
SoundByte.PlayOneShotGame(sfxName+"slap");
isStaring = false;

View file

@ -47,7 +47,7 @@ namespace HeavenStudio.Games.Scripts_OctopusMachine
}
if (PlayerInput.PressedUp() && !game.IsExpectingInputNow(InputType.STANDARD_UP)) {
OctoAction(PlayerInput.Pressing(true) ? "Pop" : "Release");
OctoAction(PlayerInput.Pressing() ? "Pop" : "Release");
SoundByte.PlayOneShotGame("nearMiss");
game.hasMissed = true;
}

View file

@ -46,7 +46,7 @@ namespace HeavenStudio.Games.Scripts_RhythmTweezers
float normalizedBeat = Conductor.instance.GetPositionFromBeat(inputBeat, 0.5f);
anim.Play("LoopPull", 0, normalizedBeat);
tweezers.anim.Play("Tweezers_LongPluck", 0, normalizedBeat);
if (!game.IsExpectingInputNow(InputType.STANDARD_UP | InputType.DIRECTION_DOWN_UP) && PlayerInput.PressedUp(true) && normalizedBeat < 1f)
if (!game.IsExpectingInputNow(InputType.STANDARD_UP | InputType.DIRECTION_DOWN_UP) && (PlayerInput.PressedUp() || PlayerInput.GetAnyDirectionUp()) && normalizedBeat < 1f)
{
EndEarly();
endEvent.Disable();

View file

@ -64,7 +64,7 @@ namespace HeavenStudio.Games.Scripts_RhythmTweezers
private void LateUpdate()
{
if (PlayerInput.Pressed(true))
if (PlayerInput.Pressed() || PlayerInput.GetAnyDirectionDown())
{
if (!pluckingThisFrame) // Did you do a successful pluck earlier in the frame?
{

View file

@ -40,7 +40,7 @@ namespace HeavenStudio.Games.Scripts_WizardsWaltz
private void LateUpdate()
{
if (PlayerInput.Pressed(true))
if (PlayerInput.Pressed() || PlayerInput.GetAnyDirectionDown())
{
animator.Play("Magic", 0, 0);
SoundByte.PlayOneShotGame("wizardsWaltz/wand");

View file

@ -662,7 +662,7 @@ namespace HeavenStudio.InputSystem
return -1;
}
public override bool GetAction(int button)
public override bool GetAction(ControlStyles style, int button)
{
if (button == -1) { return false; }
if (otherHalf != null)
@ -672,10 +672,10 @@ namespace HeavenStudio.InputSystem
return actionStates[button].pressed;
}
public override bool GetActionDown(int button, out double dt)
public override bool GetActionDown(ControlStyles style, int button, out double dt)
{
if (button == -1) { dt = 0; return false; }
if (otherHalf != null && otherHalf.GetActionDown(button, out dt))
if (otherHalf != null && otherHalf.GetActionDown(style, button, out dt))
{
return true;
}
@ -683,10 +683,10 @@ namespace HeavenStudio.InputSystem
return actionStates[button].pressed && actionStates[button].isDelta;
}
public override bool GetActionUp(int button, out double dt)
public override bool GetActionUp(ControlStyles style, int button, out double dt)
{
if (button == -1) { dt = 0; return false; }
if (otherHalf != null && otherHalf.GetActionUp(button, out dt))
if (otherHalf != null && otherHalf.GetActionUp(style, button, out dt))
{
return true;
}
@ -764,9 +764,9 @@ namespace HeavenStudio.InputSystem
}
if (otherHalf != null)
{
return GetAction(bt) || BitwiseUtils.WantCurrent(otherHalf.directionStateCurrent, 1 << (int)direction) || BitwiseUtils.WantCurrent(directionStateCurrent, 1 << (int)direction);
return GetAction(ControlStyles.Pad, bt) || BitwiseUtils.WantCurrent(otherHalf.directionStateCurrent, 1 << (int)direction) || BitwiseUtils.WantCurrent(directionStateCurrent, 1 << (int)direction);
}
return GetAction(bt) || BitwiseUtils.WantCurrent(directionStateCurrent, 1 << (int)direction);
return GetAction(ControlStyles.Pad, bt) || BitwiseUtils.WantCurrent(directionStateCurrent, 1 << (int)direction);
}
public override bool GetHatDirectionDown(InputDirection direction, out double dt)
@ -790,7 +790,7 @@ namespace HeavenStudio.InputSystem
dt = 0;
return false;
}
bool btbool = GetActionDown(bt, out dt);
bool btbool = GetActionDown(ControlStyles.Pad, bt, out dt);
if (!btbool) dt = 0;
if (otherHalf != null)
{
@ -820,7 +820,7 @@ namespace HeavenStudio.InputSystem
dt = 0;
return false;
}
bool btbool = GetActionUp(bt, out dt);
bool btbool = GetActionUp(ControlStyles.Pad, bt, out dt);
if (!btbool) dt = 0;
if (otherHalf != null)
{
@ -966,5 +966,68 @@ namespace HeavenStudio.InputSystem
{
return otherHalf;
}
public override bool GetFlick(out double dt, out InputDirection direction)
{
dt = 0;
direction = InputDirection.Up;
return false;
}
public override bool GetSwipe(out double dt, out InputDirection direction)
{
dt = 0;
direction = InputDirection.Up;
return false;
}
public override void SetMaterialProperties(Material m)
{
Color colour;
switch (GetDeviceName())
{
case "Joy-Con (L)":
case "Joy-Con (R)":
m.SetColor("_BodyColor", GetBodyColor());
m.SetColor("_BtnColor", GetButtonColor());
m.SetColor("_LGripColor", ColorUtility.TryParseHtmlString("#2F353A", out colour) ? colour : Color.white);
m.SetColor("_RGripColor", ColorUtility.TryParseHtmlString("#2F353A", out colour) ? colour : Color.white);
break;
case "Joy-Con Pair":
m.SetColor("_BodyColor", splitType == SplitRight ? GetButtonColor() : GetOtherHalf().GetButtonColor());
m.SetColor("_BtnColor", splitType == SplitLeft ? GetButtonColor() : GetOtherHalf().GetButtonColor());
m.SetColor("_LGripColor", GetLeftGripColor());
m.SetColor("_RGripColor", GetRightGripColor());
break;
case "DualShock 4":
m.SetColor("_BodyColor", ColorUtility.TryParseHtmlString("#E1E2E4", out colour) ? colour : Color.white);
m.SetColor("_BtnColor", ColorUtility.TryParseHtmlString("#414246", out colour) ? colour : Color.white);
m.SetColor("_LGripColor", GetLightbarColour());
m.SetColor("_RGripColor", GetLightbarColour());
break;
case "DualSense":
m.SetColor("_BodyColor", ColorUtility.TryParseHtmlString("#DEE0EB", out colour) ? colour : Color.white);
m.SetColor("_BtnColor", ColorUtility.TryParseHtmlString("#272D39", out colour) ? colour : Color.white);
m.SetColor("_LGripColor", GetLightbarColour());
m.SetColor("_RGripColor", GetLightbarColour());
break;
default:
m.SetColor("_BodyColor", GetBodyColor());
m.SetColor("_BtnColor", GetButtonColor());
m.SetColor("_LGripColor", GetLeftGripColor());
m.SetColor("_RGripColor", GetRightGripColor());
break;
}
}
public override bool GetCurrentStyleSupported()
{
return PlayerInput.CurrentControlStyle is ControlStyles.Pad; // or ControlStyles.Baton
}
public override ControlStyles GetDefaultStyle()
{
return ControlStyles.Pad;
}
}
}

View file

@ -38,7 +38,8 @@ namespace HeavenStudio.InputSystem
.Where(k => ((int)k < (int)KeyCode.Mouse0))
.ToArray();
static ControlBindings defaultBindings {
static ControlBindings defaultBindings
{
get
{
return new ControlBindings()
@ -75,10 +76,10 @@ namespace HeavenStudio.InputSystem
}
public override void OnSelected()
{
{
}
public override string GetDeviceName()
{
return "Keyboard";
@ -157,20 +158,23 @@ namespace HeavenStudio.InputSystem
return -1;
}
public override bool GetAction(int button)
public override bool GetAction(ControlStyles style, int button)
{
if (button < 0) return false;
return Input.GetKey((KeyCode)currentBindings.Pad[button]);
}
public override bool GetActionDown(int button, out double dt)
public override bool GetActionDown(ControlStyles style, int button, out double dt)
{
dt = 0;
if (button < 0) return false;
return Input.GetKeyDown((KeyCode)currentBindings.Pad[button]);
}
public override bool GetActionUp(int button, out double dt)
public override bool GetActionUp(ControlStyles style, int button, out double dt)
{
dt = 0;
if (button < 0) return false;
return Input.GetKeyUp((KeyCode)currentBindings.Pad[button]);
}
@ -250,12 +254,42 @@ namespace HeavenStudio.InputSystem
this.playerNum = null;
return;
}
this.playerNum = (int) playerNum;
this.playerNum = (int)playerNum;
}
public override int? GetPlayer()
{
return playerNum;
}
public override bool GetFlick(out double dt, out InputDirection direction)
{
dt = 0;
direction = InputDirection.Up;
return false;
}
public override bool GetSwipe(out double dt, out InputDirection direction)
{
dt = 0;
direction = InputDirection.Up;
return false;
}
public override void SetMaterialProperties(Material m)
{
bool b = ColorUtility.TryParseHtmlString("#F4F4F4", out Color colour);
m.SetColor("_BodyColor", b ? colour : Color.white);
}
public override bool GetCurrentStyleSupported()
{
return PlayerInput.CurrentControlStyle is ControlStyles.Pad; // or ControlStyles.Baton
}
public override ControlStyles GetDefaultStyle()
{
return ControlStyles.Pad;
}
}
}

View file

@ -8,28 +8,25 @@ using HeavenStudio.Util;
namespace HeavenStudio.InputSystem.Loaders
{
namespace HeavenStudio.InputSystem.Loaders
public static class InputMouseInitializer
{
public static class InputMouseInitializer
[LoadOrder(1)]
public static InputController[] Initialize()
{
[LoadOrder(1)]
public static InputController[] Initialize()
{
PlayerInput.PlayerInputRefresh.Add(Refresh);
PlayerInput.PlayerInputRefresh.Add(Refresh);
InputMouse mouse = new InputMouse();
mouse.SetPlayer(null);
mouse.InitializeController();
return new InputController[] { mouse };
}
InputMouse mouse = new InputMouse();
mouse.SetPlayer(null);
mouse.InitializeController();
return new InputController[] { mouse };
}
public static InputController[] Refresh()
{
InputMouse mouse = new InputMouse();
mouse.SetPlayer(null);
mouse.InitializeController();
return new InputController[] { mouse };
}
public static InputController[] Refresh()
{
InputMouse mouse = new InputMouse();
mouse.SetPlayer(null);
mouse.InitializeController();
return new InputController[] { mouse };
}
}
}
@ -38,12 +35,16 @@ namespace HeavenStudio.InputSystem
{
public class InputMouse : InputController
{
const double FlickMarginTime = 0.1;
const double BigMoveMarginRate = 1.25;
private static readonly KeyCode[] keyCodes = Enum.GetValues(typeof(KeyCode))
.Cast<KeyCode>()
.Where(k => ((int)k <= (int)KeyCode.Mouse6))
.ToArray();
static ControlBindings defaultBindings {
static ControlBindings defaultBindings
{
get
{
return new ControlBindings()
@ -61,20 +62,46 @@ namespace HeavenStudio.InputSystem
}
}
static Vector3 screenBounds = Vector3.zero;
static Vector3 ScreenBounds
{
get
{
screenBounds.x = Screen.width;
screenBounds.y = Screen.height;
return screenBounds;
}
}
Vector3 rawPointerPos, lastRawPointerPos, startPointerPos, lastDownPointerPos, lastUpPointerPos;
Vector3 deltaPointerPos, lastDeltaPointerPos;
double timeMoveChange, timeDirectionChange;
byte dirLeftRight, dirUpDown;
public override void InitializeController()
{
LoadBindings();
}
public override void UpdateState()
{
// Update the state of the controller
lastRawPointerPos = rawPointerPos;
lastDeltaPointerPos = deltaPointerPos;
rawPointerPos = Input.mousePosition;
deltaPointerPos = rawPointerPos - lastRawPointerPos;
if (GetAction(ControlStyles.Touch, 0))
{
Debug.Log(deltaPointerPos.normalized);
}
}
public override void OnSelected()
{
{
}
public override string GetDeviceName()
{
return "Mouse";
@ -82,7 +109,7 @@ namespace HeavenStudio.InputSystem
public override string[] GetButtonNames()
{
string[] names = new string[(int)KeyCode.Mouse6];
string[] names = new string[(int)KeyCode.Mouse6 + 1];
for (int i = 0; i < keyCodes.Length; i++)
{
names[(int)keyCodes[i]] = keyCodes[i].ToString();
@ -97,7 +124,7 @@ namespace HeavenStudio.InputSystem
public override bool GetIsConnected()
{
return true;
return Input.mousePresent;
}
public override bool GetIsPoorConnection()
@ -134,7 +161,7 @@ namespace HeavenStudio.InputSystem
{
if (Input.anyKeyDown)
{
for (KeyCode i = keyCodes[1]; i <= KeyCode.Menu; i++)
for (KeyCode i = keyCodes[1]; i <= KeyCode.Mouse6; i++)
{
if (Input.GetKeyDown(i))
return (int)i;
@ -153,21 +180,95 @@ namespace HeavenStudio.InputSystem
return -1;
}
public override bool GetAction(int button)
public override bool GetAction(ControlStyles style, int button)
{
return Input.GetKey((KeyCode)currentBindings.Pad[button]);
if (button < 0) return false;
if (button is 0 or 1 or 2)
{
bool bt = Input.GetKey((KeyCode)currentBindings.Touch[1]) || Input.GetKey((KeyCode)currentBindings.Touch[2]);
switch (button)
{
case 0:
return bt;
case 1:
if (bt && rawPointerPos.x <= screenBounds.x * 0.5f)
{
lastDownPointerPos = rawPointerPos;
return true;
}
return false;
case 2:
if (bt && rawPointerPos.x >= screenBounds.x * 0.5f)
{
lastDownPointerPos = rawPointerPos;
return true;
}
return false;
}
}
return Input.GetKey((KeyCode)currentBindings.Touch[button]);
}
public override bool GetActionDown(int button, out double dt)
public override bool GetActionDown(ControlStyles style, int button, out double dt)
{
dt = 0;
return Input.GetKeyDown((KeyCode)currentBindings.Pad[button]);
if (button < 0) return false;
if (button is 0 or 1 or 2)
{
bool bt = Input.GetKeyDown((KeyCode)currentBindings.Touch[1]) || Input.GetKeyDown((KeyCode)currentBindings.Touch[2]);
switch (button)
{
case 0:
return bt;
case 1:
if (bt && rawPointerPos.x <= screenBounds.x * 0.5f)
{
lastDownPointerPos = rawPointerPos;
startPointerPos = rawPointerPos;
return true;
}
return false;
case 2:
if (bt && rawPointerPos.x >= screenBounds.x * 0.5f)
{
lastDownPointerPos = rawPointerPos;
startPointerPos = rawPointerPos;
return true;
}
return false;
}
}
return Input.GetKeyDown((KeyCode)currentBindings.Touch[button]);
}
public override bool GetActionUp(int button, out double dt)
public override bool GetActionUp(ControlStyles style, int button, out double dt)
{
dt = 0;
return Input.GetKeyUp((KeyCode)currentBindings.Pad[button]);
if (button < 0) return false;
if (button is 0 or 1 or 2)
{
bool bt = Input.GetKeyUp((KeyCode)currentBindings.Touch[1]) || Input.GetKeyUp((KeyCode)currentBindings.Touch[2]);
switch (button)
{
case 0:
return bt;
case 1:
if (bt && rawPointerPos.x <= screenBounds.x * 0.5f)
{
lastUpPointerPos = rawPointerPos;
return true;
}
return false;
case 2:
if (bt && rawPointerPos.x >= screenBounds.x * 0.5f)
{
lastUpPointerPos = rawPointerPos;
return true;
}
return false;
}
}
return Input.GetKeyUp((KeyCode)currentBindings.Touch[button]);
}
public override float GetAxis(InputAxis axis)
@ -246,12 +347,42 @@ namespace HeavenStudio.InputSystem
this.playerNum = null;
return;
}
this.playerNum = (int) playerNum;
this.playerNum = (int)playerNum;
}
public override int? GetPlayer()
{
return playerNum;
}
public override bool GetFlick(out double dt, out InputDirection direction)
{
dt = 0;
direction = InputDirection.Up;
return false;
}
public override bool GetSwipe(out double dt, out InputDirection direction)
{
dt = 0;
direction = InputDirection.Up;
return false;
}
public override void SetMaterialProperties(Material m)
{
bool b = ColorUtility.TryParseHtmlString("#F4F4F4", out Color colour);
m.SetColor("_BodyColor", b ? colour : Color.white);
}
public override bool GetCurrentStyleSupported()
{
return PlayerInput.CurrentControlStyle is ControlStyles.Touch;
}
public override ControlStyles GetDefaultStyle()
{
return ControlStyles.Touch;
}
}
}

View file

@ -23,7 +23,7 @@ namespace HeavenStudio.InputSystem
TouchpadY = 7
}
public enum InputVector: int
public enum InputVector : int
{
LStick = 0,
RStick = 1,
@ -46,31 +46,31 @@ namespace HeavenStudio.InputSystem
public enum InputFeatures
{
//readable properties
Readable_ShellColour = 1 << 0,
Readable_ButtonColour = 1 << 1,
Readable_LeftGripColour = 1 << 2,
Readable_RightGripColour = 1 << 3,
Readable_AnalogueTriggers = 1 << 4,
Readable_StringInput = 1 << 5,
Readable_Pointer = 1 << 6,
Readable_MotionSensor = 1 << 7,
Readable_ShellColour = 1 << 0,
Readable_ButtonColour = 1 << 1,
Readable_LeftGripColour = 1 << 2,
Readable_RightGripColour = 1 << 3,
Readable_AnalogueTriggers = 1 << 4,
Readable_StringInput = 1 << 5,
Readable_Pointer = 1 << 6,
Readable_MotionSensor = 1 << 7,
//writable properties
Writable_PlayerLED = 1 << 8,
Writable_LightBar = 1 << 9,
Writable_Chroma = 1 << 10,
Writable_Speaker = 1 << 11,
Writable_PlayerLED = 1 << 8,
Writable_LightBar = 1 << 9,
Writable_Chroma = 1 << 10,
Writable_Speaker = 1 << 11,
//other / "special" properties
Extra_SplitControllerLeft = 1 << 12,
Extra_SplitControllerRight = 1 << 13,
Extra_Rumble = 1 << 14,
Extra_HDRumble = 1 << 15,
Extra_SplitControllerLeft = 1 << 12,
Extra_SplitControllerRight = 1 << 13,
Extra_Rumble = 1 << 14,
Extra_HDRumble = 1 << 15,
//supported control styles
Style_Pad = 1 << 16,
Style_Baton = 1 << 17,
Style_Touch = 1 << 18,
Style_Pad = 1 << 16,
Style_Baton = 1 << 17,
Style_Touch = 1 << 18,
};
//Following enums are specific to Heaven Studio, can be removed in other applications
@ -101,7 +101,7 @@ namespace HeavenStudio.InputSystem
Pause = 10,
}
//FUTURE: buttons used in Heaven Studio gameplay ("Form Baton" / WiiMote Style)
//buttons used in Heaven Studio gameplay ("Form Baton" / WiiMote Style)
public enum ActionsBaton : int
{
South = 0, //-- all these...
@ -115,23 +115,32 @@ namespace HeavenStudio.InputSystem
Pause = 8,
}
//FUTURE: buttons used in Heaven Studio gameplay (Touch Style)
//buttons used in Heaven Studio gameplay (Touch Style)
public enum ActionsTouch : int
{
Tap = 0, // flicks are handled like a motion, don't have a binding
Left = 1, // also maps to tap, but with directionality (tap the left side of the panel)
Right = 2, // also maps to tap, but with directionality (tap the right side of the panel)
// flicks and swipes are handled as motions, and don't have bindings
Tap = 0,
Left = 1, // also maps to tap, but with directionality (tap the left side of the panel). internally, maps to Pointer 1
Right = 2, // also maps to tap, but with directionality (tap the right side of the panel). internally, maps to Pointer 2
ButtonL = 3,
ButtonR = 4,
Pause = 5,
}
//buttons used in Heaven Studio gameplay (Move Style)
public enum ActionsMove : int
{
Button = 0,
Pause = 1,
}
[System.Serializable]
public struct ControlBindings
{
public int[] Pad;
public int[] Baton;
public int[] Touch;
public int[] Move;
}
// FUTURE: Move Style needs to be implemented per-game (maybe implement checks for common actions?)
@ -224,7 +233,7 @@ namespace HeavenStudio.InputSystem
/// </summary>
/// <param name="action"></param>
/// <returns></returns>
public abstract bool GetAction(int action);
public abstract bool GetAction(ControlStyles style, int action);
/// <summary>
/// True if the action was just pressed this Update
@ -232,7 +241,7 @@ namespace HeavenStudio.InputSystem
/// <param name="action"></param>
/// <param name="dt">time since the reported event, use to compensate for controller delays</param>
/// <returns></returns>
public abstract bool GetActionDown(int action, out double dt);
public abstract bool GetActionDown(ControlStyles style, int action, out double dt);
/// <summary>
/// True if the action was just released this Update
@ -240,7 +249,7 @@ namespace HeavenStudio.InputSystem
/// <param name="action"></param>
/// <param name="dt">time since the reported event, use to compensate for controller delays</param>
/// <returns></returns>
public abstract bool GetActionUp(int action, out double dt);
public abstract bool GetActionUp(ControlStyles style, int action, out double dt);
/// <summary>
/// Get the value of an analogue axis
@ -249,8 +258,17 @@ namespace HeavenStudio.InputSystem
/// <returns></returns>
public abstract float GetAxis(InputAxis axis);
/// <summary>
/// Get the value of a 3d vector (2d vectors have z set to 0)
/// </summary>
/// <param name="vector"></param>
/// <returns></returns>
public abstract Vector3 GetVector(InputVector vector);
/// <summary>
/// Get the value of a pointer mapped to screen coordinates
/// </summary>
/// <returns></returns>
public abstract Vector2 GetPointer();
/// <summary>
@ -276,6 +294,9 @@ namespace HeavenStudio.InputSystem
/// <returns></returns>
public abstract bool GetHatDirectionUp(InputDirection direction, out double dt);
public abstract bool GetFlick(out double dt, out InputDirection direction);
public abstract bool GetSwipe(out double dt, out InputDirection direction);
/// <summary>
/// Sets the player number (starts at 1, set to -1 or null for no player)
/// </summary>
@ -288,7 +309,9 @@ namespace HeavenStudio.InputSystem
/// <returns></returns>
public abstract int? GetPlayer();
//public abstract Sprite GetDisplayIcon(); //"big icon" for the controller in the settings menu
//public abstract Sprite GetPlaybackIcon(); //"small icon" for the controller during playback
public abstract void SetMaterialProperties(Material m);
public abstract bool GetCurrentStyleSupported();
public abstract ControlStyles GetDefaultStyle();
}
}

View file

@ -12,9 +12,11 @@ using HeavenStudio.Games;
namespace HeavenStudio.InputSystem
{
public class LoadOrder : Attribute {
public class LoadOrder : Attribute
{
public int Order { get; set; }
public LoadOrder(int order) {
public LoadOrder(int order)
{
Order = order;
}
}
@ -47,7 +49,7 @@ namespace HeavenStudio
public const int LEFT = 3;
public static InputController.ControlStyles CurrentControlStyle = InputController.ControlStyles.Pad;
static List<InputController> inputDevices;
public delegate InputController[] InputControllerInitializer();
@ -59,14 +61,15 @@ namespace HeavenStudio
public static List<InputControllerRefresh> PlayerInputRefresh;
static List<InputControllerInitializer> loadRunners;
static void BuildLoadRunnerList() {
static void BuildLoadRunnerList()
{
PlayerInputRefresh = new();
loadRunners = System.Reflection.Assembly.GetExecutingAssembly()
.GetTypes()
.Where(x => x.Namespace == "HeavenStudio.InputSystem.Loaders" && x.GetMethod("Initialize", BindingFlags.Public | BindingFlags.Static) != null)
.Select(t => (InputControllerInitializer) Delegate.CreateDelegate(
typeof(InputControllerInitializer),
null,
.Select(t => (InputControllerInitializer)Delegate.CreateDelegate(
typeof(InputControllerInitializer),
null,
t.GetMethod("Initialize", BindingFlags.Public | BindingFlags.Static),
false
))
@ -80,44 +83,49 @@ namespace HeavenStudio
inputDevices = new List<InputController>();
BuildLoadRunnerList();
foreach (InputControllerInitializer runner in loadRunners) {
foreach (InputControllerInitializer runner in loadRunners)
{
InputController[] controllers = runner();
if (controllers != null) {
if (controllers != null)
{
inputDevices.AddRange(controllers);
}
}
return inputDevices.Count;
}
public static int RefreshInputControllers()
{
inputDevices = new List<InputController>();
if (PlayerInputRefresh != null) {
foreach (InputControllerRefresh runner in PlayerInputRefresh) {
if (PlayerInputRefresh != null)
{
foreach (InputControllerRefresh runner in PlayerInputRefresh)
{
InputController[] controllers = runner();
if (controllers != null) {
if (controllers != null)
{
inputDevices.AddRange(controllers);
}
}
}
return inputDevices.Count;
}
public static int GetNumControllersConnected()
{
return inputDevices.Count;
}
public static List<InputController> GetInputControllers()
{
return inputDevices;
}
public static InputController GetInputController(int player)
{
// Needed so Keyboard works on MacOS and Linux
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
inputDevices = new List<InputController>();
if(inputDevices.Count < 1)
{
@ -126,7 +134,7 @@ namespace HeavenStudio
keyboard.InitializeController();
inputDevices.Add(keyboard);
}
#endif
#endif
//select input controller 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
@ -139,17 +147,17 @@ 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)
// Needed so Keyboard works on MacOS and Linux
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
inputDevices = new List<InputController>();
if(inputDevices.Count < 1)
{
@ -158,7 +166,7 @@ namespace HeavenStudio
keyboard.InitializeController();
inputDevices.Add(keyboard);
}
#endif
#endif
for (int i = 0; i < inputDevices.Count; i++)
{
if (inputDevices[i].GetPlayer() == player)
@ -168,11 +176,11 @@ namespace HeavenStudio
}
return -1;
}
public static void UpdateInputControllers()
{
// Needed so Keyboard works on MacOS and Linux
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
inputDevices = new List<InputController>();
if(inputDevices.Count < 1)
{
@ -181,18 +189,18 @@ namespace HeavenStudio
keyboard.InitializeController();
inputDevices.Add(keyboard);
}
#endif
#endif
foreach (InputController i in inputDevices)
{
i.UpdateState();
}
}
public static void CleanUp()
{
PlayerInputCleanUp?.Invoke();
}
// The autoplay isn't activated AND
// The song is actually playing AND
// The GameManager allows you to Input
@ -200,7 +208,7 @@ namespace HeavenStudio
{
return !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
/*--------------------*/
/* MAIN INPUT METHODS */
/*--------------------*/
@ -219,82 +227,162 @@ namespace HeavenStudio
}
return false;
}
// BUTTONS
public static bool Pressed(bool includeDPad = false)
public static bool GetPadDown(InputController.ActionsPad ac, out double dt)
{
bool keyDown = GetInputController(1).GetActionDown((int) InputController.ActionsPad.East, out _) || (includeDPad && GetAnyDirectionDown());
bool a = GetInputController(1).GetActionDown(InputController.ControlStyles.Pad, (int)ac, out dt);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetPadDown(InputController.ActionsPad ac)
{
bool a = GetInputController(1).GetActionDown(InputController.ControlStyles.Pad, (int)ac, out _);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetPadUp(InputController.ActionsPad ac, out double dt)
{
bool a = GetInputController(1).GetActionUp(InputController.ControlStyles.Pad, (int)ac, out dt);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetPadUp(InputController.ActionsPad ac)
{
bool a = GetInputController(1).GetActionUp(InputController.ControlStyles.Pad, (int)ac, out _);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetPad(InputController.ActionsPad ac)
{
bool a = GetInputController(1).GetAction(InputController.ControlStyles.Pad, (int)ac);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetTouchDown(InputController.ActionsPad ac, out double dt)
{
bool a = GetInputController(1).GetActionDown(InputController.ControlStyles.Touch, (int)ac, out dt);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetTouchDown(InputController.ActionsPad ac)
{
bool a = GetInputController(1).GetActionDown(InputController.ControlStyles.Touch, (int)ac, out _);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetTouchUp(InputController.ActionsPad ac, out double dt)
{
bool a = GetInputController(1).GetActionUp(InputController.ControlStyles.Touch, (int)ac, out dt);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetTouchUp(InputController.ActionsPad ac)
{
bool a = GetInputController(1).GetActionUp(InputController.ControlStyles.Touch, (int)ac, out _);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetTouch(InputController.ActionsTouch ac)
{
bool a = GetInputController(1).GetAction(InputController.ControlStyles.Touch, (int)ac);
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetSwipe()
{
bool a = false;
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool GetFlick()
{
bool a = false;
return a && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
#region Deprecated Input Methods
[Obsolete("Use GetPadDown instead")]
public static bool Pressed()
{
bool keyDown = GetInputController(1).GetActionDown(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.East, out _);
return keyDown && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool Pressed(out double dt, bool includeDPad = false)
[Obsolete("Use GetPadDown instead")]
public static bool Pressed(out double dt)
{
bool keyDown = GetInputController(1).GetActionDown((int) InputController.ActionsPad.East, out dt) || (includeDPad && GetAnyDirectionDown());
bool keyDown = GetInputController(1).GetActionDown(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.East, out dt);
return keyDown && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool PressedUp(bool includeDPad = false)
[Obsolete("Use GetPadUp instead")]
public static bool PressedUp()
{
bool keyUp = GetInputController(1).GetActionUp((int) InputController.ActionsPad.East, out _) || (includeDPad && GetAnyDirectionUp());
bool keyUp = GetInputController(1).GetActionUp(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.East, out _);
return keyUp && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool PressedUp(out double dt, bool includeDPad = false)
[Obsolete("Use GetPadUp instead")]
public static bool PressedUp(out double dt)
{
bool keyUp = GetInputController(1).GetActionUp((int) InputController.ActionsPad.East, out dt) || (includeDPad && GetAnyDirectionUp());
bool keyUp = GetInputController(1).GetActionUp(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.East, out dt);
return keyUp && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
public static bool Pressing(bool includeDPad = false)
[Obsolete("Use GetPad instead")]
public static bool Pressing()
{
bool pressing = GetInputController(1).GetAction((int) InputController.ActionsPad.East) || (includeDPad && GetAnyDirection());
bool pressing = GetInputController(1).GetAction(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.East);
return pressing && !GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput;
}
[Obsolete("Use GetPadDown instead")]
public static bool AltPressed()
{
bool down = GetInputController(1).GetActionDown((int) InputController.ActionsPad.South, out _);
bool down = GetInputController(1).GetActionDown(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.South, out _);
return down && PlayerHasControl();
}
[Obsolete("Use GetPadDown instead")]
public static bool AltPressed(out double dt)
{
bool down = GetInputController(1).GetActionDown((int) InputController.ActionsPad.South, out dt);
bool down = GetInputController(1).GetActionDown(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.South, out dt);
return down && PlayerHasControl();
}
[Obsolete("Use GetPadUp instead")]
public static bool AltPressedUp()
{
bool up = GetInputController(1).GetActionUp((int) InputController.ActionsPad.South, out _);
bool up = GetInputController(1).GetActionUp(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.South, out _);
return up && PlayerHasControl();
}
[Obsolete("Use GetPadUp instead")]
public static bool AltPressedUp(out double dt)
{
bool up = GetInputController(1).GetActionUp((int) InputController.ActionsPad.South, out dt);
bool up = GetInputController(1).GetActionUp(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.South, out dt);
return up && PlayerHasControl();
}
[Obsolete("Use GetPad instead")]
public static bool AltPressing()
{
bool pressing = GetInputController(1).GetAction((int) InputController.ActionsPad.South);
bool pressing = GetInputController(1).GetAction(InputController.ControlStyles.Pad, (int)InputController.ActionsPad.South);
return pressing && PlayerHasControl();
}
//Directions
[Obsolete("Use GetPadDown instead")]
public static bool GetAnyDirectionDown()
{
InputController c = GetInputController(1);
return (c.GetHatDirectionDown((InputController.InputDirection) UP, out _)
|| c.GetHatDirectionDown((InputController.InputDirection) DOWN, out _)
|| c.GetHatDirectionDown((InputController.InputDirection) LEFT, out _)
|| c.GetHatDirectionDown((InputController.InputDirection) RIGHT, out _)
return (c.GetHatDirectionDown((InputController.InputDirection)UP, out _)
|| c.GetHatDirectionDown((InputController.InputDirection)DOWN, out _)
|| c.GetHatDirectionDown((InputController.InputDirection)LEFT, out _)
|| c.GetHatDirectionDown((InputController.InputDirection)RIGHT, out _)
) && PlayerHasControl();
}
[Obsolete("Use GetPadDown instead")]
public static bool GetAnyDirectionDown(out double dt)
{
InputController c = GetInputController(1);
@ -306,17 +394,19 @@ namespace HeavenStudio
dt = Math.Max(Math.Max(Math.Max(d1, d2), d3), d4);
return r;
}
[Obsolete("Use GetPadUp instead")]
public static bool GetAnyDirectionUp()
{
InputController c = GetInputController(1);
return (c.GetHatDirectionUp((InputController.InputDirection) UP, out _)
|| c.GetHatDirectionUp((InputController.InputDirection) DOWN, out _)
|| c.GetHatDirectionUp((InputController.InputDirection) LEFT, out _)
|| c.GetHatDirectionUp((InputController.InputDirection) RIGHT, out _)
) && PlayerHasControl();
return (c.GetHatDirectionUp((InputController.InputDirection)UP, out _)
|| c.GetHatDirectionUp((InputController.InputDirection)DOWN, out _)
|| c.GetHatDirectionUp((InputController.InputDirection)LEFT, out _)
|| c.GetHatDirectionUp((InputController.InputDirection)RIGHT, out _)
) && PlayerHasControl();
}
[Obsolete("Use GetPadUp instead")]
public static bool GetAnyDirectionUp(out double dt)
{
InputController c = GetInputController(1);
@ -328,40 +418,47 @@ namespace HeavenStudio
dt = Math.Max(Math.Max(Math.Max(d1, d2), d3), d4);
return r;
}
[Obsolete("Use GetPad instead")]
public static bool GetAnyDirection()
{
InputController c = GetInputController(1);
return (c.GetHatDirection((InputController.InputDirection) UP)
|| c.GetHatDirection((InputController.InputDirection) DOWN)
|| c.GetHatDirection((InputController.InputDirection) LEFT)
|| c.GetHatDirection((InputController.InputDirection) RIGHT)
return (c.GetHatDirection((InputController.InputDirection)UP)
|| c.GetHatDirection((InputController.InputDirection)DOWN)
|| c.GetHatDirection((InputController.InputDirection)LEFT)
|| c.GetHatDirection((InputController.InputDirection)RIGHT)
) && PlayerHasControl();
}
[Obsolete("Use GetPad instead")]
public static bool GetSpecificDirection(int direction)
{
return GetInputController(1).GetHatDirection((InputController.InputDirection) direction) && PlayerHasControl();
return GetInputController(1).GetHatDirection((InputController.InputDirection)direction) && PlayerHasControl();
}
[Obsolete("Use GetPadDown instead")]
public static bool GetSpecificDirectionDown(int direction)
{
return GetInputController(1).GetHatDirectionDown((InputController.InputDirection) direction, out _) && PlayerHasControl();
return GetInputController(1).GetHatDirectionDown((InputController.InputDirection)direction, out _) && PlayerHasControl();
}
[Obsolete("Use GetPadUp instead")]
public static bool GetSpecificDirectionUp(int direction)
{
return GetInputController(1).GetHatDirectionUp((InputController.InputDirection) direction, out _) && PlayerHasControl();
return GetInputController(1).GetHatDirectionUp((InputController.InputDirection)direction, out _) && PlayerHasControl();
}
[Obsolete("Use GetPadDown instead")]
public static bool GetSpecificDirectionDown(int direction, out double dt)
{
return GetInputController(1).GetHatDirectionDown((InputController.InputDirection) direction, out dt) && PlayerHasControl();
return GetInputController(1).GetHatDirectionDown((InputController.InputDirection)direction, out dt) && PlayerHasControl();
}
[Obsolete("Use GetPadUp instead")]
public static bool GetSpecificDirectionUp(int direction, out double dt)
{
return GetInputController(1).GetHatDirectionUp((InputController.InputDirection) direction, out dt) && PlayerHasControl();
return GetInputController(1).GetHatDirectionUp((InputController.InputDirection)direction, out dt) && PlayerHasControl();
}
#endregion
}
}

View file

@ -31,7 +31,7 @@ namespace HeavenStudio.Common
[SerializeField] RectTransform patternL;
[SerializeField] RectTransform patternR;
public static bool IsPaused { get { return isPaused; } }
private static bool isPaused = false;
@ -40,6 +40,8 @@ namespace HeavenStudio.Common
private bool isQuitting = false;
private int optionSelected = 0;
int btPause, btUp, btDown, btConfirm;
void Pause()
{
if (GlobalGameManager.IsShowingDialog) return;
@ -69,7 +71,7 @@ namespace HeavenStudio.Common
animator.Play("PauseHide");
SoundByte.PlayOneShot("ui/PauseOut");
}
isPaused = false;
canPick = false;
}
@ -84,8 +86,31 @@ namespace HeavenStudio.Common
// Update is called once per frame
void Update()
{
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
btPause = (int)InputController.ActionsTouch.Pause;
btConfirm = (int)InputController.ActionsTouch.Tap;
btUp = -1;
btDown = -1;
break;
case InputController.ControlStyles.Baton:
btPause = (int)InputController.ActionsBaton.Pause;
btUp = (int)InputController.ActionsBaton.Up;
btDown = (int)InputController.ActionsBaton.Down;
btConfirm = (int)InputController.ActionsBaton.Face;
break;
default:
btPause = (int)InputController.ActionsPad.Pause;
btUp = (int)InputController.ActionsPad.Up;
btDown = (int)InputController.ActionsPad.Down;
btConfirm = (int)InputController.ActionsPad.East;
break;
}
if (isQuitting) return;
if (PlayerInput.GetInputController(1).GetActionDown((int) InputController.ActionsPad.Pause, out _))
if (PlayerInput.GetInputController(1).GetActionDown(PlayerInput.CurrentControlStyle, btPause, out _))
{
if (isPaused)
{
@ -98,27 +123,27 @@ namespace HeavenStudio.Common
}
else if (isPaused && canPick && !settingsDialog.IsOpen)
{
if (Input.GetKeyDown(KeyCode.UpArrow) || PlayerInput.GetInputController(1).GetActionDown((int)InputController.ActionsPad.Up, out _))
if (Input.GetKeyDown(KeyCode.UpArrow) || PlayerInput.GetInputController(1).GetActionDown(PlayerInput.CurrentControlStyle, btUp, out _))
{
optionSelected--;
if (optionSelected < 0)
{
optionSelected = optionHolder.transform.childCount - 1;
}
ChooseOption((Options) optionSelected);
ChooseOption((Options)optionSelected);
}
else if (Input.GetKeyDown(KeyCode.DownArrow) || PlayerInput.GetInputController(1).GetActionDown((int)InputController.ActionsPad.Down, out _))
else if (Input.GetKeyDown(KeyCode.DownArrow) || PlayerInput.GetInputController(1).GetActionDown(PlayerInput.CurrentControlStyle, btDown, out _))
{
optionSelected++;
if (optionSelected > optionHolder.transform.childCount - 1)
{
optionSelected = 0;
}
ChooseOption((Options) optionSelected);
ChooseOption((Options)optionSelected);
}
else if (Input.GetKeyDown(KeyCode.Return) || PlayerInput.GetInputController(1).GetActionDown((int)InputController.ActionsPad.East, out _))
else if (Input.GetKeyDown(KeyCode.Return) || PlayerInput.GetInputController(1).GetActionDown(PlayerInput.CurrentControlStyle, btConfirm, out _))
{
UseOption((Options) optionSelected);
UseOption((Options)optionSelected);
}
}
@ -131,18 +156,18 @@ namespace HeavenStudio.Common
public void ChooseCurrentOption()
{
ChooseOption((Options) optionSelected, false);
ChooseOption((Options)optionSelected, false);
canPick = true;
}
public void ChooseOption(Options option, bool sound = true)
{
optionArrow.transform.position = new Vector3(optionArrow.transform.position.x, optionHolder.transform.GetChild((int) option).position.y, optionArrow.transform.position.z);
optionArrow.transform.position = new Vector3(optionArrow.transform.position.x, optionHolder.transform.GetChild((int)option).position.y, optionArrow.transform.position.z);
foreach (Transform child in optionHolder.transform)
{
child.transform.localScale = new Vector3(1f, 1f, 1f);
}
optionHolder.transform.GetChild((int) option).transform.localScale = new Vector3(1.2f, 1.2f, 1.2f);
optionHolder.transform.GetChild((int)option).transform.localScale = new Vector3(1.2f, 1.2f, 1.2f);
if (sound)
SoundByte.PlayOneShot("ui/UIOption");
}

View file

@ -12,7 +12,7 @@ using HeavenStudio.Util;
using HeavenStudio.InputSystem;
using static JSL;
namespace HeavenStudio.Editor
namespace HeavenStudio.Editor
{
public class ControllerSettings : TabsContent
{
@ -45,19 +45,29 @@ namespace HeavenStudio.Editor
private bool bindAllMode;
private int currentBindingBt;
private void Start() {
PopulateStylesDropdown();
private void Start()
{
numConnectedLabel.text = "Connected: " + PlayerInput.GetNumControllersConnected();
currentControllerLabel.text = "Current Controller: " + PlayerInput.GetInputController(1).GetDeviceName();
PopulateControllersDropdown();
PopulateStylesDropdown();
pairSearchItem.SetActive(false);
ShowControllerBinds(PlayerInput.GetInputController(1));
ShowControllerIcon(PlayerInput.GetInputController(1));
InputController initController = PlayerInput.GetInputController(1);
if (!initController.GetCurrentStyleSupported())
{
PlayerInput.CurrentControlStyle = initController.GetDefaultStyle();
stylesDropdown.value = (int)PlayerInput.CurrentControlStyle;
}
UpdateControlStyleMapping();
ShowControllerBinds(initController);
ShowControllerIcon(initController);
}
private void Update() {
private void Update()
{
InputController currentController = PlayerInput.GetInputController(1);
if (currentBindingBt >= 0)
{
@ -65,7 +75,18 @@ namespace HeavenStudio.Editor
if (bt > 0)
{
InputController.ControlBindings binds = currentController.GetCurrentBindings();
binds.Pad[currentBindingBt] = bt;
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
binds.Touch[currentBindingBt] = bt;
break;
case InputController.ControlStyles.Baton:
binds.Baton[currentBindingBt] = bt;
break;
default:
binds.Pad[currentBindingBt] = bt;
break;
}
currentController.SetCurrentBindings(binds);
currentControllerLabel.text = "Current Controller: " + currentController.GetDeviceName();
ShowControllerBinds(currentController);
@ -75,10 +96,12 @@ namespace HeavenStudio.Editor
}
else
{
if (isAutoSearching) {
if (isAutoSearching)
{
var controllers = PlayerInput.GetInputControllers();
foreach (var newController in controllers) {
if (newController.GetLastButtonDown() > 0)
foreach (var newController in controllers)
{
if (newController.GetLastButtonDown() > 0)
{
isAutoSearching = false;
autoSearchLabel.SetActive(false);
@ -88,18 +111,20 @@ namespace HeavenStudio.Editor
}
}
}
else if (isPairSearching) {
else if (isPairSearching)
{
var controllers = PlayerInput.GetInputControllers();
InputController.InputFeatures lrFlag = pairSelectLR ? InputController.InputFeatures.Extra_SplitControllerLeft : InputController.InputFeatures.Extra_SplitControllerRight;
foreach (var pairController in controllers) {
foreach (var pairController in controllers)
{
if (pairController == currentController) continue;
InputController.InputFeatures features = pairController.GetFeatures();
if (!features.HasFlag(lrFlag)) continue;
if (pairController.GetLastButtonDown() > 0)
if (pairController.GetLastButtonDown() > 0)
{
(PlayerInput.GetInputController(1) as InputJoyshock)?.AssignOtherHalf((InputJoyshock) pairController);
(PlayerInput.GetInputController(1) as InputJoyshock)?.AssignOtherHalf((InputJoyshock)pairController);
isPairSearching = false;
pairSearchLabel.SetActive(false);
currentControllerLabel.text = "Current Controller: " + pairController.GetDeviceName();
@ -116,23 +141,41 @@ namespace HeavenStudio.Editor
void AdvanceAutoBind(InputController currentController)
{
int pauseVal;
Type enumType;
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
enumType = typeof(InputController.ActionsTouch);
pauseVal = (int)InputController.ActionsTouch.Pause;
break;
case InputController.ControlStyles.Baton:
enumType = typeof(InputController.ActionsBaton);
pauseVal = (int)InputController.ActionsBaton.Pause;
break;
default:
enumType = typeof(InputController.ActionsPad);
pauseVal = (int)InputController.ActionsPad.Pause;
break;
}
if (bindAllMode)
{
currentBindingBt++;
Debug.Log("Binding: " + currentBindingBt);
while (currentController.GetIsActionUnbindable(currentBindingBt, InputController.ControlStyles.Pad) && currentBindingBt < (int)InputController.ActionsPad.Pause)
while (currentController.GetIsActionUnbindable(currentBindingBt, PlayerInput.CurrentControlStyle) && currentBindingBt < pauseVal)
{
currentBindingBt++;
Debug.Log("Unbindable, binding: " + currentBindingBt);
}
if (currentBindingBt > (int)InputController.ActionsPad.Pause)
if (currentBindingBt > pauseVal)
{
currentController.SaveBindings();
CancelBind();
return;
}
currentControllerLabel.text = $"Now Binding: {(InputController.ActionsPad) currentBindingBt}";
currentControllerLabel.text = $"Now Binding: {enumType.GetEnumName(currentBindingBt)}";
}
else
{
@ -145,41 +188,51 @@ namespace HeavenStudio.Editor
{
Debug.Log("Assigning controller: " + newController.GetDeviceName());
lastController.SetPlayer(-1);
lastController.SetPlayer(null);
newController.SetPlayer(1);
if ((lastController as InputJoyshock) != null)
if ((lastController as InputJoyshock) != null)
{
(lastController as InputJoyshock)?.UnAssignOtherHalf();
}
if ((newController as InputJoyshock) != null)
if ((newController as InputJoyshock) != null)
{
newController.OnSelected();
(newController as InputJoyshock)?.UnAssignOtherHalf();
}
currentControllerLabel.text = "Current Controller: " + newController.GetDeviceName();
if (!newController.GetCurrentStyleSupported())
{
PlayerInput.CurrentControlStyle = newController.GetDefaultStyle();
stylesDropdown.value = (int)PlayerInput.CurrentControlStyle;
}
UpdateControlStyleMapping();
ShowControllerBinds(newController);
ShowControllerIcon(newController);
InputController.InputFeatures features = newController.GetFeatures();
if (features.HasFlag(InputController.InputFeatures.Extra_SplitControllerLeft)) {
if (features.HasFlag(InputController.InputFeatures.Extra_SplitControllerLeft))
{
pairingLabel.text = "Joy-Con (L) Selected\nPress any button on Joy-Con (R) to pair.";
pairSelectLR = !features.HasFlag(InputController.InputFeatures.Extra_SplitControllerLeft);
pairSearchItem.SetActive(true);
StartPairSearch();
}
else if (features.HasFlag(InputController.InputFeatures.Extra_SplitControllerRight)) {
else if (features.HasFlag(InputController.InputFeatures.Extra_SplitControllerRight))
{
pairingLabel.text = "Joy-Con (R) Selected\nPress any button on Joy-Con (L) to pair.";
pairSelectLR = !features.HasFlag(InputController.InputFeatures.Extra_SplitControllerLeft);
pairSearchItem.SetActive(true);
StartPairSearch();
}
else {
else
{
CancelPairSearch();
pairSearchItem.SetActive(false);
}
@ -198,12 +251,24 @@ namespace HeavenStudio.Editor
public void StartBindSingle(int bt)
{
CancelBind();
if (PlayerInput.GetInputController(1).GetIsActionUnbindable(bt, InputController.ControlStyles.Pad))
if (PlayerInput.GetInputController(1).GetIsActionUnbindable(bt, PlayerInput.CurrentControlStyle))
{
return;
}
currentBindingBt = bt;
currentControllerLabel.text = $"Now Binding: {(InputController.ActionsPad) bt}";
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
currentControllerLabel.text = $"Now Binding: {(InputController.ActionsTouch)bt}";
break;
case InputController.ControlStyles.Baton:
currentControllerLabel.text = $"Now Binding: {(InputController.ActionsBaton)bt}";
break;
default:
currentControllerLabel.text = $"Now Binding: {(InputController.ActionsPad)bt}";
break;
}
}
public void StartBindAll()
@ -230,7 +295,8 @@ namespace HeavenStudio.Editor
controller.SaveBindings();
}
public void StartAutoSearch() {
public void StartAutoSearch()
{
CancelBind();
if (!isPairSearching)
{
@ -239,18 +305,22 @@ namespace HeavenStudio.Editor
}
}
public void StartPairSearch() {
public void StartPairSearch()
{
CancelBind();
if (!isAutoSearching) {
if (!isAutoSearching)
{
pairSearchLabel.SetActive(true);
pairSearchCancelBt.SetActive(true);
isPairSearching = true;
}
}
public void CancelPairSearch() {
public void CancelPairSearch()
{
CancelBind();
if (isPairSearching) {
if (isPairSearching)
{
pairSearchLabel.SetActive(false);
pairSearchCancelBt.SetActive(false);
isPairSearching = false;
@ -272,9 +342,9 @@ namespace HeavenStudio.Editor
var enumNames = Enum.GetNames(typeof(InputController.ControlStyles)).ToList();
controllersDropdown.ClearOptions();
stylesDropdown.ClearOptions();
stylesDropdown.AddOptions(enumNames);
stylesDropdown.value = (int) PlayerInput.CurrentControlStyle;
stylesDropdown.value = (int)PlayerInput.CurrentControlStyle;
}
public void PopulateControllersDropdown()
@ -292,27 +362,78 @@ namespace HeavenStudio.Editor
controllersDropdown.value = PlayerInput.GetInputControllerId(1);
}
public void ChangeControlStyle()
{
CancelBind();
PlayerInput.CurrentControlStyle = (InputController.ControlStyles)stylesDropdown.value;
}
public void UpdateControlStyleMapping()
{
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
PadBindingsMenus.ForEach(x => x.SetActive(false));
BatonBindingsMenus.ForEach(x => x.SetActive(false));
TouchBindingsMenus.ForEach(x => x.SetActive(true));
break;
case InputController.ControlStyles.Baton:
PadBindingsMenus.ForEach(x => x.SetActive(false));
BatonBindingsMenus.ForEach(x => x.SetActive(true));
TouchBindingsMenus.ForEach(x => x.SetActive(false));
break;
default:
PadBindingsMenus.ForEach(x => x.SetActive(true));
BatonBindingsMenus.ForEach(x => x.SetActive(false));
TouchBindingsMenus.ForEach(x => x.SetActive(false));
break;
}
}
public void ShowControllerBinds(InputController controller)
{
string[] buttons = controller.GetButtonNames();
List<TMP_Text> bindsTxt;
int[] binds;
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
bindsTxt = TouchBindingsTxt;
binds = controller.GetCurrentBindings().Touch;
break;
case InputController.ControlStyles.Baton:
bindsTxt = BatonBindingsTxt;
binds = controller.GetCurrentBindings().Baton;
break;
default:
bindsTxt = PadBindingsTxt;
binds = controller.GetCurrentBindings().Pad;
break;
}
//show binds
int ac = 0;
foreach (int i in controller.GetCurrentBindings().Pad)
foreach (int i in binds)
{
if (ac >= PadBindingsTxt.Count) break;
if (ac >= bindsTxt.Count) break;
if (bindsTxt[ac] == null)
{
ac++;
continue;
}
if (i == -1)
{
PadBindingsTxt[ac].text = "NOT BOUND";
bindsTxt[ac].text = "NOT BOUND";
}
else if (buttons[i] == null)
{
PadBindingsTxt[ac].text = "UNKNOWN";
bindsTxt[ac].text = "UNKNOWN";
}
else
{
PadBindingsTxt[ac].text = buttons[i];
bindsTxt[ac].text = buttons[i];
}
ac++;
}
@ -336,56 +457,7 @@ namespace HeavenStudio.Editor
}
//setup material
Color colour;
switch (name)
{
case "Keyboard":
controllerMat.SetColor("_BodyColor", ColorUtility.TryParseHtmlString("#F4F4F4", out colour) ? colour : Color.white);
break;
case "Joy-Con (L)":
case "Joy-Con (R)":
InputJoyshock joy = (InputJoyshock) controller;
controllerMat.SetColor("_BodyColor", joy.GetBodyColor());
controllerMat.SetColor("_BtnColor", joy.GetButtonColor());
controllerMat.SetColor("_LGripColor", ColorUtility.TryParseHtmlString("#2F353A", out colour) ? colour : Color.white);
controllerMat.SetColor("_RGripColor", ColorUtility.TryParseHtmlString("#2F353A", out colour) ? colour : Color.white);
break;
case "Joy-Con Pair":
joy = (InputJoyshock) controller;
int joySide = JslGetControllerSplitType(joy.GetHandle());
controllerMat.SetColor("_BodyColor", joySide == SplitRight ? joy.GetButtonColor() : joy.GetOtherHalf().GetButtonColor());
controllerMat.SetColor("_BtnColor", joySide == SplitLeft ? joy.GetButtonColor() : joy.GetOtherHalf().GetButtonColor());
controllerMat.SetColor("_LGripColor", joy.GetLeftGripColor());
controllerMat.SetColor("_RGripColor", joy.GetRightGripColor());
break;
case "Pro Controller":
joy = (InputJoyshock) controller;
controllerMat.SetColor("_BodyColor", joy.GetBodyColor());
controllerMat.SetColor("_BtnColor", joy.GetButtonColor());
controllerMat.SetColor("_LGripColor", joy.GetLeftGripColor());
controllerMat.SetColor("_RGripColor", joy.GetRightGripColor());
break;
case "DualShock 4":
joy = (InputJoyshock) controller;
controllerMat.SetColor("_BodyColor", ColorUtility.TryParseHtmlString("#E1E2E4", out colour) ? colour : Color.white);
controllerMat.SetColor("_BtnColor", ColorUtility.TryParseHtmlString("#414246", out colour) ? colour : Color.white);
controllerMat.SetColor("_LGripColor", joy.GetLightbarColour());
controllerMat.SetColor("_RGripColor", joy.GetLightbarColour());
break;
case "DualSense":
joy = (InputJoyshock) controller;
controllerMat.SetColor("_BodyColor", ColorUtility.TryParseHtmlString("#DEE0EB", out colour) ? colour : Color.white);
controllerMat.SetColor("_BtnColor", ColorUtility.TryParseHtmlString("#272D39", out colour) ? colour : Color.white);
controllerMat.SetColor("_LGripColor", joy.GetLightbarColour());
controllerMat.SetColor("_RGripColor", joy.GetLightbarColour());
break;
default:
controllerMat.SetColor("_BodyColor", Color.white);
controllerMat.SetColor("_BtnColor", Color.white);
controllerMat.SetColor("_LGripColor", Color.white);
controllerMat.SetColor("_RGripColor", Color.white);
break;
}
controller.SetMaterialProperties(controllerMat);
}
public override void OnOpenTab()