aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Input
diff options
context:
space:
mode:
authorIsaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com>2023-10-21 07:26:51 -0400
committerGitHub <noreply@github.com>2023-10-21 13:26:51 +0200
commit49b37550cae6b3c69f59a9c7a44b17e3c12a813b (patch)
tree0cc8e6a3bfd65a876270b682effdb8f9505ff929 /src/Ryujinx.Input
parenta42f0bbb87b890d4f16b1148f9398210a5bfedfa (diff)
Ava UI: Input Menu Refactor (#4998)
* So much boilerplate * Slow and steady * Restructure + Ack suggestions * Restructure + Ack suggestions * Restructure * Clean * Propogate those fields i forgot about * It builds * Progress * Almost there * Fix stupid mistake * Fix more stupid mistakes * Actually fix fuck ups * Start localising * r/therestofthefuckingowl * Localise ButtonKeyAssigner * Are you feeling it now mr krabs * We’re done at last * Crimes against code * Try me in the Hague * Please be quiet * Crimes are here to stay * Dispose stuff * Cleanup a couple things * Visual fixes and improvements One weird bug * Fix rebase errors * Fixes * Ack Suggestions Remaining ack suggestions Update src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> Update src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> * Formatting and error More Ava 11-ness Whoops * Code style fixes * Style fixes * Analyzer fix * Remove all ReflectionBindings * Remove ambigious object * Remove redundant property * Old man yells at formatter * r e a d o n l y * Fix profiles * Use new Sliders --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
Diffstat (limited to 'src/Ryujinx.Input')
-rw-r--r--src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs6
-rw-r--r--src/Ryujinx.Input/Assigner/IButtonAssigner.cs2
-rw-r--r--src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs10
-rw-r--r--src/Ryujinx.Input/ButtonValue.cs48
4 files changed, 57 insertions, 9 deletions
diff --git a/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs b/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs
index 388ebcc0..bf8319a6 100644
--- a/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs
+++ b/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs
@@ -59,16 +59,16 @@ namespace Ryujinx.Input.Assigner
return _gamepad == null || !_gamepad.IsConnected;
}
- public string GetPressedButton()
+ public ButtonValue? GetPressedButton()
{
IEnumerable<GamepadButtonInputId> pressedButtons = _detector.GetPressedButtons();
if (pressedButtons.Any())
{
- return !_forStick ? pressedButtons.First().ToString() : ((StickInputId)pressedButtons.First()).ToString();
+ return !_forStick ? new(pressedButtons.First()) : new(((StickInputId)pressedButtons.First()));
}
- return "";
+ return null;
}
private void CollectButtonStats()
diff --git a/src/Ryujinx.Input/Assigner/IButtonAssigner.cs b/src/Ryujinx.Input/Assigner/IButtonAssigner.cs
index 76a9fece..65371713 100644
--- a/src/Ryujinx.Input/Assigner/IButtonAssigner.cs
+++ b/src/Ryujinx.Input/Assigner/IButtonAssigner.cs
@@ -31,6 +31,6 @@ namespace Ryujinx.Input.Assigner
/// Get the pressed button that was read in <see cref="ReadInput"/> by the button assigner.
/// </summary>
/// <returns>The pressed button that was read</returns>
- string GetPressedButton();
+ ButtonValue? GetPressedButton();
}
}
diff --git a/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs b/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs
index e52ef4a2..c66812ba 100644
--- a/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs
+++ b/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs
@@ -23,7 +23,7 @@ namespace Ryujinx.Input.Assigner
public bool HasAnyButtonPressed()
{
- return GetPressedButton().Length != 0;
+ return GetPressedButton() is not null;
}
public bool ShouldCancel()
@@ -31,20 +31,20 @@ namespace Ryujinx.Input.Assigner
return _keyboardState.IsPressed(Key.Escape);
}
- public string GetPressedButton()
+ public ButtonValue? GetPressedButton()
{
- string keyPressed = "";
+ ButtonValue? keyPressed = null;
for (Key key = Key.Unknown; key < Key.Count; key++)
{
if (_keyboardState.IsPressed(key))
{
- keyPressed = key.ToString();
+ keyPressed = new(key);
break;
}
}
- return !ShouldCancel() ? keyPressed : "";
+ return !ShouldCancel() ? keyPressed : null;
}
}
}
diff --git a/src/Ryujinx.Input/ButtonValue.cs b/src/Ryujinx.Input/ButtonValue.cs
new file mode 100644
index 00000000..f037e6b6
--- /dev/null
+++ b/src/Ryujinx.Input/ButtonValue.cs
@@ -0,0 +1,48 @@
+using System.Diagnostics;
+
+namespace Ryujinx.Input
+{
+ public enum ButtonValueType { Key, GamepadButtonInputId, StickId }
+
+ public readonly struct ButtonValue
+ {
+ private readonly ButtonValueType _type;
+ private readonly uint _rawValue;
+
+ public ButtonValue(Key key)
+ {
+ _type = ButtonValueType.Key;
+ _rawValue = (uint)key;
+ }
+
+ public ButtonValue(GamepadButtonInputId gamepad)
+ {
+ _type = ButtonValueType.GamepadButtonInputId;
+ _rawValue = (uint)gamepad;
+ }
+
+ public ButtonValue(StickInputId stick)
+ {
+ _type = ButtonValueType.StickId;
+ _rawValue = (uint)stick;
+ }
+
+ public Common.Configuration.Hid.Key AsKey()
+ {
+ Debug.Assert(_type == ButtonValueType.Key);
+ return (Common.Configuration.Hid.Key)_rawValue;
+ }
+
+ public Common.Configuration.Hid.Controller.GamepadInputId AsGamepadButtonInputId()
+ {
+ Debug.Assert(_type == ButtonValueType.GamepadButtonInputId);
+ return (Common.Configuration.Hid.Controller.GamepadInputId)_rawValue;
+ }
+
+ public Common.Configuration.Hid.Controller.StickInputId AsGamepadStickId()
+ {
+ Debug.Assert(_type == ButtonValueType.StickId);
+ return (Common.Configuration.Hid.Controller.StickInputId)_rawValue;
+ }
+ }
+}