methods for working on controller binds
doc parts of the InputController class
This commit is contained in:
parent
aeddb144e0
commit
cf31db9f87
|
@ -98,7 +98,7 @@ namespace HeavenStudio.InputSystem
|
||||||
{
|
{
|
||||||
public class InputJoyshock : InputController
|
public class InputJoyshock : InputController
|
||||||
{
|
{
|
||||||
static string[] joyShockNames =
|
static readonly string[] joyShockNames =
|
||||||
{
|
{
|
||||||
"Unknown",
|
"Unknown",
|
||||||
"Joy-Con (L)",
|
"Joy-Con (L)",
|
||||||
|
@ -108,7 +108,7 @@ namespace HeavenStudio.InputSystem
|
||||||
"DualSense"
|
"DualSense"
|
||||||
};
|
};
|
||||||
|
|
||||||
static int[] dsPlayerColours = new[]
|
static readonly int[] dsPlayerColours = new[]
|
||||||
{
|
{
|
||||||
0xd41817,
|
0xd41817,
|
||||||
0x04d4fa,
|
0x04d4fa,
|
||||||
|
@ -119,8 +119,7 @@ namespace HeavenStudio.InputSystem
|
||||||
0x888888
|
0x888888
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: see if single joy-con mappings differ from a normal pad (they don't!)
|
static readonly int[] defaultMappings = new[]
|
||||||
int[] defaultMappings = new[]
|
|
||||||
{
|
{
|
||||||
ButtonMaskUp,
|
ButtonMaskUp,
|
||||||
ButtonMaskDown,
|
ButtonMaskDown,
|
||||||
|
@ -135,7 +134,7 @@ namespace HeavenStudio.InputSystem
|
||||||
ButtonMaskPlus,
|
ButtonMaskPlus,
|
||||||
-1
|
-1
|
||||||
};
|
};
|
||||||
int[] defaultMappingsL = new[]
|
static readonly int[] defaultMappingsL = new[]
|
||||||
{
|
{
|
||||||
-1,
|
-1,
|
||||||
-1,
|
-1,
|
||||||
|
@ -150,7 +149,7 @@ namespace HeavenStudio.InputSystem
|
||||||
ButtonMaskMinus,
|
ButtonMaskMinus,
|
||||||
-1
|
-1
|
||||||
};
|
};
|
||||||
int[] defaultMappingsR = new[]
|
static readonly int[] defaultMappingsR = new[]
|
||||||
{
|
{
|
||||||
-1,
|
-1,
|
||||||
-1,
|
-1,
|
||||||
|
@ -189,6 +188,7 @@ namespace HeavenStudio.InputSystem
|
||||||
JSL_SETTINGS joySettings;
|
JSL_SETTINGS joySettings;
|
||||||
|
|
||||||
InputJoyshock otherHalf;
|
InputJoyshock otherHalf;
|
||||||
|
bool isPair;
|
||||||
|
|
||||||
public struct JoyshockButtonState
|
public struct JoyshockButtonState
|
||||||
{
|
{
|
||||||
|
@ -215,20 +215,21 @@ namespace HeavenStudio.InputSystem
|
||||||
|
|
||||||
int GetButtonForSplitType(int action)
|
int GetButtonForSplitType(int action)
|
||||||
{
|
{
|
||||||
|
if (currentBindings.ControllerName == null) return -1;
|
||||||
if (action < 0 || action >= BINDS_MAX) return -1;
|
if (action < 0 || action >= BINDS_MAX) return -1;
|
||||||
|
ControlBindings actionMap = currentBindings;
|
||||||
if (otherHalf == null)
|
if (otherHalf == null)
|
||||||
{
|
{
|
||||||
switch (splitType)
|
switch (splitType)
|
||||||
{
|
{
|
||||||
case SplitLeft:
|
case SplitLeft:
|
||||||
return defaultMappingsL[action];
|
|
||||||
case SplitRight:
|
case SplitRight:
|
||||||
return defaultMappingsR[action];
|
return actionMap.Pad[action];
|
||||||
default:
|
default:
|
||||||
return defaultMappings[action];
|
return defaultMappings[action];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return defaultMappings[action];
|
return actionMap.Pad[action];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void JslEventInit()
|
public static void JslEventInit()
|
||||||
|
@ -239,7 +240,7 @@ namespace HeavenStudio.InputSystem
|
||||||
static void JslEventCallback(int handle, JOY_SHOCK_STATE state, JOY_SHOCK_STATE lastState,
|
static void JslEventCallback(int handle, JOY_SHOCK_STATE state, JOY_SHOCK_STATE lastState,
|
||||||
IMU_STATE imuState, IMU_STATE lastImuState, float deltaTime)
|
IMU_STATE imuState, IMU_STATE lastImuState, float deltaTime)
|
||||||
{
|
{
|
||||||
if (!joyshocks.ContainsKey(handle)) return;
|
if (joyshocks == null || !joyshocks.ContainsKey(handle)) return;
|
||||||
InputJoyshock js = joyshocks[handle];
|
InputJoyshock js = joyshocks[handle];
|
||||||
if (js == null) return;
|
if (js == null) return;
|
||||||
if (js.inputStack == null) return;
|
if (js.inputStack == null) return;
|
||||||
|
@ -272,14 +273,14 @@ namespace HeavenStudio.InputSystem
|
||||||
joyTouchStateLast = new TOUCH_STATE();
|
joyTouchStateLast = new TOUCH_STATE();
|
||||||
|
|
||||||
|
|
||||||
//FUTURE: remappable controls
|
|
||||||
|
|
||||||
joySettings = JslGetControllerInfoAndSettings(joyshockHandle);
|
joySettings = JslGetControllerInfoAndSettings(joyshockHandle);
|
||||||
type = joySettings.controllerType;
|
type = joySettings.controllerType;
|
||||||
joyshockName = joyShockNames[type];
|
joyshockName = joyShockNames[type];
|
||||||
|
|
||||||
splitType = joySettings.splitType;
|
splitType = joySettings.splitType;
|
||||||
|
|
||||||
|
currentBindings = GetDefaultBindings();
|
||||||
|
|
||||||
joyshocks.Add(joyshockHandle, this);
|
joyshocks.Add(joyshockHandle, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,6 +401,46 @@ namespace HeavenStudio.InputSystem
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override ControlBindings GetDefaultBindings()
|
||||||
|
{
|
||||||
|
ControlBindings binds = new ControlBindings();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case TypeJoyConLeft:
|
||||||
|
binds.Pad = defaultMappingsL;
|
||||||
|
binds.ControllerName = "Joy-Con (L)";
|
||||||
|
break;
|
||||||
|
case TypeJoyConRight:
|
||||||
|
binds.Pad = defaultMappingsR;
|
||||||
|
binds.ControllerName = "Joy-Con (R)";
|
||||||
|
break;
|
||||||
|
case TypeProController:
|
||||||
|
binds.Pad = defaultMappings;
|
||||||
|
binds.ControllerName = "Pro Controller";
|
||||||
|
break;
|
||||||
|
case TypeDualShock4:
|
||||||
|
binds.Pad = defaultMappings;
|
||||||
|
binds.ControllerName = "DualShock 4";
|
||||||
|
break;
|
||||||
|
case TypeDualSense:
|
||||||
|
binds.Pad = defaultMappings;
|
||||||
|
binds.ControllerName = "DualSense";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return binds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ResetBindings()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public override ControlBindings GetCurrentBindings()
|
||||||
|
{
|
||||||
|
return currentBindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetCurrentBindings(ControlBindings newBinds)
|
||||||
|
{ }
|
||||||
|
|
||||||
public override int GetLastButtonDown()
|
public override int GetLastButtonDown()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < buttonStates.Length; i++)
|
for (int i = 0; i < buttonStates.Length; i++)
|
||||||
|
|
|
@ -40,21 +40,23 @@ namespace HeavenStudio.InputSystem
|
||||||
.Where(k => ((int)k < (int)KeyCode.Mouse0))
|
.Where(k => ((int)k < (int)KeyCode.Mouse0))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
//FUTURE: remappable controls
|
static readonly ControlBindings defaultBindings = new()
|
||||||
//KeyCode[] mappings = new KeyCode[Enum.GetNames(typeof(ButtonsPad)).Length];
|
|
||||||
KeyCode[] defaultMappings = new KeyCode[]
|
|
||||||
{
|
{
|
||||||
KeyCode.W, // dpad up
|
ControllerName = "Keyboard",
|
||||||
KeyCode.S, // dpad down
|
Pad = new int[]
|
||||||
KeyCode.A, // dpad left
|
{
|
||||||
KeyCode.D, // dpad right
|
(int)KeyCode.W,
|
||||||
KeyCode.K, // south face button
|
(int)KeyCode.S,
|
||||||
KeyCode.J, // east face button
|
(int)KeyCode.A,
|
||||||
KeyCode.I, // west face button
|
(int)KeyCode.D,
|
||||||
KeyCode.U, // north face button
|
(int)KeyCode.K,
|
||||||
KeyCode.C, // left shoulder button
|
(int)KeyCode.J,
|
||||||
KeyCode.N, // right shoulder button
|
(int)KeyCode.I,
|
||||||
KeyCode.Escape, // start button
|
(int)KeyCode.U,
|
||||||
|
(int)KeyCode.C,
|
||||||
|
(int)KeyCode.N,
|
||||||
|
(int)KeyCode.Escape,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
InputDirection hatDirectionCurrent;
|
InputDirection hatDirectionCurrent;
|
||||||
|
@ -62,7 +64,7 @@ namespace HeavenStudio.InputSystem
|
||||||
|
|
||||||
public override void InitializeController()
|
public override void InitializeController()
|
||||||
{
|
{
|
||||||
//FUTURE: remappable controls
|
currentBindings = GetDefaultBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateState()
|
public override void UpdateState()
|
||||||
|
@ -90,6 +92,22 @@ namespace HeavenStudio.InputSystem
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override ControlBindings GetDefaultBindings()
|
||||||
|
{
|
||||||
|
return defaultBindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ResetBindings()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public override ControlBindings GetCurrentBindings()
|
||||||
|
{
|
||||||
|
return currentBindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetCurrentBindings(ControlBindings newBinds)
|
||||||
|
{ }
|
||||||
|
|
||||||
public override int GetLastButtonDown()
|
public override int GetLastButtonDown()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -110,19 +128,19 @@ namespace HeavenStudio.InputSystem
|
||||||
|
|
||||||
public override bool GetButton(int button)
|
public override bool GetButton(int button)
|
||||||
{
|
{
|
||||||
return Input.GetKey(defaultMappings[button]);
|
return Input.GetKey((KeyCode)defaultBindings.Pad[button]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool GetButtonDown(int button, out double dt)
|
public override bool GetButtonDown(int button, out double dt)
|
||||||
{
|
{
|
||||||
dt = 0;
|
dt = 0;
|
||||||
return Input.GetKeyDown(defaultMappings[button]);
|
return Input.GetKeyDown((KeyCode)defaultBindings.Pad[button]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool GetButtonUp(int button, out double dt)
|
public override bool GetButtonUp(int button, out double dt)
|
||||||
{
|
{
|
||||||
dt = 0;
|
dt = 0;
|
||||||
return Input.GetKeyUp(defaultMappings[button]);
|
return Input.GetKeyUp((KeyCode)defaultBindings.Pad[button]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float GetAxis(InputAxis axis)
|
public override float GetAxis(InputAxis axis)
|
||||||
|
@ -136,13 +154,13 @@ namespace HeavenStudio.InputSystem
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case InputDirection.Up:
|
case InputDirection.Up:
|
||||||
return Input.GetKey(defaultMappings[0]);
|
return Input.GetKey((KeyCode)defaultBindings.Pad[0]);
|
||||||
case InputDirection.Down:
|
case InputDirection.Down:
|
||||||
return Input.GetKey(defaultMappings[1]);
|
return Input.GetKey((KeyCode)defaultBindings.Pad[1]);
|
||||||
case InputDirection.Left:
|
case InputDirection.Left:
|
||||||
return Input.GetKey(defaultMappings[2]);
|
return Input.GetKey((KeyCode)defaultBindings.Pad[2]);
|
||||||
case InputDirection.Right:
|
case InputDirection.Right:
|
||||||
return Input.GetKey(defaultMappings[3]);
|
return Input.GetKey((KeyCode)defaultBindings.Pad[3]);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -154,13 +172,13 @@ namespace HeavenStudio.InputSystem
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case InputDirection.Up:
|
case InputDirection.Up:
|
||||||
return Input.GetKeyDown(defaultMappings[0]);
|
return Input.GetKeyDown((KeyCode)defaultBindings.Pad[0]);
|
||||||
case InputDirection.Down:
|
case InputDirection.Down:
|
||||||
return Input.GetKeyDown(defaultMappings[1]);
|
return Input.GetKeyDown((KeyCode)defaultBindings.Pad[1]);
|
||||||
case InputDirection.Left:
|
case InputDirection.Left:
|
||||||
return Input.GetKeyDown(defaultMappings[2]);
|
return Input.GetKeyDown((KeyCode)defaultBindings.Pad[2]);
|
||||||
case InputDirection.Right:
|
case InputDirection.Right:
|
||||||
return Input.GetKeyDown(defaultMappings[3]);
|
return Input.GetKeyDown((KeyCode)defaultBindings.Pad[3]);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -172,13 +190,13 @@ namespace HeavenStudio.InputSystem
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case InputDirection.Up:
|
case InputDirection.Up:
|
||||||
return Input.GetKeyUp(defaultMappings[0]);
|
return Input.GetKeyUp((KeyCode)defaultBindings.Pad[0]);
|
||||||
case InputDirection.Down:
|
case InputDirection.Down:
|
||||||
return Input.GetKeyUp(defaultMappings[1]);
|
return Input.GetKeyUp((KeyCode)defaultBindings.Pad[1]);
|
||||||
case InputDirection.Left:
|
case InputDirection.Left:
|
||||||
return Input.GetKeyUp(defaultMappings[2]);
|
return Input.GetKeyUp((KeyCode)defaultBindings.Pad[2]);
|
||||||
case InputDirection.Right:
|
case InputDirection.Right:
|
||||||
return Input.GetKeyUp(defaultMappings[3]);
|
return Input.GetKeyUp((KeyCode)defaultBindings.Pad[3]);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,8 +127,7 @@ namespace HeavenStudio.InputSystem
|
||||||
|
|
||||||
// FUTURE: Move Style needs to be implemented per-game (maybe implement checks for common actions?)
|
// FUTURE: Move Style needs to be implemented per-game (maybe implement checks for common actions?)
|
||||||
|
|
||||||
protected int currentInputFlags = 0;
|
protected ControlBindings currentBindings;
|
||||||
protected int lastInputFlags = 0;
|
|
||||||
|
|
||||||
protected int? playerNum;
|
protected int? playerNum;
|
||||||
protected int directionStateCurrent = 0;
|
protected int directionStateCurrent = 0;
|
||||||
|
@ -142,22 +141,105 @@ namespace HeavenStudio.InputSystem
|
||||||
public abstract bool GetIsConnected();
|
public abstract bool GetIsConnected();
|
||||||
public abstract bool GetIsPoorConnection();
|
public abstract bool GetIsPoorConnection();
|
||||||
|
|
||||||
// public abstract int[] GetDefaultMappings(ControlStyles style);
|
/// <summary>
|
||||||
// public abstract int[] GetCurrentMappings(ControlStyles style);
|
/// Gets the controller's default mappings
|
||||||
// public abstract int[] SetCurrentMappings(ControlStyles style);
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract ControlBindings GetDefaultBindings();
|
||||||
|
|
||||||
public abstract int GetLastButtonDown(); // Get the last button down
|
/// <summary>
|
||||||
public abstract KeyCode GetLastKeyDown(); // Get the last key down (used for keyboards and other devices that use Keycode)
|
/// Resets the controller's mappings to default
|
||||||
public abstract bool GetButton(int button); // is button currently pressed?
|
/// </summary>
|
||||||
public abstract bool GetButtonDown(int button, out double dt); // is button just pressed?
|
public abstract void ResetBindings();
|
||||||
public abstract bool GetButtonUp(int button, out double dt); // is button just released?
|
|
||||||
public abstract float GetAxis(InputAxis axis); // Get the value of an axis
|
|
||||||
public abstract bool GetHatDirection(InputDirection direction); // is direction active?
|
|
||||||
public abstract bool GetHatDirectionDown(InputDirection direction, out double dt); // direction just became active?
|
|
||||||
public abstract bool GetHatDirectionUp(InputDirection direction, out double dt); // 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)
|
/// <summary>
|
||||||
public abstract int? GetPlayer(); // Get the player number (null if no player)
|
/// Gets the controller's current mappings
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract ControlBindings GetCurrentBindings();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the controller's current mappings
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newBinds"></param>
|
||||||
|
public abstract void SetCurrentBindings(ControlBindings newBinds);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the last pressed button
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract int GetLastButtonDown();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the last pressed key (keyboards)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract KeyCode GetLastKeyDown();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if the given button is being held
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="button"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract bool GetButton(int button);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if the button was just pressed this Update
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="button"></param>
|
||||||
|
/// <param name="dt">time since the reported event, use to compensate for controller delays</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract bool GetButtonDown(int button, out double dt);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if the button was just released this Update
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="button"></param>
|
||||||
|
/// <param name="dt">time since the reported event, use to compensate for controller delays</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract bool GetButtonUp(int button, out double dt);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the value of an analogue axis
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="axis"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract float GetAxis(InputAxis axis);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if the current direction is active
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract bool GetHatDirection(InputDirection direction);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if the current direction just became active this Update
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <param name="dt">time since the reported event, use to compensate for controller delays</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract bool GetHatDirectionDown(InputDirection direction, out double dt);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if the current direction just became inactive this Update
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <param name="dt">time since the reported event, use to compensate for controller delays</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract bool GetHatDirectionUp(InputDirection direction, out double dt);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the player number (starts at 1, set to -1 or null for no player)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerNum"></param>
|
||||||
|
public abstract void SetPlayer(int? playerNum);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the player number (starts at 1, -1 or null for no player)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract int? GetPlayer();
|
||||||
|
|
||||||
//public abstract Sprite GetDisplayIcon(); //"big icon" for the controller in the settings menu
|
//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 Sprite GetPlaybackIcon(); //"small icon" for the controller during playback
|
||||||
|
|
Loading…
Reference in a new issue