From d3f0c085d32c5f3b2eee7df1b53103412e8da41b Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 17 May 2023 09:35:50 -0400 Subject: [PATCH 01/54] So much boilerplate --- .../UI/Models/ControllerInputConfig.cs | 618 ++++++++++++++++++ .../UI/Models/KeyboardInputConfig.cs | 421 ++++++++++++ 2 files changed, 1039 insertions(+) create mode 100644 src/Ryujinx.Ava/UI/Models/ControllerInputConfig.cs create mode 100644 src/Ryujinx.Ava/UI/Models/KeyboardInputConfig.cs diff --git a/src/Ryujinx.Ava/UI/Models/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/ControllerInputConfig.cs new file mode 100644 index 0000000000..fce2191e21 --- /dev/null +++ b/src/Ryujinx.Ava/UI/Models/ControllerInputConfig.cs @@ -0,0 +1,618 @@ +using Ryujinx.Ava.UI.ViewModels; +using Ryujinx.Common.Configuration.Hid; +using Ryujinx.Common.Configuration.Hid.Controller; +using Ryujinx.Common.Configuration.Hid.Controller.Motion; +using System; + +namespace Ryujinx.Ava.UI.Models +{ + public class ControllerInputConfig : BaseModel + { + private StickInputId _leftJoystick; + private bool _leftInvertStickX; + private bool _leftInvertStickY; + private bool _leftRotate90; + private GamepadInputId _leftControllerStickButton; + + private StickInputId _rightJoystick; + private bool _rightInvertStickX; + private bool _rightInvertStickY; + private bool _rightRotate90; + private GamepadInputId _rightControllerStickButton; + + private GamepadInputId _buttonA; + private GamepadInputId _buttonB; + private GamepadInputId _buttonX; + private GamepadInputId _buttonY; + private GamepadInputId _buttonR; + private GamepadInputId _rightButtonSl; + private GamepadInputId _rightButtonSr; + private GamepadInputId _buttonZr; + private GamepadInputId _buttonPlus; + + private GamepadInputId _dpadUp; + private GamepadInputId _dpadDown; + private GamepadInputId _dpadLeft; + private GamepadInputId _dpadRight; + private GamepadInputId _buttonL; + private GamepadInputId _leftButtonSl; + private GamepadInputId _leftButtonSr; + private GamepadInputId _buttonZl; + private GamepadInputId _buttonMinus; + + private float _deadzoneLeft; + private float _deadzoneRight; + private float _rangeLeft; + private float _rangeRight; + private float _triggerThreshold; + private double _gyroDeadzone; + private int _sensitivity; + private bool _enableRumble; + private bool _enableMotion; + private float _weakRumble; + private float _strongRumble; + private MotionInputBackendType _motionBackend; + + public bool EnableCemuHookMotion { get; set; } + public string DsuServerHost { get; set; } + public int DsuServerPort { get; set; } + public int Slot { get; set; } + public int AltSlot { get; set; } + public bool MirrorInput { get; set; } + + public string Id { get; set; } + public ControllerType ControllerType { get; set; } + public PlayerIndex PlayerIndex { get; set; } + + public StickInputId LeftJoystick + { + get => _leftJoystick; + set + { + _leftJoystick = value; + OnPropertyChanged(); + } + } + + public bool LeftInvertStickX + { + get => _leftInvertStickX; + set + { + _leftInvertStickX = value; + OnPropertyChanged(); + } + } + + public bool LeftInvertStickY + { + get => _leftInvertStickY; + set + { + _leftInvertStickY = value; + OnPropertyChanged(); + } + } + + public bool LeftRotate90 + { + get => _leftRotate90; + set + { + _leftRotate90 = value; + OnPropertyChanged(); + } + } + + public GamepadInputId LeftControllerStickButton + { + get => _leftControllerStickButton; + set + { + _leftControllerStickButton = value; + OnPropertyChanged(); + } + } + + public StickInputId RightJoystick + { + get => _rightJoystick; + set + { + _rightJoystick = value; + OnPropertyChanged(); + } + } + + public bool RightInvertStickX + { + get => _rightInvertStickX; + set + { + _rightInvertStickX = value; + OnPropertyChanged(); + } + } + + public bool RightInvertStickY + { + get => _rightInvertStickY; + set + { + _rightInvertStickY = value; + OnPropertyChanged(); + } + } + + public bool RightRotate90 + { + get => _rightRotate90; + set + { + _rightRotate90 = value; + OnPropertyChanged(); + } + } + + public GamepadInputId RightControllerStickButton + { + get => _rightControllerStickButton; + set + { + _rightControllerStickButton = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonA + { + get => _buttonA; + set + { + _buttonA = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonB + { + get => _buttonB; + set + { + _buttonB = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonX + { + get => _buttonX; + set + { + _buttonX = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonY + { + get => _buttonY; + set + { + _buttonY = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonR + { + get => _buttonR; + set + { + _buttonR = value; + OnPropertyChanged(); + } + } + + public GamepadInputId RightButtonSl + { + get => _rightButtonSl; + set + { + _rightButtonSl = value; + OnPropertyChanged(); + } + } + + public GamepadInputId RightButtonSr + { + get => _rightButtonSr; + set + { + _rightButtonSr = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonZr + { + get => _buttonZr; + set + { + _buttonZr = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonPlus + { + get => _buttonPlus; + set + { + _buttonPlus = value; + OnPropertyChanged(); + } + } + + public GamepadInputId DpadUp + { + get => _dpadUp; + set + { + _dpadUp = value; + OnPropertyChanged(); + } + } + + public GamepadInputId DpadDown + { + get => _dpadDown; + set + { + _dpadDown = value; + OnPropertyChanged(); + } + } + + public GamepadInputId DpadLeft + { + get => _dpadLeft; + set + { + _dpadLeft = value; + OnPropertyChanged(); + } + } + + public GamepadInputId DpadRight + { + get => _dpadRight; + set + { + _dpadRight = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonL + { + get => _buttonL; + set + { + _buttonL = value; + OnPropertyChanged(); + } + } + + public GamepadInputId LeftButtonSl + { + get => _leftButtonSl; + set + { + _leftButtonSl = value; + OnPropertyChanged(); + } + } + + public GamepadInputId LeftButtonSr + { + get => _leftButtonSr; + set + { + _leftButtonSr = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonZl + { + get => _buttonZl; + set + { + _buttonZl = value; + OnPropertyChanged(); + } + } + + public GamepadInputId ButtonMinus + { + get => _buttonMinus; + set + { + _buttonMinus = value; + OnPropertyChanged(); + } + } + + public float DeadzoneLeft + { + get => _deadzoneLeft; + set + { + _deadzoneLeft = MathF.Round(value, 3); + + OnPropertyChanged(); + } + } + + public float DeadzoneRight + { + get => _deadzoneRight; + set + { + _deadzoneRight = MathF.Round(value, 3); + + OnPropertyChanged(); + } + } + + public float RangeLeft + { + get => _rangeLeft; + set + { + _rangeLeft = MathF.Round(value, 3); + + OnPropertyChanged(); + } + } + + public float RangeRight + { + get => _rangeRight; + set + { + _rangeRight = MathF.Round(value, 3); + + OnPropertyChanged(); + } + } + + public float TriggerThreshold + { + get => _triggerThreshold; + set + { + _triggerThreshold = MathF.Round(value, 3); + + OnPropertyChanged(); + } + } + + public int Sensitivity + { + get => _sensitivity; + set + { + _sensitivity = value; + + OnPropertyChanged(); + } + } + + public double GyroDeadzone + { + get => _gyroDeadzone; + set + { + _gyroDeadzone = Math.Round(value, 3); + + OnPropertyChanged(); + } + } + + public MotionInputBackendType MotionBackend + { + get => _motionBackend; + set + { + _motionBackend = value; + OnPropertyChanged(); + } + } + + public bool EnableRumble + { + get => _enableRumble; + set + { + _enableRumble = value; + OnPropertyChanged(); + } + } + + public bool EnableMotion + { + get => _enableMotion; + set + { + _enableMotion = value; + OnPropertyChanged(); + } + } + + public float WeakRumble + { + get => _weakRumble; + set + { + _weakRumble = value; + OnPropertyChanged(); + } + } + public float StrongRumble + { + get => _strongRumble; + set + { + _strongRumble = value; + OnPropertyChanged(); + } + } + + public ControllerInputConfig(InputConfig config) + { + if (config != null) + { + Id = config.Id; + ControllerType = config.ControllerType; + PlayerIndex = config.PlayerIndex; + + if (config is StandardControllerInputConfig controllerInput) + { + LeftJoystick = controllerInput.LeftJoyconStick.Joystick; + LeftInvertStickX = controllerInput.LeftJoyconStick.InvertStickX; + LeftInvertStickY = controllerInput.LeftJoyconStick.InvertStickY; + LeftRotate90 = controllerInput.LeftJoyconStick.Rotate90CW; + LeftControllerStickButton = controllerInput.LeftJoyconStick.StickButton; + + RightJoystick = controllerInput.RightJoyconStick.Joystick; + RightInvertStickX = controllerInput.RightJoyconStick.InvertStickX; + RightInvertStickY = controllerInput.RightJoyconStick.InvertStickY; + RightRotate90 = controllerInput.RightJoyconStick.Rotate90CW; + RightControllerStickButton = controllerInput.RightJoyconStick.StickButton; + + DpadUp = controllerInput.LeftJoycon.DpadUp; + DpadDown = controllerInput.LeftJoycon.DpadDown; + DpadLeft = controllerInput.LeftJoycon.DpadLeft; + DpadRight = controllerInput.LeftJoycon.DpadRight; + ButtonL = controllerInput.LeftJoycon.ButtonL; + ButtonMinus = controllerInput.LeftJoycon.ButtonMinus; + LeftButtonSl = controllerInput.LeftJoycon.ButtonSl; + LeftButtonSr = controllerInput.LeftJoycon.ButtonSr; + ButtonZl = controllerInput.LeftJoycon.ButtonZl; + + ButtonA = controllerInput.RightJoycon.ButtonA; + ButtonB = controllerInput.RightJoycon.ButtonB; + ButtonX = controllerInput.RightJoycon.ButtonX; + ButtonY = controllerInput.RightJoycon.ButtonY; + ButtonR = controllerInput.RightJoycon.ButtonR; + ButtonPlus = controllerInput.RightJoycon.ButtonPlus; + RightButtonSl = controllerInput.RightJoycon.ButtonSl; + RightButtonSr = controllerInput.RightJoycon.ButtonSr; + ButtonZr = controllerInput.RightJoycon.ButtonZr; + + DeadzoneLeft = controllerInput.DeadzoneLeft; + DeadzoneRight = controllerInput.DeadzoneRight; + RangeLeft = controllerInput.RangeLeft; + RangeRight = controllerInput.RangeRight; + TriggerThreshold = controllerInput.TriggerThreshold; + + if (controllerInput.Motion != null) + { + EnableMotion = controllerInput.Motion.EnableMotion; + MotionBackend = controllerInput.Motion.MotionBackend; + GyroDeadzone = controllerInput.Motion.GyroDeadzone; + Sensitivity = controllerInput.Motion.Sensitivity; + + if (controllerInput.Motion is CemuHookMotionConfigController cemuHook) + { + EnableCemuHookMotion = true; + DsuServerHost = cemuHook.DsuServerHost; + DsuServerPort = cemuHook.DsuServerPort; + Slot = cemuHook.Slot; + AltSlot = cemuHook.AltSlot; + MirrorInput = cemuHook.MirrorInput; + } + + if (controllerInput.Rumble != null) + { + EnableRumble = controllerInput.Rumble.EnableRumble; + WeakRumble = controllerInput.Rumble.WeakRumble; + StrongRumble = controllerInput.Rumble.StrongRumble; + } + } + } + } + } + + public InputConfig GetConfig() + { + var config = new StandardControllerInputConfig + { + Id = Id, + Backend = InputBackendType.GamepadSDL2, + PlayerIndex = PlayerIndex, + ControllerType = ControllerType, + LeftJoycon = new LeftJoyconCommonConfig + { + DpadUp = DpadUp, + DpadDown = DpadDown, + DpadLeft = DpadLeft, + DpadRight = DpadRight, + ButtonL = ButtonL, + ButtonMinus = ButtonMinus, + ButtonSl = LeftButtonSl, + ButtonSr = LeftButtonSr, + ButtonZl = ButtonZl + }, + RightJoycon = new RightJoyconCommonConfig + { + ButtonA = ButtonA, + ButtonB = ButtonB, + ButtonX = ButtonX, + ButtonY = ButtonY, + ButtonPlus = ButtonPlus, + ButtonSl = RightButtonSl, + ButtonSr = RightButtonSr, + ButtonR = ButtonR, + ButtonZr = ButtonZr, + }, + LeftJoyconStick = new JoyconConfigControllerStick + { + Joystick = LeftJoystick, + InvertStickX = LeftInvertStickX, + InvertStickY = LeftInvertStickY, + Rotate90CW = LeftRotate90, + StickButton = LeftControllerStickButton, + }, + RightJoyconStick = new JoyconConfigControllerStick + { + Joystick = RightJoystick, + InvertStickX = RightInvertStickX, + InvertStickY = RightInvertStickY, + Rotate90CW = RightRotate90, + StickButton = RightControllerStickButton, + }, + Rumble = new RumbleConfigController + { + EnableRumble = EnableRumble, + WeakRumble = WeakRumble, + StrongRumble = StrongRumble + }, + Version = InputConfig.CurrentVersion, + DeadzoneLeft = DeadzoneLeft, + DeadzoneRight = DeadzoneRight, + RangeLeft = RangeLeft, + RangeRight = RangeRight, + TriggerThreshold = TriggerThreshold, + }; + + config.Motion.Sensitivity = Sensitivity; + config.Motion.EnableMotion = EnableMotion; + config.Motion.GyroDeadzone = GyroDeadzone; + + return config; + } + } +} \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Models/KeyboardInputConfig.cs b/src/Ryujinx.Ava/UI/Models/KeyboardInputConfig.cs new file mode 100644 index 0000000000..de825eded1 --- /dev/null +++ b/src/Ryujinx.Ava/UI/Models/KeyboardInputConfig.cs @@ -0,0 +1,421 @@ +using Ryujinx.Ava.UI.ViewModels; +using Ryujinx.Common.Configuration.Hid; +using Ryujinx.Common.Configuration.Hid.Keyboard; + +namespace Ryujinx.Ava.UI.Models +{ + public class KeyboardInputConfig : BaseModel + { + private Key _leftStickUp; + private Key _leftStickDown; + private Key _leftStickLeft; + private Key _leftStickRight; + private Key _leftKeyboardStickButton; + + private Key _rightStickUp; + private Key _rightStickDown; + private Key _rightStickLeft; + private Key _rightStickRight; + private Key _rightKeyboardStickButton; + + private Key _buttonA; + private Key _buttonB; + private Key _buttonX; + private Key _buttonY; + private Key _buttonR; + private Key _rightButtonSl; + private Key _rightButtonSr; + private Key _buttonZr; + private Key _buttonPlus; + + private Key _dpadUp; + private Key _dpadDown; + private Key _dpadLeft; + private Key _dpadRight; + private Key _buttonL; + private Key _leftButtonSl; + private Key _leftButtonSr; + private Key _buttonZl; + private Key _buttonMinus; + + public string Id { get; set; } + public ControllerType ControllerType { get; set; } + public PlayerIndex PlayerIndex { get; set; } + + public Key LeftStickUp + { + get => _leftStickUp; + set + { + _leftStickUp = value; + OnPropertyChanged(); + } + } + + public Key LeftStickDown + { + get => _leftStickDown; + set + { + _leftStickDown = value; + OnPropertyChanged(); + } + } + + public Key LeftStickLeft + { + get => _leftStickLeft; + set + { + _leftStickLeft = value; + OnPropertyChanged(); + } + } + + public Key LeftStickRight + { + get => _leftStickRight; + set + { + _leftStickRight = value; + OnPropertyChanged(); + } + } + + public Key LeftKeyboardStickButton + { + get => _leftKeyboardStickButton; + set + { + _leftKeyboardStickButton = value; + OnPropertyChanged(); + } + } + + public Key RightStickUp + { + get => _rightStickUp; + set + { + _rightStickUp = value; + OnPropertyChanged(); + } + } + + public Key RightStickDown + { + get => _rightStickDown; + set + { + _rightStickDown = value; + OnPropertyChanged(); + } + } + + public Key RightStickLeft + { + get => _rightStickLeft; + set + { + _rightStickLeft = value; + OnPropertyChanged(); + } + } + + public Key RightStickRight + { + get => _rightStickRight; + set + { + _rightStickRight = value; + OnPropertyChanged(); + } + } + + public Key RightKeyboardStickButton + { + get => _rightKeyboardStickButton; + set + { + _rightKeyboardStickButton = value; + OnPropertyChanged(); + } + } + + public Key ButtonA + { + get => _buttonA; + set + { + _buttonA = value; + OnPropertyChanged(); + } + } + + public Key ButtonB + { + get => _buttonB; + set + { + _buttonB = value; + OnPropertyChanged(); + } + } + + public Key ButtonX + { + get => _buttonX; + set + { + _buttonX = value; + OnPropertyChanged(); + } + } + + public Key ButtonY + { + get => _buttonY; + set + { + _buttonY = value; + OnPropertyChanged(); + } + } + + public Key ButtonR + { + get => _buttonR; + set + { + _buttonR = value; + OnPropertyChanged(); + } + } + + public Key RightButtonSl + { + get => _rightButtonSl; + set + { + _rightButtonSl = value; + OnPropertyChanged(); + } + } + + public Key RightButtonSr + { + get => _rightButtonSr; + set + { + _rightButtonSr = value; + OnPropertyChanged(); + } + } + + public Key ButtonZr + { + get => _buttonZr; + set + { + _buttonZr = value; + OnPropertyChanged(); + } + } + + public Key ButtonPlus + { + get => _buttonPlus; + set + { + _buttonPlus = value; + OnPropertyChanged(); + } + } + + public Key DpadUp + { + get => _dpadUp; + set + { + _dpadUp = value; + OnPropertyChanged(); + } + } + + public Key DpadDown + { + get => _dpadDown; + set + { + _dpadDown = value; + OnPropertyChanged(); + } + } + + public Key DpadLeft + { + get => _dpadLeft; + set + { + _dpadLeft = value; + OnPropertyChanged(); + } + } + + public Key DpadRight + { + get => _dpadRight; + set + { + _dpadRight = value; + OnPropertyChanged(); + } + } + + public Key ButtonL + { + get => _buttonL; + set + { + _buttonL = value; + OnPropertyChanged(); + } + } + + public Key LeftButtonSl + { + get => _leftButtonSl; + set + { + _leftButtonSl = value; + OnPropertyChanged(); + } + } + + public Key LeftButtonSr + { + get => _leftButtonSr; + set + { + _leftButtonSr = value; + OnPropertyChanged(); + } + } + + public Key ButtonZl + { + get => _buttonZl; + set + { + _buttonZl = value; + OnPropertyChanged(); + } + } + + public Key ButtonMinus + { + get => _buttonMinus; + set + { + _buttonMinus = value; + OnPropertyChanged(); + } + } + + public KeyboardInputConfig(InputConfig config) + { + if (config != null) + { + if (config is StandardKeyboardInputConfig keyboardConfig) + { + LeftStickUp = keyboardConfig.LeftJoyconStick.StickUp; + LeftStickDown = keyboardConfig.LeftJoyconStick.StickDown; + LeftStickLeft = keyboardConfig.LeftJoyconStick.StickLeft; + LeftStickRight = keyboardConfig.LeftJoyconStick.StickRight; + + RightStickUp = keyboardConfig.RightJoyconStick.StickUp; + RightStickDown = keyboardConfig.RightJoyconStick.StickDown; + RightStickLeft = keyboardConfig.RightJoyconStick.StickLeft; + RightStickRight = keyboardConfig.RightJoyconStick.StickRight; + + ButtonA = keyboardConfig.RightJoycon.ButtonA; + ButtonB = keyboardConfig.RightJoycon.ButtonB; + ButtonX = keyboardConfig.RightJoycon.ButtonX; + ButtonY = keyboardConfig.RightJoycon.ButtonY; + ButtonR = keyboardConfig.RightJoycon.ButtonR; + RightButtonSl = keyboardConfig.RightJoycon.ButtonSl; + RightButtonSr = keyboardConfig.RightJoycon.ButtonSr; + ButtonZr = keyboardConfig.RightJoycon.ButtonZr; + ButtonPlus = keyboardConfig.RightJoycon.ButtonPlus; + + DpadUp = keyboardConfig.LeftJoycon.DpadUp; + DpadDown = keyboardConfig.LeftJoycon.DpadDown; + DpadLeft = keyboardConfig.LeftJoycon.DpadLeft; + DpadRight = keyboardConfig.LeftJoycon.DpadRight; + ButtonMinus = keyboardConfig.LeftJoycon.ButtonMinus; + LeftButtonSl = keyboardConfig.LeftJoycon.ButtonSl; + LeftButtonSr = keyboardConfig.LeftJoycon.ButtonSr; + ButtonZl = keyboardConfig.LeftJoycon.ButtonZl; + ButtonL = keyboardConfig.LeftJoycon.ButtonL; + } + } + } + + public InputConfig GetConfig() + { + var config = new StandardKeyboardInputConfig + { + Id = Id, + Backend = InputBackendType.WindowKeyboard, + PlayerIndex = PlayerIndex, + ControllerType = ControllerType, + LeftJoycon = + new LeftJoyconCommonConfig + { + DpadUp = DpadUp, + DpadDown = DpadDown, + DpadLeft = DpadLeft, + DpadRight = DpadRight, + ButtonL = ButtonL, + ButtonZl = ButtonZl, + ButtonSl = LeftButtonSl, + ButtonSr = LeftButtonSr, + ButtonMinus = ButtonMinus + }, + RightJoycon = + new RightJoyconCommonConfig + { + ButtonA = ButtonA, + ButtonB = ButtonB, + ButtonX = ButtonX, + ButtonY = ButtonY, + ButtonPlus = ButtonPlus, + ButtonSl = RightButtonSl, + ButtonSr = RightButtonSr, + ButtonR = ButtonR, + ButtonZr = ButtonZr + }, + LeftJoyconStick = + new JoyconConfigKeyboardStick + { + StickUp = LeftStickUp, + StickDown = LeftStickDown, + StickRight = LeftStickRight, + StickLeft = LeftStickLeft, + StickButton = LeftKeyboardStickButton + }, + RightJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = RightStickUp, + StickDown = RightStickDown, + StickLeft = RightStickLeft, + StickRight = RightStickRight, + StickButton = RightKeyboardStickButton + }, + Version = InputConfig.CurrentVersion + }; + + return config; + } + } +} \ No newline at end of file From 139a4b1fe784ab4f01b45a6e3e18d286281d452d Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 17 May 2023 10:08:55 -0400 Subject: [PATCH 02/54] Slow and steady --- .../UI/Models/InputConfiguration.cs | 456 --------- .../UI/ViewModels/ControllerInputViewModel.cs | 864 +---------------- .../UI/ViewModels/InputViewModel.cs | 890 ++++++++++++++++++ .../UI/ViewModels/KeyboardInputViewModel.cs | 64 ++ .../UI/Views/Input/ControllerInputView.axaml | 469 +-------- .../Views/Input/ControllerInputView.axaml.cs | 172 +--- .../UI/Views/Input/InputView.axaml | 217 +++++ .../UI/Views/Input/InputView.axaml.cs | 180 ++++ .../UI/Views/Input/KeyboardInputView.axaml | 678 +++++++++++++ .../UI/Views/Input/KeyboardInputView.axaml.cs | 19 + .../UI/Views/Settings/SettingsInputView.axaml | 2 +- 11 files changed, 2125 insertions(+), 1886 deletions(-) delete mode 100644 src/Ryujinx.Ava/UI/Models/InputConfiguration.cs create mode 100644 src/Ryujinx.Ava/UI/ViewModels/InputViewModel.cs create mode 100644 src/Ryujinx.Ava/UI/ViewModels/KeyboardInputViewModel.cs create mode 100644 src/Ryujinx.Ava/UI/Views/Input/InputView.axaml create mode 100644 src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs create mode 100644 src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml create mode 100644 src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs diff --git a/src/Ryujinx.Ava/UI/Models/InputConfiguration.cs b/src/Ryujinx.Ava/UI/Models/InputConfiguration.cs deleted file mode 100644 index f1352c6d8b..0000000000 --- a/src/Ryujinx.Ava/UI/Models/InputConfiguration.cs +++ /dev/null @@ -1,456 +0,0 @@ -using Ryujinx.Ava.UI.ViewModels; -using Ryujinx.Common.Configuration.Hid; -using Ryujinx.Common.Configuration.Hid.Controller; -using Ryujinx.Common.Configuration.Hid.Controller.Motion; -using Ryujinx.Common.Configuration.Hid.Keyboard; -using System; - -namespace Ryujinx.Ava.UI.Models -{ - internal class InputConfiguration : BaseModel - { - private float _deadzoneRight; - private float _triggerThreshold; - private float _deadzoneLeft; - private double _gyroDeadzone; - private int _sensitivity; - private bool _enableMotion; - private float _weakRumble; - private float _strongRumble; - private float _rangeLeft; - private float _rangeRight; - - public InputBackendType Backend { get; set; } - - /// - /// Controller id - /// - public string Id { get; set; } - - /// - /// Controller's Type - /// - public ControllerType ControllerType { get; set; } - - /// - /// Player's Index for the controller - /// - public PlayerIndex PlayerIndex { get; set; } - - public TStick LeftJoystick { get; set; } - public bool LeftInvertStickX { get; set; } - public bool LeftInvertStickY { get; set; } - public bool RightRotate90 { get; set; } - public TKey LeftControllerStickButton { get; set; } - - public TStick RightJoystick { get; set; } - public bool RightInvertStickX { get; set; } - public bool RightInvertStickY { get; set; } - public bool LeftRotate90 { get; set; } - public TKey RightControllerStickButton { get; set; } - - public float DeadzoneLeft - { - get => _deadzoneLeft; - set - { - _deadzoneLeft = MathF.Round(value, 3); - - OnPropertyChanged(); - } - } - - public float RangeLeft - { - get => _rangeLeft; - set - { - _rangeLeft = MathF.Round(value, 3); - - OnPropertyChanged(); - } - } - - public float DeadzoneRight - { - get => _deadzoneRight; - set - { - _deadzoneRight = MathF.Round(value, 3); - - OnPropertyChanged(); - } - } - - public float RangeRight - { - get => _rangeRight; - set - { - _rangeRight = MathF.Round(value, 3); - - OnPropertyChanged(); - } - } - - public float TriggerThreshold - { - get => _triggerThreshold; - set - { - _triggerThreshold = MathF.Round(value, 3); - - OnPropertyChanged(); - } - } - - public MotionInputBackendType MotionBackend { get; set; } - - public TKey ButtonMinus { get; set; } - public TKey ButtonL { get; set; } - public TKey ButtonZl { get; set; } - public TKey LeftButtonSl { get; set; } - public TKey LeftButtonSr { get; set; } - public TKey DpadUp { get; set; } - public TKey DpadDown { get; set; } - public TKey DpadLeft { get; set; } - public TKey DpadRight { get; set; } - - public TKey ButtonPlus { get; set; } - public TKey ButtonR { get; set; } - public TKey ButtonZr { get; set; } - public TKey RightButtonSl { get; set; } - public TKey RightButtonSr { get; set; } - public TKey ButtonX { get; set; } - public TKey ButtonB { get; set; } - public TKey ButtonY { get; set; } - public TKey ButtonA { get; set; } - - public TKey LeftStickUp { get; set; } - public TKey LeftStickDown { get; set; } - public TKey LeftStickLeft { get; set; } - public TKey LeftStickRight { get; set; } - public TKey LeftKeyboardStickButton { get; set; } - - public TKey RightStickUp { get; set; } - public TKey RightStickDown { get; set; } - public TKey RightStickLeft { get; set; } - public TKey RightStickRight { get; set; } - public TKey RightKeyboardStickButton { get; set; } - - public int Sensitivity - { - get => _sensitivity; - set - { - _sensitivity = value; - - OnPropertyChanged(); - } - } - - public double GyroDeadzone - { - get => _gyroDeadzone; - set - { - _gyroDeadzone = Math.Round(value, 3); - - OnPropertyChanged(); - } - } - - public bool EnableMotion - { - get => _enableMotion; set - { - _enableMotion = value; - - OnPropertyChanged(); - } - } - - public bool EnableCemuHookMotion { get; set; } - public int Slot { get; set; } - public int AltSlot { get; set; } - public bool MirrorInput { get; set; } - public string DsuServerHost { get; set; } - public int DsuServerPort { get; set; } - - public bool EnableRumble { get; set; } - public float WeakRumble - { - get => _weakRumble; set - { - _weakRumble = value; - - OnPropertyChanged(); - } - } - public float StrongRumble - { - get => _strongRumble; set - { - _strongRumble = value; - - OnPropertyChanged(); - } - } - - public InputConfiguration(InputConfig config) - { - if (config != null) - { - Backend = config.Backend; - Id = config.Id; - ControllerType = config.ControllerType; - PlayerIndex = config.PlayerIndex; - - if (config is StandardKeyboardInputConfig keyboardConfig) - { - LeftStickUp = (TKey)(object)keyboardConfig.LeftJoyconStick.StickUp; - LeftStickDown = (TKey)(object)keyboardConfig.LeftJoyconStick.StickDown; - LeftStickLeft = (TKey)(object)keyboardConfig.LeftJoyconStick.StickLeft; - LeftStickRight = (TKey)(object)keyboardConfig.LeftJoyconStick.StickRight; - LeftKeyboardStickButton = (TKey)(object)keyboardConfig.LeftJoyconStick.StickButton; - - RightStickUp = (TKey)(object)keyboardConfig.RightJoyconStick.StickUp; - RightStickDown = (TKey)(object)keyboardConfig.RightJoyconStick.StickDown; - RightStickLeft = (TKey)(object)keyboardConfig.RightJoyconStick.StickLeft; - RightStickRight = (TKey)(object)keyboardConfig.RightJoyconStick.StickRight; - RightKeyboardStickButton = (TKey)(object)keyboardConfig.RightJoyconStick.StickButton; - - ButtonA = (TKey)(object)keyboardConfig.RightJoycon.ButtonA; - ButtonB = (TKey)(object)keyboardConfig.RightJoycon.ButtonB; - ButtonX = (TKey)(object)keyboardConfig.RightJoycon.ButtonX; - ButtonY = (TKey)(object)keyboardConfig.RightJoycon.ButtonY; - ButtonR = (TKey)(object)keyboardConfig.RightJoycon.ButtonR; - RightButtonSl = (TKey)(object)keyboardConfig.RightJoycon.ButtonSl; - RightButtonSr = (TKey)(object)keyboardConfig.RightJoycon.ButtonSr; - ButtonZr = (TKey)(object)keyboardConfig.RightJoycon.ButtonZr; - ButtonPlus = (TKey)(object)keyboardConfig.RightJoycon.ButtonPlus; - - DpadUp = (TKey)(object)keyboardConfig.LeftJoycon.DpadUp; - DpadDown = (TKey)(object)keyboardConfig.LeftJoycon.DpadDown; - DpadLeft = (TKey)(object)keyboardConfig.LeftJoycon.DpadLeft; - DpadRight = (TKey)(object)keyboardConfig.LeftJoycon.DpadRight; - ButtonMinus = (TKey)(object)keyboardConfig.LeftJoycon.ButtonMinus; - LeftButtonSl = (TKey)(object)keyboardConfig.LeftJoycon.ButtonSl; - LeftButtonSr = (TKey)(object)keyboardConfig.LeftJoycon.ButtonSr; - ButtonZl = (TKey)(object)keyboardConfig.LeftJoycon.ButtonZl; - ButtonL = (TKey)(object)keyboardConfig.LeftJoycon.ButtonL; - } - else if (config is StandardControllerInputConfig controllerConfig) - { - LeftJoystick = (TStick)(object)controllerConfig.LeftJoyconStick.Joystick; - LeftInvertStickX = controllerConfig.LeftJoyconStick.InvertStickX; - LeftInvertStickY = controllerConfig.LeftJoyconStick.InvertStickY; - LeftRotate90 = controllerConfig.LeftJoyconStick.Rotate90CW; - LeftControllerStickButton = (TKey)(object)controllerConfig.LeftJoyconStick.StickButton; - - RightJoystick = (TStick)(object)controllerConfig.RightJoyconStick.Joystick; - RightInvertStickX = controllerConfig.RightJoyconStick.InvertStickX; - RightInvertStickY = controllerConfig.RightJoyconStick.InvertStickY; - RightRotate90 = controllerConfig.RightJoyconStick.Rotate90CW; - RightControllerStickButton = (TKey)(object)controllerConfig.RightJoyconStick.StickButton; - - ButtonA = (TKey)(object)controllerConfig.RightJoycon.ButtonA; - ButtonB = (TKey)(object)controllerConfig.RightJoycon.ButtonB; - ButtonX = (TKey)(object)controllerConfig.RightJoycon.ButtonX; - ButtonY = (TKey)(object)controllerConfig.RightJoycon.ButtonY; - ButtonR = (TKey)(object)controllerConfig.RightJoycon.ButtonR; - RightButtonSl = (TKey)(object)controllerConfig.RightJoycon.ButtonSl; - RightButtonSr = (TKey)(object)controllerConfig.RightJoycon.ButtonSr; - ButtonZr = (TKey)(object)controllerConfig.RightJoycon.ButtonZr; - ButtonPlus = (TKey)(object)controllerConfig.RightJoycon.ButtonPlus; - - DpadUp = (TKey)(object)controllerConfig.LeftJoycon.DpadUp; - DpadDown = (TKey)(object)controllerConfig.LeftJoycon.DpadDown; - DpadLeft = (TKey)(object)controllerConfig.LeftJoycon.DpadLeft; - DpadRight = (TKey)(object)controllerConfig.LeftJoycon.DpadRight; - ButtonMinus = (TKey)(object)controllerConfig.LeftJoycon.ButtonMinus; - LeftButtonSl = (TKey)(object)controllerConfig.LeftJoycon.ButtonSl; - LeftButtonSr = (TKey)(object)controllerConfig.LeftJoycon.ButtonSr; - ButtonZl = (TKey)(object)controllerConfig.LeftJoycon.ButtonZl; - ButtonL = (TKey)(object)controllerConfig.LeftJoycon.ButtonL; - - DeadzoneLeft = controllerConfig.DeadzoneLeft; - DeadzoneRight = controllerConfig.DeadzoneRight; - RangeLeft = controllerConfig.RangeLeft; - RangeRight = controllerConfig.RangeRight; - TriggerThreshold = controllerConfig.TriggerThreshold; - - if (controllerConfig.Motion != null) - { - EnableMotion = controllerConfig.Motion.EnableMotion; - MotionBackend = controllerConfig.Motion.MotionBackend; - GyroDeadzone = controllerConfig.Motion.GyroDeadzone; - Sensitivity = controllerConfig.Motion.Sensitivity; - - if (controllerConfig.Motion is CemuHookMotionConfigController cemuHook) - { - EnableCemuHookMotion = true; - DsuServerHost = cemuHook.DsuServerHost; - DsuServerPort = cemuHook.DsuServerPort; - Slot = cemuHook.Slot; - AltSlot = cemuHook.AltSlot; - MirrorInput = cemuHook.MirrorInput; - } - - if (controllerConfig.Rumble != null) - { - EnableRumble = controllerConfig.Rumble.EnableRumble; - WeakRumble = controllerConfig.Rumble.WeakRumble; - StrongRumble = controllerConfig.Rumble.StrongRumble; - } - } - } - } - } - - public InputConfiguration() - { - } - - public InputConfig GetConfig() - { - if (Backend == InputBackendType.WindowKeyboard) - { - return new StandardKeyboardInputConfig - { - Id = Id, - Backend = Backend, - PlayerIndex = PlayerIndex, - ControllerType = ControllerType, - LeftJoycon = new LeftJoyconCommonConfig - { - DpadUp = (Key)(object)DpadUp, - DpadDown = (Key)(object)DpadDown, - DpadLeft = (Key)(object)DpadLeft, - DpadRight = (Key)(object)DpadRight, - ButtonL = (Key)(object)ButtonL, - ButtonZl = (Key)(object)ButtonZl, - ButtonSl = (Key)(object)LeftButtonSl, - ButtonSr = (Key)(object)LeftButtonSr, - ButtonMinus = (Key)(object)ButtonMinus, - }, - RightJoycon = new RightJoyconCommonConfig - { - ButtonA = (Key)(object)ButtonA, - ButtonB = (Key)(object)ButtonB, - ButtonX = (Key)(object)ButtonX, - ButtonY = (Key)(object)ButtonY, - ButtonPlus = (Key)(object)ButtonPlus, - ButtonSl = (Key)(object)RightButtonSl, - ButtonSr = (Key)(object)RightButtonSr, - ButtonR = (Key)(object)ButtonR, - ButtonZr = (Key)(object)ButtonZr, - }, - LeftJoyconStick = new JoyconConfigKeyboardStick - { - StickUp = (Key)(object)LeftStickUp, - StickDown = (Key)(object)LeftStickDown, - StickRight = (Key)(object)LeftStickRight, - StickLeft = (Key)(object)LeftStickLeft, - StickButton = (Key)(object)LeftKeyboardStickButton, - }, - RightJoyconStick = new JoyconConfigKeyboardStick - { - StickUp = (Key)(object)RightStickUp, - StickDown = (Key)(object)RightStickDown, - StickLeft = (Key)(object)RightStickLeft, - StickRight = (Key)(object)RightStickRight, - StickButton = (Key)(object)RightKeyboardStickButton, - }, - Version = InputConfig.CurrentVersion, - }; - - } - - if (Backend == InputBackendType.GamepadSDL2) - { - var config = new StandardControllerInputConfig - { - Id = Id, - Backend = Backend, - PlayerIndex = PlayerIndex, - ControllerType = ControllerType, - LeftJoycon = new LeftJoyconCommonConfig - { - DpadUp = (GamepadInputId)(object)DpadUp, - DpadDown = (GamepadInputId)(object)DpadDown, - DpadLeft = (GamepadInputId)(object)DpadLeft, - DpadRight = (GamepadInputId)(object)DpadRight, - ButtonL = (GamepadInputId)(object)ButtonL, - ButtonZl = (GamepadInputId)(object)ButtonZl, - ButtonSl = (GamepadInputId)(object)LeftButtonSl, - ButtonSr = (GamepadInputId)(object)LeftButtonSr, - ButtonMinus = (GamepadInputId)(object)ButtonMinus, - }, - RightJoycon = new RightJoyconCommonConfig - { - ButtonA = (GamepadInputId)(object)ButtonA, - ButtonB = (GamepadInputId)(object)ButtonB, - ButtonX = (GamepadInputId)(object)ButtonX, - ButtonY = (GamepadInputId)(object)ButtonY, - ButtonPlus = (GamepadInputId)(object)ButtonPlus, - ButtonSl = (GamepadInputId)(object)RightButtonSl, - ButtonSr = (GamepadInputId)(object)RightButtonSr, - ButtonR = (GamepadInputId)(object)ButtonR, - ButtonZr = (GamepadInputId)(object)ButtonZr, - }, - LeftJoyconStick = new JoyconConfigControllerStick - { - Joystick = (StickInputId)(object)LeftJoystick, - InvertStickX = LeftInvertStickX, - InvertStickY = LeftInvertStickY, - Rotate90CW = LeftRotate90, - StickButton = (GamepadInputId)(object)LeftControllerStickButton, - }, - RightJoyconStick = new JoyconConfigControllerStick - { - Joystick = (StickInputId)(object)RightJoystick, - InvertStickX = RightInvertStickX, - InvertStickY = RightInvertStickY, - Rotate90CW = RightRotate90, - StickButton = (GamepadInputId)(object)RightControllerStickButton, - }, - Rumble = new RumbleConfigController - { - EnableRumble = EnableRumble, - WeakRumble = WeakRumble, - StrongRumble = StrongRumble, - }, - Version = InputConfig.CurrentVersion, - DeadzoneLeft = DeadzoneLeft, - DeadzoneRight = DeadzoneRight, - RangeLeft = RangeLeft, - RangeRight = RangeRight, - TriggerThreshold = TriggerThreshold, - Motion = EnableCemuHookMotion - ? new CemuHookMotionConfigController - { - DsuServerHost = DsuServerHost, - DsuServerPort = DsuServerPort, - Slot = Slot, - AltSlot = AltSlot, - MirrorInput = MirrorInput, - MotionBackend = MotionInputBackendType.CemuHook, - } - : new StandardMotionConfigController - { - MotionBackend = MotionInputBackendType.GamepadDriver, - }, - }; - - config.Motion.Sensitivity = Sensitivity; - config.Motion.EnableMotion = EnableMotion; - config.Motion.GyroDeadzone = GyroDeadzone; - - return config; - } - - return null; - } - } -} diff --git a/src/Ryujinx.Ava/UI/ViewModels/ControllerInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/ControllerInputViewModel.cs index 71ad2c1278..11b555db6a 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/ControllerInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/ControllerInputViewModel.cs @@ -1,325 +1,64 @@ -using Avalonia; -using Avalonia.Collections; -using Avalonia.Controls; -using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Svg.Skia; -using Avalonia.Threading; -using Ryujinx.Ava.Common.Locale; -using Ryujinx.Ava.Input; -using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.Models; using Ryujinx.Ava.UI.Views.Input; -using Ryujinx.Ava.UI.Windows; -using Ryujinx.Common; -using Ryujinx.Common.Configuration; -using Ryujinx.Common.Configuration.Hid; -using Ryujinx.Common.Configuration.Hid.Controller; -using Ryujinx.Common.Configuration.Hid.Controller.Motion; -using Ryujinx.Common.Configuration.Hid.Keyboard; -using Ryujinx.Common.Logging; -using Ryujinx.Common.Utilities; -using Ryujinx.Input; -using Ryujinx.UI.Common.Configuration; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Linq; -using System.Text.Json; -using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId; -using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; -using Key = Ryujinx.Common.Configuration.Hid.Key; namespace Ryujinx.Ava.UI.ViewModels { - public class ControllerInputViewModel : BaseModel, IDisposable + public class ControllerInputViewModel : BaseModel { - private const string Disabled = "disabled"; - private const string ProControllerResource = "Ryujinx.UI.Common/Resources/Controller_ProCon.svg"; - private const string JoyConPairResource = "Ryujinx.UI.Common/Resources/Controller_JoyConPair.svg"; - private const string JoyConLeftResource = "Ryujinx.UI.Common/Resources/Controller_JoyConLeft.svg"; - private const string JoyConRightResource = "Ryujinx.UI.Common/Resources/Controller_JoyConRight.svg"; - private const string KeyboardString = "keyboard"; - private const string ControllerString = "controller"; - private readonly MainWindow _mainWindow; + private ControllerInputConfig _config; + private bool _isLeft; + private bool _isRight; + private bool _showSettings; + private SvgImage _image; - private PlayerIndex _playerId; - private int _controller; - private int _controllerNumber; - private string _controllerImage; - private int _device; - private object _configuration; - private string _profileName; - private bool _isLoaded; - - private static readonly InputConfigJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions()); - - public IGamepadDriver AvaloniaKeyboardDriver { get; } - public IGamepad SelectedGamepad { get; private set; } - - public ObservableCollection PlayerIndexes { get; set; } - public ObservableCollection<(DeviceType Type, string Id, string Name)> Devices { get; set; } - internal ObservableCollection Controllers { get; set; } - public AvaloniaList ProfilesList { get; set; } - public AvaloniaList DeviceList { get; set; } - - // XAML Flags - public bool ShowSettings => _device > 0; - public bool IsController => _device > 1; - public bool IsKeyboard => !IsController; - public bool IsRight { get; set; } - public bool IsLeft { get; set; } - - public bool IsModified { get; set; } - - public object Configuration + public ControllerInputConfig Config { - get => _configuration; + get => _config; set { - _configuration = value; - + _config = value; OnPropertyChanged(); } } - public PlayerIndex PlayerId + public bool IsLeft { - get => _playerId; + get => _isLeft; set { - if (IsModified) - { - return; - } - - IsModified = false; - _playerId = value; - - if (!Enum.IsDefined(typeof(PlayerIndex), _playerId)) - { - _playerId = PlayerIndex.Player1; - } - - LoadConfiguration(); - LoadDevice(); - LoadProfiles(); - - _isLoaded = true; - + _isLeft = value; OnPropertyChanged(); } } - public int Controller + public bool IsRight { - get => _controller; + get => _isRight; set { - _controller = value; - - if (_controller == -1) - { - _controller = 0; - } - - if (Controllers.Count > 0 && value < Controllers.Count && _controller > -1) - { - ControllerType controller = Controllers[_controller].Type; - - IsLeft = true; - IsRight = true; - - switch (controller) - { - case ControllerType.Handheld: - ControllerImage = JoyConPairResource; - break; - case ControllerType.ProController: - ControllerImage = ProControllerResource; - break; - case ControllerType.JoyconPair: - ControllerImage = JoyConPairResource; - break; - case ControllerType.JoyconLeft: - ControllerImage = JoyConLeftResource; - IsRight = false; - break; - case ControllerType.JoyconRight: - ControllerImage = JoyConRightResource; - IsLeft = false; - break; - } - - LoadInputDriver(); - LoadProfiles(); - } - + _isRight = value; OnPropertyChanged(); - NotifyChanges(); } } - public string ControllerImage + public bool ShowSettings { - get => _controllerImage; + get => _showSettings; set { - _controllerImage = value; - + _showSettings = value; OnPropertyChanged(); - OnPropertyChanged(nameof(Image)); } } public SvgImage Image { - get - { - SvgImage image = new(); - - if (!string.IsNullOrWhiteSpace(_controllerImage)) - { - SvgSource source = new(default(Uri)); - - source.Load(EmbeddedResources.GetStream(_controllerImage)); - - image.Source = source; - } - - return image; - } - } - - public string ProfileName - { - get => _profileName; set - { - _profileName = value; - - OnPropertyChanged(); - } - } - - public int Device - { - get => _device; + get => _image; set { - _device = value < 0 ? 0 : value; - - if (_device >= Devices.Count) - { - return; - } - - var selected = Devices[_device].Type; - - if (selected != DeviceType.None) - { - LoadControllers(); - - if (_isLoaded) - { - LoadConfiguration(LoadDefaultConfiguration()); - } - } - + _image = value; OnPropertyChanged(); - NotifyChanges(); - } - } - - public InputConfig Config { get; set; } - - public ControllerInputViewModel(UserControl owner) : this() - { - if (Program.PreviewerDetached) - { - _mainWindow = - (MainWindow)((IClassicDesktopStyleApplicationLifetime)Application.Current - .ApplicationLifetime).MainWindow; - - AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner); - - _mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; - _mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected; - - _mainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates(); - - _isLoaded = false; - - LoadDevices(); - - PlayerId = PlayerIndex.Player1; - } - } - - public ControllerInputViewModel() - { - PlayerIndexes = new ObservableCollection(); - Controllers = new ObservableCollection(); - Devices = new ObservableCollection<(DeviceType Type, string Id, string Name)>(); - ProfilesList = new AvaloniaList(); - DeviceList = new AvaloniaList(); - - ControllerImage = ProControllerResource; - - PlayerIndexes.Add(new(PlayerIndex.Player1, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer1])); - PlayerIndexes.Add(new(PlayerIndex.Player2, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer2])); - PlayerIndexes.Add(new(PlayerIndex.Player3, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer3])); - PlayerIndexes.Add(new(PlayerIndex.Player4, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer4])); - PlayerIndexes.Add(new(PlayerIndex.Player5, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer5])); - PlayerIndexes.Add(new(PlayerIndex.Player6, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer6])); - PlayerIndexes.Add(new(PlayerIndex.Player7, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer7])); - PlayerIndexes.Add(new(PlayerIndex.Player8, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer8])); - PlayerIndexes.Add(new(PlayerIndex.Handheld, LocaleManager.Instance[LocaleKeys.ControllerSettingsHandheld])); - } - - private void LoadConfiguration(InputConfig inputConfig = null) - { - Config = inputConfig ?? ConfigurationState.Instance.Hid.InputConfig.Value.Find(inputConfig => inputConfig.PlayerIndex == _playerId); - - if (Config is StandardKeyboardInputConfig keyboardInputConfig) - { - Configuration = new InputConfiguration(keyboardInputConfig); - } - - if (Config is StandardControllerInputConfig controllerInputConfig) - { - Configuration = new InputConfiguration(controllerInputConfig); - } - } - - public void LoadDevice() - { - if (Config == null || Config.Backend == InputBackendType.Invalid) - { - Device = 0; - } - else - { - var type = DeviceType.None; - - if (Config is StandardKeyboardInputConfig) - { - type = DeviceType.Keyboard; - } - - if (Config is StandardControllerInputConfig) - { - type = DeviceType.Controller; - } - - var item = Devices.FirstOrDefault(x => x.Type == type && x.Id == Config.Id); - if (item != default) - { - Device = Devices.ToList().FindIndex(x => x.Id == item.Id); - } - else - { - Device = 0; - } } } @@ -332,566 +71,5 @@ namespace Ryujinx.Ava.UI.ViewModels { await RumbleInputView.Show(this); } - - private void LoadInputDriver() - { - if (_device < 0) - { - return; - } - - string id = GetCurrentGamepadId(); - var type = Devices[Device].Type; - - if (type == DeviceType.None) - { - return; - } - - if (type == DeviceType.Keyboard) - { - if (_mainWindow.InputManager.KeyboardDriver is AvaloniaKeyboardDriver) - { - // NOTE: To get input in this window, we need to bind a custom keyboard driver instead of using the InputManager one as the main window isn't focused... - SelectedGamepad = AvaloniaKeyboardDriver.GetGamepad(id); - } - else - { - SelectedGamepad = _mainWindow.InputManager.KeyboardDriver.GetGamepad(id); - } - } - else - { - SelectedGamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id); - } - } - - private void HandleOnGamepadDisconnected(string id) - { - Dispatcher.UIThread.Post(() => - { - LoadDevices(); - }); - } - - private void HandleOnGamepadConnected(string id) - { - Dispatcher.UIThread.Post(() => - { - LoadDevices(); - }); - } - - private string GetCurrentGamepadId() - { - if (_device < 0) - { - return string.Empty; - } - - var device = Devices[Device]; - - if (device.Type == DeviceType.None) - { - return null; - } - - return device.Id.Split(" ")[0]; - } - - public void LoadControllers() - { - Controllers.Clear(); - - if (_playerId == PlayerIndex.Handheld) - { - Controllers.Add(new(ControllerType.Handheld, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeHandheld])); - - Controller = 0; - } - else - { - Controllers.Add(new(ControllerType.ProController, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeProController])); - Controllers.Add(new(ControllerType.JoyconPair, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeJoyConPair])); - Controllers.Add(new(ControllerType.JoyconLeft, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeJoyConLeft])); - Controllers.Add(new(ControllerType.JoyconRight, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeJoyConRight])); - - if (Config != null && Controllers.ToList().FindIndex(x => x.Type == Config.ControllerType) != -1) - { - Controller = Controllers.ToList().FindIndex(x => x.Type == Config.ControllerType); - } - else - { - Controller = 0; - } - } - } - - private static string GetShortGamepadName(string str) - { - const string Ellipsis = "..."; - const int MaxSize = 50; - - if (str.Length > MaxSize) - { - return $"{str.AsSpan(0, MaxSize - Ellipsis.Length)}{Ellipsis}"; - } - - return str; - } - - private static string GetShortGamepadId(string str) - { - const string Hyphen = "-"; - const int Offset = 1; - - return str[(str.IndexOf(Hyphen) + Offset)..]; - } - - public void LoadDevices() - { - lock (Devices) - { - Devices.Clear(); - DeviceList.Clear(); - Devices.Add((DeviceType.None, Disabled, LocaleManager.Instance[LocaleKeys.ControllerSettingsDeviceDisabled])); - - foreach (string id in _mainWindow.InputManager.KeyboardDriver.GamepadsIds) - { - using IGamepad gamepad = _mainWindow.InputManager.KeyboardDriver.GetGamepad(id); - - if (gamepad != null) - { - Devices.Add((DeviceType.Keyboard, id, $"{GetShortGamepadName(gamepad.Name)}")); - } - } - - foreach (string id in _mainWindow.InputManager.GamepadDriver.GamepadsIds) - { - using IGamepad gamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id); - - if (gamepad != null) - { - if (Devices.Any(controller => GetShortGamepadId(controller.Id) == GetShortGamepadId(gamepad.Id))) - { - _controllerNumber++; - } - - Devices.Add((DeviceType.Controller, id, $"{GetShortGamepadName(gamepad.Name)} ({_controllerNumber})")); - } - } - - _controllerNumber = 0; - - DeviceList.AddRange(Devices.Select(x => x.Name)); - Device = Math.Min(Device, DeviceList.Count); - } - } - - private string GetProfileBasePath() - { - string path = AppDataManager.ProfilesDirPath; - var type = Devices[Device == -1 ? 0 : Device].Type; - - if (type == DeviceType.Keyboard) - { - path = Path.Combine(path, KeyboardString); - } - else if (type == DeviceType.Controller) - { - path = Path.Combine(path, ControllerString); - } - - return path; - } - - private void LoadProfiles() - { - ProfilesList.Clear(); - - string basePath = GetProfileBasePath(); - - if (!Directory.Exists(basePath)) - { - Directory.CreateDirectory(basePath); - } - - ProfilesList.Add((LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault])); - - foreach (string profile in Directory.GetFiles(basePath, "*.json", SearchOption.AllDirectories)) - { - ProfilesList.Add(Path.GetFileNameWithoutExtension(profile)); - } - - if (string.IsNullOrWhiteSpace(ProfileName)) - { - ProfileName = LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault]; - } - } - - public InputConfig LoadDefaultConfiguration() - { - var activeDevice = Devices.FirstOrDefault(); - - if (Devices.Count > 0 && Device < Devices.Count && Device >= 0) - { - activeDevice = Devices[Device]; - } - - InputConfig config; - if (activeDevice.Type == DeviceType.Keyboard) - { - string id = activeDevice.Id; - - config = new StandardKeyboardInputConfig - { - Version = InputConfig.CurrentVersion, - Backend = InputBackendType.WindowKeyboard, - Id = id, - ControllerType = ControllerType.ProController, - LeftJoycon = new LeftJoyconCommonConfig - { - DpadUp = Key.Up, - DpadDown = Key.Down, - DpadLeft = Key.Left, - DpadRight = Key.Right, - ButtonMinus = Key.Minus, - ButtonL = Key.E, - ButtonZl = Key.Q, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, - }, - LeftJoyconStick = - new JoyconConfigKeyboardStick - { - StickUp = Key.W, - StickDown = Key.S, - StickLeft = Key.A, - StickRight = Key.D, - StickButton = Key.F, - }, - RightJoycon = new RightJoyconCommonConfig - { - ButtonA = Key.Z, - ButtonB = Key.X, - ButtonX = Key.C, - ButtonY = Key.V, - ButtonPlus = Key.Plus, - ButtonR = Key.U, - ButtonZr = Key.O, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound, - }, - RightJoyconStick = new JoyconConfigKeyboardStick - { - StickUp = Key.I, - StickDown = Key.K, - StickLeft = Key.J, - StickRight = Key.L, - StickButton = Key.H, - }, - }; - } - else if (activeDevice.Type == DeviceType.Controller) - { - bool isNintendoStyle = Devices.ToList().Find(x => x.Id == activeDevice.Id).Name.Contains("Nintendo"); - - string id = activeDevice.Id.Split(" ")[0]; - - config = new StandardControllerInputConfig - { - Version = InputConfig.CurrentVersion, - Backend = InputBackendType.GamepadSDL2, - Id = id, - ControllerType = ControllerType.ProController, - DeadzoneLeft = 0.1f, - DeadzoneRight = 0.1f, - RangeLeft = 1.0f, - RangeRight = 1.0f, - TriggerThreshold = 0.5f, - LeftJoycon = new LeftJoyconCommonConfig - { - DpadUp = ConfigGamepadInputId.DpadUp, - DpadDown = ConfigGamepadInputId.DpadDown, - DpadLeft = ConfigGamepadInputId.DpadLeft, - DpadRight = ConfigGamepadInputId.DpadRight, - ButtonMinus = ConfigGamepadInputId.Minus, - ButtonL = ConfigGamepadInputId.LeftShoulder, - ButtonZl = ConfigGamepadInputId.LeftTrigger, - ButtonSl = ConfigGamepadInputId.Unbound, - ButtonSr = ConfigGamepadInputId.Unbound, - }, - LeftJoyconStick = new JoyconConfigControllerStick - { - Joystick = ConfigStickInputId.Left, - StickButton = ConfigGamepadInputId.LeftStick, - InvertStickX = false, - InvertStickY = false, - }, - RightJoycon = new RightJoyconCommonConfig - { - ButtonA = isNintendoStyle ? ConfigGamepadInputId.A : ConfigGamepadInputId.B, - ButtonB = isNintendoStyle ? ConfigGamepadInputId.B : ConfigGamepadInputId.A, - ButtonX = isNintendoStyle ? ConfigGamepadInputId.X : ConfigGamepadInputId.Y, - ButtonY = isNintendoStyle ? ConfigGamepadInputId.Y : ConfigGamepadInputId.X, - ButtonPlus = ConfigGamepadInputId.Plus, - ButtonR = ConfigGamepadInputId.RightShoulder, - ButtonZr = ConfigGamepadInputId.RightTrigger, - ButtonSl = ConfigGamepadInputId.Unbound, - ButtonSr = ConfigGamepadInputId.Unbound, - }, - RightJoyconStick = new JoyconConfigControllerStick - { - Joystick = ConfigStickInputId.Right, - StickButton = ConfigGamepadInputId.RightStick, - InvertStickX = false, - InvertStickY = false, - }, - Motion = new StandardMotionConfigController - { - MotionBackend = MotionInputBackendType.GamepadDriver, - EnableMotion = true, - Sensitivity = 100, - GyroDeadzone = 1, - }, - Rumble = new RumbleConfigController - { - StrongRumble = 1f, - WeakRumble = 1f, - EnableRumble = false, - }, - }; - } - else - { - config = new InputConfig(); - } - - config.PlayerIndex = _playerId; - - return config; - } - - public async void LoadProfile() - { - if (Device == 0) - { - return; - } - - InputConfig config = null; - - if (string.IsNullOrWhiteSpace(ProfileName)) - { - return; - } - - if (ProfileName == LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault]) - { - config = LoadDefaultConfiguration(); - } - else - { - string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json"); - - if (!File.Exists(path)) - { - var index = ProfilesList.IndexOf(ProfileName); - if (index != -1) - { - ProfilesList.RemoveAt(index); - } - return; - } - - try - { - config = JsonHelper.DeserializeFromFile(path, _serializerContext.InputConfig); - } - catch (JsonException) { } - catch (InvalidOperationException) - { - Logger.Error?.Print(LogClass.Configuration, $"Profile {ProfileName} is incompatible with the current input configuration system."); - - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogProfileInvalidProfileErrorMessage, ProfileName)); - - return; - } - } - - if (config != null) - { - _isLoaded = false; - - LoadConfiguration(config); - - LoadDevice(); - - _isLoaded = true; - - NotifyChanges(); - } - } - - public async void SaveProfile() - { - if (Device == 0) - { - return; - } - - if (Configuration == null) - { - return; - } - - if (ProfileName == LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault]) - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogProfileDefaultProfileOverwriteErrorMessage]); - - return; - } - - bool validFileName = ProfileName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1; - - if (validFileName) - { - string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json"); - - InputConfig config = null; - - if (IsKeyboard) - { - config = (Configuration as InputConfiguration).GetConfig(); - } - else if (IsController) - { - config = (Configuration as InputConfiguration).GetConfig(); - } - - config.ControllerType = Controllers[_controller].Type; - - string jsonString = JsonHelper.Serialize(config, _serializerContext.InputConfig); - - await File.WriteAllTextAsync(path, jsonString); - - LoadProfiles(); - } - else - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogProfileInvalidProfileNameErrorMessage]); - } - } - - public async void RemoveProfile() - { - if (Device == 0 || ProfileName == LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault] || ProfilesList.IndexOf(ProfileName) == -1) - { - return; - } - - UserResult result = await ContentDialogHelper.CreateConfirmationDialog( - LocaleManager.Instance[LocaleKeys.DialogProfileDeleteProfileTitle], - LocaleManager.Instance[LocaleKeys.DialogProfileDeleteProfileMessage], - LocaleManager.Instance[LocaleKeys.InputDialogYes], - LocaleManager.Instance[LocaleKeys.InputDialogNo], - LocaleManager.Instance[LocaleKeys.RyujinxConfirm]); - - if (result == UserResult.Yes) - { - string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json"); - - if (File.Exists(path)) - { - File.Delete(path); - } - - LoadProfiles(); - } - } - - public void Save() - { - IsModified = false; - - List newConfig = new(); - - newConfig.AddRange(ConfigurationState.Instance.Hid.InputConfig.Value); - - newConfig.Remove(newConfig.Find(x => x == null)); - - if (Device == 0) - { - newConfig.Remove(newConfig.Find(x => x.PlayerIndex == this.PlayerId)); - } - else - { - var device = Devices[Device]; - - if (device.Type == DeviceType.Keyboard) - { - var inputConfig = Configuration as InputConfiguration; - inputConfig.Id = device.Id; - } - else - { - var inputConfig = Configuration as InputConfiguration; - inputConfig.Id = device.Id.Split(" ")[0]; - } - - var config = !IsController - ? (Configuration as InputConfiguration).GetConfig() - : (Configuration as InputConfiguration).GetConfig(); - config.ControllerType = Controllers[_controller].Type; - config.PlayerIndex = _playerId; - - int i = newConfig.FindIndex(x => x.PlayerIndex == PlayerId); - if (i == -1) - { - newConfig.Add(config); - } - else - { - newConfig[i] = config; - } - } - - _mainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse); - - // Atomically replace and signal input change. - // NOTE: Do not modify InputConfig.Value directly as other code depends on the on-change event. - ConfigurationState.Instance.Hid.InputConfig.Value = newConfig; - - ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath); - } - - public void NotifyChange(string property) - { - OnPropertyChanged(property); - } - - public void NotifyChanges() - { - OnPropertyChanged(nameof(Configuration)); - OnPropertyChanged(nameof(IsController)); - OnPropertyChanged(nameof(ShowSettings)); - OnPropertyChanged(nameof(IsKeyboard)); - OnPropertyChanged(nameof(IsRight)); - OnPropertyChanged(nameof(IsLeft)); - } - - public void Dispose() - { - GC.SuppressFinalize(this); - - _mainWindow.InputManager.GamepadDriver.OnGamepadConnected -= HandleOnGamepadConnected; - _mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected -= HandleOnGamepadDisconnected; - - _mainWindow.ViewModel.AppHost?.NpadManager.UnblockInputUpdates(); - - SelectedGamepad?.Dispose(); - - AvaloniaKeyboardDriver.Dispose(); - } } -} +} \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/ViewModels/InputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/InputViewModel.cs new file mode 100644 index 0000000000..6f213e31ff --- /dev/null +++ b/src/Ryujinx.Ava/UI/ViewModels/InputViewModel.cs @@ -0,0 +1,890 @@ +using Avalonia.Collections; +using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Svg.Skia; +using Avalonia.Threading; +using Ryujinx.Ava.Common.Locale; +using Ryujinx.Ava.Input; +using Ryujinx.Ava.UI.Helpers; +using Ryujinx.Ava.UI.Models; +using Ryujinx.Ava.UI.Views.Input; +using Ryujinx.Ava.UI.Windows; +using Ryujinx.Common; +using Ryujinx.Common.Configuration; +using Ryujinx.Common.Configuration.Hid; +using Ryujinx.Common.Configuration.Hid.Controller; +using Ryujinx.Common.Configuration.Hid.Controller.Motion; +using Ryujinx.Common.Configuration.Hid.Keyboard; +using Ryujinx.Common.Logging; +using Ryujinx.Common.Utilities; +using Ryujinx.Input; +using Ryujinx.Ui.Common.Configuration; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Text.Json; +using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId; +using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; +using Key = Ryujinx.Common.Configuration.Hid.Key; + +namespace Ryujinx.Ava.UI.ViewModels +{ + public class InputViewModel : BaseModel, IDisposable + { + private const string Disabled = "disabled"; + private const string ProControllerResource = "Ryujinx.Ui.Common/Resources/Controller_ProCon.svg"; + private const string JoyConPairResource = "Ryujinx.Ui.Common/Resources/Controller_JoyConPair.svg"; + private const string JoyConLeftResource = "Ryujinx.Ui.Common/Resources/Controller_JoyConLeft.svg"; + private const string JoyConRightResource = "Ryujinx.Ui.Common/Resources/Controller_JoyConRight.svg"; + private const string KeyboardString = "keyboard"; + private const string ControllerString = "controller"; + private readonly MainWindow _mainWindow; + + private PlayerIndex _playerId; + private int _controller; + private int _controllerNumber = 0; + private string _controllerImage; + private int _device; + private object _configuration; + private string _profileName; + private bool _isLoaded; + private readonly UserControl _owner; + + private static readonly InputConfigJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); + + public IGamepadDriver AvaloniaKeyboardDriver { get; } + public IGamepad SelectedGamepad { get; private set; } + + public ObservableCollection PlayerIndexes { get; set; } + public ObservableCollection<(DeviceType Type, string Id, string Name)> Devices { get; set; } + internal ObservableCollection Controllers { get; set; } + public AvaloniaList ProfilesList { get; set; } + public AvaloniaList DeviceList { get; set; } + + // XAML Flags + public bool ShowSettings => _device > 0; + public bool IsController => _device > 1; + public bool IsKeyboard => !IsController; + public bool IsRight { get; set; } + public bool IsLeft { get; set; } + + public bool IsModified { get; set; } + + public object Configuration + { + get => _configuration; + set + { + _configuration = value; + + OnPropertyChanged(); + } + } + + public PlayerIndex PlayerId + { + get => _playerId; + set + { + if (IsModified) + { + return; + } + + IsModified = false; + _playerId = value; + + if (!Enum.IsDefined(typeof(PlayerIndex), _playerId)) + { + _playerId = PlayerIndex.Player1; + } + + LoadConfiguration(); + LoadDevice(); + LoadProfiles(); + + _isLoaded = true; + + OnPropertyChanged(); + } + } + + public int Controller + { + get => _controller; + set + { + _controller = value; + + if (_controller == -1) + { + _controller = 0; + } + + if (Controllers.Count > 0 && value < Controllers.Count && _controller > -1) + { + ControllerType controller = Controllers[_controller].Type; + + IsLeft = true; + IsRight = true; + + switch (controller) + { + case ControllerType.Handheld: + ControllerImage = JoyConPairResource; + break; + case ControllerType.ProController: + ControllerImage = ProControllerResource; + break; + case ControllerType.JoyconPair: + ControllerImage = JoyConPairResource; + break; + case ControllerType.JoyconLeft: + ControllerImage = JoyConLeftResource; + IsRight = false; + break; + case ControllerType.JoyconRight: + ControllerImage = JoyConRightResource; + IsLeft = false; + break; + } + + LoadInputDriver(); + LoadProfiles(); + } + + OnPropertyChanged(); + NotifyChanges(); + } + } + + public string ControllerImage + { + get => _controllerImage; + set + { + _controllerImage = value; + + OnPropertyChanged(); + OnPropertyChanged(nameof(Image)); + } + } + + public SvgImage Image + { + get + { + SvgImage image = new SvgImage(); + + if (!string.IsNullOrWhiteSpace(_controllerImage)) + { + SvgSource source = new SvgSource(); + + source.Load(EmbeddedResources.GetStream(_controllerImage)); + + image.Source = source; + } + + return image; + } + } + + public string ProfileName + { + get => _profileName; set + { + _profileName = value; + + OnPropertyChanged(); + } + } + + public int Device + { + get => _device; + set + { + _device = value < 0 ? 0 : value; + + if (_device >= Devices.Count) + { + return; + } + + var selected = Devices[_device].Type; + + if (selected != DeviceType.None) + { + LoadControllers(); + + if (_isLoaded) + { + LoadConfiguration(LoadDefaultConfiguration()); + } + } + + OnPropertyChanged(); + NotifyChanges(); + } + } + + public InputConfig Config { get; set; } + + public InputViewModel(UserControl owner) : this() + { + _owner = owner; + + if (Program.PreviewerDetached) + { + _mainWindow = + (MainWindow)((IClassicDesktopStyleApplicationLifetime)Avalonia.Application.Current + .ApplicationLifetime).MainWindow; + + AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner); + + _mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; + _mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected; + if (_mainWindow.ViewModel.AppHost != null) + { + _mainWindow.ViewModel.AppHost.NpadManager.BlockInputUpdates(); + } + + _isLoaded = false; + + LoadDevices(); + + PlayerId = PlayerIndex.Player1; + } + } + + public InputViewModel() + { + PlayerIndexes = new ObservableCollection(); + Controllers = new ObservableCollection(); + Devices = new ObservableCollection<(DeviceType Type, string Id, string Name)>(); + ProfilesList = new AvaloniaList(); + DeviceList = new AvaloniaList(); + + ControllerImage = ProControllerResource; + + PlayerIndexes.Add(new(PlayerIndex.Player1, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer1])); + PlayerIndexes.Add(new(PlayerIndex.Player2, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer2])); + PlayerIndexes.Add(new(PlayerIndex.Player3, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer3])); + PlayerIndexes.Add(new(PlayerIndex.Player4, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer4])); + PlayerIndexes.Add(new(PlayerIndex.Player5, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer5])); + PlayerIndexes.Add(new(PlayerIndex.Player6, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer6])); + PlayerIndexes.Add(new(PlayerIndex.Player7, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer7])); + PlayerIndexes.Add(new(PlayerIndex.Player8, LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer8])); + PlayerIndexes.Add(new(PlayerIndex.Handheld, LocaleManager.Instance[LocaleKeys.ControllerSettingsHandheld])); + } + + private void LoadConfiguration(InputConfig inputConfig = null) + { + Config = inputConfig ?? ConfigurationState.Instance.Hid.InputConfig.Value.Find(inputConfig => inputConfig.PlayerIndex == _playerId); + + if (Config is StandardKeyboardInputConfig keyboardInputConfig) + { + Configuration = new KeyboardInputConfig(keyboardInputConfig); + } + + if (Config is StandardControllerInputConfig controllerInputConfig) + { + Configuration = new ControllerInputConfig(controllerInputConfig); + } + } + + public void LoadDevice() + { + if (Config == null || Config.Backend == InputBackendType.Invalid) + { + Device = 0; + } + else + { + var type = DeviceType.None; + + if (Config is StandardKeyboardInputConfig) + { + type = DeviceType.Keyboard; + } + + if (Config is StandardControllerInputConfig) + { + type = DeviceType.Controller; + } + + var item = Devices.FirstOrDefault(x => x.Type == type && x.Id == Config.Id); + if (item != default) + { + Device = Devices.ToList().FindIndex(x => x.Id == item.Id); + } + else + { + Device = 0; + } + } + } + + private void LoadInputDriver() + { + if (_device < 0) + { + return; + } + + string id = GetCurrentGamepadId(); + var type = Devices[Device].Type; + + if (type == DeviceType.None) + { + return; + } + else if (type == DeviceType.Keyboard) + { + if (_mainWindow.InputManager.KeyboardDriver is AvaloniaKeyboardDriver) + { + // NOTE: To get input in this window, we need to bind a custom keyboard driver instead of using the InputManager one as the main window isn't focused... + SelectedGamepad = AvaloniaKeyboardDriver.GetGamepad(id); + } + else + { + SelectedGamepad = _mainWindow.InputManager.KeyboardDriver.GetGamepad(id); + } + } + else + { + SelectedGamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id); + } + } + + private void HandleOnGamepadDisconnected(string id) + { + Dispatcher.UIThread.Post(() => + { + LoadDevices(); + }); + } + + private void HandleOnGamepadConnected(string id) + { + Dispatcher.UIThread.Post(() => + { + LoadDevices(); + }); + } + + private string GetCurrentGamepadId() + { + if (_device < 0) + { + return string.Empty; + } + + var device = Devices[Device]; + + if (device.Type == DeviceType.None) + { + return null; + } + + return device.Id.Split(" ")[0]; + } + + public void LoadControllers() + { + Controllers.Clear(); + + if (_playerId == PlayerIndex.Handheld) + { + Controllers.Add(new(ControllerType.Handheld, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeHandheld])); + + Controller = 0; + } + else + { + Controllers.Add(new(ControllerType.ProController, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeProController])); + Controllers.Add(new(ControllerType.JoyconPair, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeJoyConPair])); + Controllers.Add(new(ControllerType.JoyconLeft, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeJoyConLeft])); + Controllers.Add(new(ControllerType.JoyconRight, LocaleManager.Instance[LocaleKeys.ControllerSettingsControllerTypeJoyConRight])); + + if (Config != null && Controllers.ToList().FindIndex(x => x.Type == Config.ControllerType) != -1) + { + Controller = Controllers.ToList().FindIndex(x => x.Type == Config.ControllerType); + } + else + { + Controller = 0; + } + } + } + + private static string GetShortGamepadName(string str) + { + const string Ellipsis = "..."; + const int MaxSize = 50; + + if (str.Length > MaxSize) + { + return $"{str.AsSpan(0, MaxSize - Ellipsis.Length)}{Ellipsis}"; + } + + return str; + } + + private static string GetShortGamepadId(string str) + { + const string Hyphen = "-"; + const int Offset = 1; + + return str.Substring(str.IndexOf(Hyphen) + Offset); + } + + public void LoadDevices() + { + lock (Devices) + { + Devices.Clear(); + DeviceList.Clear(); + Devices.Add((DeviceType.None, Disabled, LocaleManager.Instance[LocaleKeys.ControllerSettingsDeviceDisabled])); + + foreach (string id in _mainWindow.InputManager.KeyboardDriver.GamepadsIds) + { + using IGamepad gamepad = _mainWindow.InputManager.KeyboardDriver.GetGamepad(id); + + if (gamepad != null) + { + Devices.Add((DeviceType.Keyboard, id, $"{GetShortGamepadName(gamepad.Name)}")); + } + } + + foreach (string id in _mainWindow.InputManager.GamepadDriver.GamepadsIds) + { + using IGamepad gamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id); + + if (gamepad != null) + { + if (Devices.Any(controller => GetShortGamepadId(controller.Id) == GetShortGamepadId(gamepad.Id))) + { + _controllerNumber++; + } + + Devices.Add((DeviceType.Controller, id, $"{GetShortGamepadName(gamepad.Name)} ({_controllerNumber})")); + } + } + + _controllerNumber = 0; + + DeviceList.AddRange(Devices.Select(x => x.Name)); + Device = Math.Min(Device, DeviceList.Count); + } + } + + private string GetProfileBasePath() + { + string path = AppDataManager.ProfilesDirPath; + var type = Devices[Device == -1 ? 0 : Device].Type; + + if (type == DeviceType.Keyboard) + { + path = Path.Combine(path, KeyboardString); + } + else if (type == DeviceType.Controller) + { + path = Path.Combine(path, ControllerString); + } + + return path; + } + + private void LoadProfiles() + { + ProfilesList.Clear(); + + string basePath = GetProfileBasePath(); + + if (!Directory.Exists(basePath)) + { + Directory.CreateDirectory(basePath); + } + + ProfilesList.Add((LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault])); + + foreach (string profile in Directory.GetFiles(basePath, "*.json", SearchOption.AllDirectories)) + { + ProfilesList.Add(Path.GetFileNameWithoutExtension(profile)); + } + + if (string.IsNullOrWhiteSpace(ProfileName)) + { + ProfileName = LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault]; + } + } + + public InputConfig LoadDefaultConfiguration() + { + var activeDevice = Devices.FirstOrDefault(); + + if (Devices.Count > 0 && Device < Devices.Count && Device >= 0) + { + activeDevice = Devices[Device]; + } + + InputConfig config; + if (activeDevice.Type == DeviceType.Keyboard) + { + string id = activeDevice.Id; + + config = new StandardKeyboardInputConfig + { + Version = InputConfig.CurrentVersion, + Backend = InputBackendType.WindowKeyboard, + Id = id, + ControllerType = ControllerType.ProController, + LeftJoycon = new LeftJoyconCommonConfig + { + DpadUp = Key.Up, + DpadDown = Key.Down, + DpadLeft = Key.Left, + DpadRight = Key.Right, + ButtonMinus = Key.Minus, + ButtonL = Key.E, + ButtonZl = Key.Q, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + LeftJoyconStick = + new JoyconConfigKeyboardStick + { + StickUp = Key.W, + StickDown = Key.S, + StickLeft = Key.A, + StickRight = Key.D, + StickButton = Key.F + }, + RightJoycon = new RightJoyconCommonConfig + { + ButtonA = Key.Z, + ButtonB = Key.X, + ButtonX = Key.C, + ButtonY = Key.V, + ButtonPlus = Key.Plus, + ButtonR = Key.U, + ButtonZr = Key.O, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + RightJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = Key.I, + StickDown = Key.K, + StickLeft = Key.J, + StickRight = Key.L, + StickButton = Key.H + } + }; + } + else if (activeDevice.Type == DeviceType.Controller) + { + bool isNintendoStyle = Devices.ToList().Find(x => x.Id == activeDevice.Id).Name.Contains("Nintendo"); + + string id = activeDevice.Id.Split(" ")[0]; + + config = new StandardControllerInputConfig + { + Version = InputConfig.CurrentVersion, + Backend = InputBackendType.GamepadSDL2, + Id = id, + ControllerType = ControllerType.ProController, + DeadzoneLeft = 0.1f, + DeadzoneRight = 0.1f, + RangeLeft = 1.0f, + RangeRight = 1.0f, + TriggerThreshold = 0.5f, + LeftJoycon = new LeftJoyconCommonConfig + { + DpadUp = ConfigGamepadInputId.DpadUp, + DpadDown = ConfigGamepadInputId.DpadDown, + DpadLeft = ConfigGamepadInputId.DpadLeft, + DpadRight = ConfigGamepadInputId.DpadRight, + ButtonMinus = ConfigGamepadInputId.Minus, + ButtonL = ConfigGamepadInputId.LeftShoulder, + ButtonZl = ConfigGamepadInputId.LeftTrigger, + ButtonSl = ConfigGamepadInputId.Unbound, + ButtonSr = ConfigGamepadInputId.Unbound + }, + LeftJoyconStick = new JoyconConfigControllerStick + { + Joystick = ConfigStickInputId.Left, + StickButton = ConfigGamepadInputId.LeftStick, + InvertStickX = false, + InvertStickY = false + }, + RightJoycon = new RightJoyconCommonConfig + { + ButtonA = isNintendoStyle ? ConfigGamepadInputId.A : ConfigGamepadInputId.B, + ButtonB = isNintendoStyle ? ConfigGamepadInputId.B : ConfigGamepadInputId.A, + ButtonX = isNintendoStyle ? ConfigGamepadInputId.X : ConfigGamepadInputId.Y, + ButtonY = isNintendoStyle ? ConfigGamepadInputId.Y : ConfigGamepadInputId.X, + ButtonPlus = ConfigGamepadInputId.Plus, + ButtonR = ConfigGamepadInputId.RightShoulder, + ButtonZr = ConfigGamepadInputId.RightTrigger, + ButtonSl = ConfigGamepadInputId.Unbound, + ButtonSr = ConfigGamepadInputId.Unbound + }, + RightJoyconStick = new JoyconConfigControllerStick + { + Joystick = ConfigStickInputId.Right, + StickButton = ConfigGamepadInputId.RightStick, + InvertStickX = false, + InvertStickY = false + }, + Motion = new StandardMotionConfigController + { + MotionBackend = MotionInputBackendType.GamepadDriver, + EnableMotion = true, + Sensitivity = 100, + GyroDeadzone = 1 + }, + Rumble = new RumbleConfigController + { + StrongRumble = 1f, + WeakRumble = 1f, + EnableRumble = false + } + }; + } + else + { + config = new InputConfig(); + } + + config.PlayerIndex = _playerId; + + return config; + } + + public async void LoadProfile() + { + if (Device == 0) + { + return; + } + + InputConfig config = null; + + if (string.IsNullOrWhiteSpace(ProfileName)) + { + return; + } + + if (ProfileName == LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault]) + { + config = LoadDefaultConfiguration(); + } + else + { + string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json"); + + if (!File.Exists(path)) + { + var index = ProfilesList.IndexOf(ProfileName); + if (index != -1) + { + ProfilesList.RemoveAt(index); + } + return; + } + + try + { + config = JsonHelper.DeserializeFromFile(path, SerializerContext.InputConfig); + } + catch (JsonException) { } + catch (InvalidOperationException) + { + Logger.Error?.Print(LogClass.Configuration, $"Profile {ProfileName} is incompatible with the current input configuration system."); + + await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogProfileInvalidProfileErrorMessage, ProfileName)); + + return; + } + } + + if (config != null) + { + _isLoaded = false; + + LoadConfiguration(config); + + LoadDevice(); + + _isLoaded = true; + + NotifyChanges(); + } + } + + public async void SaveProfile() + { + if (Device == 0) + { + return; + } + + if (Configuration == null) + { + return; + } + + if (ProfileName == LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault]) + { + await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogProfileDefaultProfileOverwriteErrorMessage]); + + return; + } + else + { + bool validFileName = ProfileName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1; + + if (validFileName) + { + string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json"); + + InputConfig config = null; + + if (IsKeyboard) + { + config = (Configuration as KeyboardInputConfig).GetConfig(); + } + else if (IsController) + { + config = (Configuration as ControllerInputConfig).GetConfig(); + } + + config.ControllerType = Controllers[_controller].Type; + + string jsonString = JsonHelper.Serialize(config, SerializerContext.InputConfig); + + await File.WriteAllTextAsync(path, jsonString); + + LoadProfiles(); + } + else + { + await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogProfileInvalidProfileNameErrorMessage]); + } + } + } + + public async void RemoveProfile() + { + if (Device == 0 || ProfileName == LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault] || ProfilesList.IndexOf(ProfileName) == -1) + { + return; + } + + UserResult result = await ContentDialogHelper.CreateConfirmationDialog( + LocaleManager.Instance[LocaleKeys.DialogProfileDeleteProfileTitle], + LocaleManager.Instance[LocaleKeys.DialogProfileDeleteProfileMessage], + LocaleManager.Instance[LocaleKeys.InputDialogYes], + LocaleManager.Instance[LocaleKeys.InputDialogNo], + LocaleManager.Instance[LocaleKeys.RyujinxConfirm]); + + if (result == UserResult.Yes) + { + string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json"); + + if (File.Exists(path)) + { + File.Delete(path); + } + + LoadProfiles(); + } + } + + public void Save() + { + IsModified = false; + + List newConfig = new(); + + newConfig.AddRange(ConfigurationState.Instance.Hid.InputConfig.Value); + + newConfig.Remove(newConfig.Find(x => x == null)); + + if (Device == 0) + { + newConfig.Remove(newConfig.Find(x => x.PlayerIndex == this.PlayerId)); + } + else + { + var device = Devices[Device]; + + if (device.Type == DeviceType.Keyboard) + { + var inputConfig = Configuration as KeyboardInputConfig; + inputConfig.Id = device.Id; + } + else + { + var inputConfig = Configuration as ControllerInputConfig; + inputConfig.Id = device.Id.Split(" ")[0]; + } + + var config = !IsController + ? (Configuration as KeyboardInputConfig).GetConfig() + : (Configuration as ControllerInputConfig).GetConfig(); + config.ControllerType = Controllers[_controller].Type; + config.PlayerIndex = _playerId; + + int i = newConfig.FindIndex(x => x.PlayerIndex == PlayerId); + if (i == -1) + { + newConfig.Add(config); + } + else + { + newConfig[i] = config; + } + } + + _mainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse); + + // Atomically replace and signal input change. + // NOTE: Do not modify InputConfig.Value directly as other code depends on the on-change event. + ConfigurationState.Instance.Hid.InputConfig.Value = newConfig; + + ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath); + } + + public void NotifyChange(string property) + { + OnPropertyChanged(property); + } + + public void NotifyChanges() + { + OnPropertyChanged(nameof(Configuration)); + OnPropertyChanged(nameof(IsController)); + OnPropertyChanged(nameof(ShowSettings)); + OnPropertyChanged(nameof(IsKeyboard)); + OnPropertyChanged(nameof(IsRight)); + OnPropertyChanged(nameof(IsLeft)); + } + + public void Dispose() + { + _mainWindow.InputManager.GamepadDriver.OnGamepadConnected -= HandleOnGamepadConnected; + _mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected -= HandleOnGamepadDisconnected; + + _mainWindow.ViewModel.AppHost?.NpadManager.UnblockInputUpdates(); + + SelectedGamepad?.Dispose(); + + AvaloniaKeyboardDriver.Dispose(); + } + } +} \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/ViewModels/KeyboardInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/KeyboardInputViewModel.cs new file mode 100644 index 0000000000..db8329073e --- /dev/null +++ b/src/Ryujinx.Ava/UI/ViewModels/KeyboardInputViewModel.cs @@ -0,0 +1,64 @@ +using Avalonia.Svg.Skia; +using Ryujinx.Ava.UI.Models; + +namespace Ryujinx.Ava.UI.ViewModels +{ + public class KeyboardInputViewModel : BaseModel + { + private KeyboardInputConfig _config; + private bool _isLeft; + private bool _isRight; + private bool _showSettings; + private SvgImage _image; + + public KeyboardInputConfig Config + { + get => _config; + set + { + _config = value; + OnPropertyChanged(); + } + } + + public bool IsLeft + { + get => _isLeft; + set + { + _isLeft = value; + OnPropertyChanged(); + } + } + + public bool IsRight + { + get => _isRight; + set + { + _isRight = value; + OnPropertyChanged(); + } + } + + public bool ShowSettings + { + get => _showSettings; + set + { + _showSettings = value; + OnPropertyChanged(); + } + } + + public SvgImage Image + { + get => _image; + set + { + _image = value; + OnPropertyChanged(); + } + } + } +} \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml index 99f2b6b694..8945fc27b7 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml @@ -1,12 +1,9 @@ @@ -34,191 +32,10 @@ HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -260,7 +77,7 @@ TextAlignment="Center" /> @@ -276,7 +93,7 @@ TextAlignment="Center" /> @@ -292,7 +109,7 @@ TextAlignment="Center" /> @@ -312,100 +129,8 @@ Margin="0,0,0,10" HorizontalAlignment="Center" Text="{locale:Locale ControllerSettingsLStick}" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -418,7 +143,7 @@ TextAlignment="Center" /> @@ -435,20 +160,20 @@ TextAlignment="Center" /> - + - + - + - + Value="{Binding Config.DeadzoneLeft, Mode=TwoWay}" /> + Text="{Binding Config.DeadzoneLeft, StringFormat=\{0:0.00\}}" /> - + Value="{Binding Config.RangeLeft, Mode=TwoWay}" /> + Text="{Binding Config.RangeLeft, StringFormat=\{0:0.00\}}" /> @@ -528,7 +253,7 @@ TextAlignment="Center" /> @@ -545,7 +270,7 @@ TextAlignment="Center" /> @@ -562,7 +287,7 @@ TextAlignment="Center" /> @@ -579,7 +304,7 @@ TextAlignment="Center" /> @@ -606,17 +331,17 @@ - + Value="{Binding Config.TriggerThreshold, Mode=TwoWay}" /> + Text="{Binding Config.TriggerThreshold, StringFormat=\{0:0.00\}}" /> @@ -650,7 +375,7 @@ TextAlignment="Center" /> @@ -668,7 +393,7 @@ TextAlignment="Center" /> @@ -686,7 +411,7 @@ TextAlignment="Center" /> @@ -710,8 +435,7 @@ BorderThickness="1" CornerRadius="5" VerticalAlignment="Bottom" - HorizontalAlignment="Stretch" - IsVisible="{Binding IsController}"> + HorizontalAlignment="Stretch"> @@ -721,7 +445,7 @@ Margin="10" MinWidth="0" Grid.Column="0" - IsChecked="{ReflectionBinding Configuration.EnableMotion, Mode=TwoWay}"> + IsChecked="{Binding Config.EnableMotion, Mode=TwoWay}"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs new file mode 100644 index 0000000000..91715b859e --- /dev/null +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs @@ -0,0 +1,180 @@ +using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.Input; +using Avalonia.Interactivity; +using Avalonia.LogicalTree; +using Ryujinx.Ava.Common.Locale; +using Ryujinx.Ava.UI.Helpers; +using Ryujinx.Ava.UI.Models; +using Ryujinx.Ava.UI.ViewModels; +using Ryujinx.Common.Configuration.Hid.Controller; +using Ryujinx.Input; +using Ryujinx.Input.Assigner; +using System; + +namespace Ryujinx.Ava.UI.Views.Input +{ + public partial class InputView : UserControl + { + private bool _dialogOpen; + + private ButtonKeyAssigner _currentAssigner; + internal InputViewModel ViewModel { get; set; } + + public InputView() + { + DataContext = ViewModel = new InputViewModel(this); + + InitializeComponent(); + + foreach (ILogical visual in SettingButtons.GetLogicalDescendants()) + { + if (visual is ToggleButton button && !(visual is CheckBox)) + { + button.Checked += Button_Checked; + button.Unchecked += Button_Unchecked; + } + } + } + + protected override void OnPointerReleased(PointerReleasedEventArgs e) + { + base.OnPointerReleased(e); + + if (_currentAssigner != null && _currentAssigner.ToggledButton != null && !_currentAssigner.ToggledButton.IsPointerOver) + { + _currentAssigner.Cancel(); + } + } + + private void Button_Checked(object sender, RoutedEventArgs e) + { + if (sender is ToggleButton button) + { + if (_currentAssigner != null && button == _currentAssigner.ToggledButton) + { + return; + } + + bool isStick = button.Tag != null && button.Tag.ToString() == "stick"; + + if (_currentAssigner == null && (bool)button.IsChecked) + { + _currentAssigner = new ButtonKeyAssigner(button); + + FocusManager.Instance.Focus(this, NavigationMethod.Pointer); + + PointerPressed += MouseClick; + + IKeyboard keyboard = (IKeyboard)ViewModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. + IButtonAssigner assigner = CreateButtonAssigner(isStick); + + _currentAssigner.ButtonAssigned += (sender, e) => + { + if (e.IsAssigned) + { + ViewModel.IsModified = true; + } + }; + + _currentAssigner.GetInputAndAssign(assigner, keyboard); + } + else + { + if (_currentAssigner != null) + { + ToggleButton oldButton = _currentAssigner.ToggledButton; + + _currentAssigner.Cancel(); + _currentAssigner = null; + button.IsChecked = false; + } + } + } + } + + public void SaveCurrentProfile() + { + ViewModel.Save(); + } + + private IButtonAssigner CreateButtonAssigner(bool forStick) + { + IButtonAssigner assigner; + + var device = ViewModel.Devices[ViewModel.Device]; + + if (device.Type == DeviceType.Keyboard) + { + assigner = new KeyboardKeyAssigner((IKeyboard)ViewModel.SelectedGamepad); + } + else if (device.Type == DeviceType.Controller) + { + assigner = new GamepadButtonAssigner(ViewModel.SelectedGamepad, (ViewModel.Config as StandardControllerInputConfig).TriggerThreshold, forStick); + } + else + { + throw new Exception("Controller not supported"); + } + + return assigner; + } + + private void Button_Unchecked(object sender, RoutedEventArgs e) + { + _currentAssigner?.Cancel(); + _currentAssigner = null; + } + + private void MouseClick(object sender, PointerPressedEventArgs e) + { + bool shouldUnbind = false; + + if (e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed) + { + shouldUnbind = true; + } + + _currentAssigner?.Cancel(shouldUnbind); + + PointerPressed -= MouseClick; + } + + private async void PlayerIndexBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (ViewModel.IsModified && !_dialogOpen) + { + _dialogOpen = true; + + var result = await ContentDialogHelper.CreateConfirmationDialog( + LocaleManager.Instance[LocaleKeys.DialogControllerSettingsModifiedConfirmMessage], + LocaleManager.Instance[LocaleKeys.DialogControllerSettingsModifiedConfirmSubMessage], + LocaleManager.Instance[LocaleKeys.InputDialogYes], + LocaleManager.Instance[LocaleKeys.InputDialogNo], + LocaleManager.Instance[LocaleKeys.RyujinxConfirm]); + + if (result == UserResult.Yes) + { + ViewModel.Save(); + } + + _dialogOpen = false; + + ViewModel.IsModified = false; + + if (e.AddedItems.Count > 0) + { + var player = (PlayerModel)e.AddedItems[0]; + ViewModel.PlayerId = player.Id; + } + } + } + + public void Dispose() + { + _currentAssigner?.Cancel(); + _currentAssigner = null; + ViewModel.Dispose(); + } + } +} \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml new file mode 100644 index 0000000000..a2ba522c79 --- /dev/null +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml @@ -0,0 +1,678 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs new file mode 100644 index 0000000000..d544660c2a --- /dev/null +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs @@ -0,0 +1,19 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Ryujinx.Ava.UI.Views.Input +{ + public partial class KeyboardInputView : UserControl + { + public KeyboardInputView() + { + InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml b/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml index 81f4b68b74..08b45f206b 100644 --- a/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml @@ -27,7 +27,7 @@ - Date: Wed, 17 May 2023 10:51:47 -0400 Subject: [PATCH 03/54] Restructure + Ack suggestions --- .../{ => Input}/ControllerInputViewModel.cs | 11 +++++------ .../UI/ViewModels/{ => Input}/InputViewModel.cs | 2 +- .../ViewModels/{ => Input}/KeyboardInputViewModel.cs | 11 +++++------ .../UI/ViewModels/{ => Input}/MotionInputViewModel.cs | 0 .../UI/ViewModels/{ => Input}/RumbleInputViewModel.cs | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) rename src/Ryujinx.Ava/UI/ViewModels/{ => Input}/ControllerInputViewModel.cs (97%) rename src/Ryujinx.Ava/UI/ViewModels/{ => Input}/InputViewModel.cs (99%) rename src/Ryujinx.Ava/UI/ViewModels/{ => Input}/KeyboardInputViewModel.cs (96%) rename src/Ryujinx.Ava/UI/ViewModels/{ => Input}/MotionInputViewModel.cs (100%) rename src/Ryujinx.Ava/UI/ViewModels/{ => Input}/RumbleInputViewModel.cs (92%) diff --git a/src/Ryujinx.Ava/UI/ViewModels/ControllerInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs similarity index 97% rename from src/Ryujinx.Ava/UI/ViewModels/ControllerInputViewModel.cs rename to src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs index 11b555db6a..2aeb29c1e6 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/ControllerInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -2,16 +2,11 @@ using Avalonia.Svg.Skia; using Ryujinx.Ava.UI.Models; using Ryujinx.Ava.UI.Views.Input; -namespace Ryujinx.Ava.UI.ViewModels +namespace Ryujinx.Ava.UI.ViewModels.Input { public class ControllerInputViewModel : BaseModel { private ControllerInputConfig _config; - private bool _isLeft; - private bool _isRight; - private bool _showSettings; - private SvgImage _image; - public ControllerInputConfig Config { get => _config; @@ -22,6 +17,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } + private bool _isLeft; public bool IsLeft { get => _isLeft; @@ -32,6 +28,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } + private bool _isRight; public bool IsRight { get => _isRight; @@ -42,6 +39,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } + private bool _showSettings; public bool ShowSettings { get => _showSettings; @@ -52,6 +50,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } + private SvgImage _image; public SvgImage Image { get => _image; diff --git a/src/Ryujinx.Ava/UI/ViewModels/InputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs similarity index 99% rename from src/Ryujinx.Ava/UI/ViewModels/InputViewModel.cs rename to src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs index 6f213e31ff..7169c38aef 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/InputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs @@ -29,7 +29,7 @@ using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.Gamepad using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; using Key = Ryujinx.Common.Configuration.Hid.Key; -namespace Ryujinx.Ava.UI.ViewModels +namespace Ryujinx.Ava.UI.ViewModels.Input { public class InputViewModel : BaseModel, IDisposable { diff --git a/src/Ryujinx.Ava/UI/ViewModels/KeyboardInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs similarity index 96% rename from src/Ryujinx.Ava/UI/ViewModels/KeyboardInputViewModel.cs rename to src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs index db8329073e..994bdb17e1 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/KeyboardInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -1,16 +1,11 @@ using Avalonia.Svg.Skia; using Ryujinx.Ava.UI.Models; -namespace Ryujinx.Ava.UI.ViewModels +namespace Ryujinx.Ava.UI.ViewModels.Input { public class KeyboardInputViewModel : BaseModel { private KeyboardInputConfig _config; - private bool _isLeft; - private bool _isRight; - private bool _showSettings; - private SvgImage _image; - public KeyboardInputConfig Config { get => _config; @@ -21,6 +16,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } + private bool _isLeft; public bool IsLeft { get => _isLeft; @@ -31,6 +27,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } + private bool _isRight; public bool IsRight { get => _isRight; @@ -41,6 +38,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } + private bool _showSettings; public bool ShowSettings { get => _showSettings; @@ -51,6 +49,7 @@ namespace Ryujinx.Ava.UI.ViewModels } } + private SvgImage _image; public SvgImage Image { get => _image; diff --git a/src/Ryujinx.Ava/UI/ViewModels/MotionInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/MotionInputViewModel.cs similarity index 100% rename from src/Ryujinx.Ava/UI/ViewModels/MotionInputViewModel.cs rename to src/Ryujinx.Ava/UI/ViewModels/Input/MotionInputViewModel.cs diff --git a/src/Ryujinx.Ava/UI/ViewModels/RumbleInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/RumbleInputViewModel.cs similarity index 92% rename from src/Ryujinx.Ava/UI/ViewModels/RumbleInputViewModel.cs rename to src/Ryujinx.Ava/UI/ViewModels/Input/RumbleInputViewModel.cs index 49de19937d..8ad33cf4ce 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/RumbleInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/RumbleInputViewModel.cs @@ -1,4 +1,4 @@ -namespace Ryujinx.Ava.UI.ViewModels +namespace Ryujinx.Ava.UI.ViewModels.Input { public class RumbleInputViewModel : BaseModel { From 12991ce0707207972ab0d3aa5ef800e9a9f7f2ce Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 17 May 2023 11:00:09 -0400 Subject: [PATCH 04/54] Restructure + Ack suggestions --- .../{ => Input}/ControllerInputConfig.cs | 362 +++++++++--------- .../Models/{ => Input}/KeyboardInputConfig.cs | 2 +- .../Input/ControllerInputViewModel.cs | 2 +- .../UI/ViewModels/Input/InputViewModel.cs | 1 - .../Input/KeyboardInputViewModel.cs | 2 +- .../UI/Views/Input/ControllerInputView.axaml | 2 +- .../UI/Views/Input/InputView.axaml | 2 +- .../UI/Views/Input/InputView.axaml.cs | 2 +- .../UI/Views/Input/KeyboardInputView.axaml | 2 +- .../UI/Views/Input/MotionInputView.axaml | 2 +- .../UI/Views/Input/RumbleInputView.axaml | 2 +- 11 files changed, 188 insertions(+), 193 deletions(-) rename src/Ryujinx.Ava/UI/Models/{ => Input}/ControllerInputConfig.cs (99%) rename src/Ryujinx.Ava/UI/Models/{ => Input}/KeyboardInputConfig.cs (99%) diff --git a/src/Ryujinx.Ava/UI/Models/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs similarity index 99% rename from src/Ryujinx.Ava/UI/Models/ControllerInputConfig.cs rename to src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs index fce2191e21..53e0d560dc 100644 --- a/src/Ryujinx.Ava/UI/Models/ControllerInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs @@ -4,55 +4,10 @@ using Ryujinx.Common.Configuration.Hid.Controller; using Ryujinx.Common.Configuration.Hid.Controller.Motion; using System; -namespace Ryujinx.Ava.UI.Models +namespace Ryujinx.Ava.UI.Models.Input { public class ControllerInputConfig : BaseModel { - private StickInputId _leftJoystick; - private bool _leftInvertStickX; - private bool _leftInvertStickY; - private bool _leftRotate90; - private GamepadInputId _leftControllerStickButton; - - private StickInputId _rightJoystick; - private bool _rightInvertStickX; - private bool _rightInvertStickY; - private bool _rightRotate90; - private GamepadInputId _rightControllerStickButton; - - private GamepadInputId _buttonA; - private GamepadInputId _buttonB; - private GamepadInputId _buttonX; - private GamepadInputId _buttonY; - private GamepadInputId _buttonR; - private GamepadInputId _rightButtonSl; - private GamepadInputId _rightButtonSr; - private GamepadInputId _buttonZr; - private GamepadInputId _buttonPlus; - - private GamepadInputId _dpadUp; - private GamepadInputId _dpadDown; - private GamepadInputId _dpadLeft; - private GamepadInputId _dpadRight; - private GamepadInputId _buttonL; - private GamepadInputId _leftButtonSl; - private GamepadInputId _leftButtonSr; - private GamepadInputId _buttonZl; - private GamepadInputId _buttonMinus; - - private float _deadzoneLeft; - private float _deadzoneRight; - private float _rangeLeft; - private float _rangeRight; - private float _triggerThreshold; - private double _gyroDeadzone; - private int _sensitivity; - private bool _enableRumble; - private bool _enableMotion; - private float _weakRumble; - private float _strongRumble; - private MotionInputBackendType _motionBackend; - public bool EnableCemuHookMotion { get; set; } public string DsuServerHost { get; set; } public int DsuServerPort { get; set; } @@ -64,6 +19,7 @@ namespace Ryujinx.Ava.UI.Models public ControllerType ControllerType { get; set; } public PlayerIndex PlayerIndex { get; set; } + private StickInputId _leftJoystick; public StickInputId LeftJoystick { get => _leftJoystick; @@ -74,6 +30,7 @@ namespace Ryujinx.Ava.UI.Models } } + private bool _leftInvertStickX; public bool LeftInvertStickX { get => _leftInvertStickX; @@ -84,6 +41,7 @@ namespace Ryujinx.Ava.UI.Models } } + private bool _leftInvertStickY; public bool LeftInvertStickY { get => _leftInvertStickY; @@ -94,6 +52,7 @@ namespace Ryujinx.Ava.UI.Models } } + private bool _leftRotate90; public bool LeftRotate90 { get => _leftRotate90; @@ -104,6 +63,7 @@ namespace Ryujinx.Ava.UI.Models } } + private GamepadInputId _leftControllerStickButton; public GamepadInputId LeftControllerStickButton { get => _leftControllerStickButton; @@ -114,6 +74,7 @@ namespace Ryujinx.Ava.UI.Models } } + private StickInputId _rightJoystick; public StickInputId RightJoystick { get => _rightJoystick; @@ -124,6 +85,7 @@ namespace Ryujinx.Ava.UI.Models } } + private bool _rightInvertStickX; public bool RightInvertStickX { get => _rightInvertStickX; @@ -134,6 +96,7 @@ namespace Ryujinx.Ava.UI.Models } } + private bool _rightInvertStickY; public bool RightInvertStickY { get => _rightInvertStickY; @@ -144,6 +107,7 @@ namespace Ryujinx.Ava.UI.Models } } + private bool _rightRotate90; public bool RightRotate90 { get => _rightRotate90; @@ -154,6 +118,7 @@ namespace Ryujinx.Ava.UI.Models } } + private GamepadInputId _rightControllerStickButton; public GamepadInputId RightControllerStickButton { get => _rightControllerStickButton; @@ -164,96 +129,7 @@ namespace Ryujinx.Ava.UI.Models } } - public GamepadInputId ButtonA - { - get => _buttonA; - set - { - _buttonA = value; - OnPropertyChanged(); - } - } - - public GamepadInputId ButtonB - { - get => _buttonB; - set - { - _buttonB = value; - OnPropertyChanged(); - } - } - - public GamepadInputId ButtonX - { - get => _buttonX; - set - { - _buttonX = value; - OnPropertyChanged(); - } - } - - public GamepadInputId ButtonY - { - get => _buttonY; - set - { - _buttonY = value; - OnPropertyChanged(); - } - } - - public GamepadInputId ButtonR - { - get => _buttonR; - set - { - _buttonR = value; - OnPropertyChanged(); - } - } - - public GamepadInputId RightButtonSl - { - get => _rightButtonSl; - set - { - _rightButtonSl = value; - OnPropertyChanged(); - } - } - - public GamepadInputId RightButtonSr - { - get => _rightButtonSr; - set - { - _rightButtonSr = value; - OnPropertyChanged(); - } - } - - public GamepadInputId ButtonZr - { - get => _buttonZr; - set - { - _buttonZr = value; - OnPropertyChanged(); - } - } - - public GamepadInputId ButtonPlus - { - get => _buttonPlus; - set - { - _buttonPlus = value; - OnPropertyChanged(); - } - } - + private GamepadInputId _dpadUp; public GamepadInputId DpadUp { get => _dpadUp; @@ -264,6 +140,7 @@ namespace Ryujinx.Ava.UI.Models } } + private GamepadInputId _dpadDown; public GamepadInputId DpadDown { get => _dpadDown; @@ -274,6 +151,7 @@ namespace Ryujinx.Ava.UI.Models } } + private GamepadInputId _dpadLeft; public GamepadInputId DpadLeft { get => _dpadLeft; @@ -284,6 +162,7 @@ namespace Ryujinx.Ava.UI.Models } } + private GamepadInputId _dpadRight; public GamepadInputId DpadRight { get => _dpadRight; @@ -294,6 +173,7 @@ namespace Ryujinx.Ava.UI.Models } } + private GamepadInputId _buttonL; public GamepadInputId ButtonL { get => _buttonL; @@ -304,36 +184,7 @@ namespace Ryujinx.Ava.UI.Models } } - public GamepadInputId LeftButtonSl - { - get => _leftButtonSl; - set - { - _leftButtonSl = value; - OnPropertyChanged(); - } - } - - public GamepadInputId LeftButtonSr - { - get => _leftButtonSr; - set - { - _leftButtonSr = value; - OnPropertyChanged(); - } - } - - public GamepadInputId ButtonZl - { - get => _buttonZl; - set - { - _buttonZl = value; - OnPropertyChanged(); - } - } - + private GamepadInputId _buttonMinus; public GamepadInputId ButtonMinus { get => _buttonMinus; @@ -344,6 +195,139 @@ namespace Ryujinx.Ava.UI.Models } } + private GamepadInputId _leftButtonSl; + public GamepadInputId LeftButtonSl + { + get => _leftButtonSl; + set + { + _leftButtonSl = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _leftButtonSr; + public GamepadInputId LeftButtonSr + { + get => _leftButtonSr; + set + { + _leftButtonSr = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _buttonZl; + public GamepadInputId ButtonZl + { + get => _buttonZl; + set + { + _buttonZl = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _buttonA; + public GamepadInputId ButtonA + { + get => _buttonA; + set + { + _buttonA = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _buttonB; + public GamepadInputId ButtonB + { + get => _buttonB; + set + { + _buttonB = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _buttonX; + public GamepadInputId ButtonX + { + get => _buttonX; + set + { + _buttonX = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _buttonY; + public GamepadInputId ButtonY + { + get => _buttonY; + set + { + _buttonY = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _buttonR; + public GamepadInputId ButtonR + { + get => _buttonR; + set + { + _buttonR = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _buttonPlus; + public GamepadInputId ButtonPlus + { + get => _buttonPlus; + set + { + _buttonPlus = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _rightButtonSl; + public GamepadInputId RightButtonSl + { + get => _rightButtonSl; + set + { + _rightButtonSl = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _rightButtonSr; + public GamepadInputId RightButtonSr + { + get => _rightButtonSr; + set + { + _rightButtonSr = value; + OnPropertyChanged(); + } + } + + private GamepadInputId _buttonZr; + public GamepadInputId ButtonZr + { + get => _buttonZr; + set + { + _buttonZr = value; + OnPropertyChanged(); + } + } + + private float _deadzoneLeft; public float DeadzoneLeft { get => _deadzoneLeft; @@ -355,6 +339,7 @@ namespace Ryujinx.Ava.UI.Models } } + private float _deadzoneRight; public float DeadzoneRight { get => _deadzoneRight; @@ -366,6 +351,7 @@ namespace Ryujinx.Ava.UI.Models } } + private float _rangeLeft; public float RangeLeft { get => _rangeLeft; @@ -377,6 +363,7 @@ namespace Ryujinx.Ava.UI.Models } } + private float _rangeRight; public float RangeRight { get => _rangeRight; @@ -388,6 +375,7 @@ namespace Ryujinx.Ava.UI.Models } } + private float _triggerThreshold; public float TriggerThreshold { get => _triggerThreshold; @@ -399,17 +387,29 @@ namespace Ryujinx.Ava.UI.Models } } - public int Sensitivity + private bool _enableMotion; + public bool EnableMotion { - get => _sensitivity; + get => _enableMotion; set { - _sensitivity = value; - + _enableMotion = value; OnPropertyChanged(); } } + private MotionInputBackendType _motionBackend; + public MotionInputBackendType MotionBackend + { + get => _motionBackend; + set + { + _motionBackend = value; + OnPropertyChanged(); + } + } + + private double _gyroDeadzone; public double GyroDeadzone { get => _gyroDeadzone; @@ -421,16 +421,19 @@ namespace Ryujinx.Ava.UI.Models } } - public MotionInputBackendType MotionBackend + private int _sensitivity; + public int Sensitivity { - get => _motionBackend; + get => _sensitivity; set { - _motionBackend = value; + _sensitivity = value; + OnPropertyChanged(); } } + private bool _enableRumble; public bool EnableRumble { get => _enableRumble; @@ -441,16 +444,7 @@ namespace Ryujinx.Ava.UI.Models } } - public bool EnableMotion - { - get => _enableMotion; - set - { - _enableMotion = value; - OnPropertyChanged(); - } - } - + private float _weakRumble; public float WeakRumble { get => _weakRumble; @@ -460,6 +454,8 @@ namespace Ryujinx.Ava.UI.Models OnPropertyChanged(); } } + + private float _strongRumble; public float StrongRumble { get => _strongRumble; diff --git a/src/Ryujinx.Ava/UI/Models/KeyboardInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs similarity index 99% rename from src/Ryujinx.Ava/UI/Models/KeyboardInputConfig.cs rename to src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs index de825eded1..94c2058255 100644 --- a/src/Ryujinx.Ava/UI/Models/KeyboardInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs @@ -2,7 +2,7 @@ using Ryujinx.Ava.UI.ViewModels; using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Configuration.Hid.Keyboard; -namespace Ryujinx.Ava.UI.Models +namespace Ryujinx.Ava.UI.Models.Input { public class KeyboardInputConfig : BaseModel { diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs index 2aeb29c1e6..eb4e485ace 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -1,5 +1,5 @@ using Avalonia.Svg.Skia; -using Ryujinx.Ava.UI.Models; +using Ryujinx.Ava.UI.Models.Input; using Ryujinx.Ava.UI.Views.Input; namespace Ryujinx.Ava.UI.ViewModels.Input diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs index 7169c38aef..ab5590c847 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs @@ -7,7 +7,6 @@ using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Input; using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.Models; -using Ryujinx.Ava.UI.Views.Input; using Ryujinx.Ava.UI.Windows; using Ryujinx.Common; using Ryujinx.Common.Configuration; diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs index 994bdb17e1..97b3aae0ec 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -1,5 +1,5 @@ using Avalonia.Svg.Skia; -using Ryujinx.Ava.UI.Models; +using Ryujinx.Ava.UI.Models.Input; namespace Ryujinx.Ava.UI.ViewModels.Input { diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml index 8945fc27b7..a75b84dd34 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml @@ -4,7 +4,7 @@ xmlns:locale="clr-namespace:Ryujinx.Ava.Common.Locale" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels" + xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Input" xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml index 19e07873d8..b56bbcb3aa 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml @@ -7,7 +7,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:models="clr-namespace:Ryujinx.Ava.UI.Models" xmlns:views="clr-namespace:Ryujinx.Ava.UI.Views.Input" - xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels" + xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Input" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" d:DesignHeight="800" diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs index 91715b859e..045f000c9d 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs @@ -6,7 +6,7 @@ using Avalonia.LogicalTree; using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.Models; -using Ryujinx.Ava.UI.ViewModels; +using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Common.Configuration.Hid.Controller; using Ryujinx.Input; using Ryujinx.Input.Assigner; diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml index a2ba522c79..9d09af81f1 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml @@ -4,7 +4,7 @@ xmlns:locale="clr-namespace:Ryujinx.Ava.Common.Locale" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels" + xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Input" xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" diff --git a/src/Ryujinx.Ava/UI/Views/Input/MotionInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/MotionInputView.axaml index a6b587f671..0d018e297a 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/MotionInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/MotionInputView.axaml @@ -6,7 +6,7 @@ xmlns:controls="clr-namespace:Ryujinx.Ava.UI.Controls" xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia" xmlns:locale="clr-namespace:Ryujinx.Ava.Common.Locale" - xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels" + xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Input" mc:Ignorable="d" x:Class="Ryujinx.Ava.UI.Views.Input.MotionInputView" x:DataType="viewModels:MotionInputViewModel" diff --git a/src/Ryujinx.Ava/UI/Views/Input/RumbleInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/RumbleInputView.axaml index 5b7087a470..1beb1f06e8 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/RumbleInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/RumbleInputView.axaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:locale="clr-namespace:Ryujinx.Ava.Common.Locale" - xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels" + xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Input" mc:Ignorable="d" x:Class="Ryujinx.Ava.UI.Views.Input.RumbleInputView" x:DataType="viewModels:RumbleInputViewModel" From b35a0e588804f70a2e800ddd0455c3ce0f9c6e2e Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 17 May 2023 11:07:36 -0400 Subject: [PATCH 05/54] Restructure --- .../UI/Models/Input/KeyboardInputConfig.cs | 270 +++++++++--------- .../UI/ViewModels/Input/InputViewModel.cs | 1 + 2 files changed, 134 insertions(+), 137 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs index 94c2058255..9b43ab7ec3 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs @@ -6,42 +6,11 @@ namespace Ryujinx.Ava.UI.Models.Input { public class KeyboardInputConfig : BaseModel { - private Key _leftStickUp; - private Key _leftStickDown; - private Key _leftStickLeft; - private Key _leftStickRight; - private Key _leftKeyboardStickButton; - - private Key _rightStickUp; - private Key _rightStickDown; - private Key _rightStickLeft; - private Key _rightStickRight; - private Key _rightKeyboardStickButton; - - private Key _buttonA; - private Key _buttonB; - private Key _buttonX; - private Key _buttonY; - private Key _buttonR; - private Key _rightButtonSl; - private Key _rightButtonSr; - private Key _buttonZr; - private Key _buttonPlus; - - private Key _dpadUp; - private Key _dpadDown; - private Key _dpadLeft; - private Key _dpadRight; - private Key _buttonL; - private Key _leftButtonSl; - private Key _leftButtonSr; - private Key _buttonZl; - private Key _buttonMinus; - public string Id { get; set; } public ControllerType ControllerType { get; set; } public PlayerIndex PlayerIndex { get; set; } + private Key _leftStickUp; public Key LeftStickUp { get => _leftStickUp; @@ -52,6 +21,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _leftStickDown; public Key LeftStickDown { get => _leftStickDown; @@ -62,6 +32,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _leftStickLeft; public Key LeftStickLeft { get => _leftStickLeft; @@ -72,6 +43,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _leftStickRight; public Key LeftStickRight { get => _leftStickRight; @@ -82,6 +54,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _leftKeyboardStickButton; public Key LeftKeyboardStickButton { get => _leftKeyboardStickButton; @@ -92,6 +65,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _rightStickUp; public Key RightStickUp { get => _rightStickUp; @@ -102,6 +76,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _rightStickDown; public Key RightStickDown { get => _rightStickDown; @@ -112,6 +87,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _rightStickLeft; public Key RightStickLeft { get => _rightStickLeft; @@ -122,6 +98,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _rightStickRight; public Key RightStickRight { get => _rightStickRight; @@ -132,6 +109,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _rightKeyboardStickButton; public Key RightKeyboardStickButton { get => _rightKeyboardStickButton; @@ -142,96 +120,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } - public Key ButtonA - { - get => _buttonA; - set - { - _buttonA = value; - OnPropertyChanged(); - } - } - - public Key ButtonB - { - get => _buttonB; - set - { - _buttonB = value; - OnPropertyChanged(); - } - } - - public Key ButtonX - { - get => _buttonX; - set - { - _buttonX = value; - OnPropertyChanged(); - } - } - - public Key ButtonY - { - get => _buttonY; - set - { - _buttonY = value; - OnPropertyChanged(); - } - } - - public Key ButtonR - { - get => _buttonR; - set - { - _buttonR = value; - OnPropertyChanged(); - } - } - - public Key RightButtonSl - { - get => _rightButtonSl; - set - { - _rightButtonSl = value; - OnPropertyChanged(); - } - } - - public Key RightButtonSr - { - get => _rightButtonSr; - set - { - _rightButtonSr = value; - OnPropertyChanged(); - } - } - - public Key ButtonZr - { - get => _buttonZr; - set - { - _buttonZr = value; - OnPropertyChanged(); - } - } - - public Key ButtonPlus - { - get => _buttonPlus; - set - { - _buttonPlus = value; - OnPropertyChanged(); - } - } - + private Key _dpadUp; public Key DpadUp { get => _dpadUp; @@ -242,6 +131,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _dpadDown; public Key DpadDown { get => _dpadDown; @@ -252,6 +142,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _dpadLeft; public Key DpadLeft { get => _dpadLeft; @@ -262,6 +153,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _dpadRight; public Key DpadRight { get => _dpadRight; @@ -272,6 +164,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _buttonL; public Key ButtonL { get => _buttonL; @@ -282,6 +175,18 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _buttonMinus; + public Key ButtonMinus + { + get => _buttonMinus; + set + { + _buttonMinus = value; + OnPropertyChanged(); + } + } + + private Key _leftButtonSl; public Key LeftButtonSl { get => _leftButtonSl; @@ -292,6 +197,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _leftButtonSr; public Key LeftButtonSr { get => _leftButtonSr; @@ -302,6 +208,7 @@ namespace Ryujinx.Ava.UI.Models.Input } } + private Key _buttonZl; public Key ButtonZl { get => _buttonZl; @@ -312,12 +219,101 @@ namespace Ryujinx.Ava.UI.Models.Input } } - public Key ButtonMinus + private Key _buttonA; + public Key ButtonA { - get => _buttonMinus; + get => _buttonA; set { - _buttonMinus = value; + _buttonA = value; + OnPropertyChanged(); + } + } + + private Key _buttonB; + public Key ButtonB + { + get => _buttonB; + set + { + _buttonB = value; + OnPropertyChanged(); + } + } + + private Key _buttonX; + public Key ButtonX + { + get => _buttonX; + set + { + _buttonX = value; + OnPropertyChanged(); + } + } + + private Key _buttonY; + public Key ButtonY + { + get => _buttonY; + set + { + _buttonY = value; + OnPropertyChanged(); + } + } + + private Key _buttonR; + public Key ButtonR + { + get => _buttonR; + set + { + _buttonR = value; + OnPropertyChanged(); + } + } + + private Key _buttonPlus; + public Key ButtonPlus + { + get => _buttonPlus; + set + { + _buttonPlus = value; + OnPropertyChanged(); + } + } + + private Key _rightButtonSl; + public Key RightButtonSl + { + get => _rightButtonSl; + set + { + _rightButtonSl = value; + OnPropertyChanged(); + } + } + + private Key _rightButtonSr; + public Key RightButtonSr + { + get => _rightButtonSr; + set + { + _rightButtonSr = value; + OnPropertyChanged(); + } + } + + private Key _buttonZr; + public Key ButtonZr + { + get => _buttonZr; + set + { + _buttonZr = value; OnPropertyChanged(); } } @@ -338,25 +334,25 @@ namespace Ryujinx.Ava.UI.Models.Input RightStickLeft = keyboardConfig.RightJoyconStick.StickLeft; RightStickRight = keyboardConfig.RightJoyconStick.StickRight; + DpadUp = keyboardConfig.LeftJoycon.DpadUp; + DpadDown = keyboardConfig.LeftJoycon.DpadDown; + DpadLeft = keyboardConfig.LeftJoycon.DpadLeft; + DpadRight = keyboardConfig.LeftJoycon.DpadRight; + ButtonL = keyboardConfig.LeftJoycon.ButtonL; + ButtonMinus = keyboardConfig.LeftJoycon.ButtonMinus; + LeftButtonSl = keyboardConfig.LeftJoycon.ButtonSl; + LeftButtonSr = keyboardConfig.LeftJoycon.ButtonSr; + ButtonZl = keyboardConfig.LeftJoycon.ButtonZl; + ButtonA = keyboardConfig.RightJoycon.ButtonA; ButtonB = keyboardConfig.RightJoycon.ButtonB; ButtonX = keyboardConfig.RightJoycon.ButtonX; ButtonY = keyboardConfig.RightJoycon.ButtonY; ButtonR = keyboardConfig.RightJoycon.ButtonR; + ButtonPlus = keyboardConfig.RightJoycon.ButtonPlus; RightButtonSl = keyboardConfig.RightJoycon.ButtonSl; RightButtonSr = keyboardConfig.RightJoycon.ButtonSr; ButtonZr = keyboardConfig.RightJoycon.ButtonZr; - ButtonPlus = keyboardConfig.RightJoycon.ButtonPlus; - - DpadUp = keyboardConfig.LeftJoycon.DpadUp; - DpadDown = keyboardConfig.LeftJoycon.DpadDown; - DpadLeft = keyboardConfig.LeftJoycon.DpadLeft; - DpadRight = keyboardConfig.LeftJoycon.DpadRight; - ButtonMinus = keyboardConfig.LeftJoycon.ButtonMinus; - LeftButtonSl = keyboardConfig.LeftJoycon.ButtonSl; - LeftButtonSr = keyboardConfig.LeftJoycon.ButtonSr; - ButtonZl = keyboardConfig.LeftJoycon.ButtonZl; - ButtonL = keyboardConfig.LeftJoycon.ButtonL; } } } @@ -377,10 +373,10 @@ namespace Ryujinx.Ava.UI.Models.Input DpadLeft = DpadLeft, DpadRight = DpadRight, ButtonL = ButtonL, + ButtonMinus = ButtonMinus, ButtonZl = ButtonZl, ButtonSl = LeftButtonSl, ButtonSr = LeftButtonSr, - ButtonMinus = ButtonMinus }, RightJoycon = new RightJoyconCommonConfig diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs index ab5590c847..ec8682e192 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs @@ -7,6 +7,7 @@ using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Input; using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.Models; +using Ryujinx.Ava.UI.Models.Input; using Ryujinx.Ava.UI.Windows; using Ryujinx.Common; using Ryujinx.Common.Configuration; From 53bc71f181d48c3da272e0ad71b8924cbbb54735 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 17 May 2023 11:19:34 -0400 Subject: [PATCH 06/54] Clean --- .../UI/Views/Input/ControllerInputView.axaml.cs | 7 ------- src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs | 7 ------- 2 files changed, 14 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index b472816d66..e2d60c1d95 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -1,6 +1,4 @@ -using Avalonia; using Avalonia.Controls; -using Avalonia.Markup.Xaml; namespace Ryujinx.Ava.UI.Views.Input { @@ -10,10 +8,5 @@ namespace Ryujinx.Ava.UI.Views.Input { InitializeComponent(); } - - private void InitializeComponent() - { - AvaloniaXamlLoader.Load(this); - } } } \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs index d544660c2a..cdfb8edd33 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs @@ -1,6 +1,4 @@ -using Avalonia; using Avalonia.Controls; -using Avalonia.Markup.Xaml; namespace Ryujinx.Ava.UI.Views.Input { @@ -10,10 +8,5 @@ namespace Ryujinx.Ava.UI.Views.Input { InitializeComponent(); } - - private void InitializeComponent() - { - AvaloniaXamlLoader.Load(this); - } } } \ No newline at end of file From 281a078773d16dcdc7aa769df02d2a80edcf9570 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 10:09:20 -0400 Subject: [PATCH 07/54] Propogate those fields i forgot about --- .../UI/Models/Input/ControllerInputConfig.cs | 112 +++++++++--------- .../UI/Models/Input/KeyboardInputConfig.cs | 66 ++++++----- 2 files changed, 93 insertions(+), 85 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs index 53e0d560dc..fc7a5fd113 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs @@ -474,69 +474,71 @@ namespace Ryujinx.Ava.UI.Models.Input ControllerType = config.ControllerType; PlayerIndex = config.PlayerIndex; - if (config is StandardControllerInputConfig controllerInput) + if (config is not StandardControllerInputConfig controllerInput) { - LeftJoystick = controllerInput.LeftJoyconStick.Joystick; - LeftInvertStickX = controllerInput.LeftJoyconStick.InvertStickX; - LeftInvertStickY = controllerInput.LeftJoyconStick.InvertStickY; - LeftRotate90 = controllerInput.LeftJoyconStick.Rotate90CW; - LeftControllerStickButton = controllerInput.LeftJoyconStick.StickButton; + return; + } - RightJoystick = controllerInput.RightJoyconStick.Joystick; - RightInvertStickX = controllerInput.RightJoyconStick.InvertStickX; - RightInvertStickY = controllerInput.RightJoyconStick.InvertStickY; - RightRotate90 = controllerInput.RightJoyconStick.Rotate90CW; - RightControllerStickButton = controllerInput.RightJoyconStick.StickButton; + LeftJoystick = controllerInput.LeftJoyconStick.Joystick; + LeftInvertStickX = controllerInput.LeftJoyconStick.InvertStickX; + LeftInvertStickY = controllerInput.LeftJoyconStick.InvertStickY; + LeftRotate90 = controllerInput.LeftJoyconStick.Rotate90CW; + LeftControllerStickButton = controllerInput.LeftJoyconStick.StickButton; - DpadUp = controllerInput.LeftJoycon.DpadUp; - DpadDown = controllerInput.LeftJoycon.DpadDown; - DpadLeft = controllerInput.LeftJoycon.DpadLeft; - DpadRight = controllerInput.LeftJoycon.DpadRight; - ButtonL = controllerInput.LeftJoycon.ButtonL; - ButtonMinus = controllerInput.LeftJoycon.ButtonMinus; - LeftButtonSl = controllerInput.LeftJoycon.ButtonSl; - LeftButtonSr = controllerInput.LeftJoycon.ButtonSr; - ButtonZl = controllerInput.LeftJoycon.ButtonZl; + RightJoystick = controllerInput.RightJoyconStick.Joystick; + RightInvertStickX = controllerInput.RightJoyconStick.InvertStickX; + RightInvertStickY = controllerInput.RightJoyconStick.InvertStickY; + RightRotate90 = controllerInput.RightJoyconStick.Rotate90CW; + RightControllerStickButton = controllerInput.RightJoyconStick.StickButton; - ButtonA = controllerInput.RightJoycon.ButtonA; - ButtonB = controllerInput.RightJoycon.ButtonB; - ButtonX = controllerInput.RightJoycon.ButtonX; - ButtonY = controllerInput.RightJoycon.ButtonY; - ButtonR = controllerInput.RightJoycon.ButtonR; - ButtonPlus = controllerInput.RightJoycon.ButtonPlus; - RightButtonSl = controllerInput.RightJoycon.ButtonSl; - RightButtonSr = controllerInput.RightJoycon.ButtonSr; - ButtonZr = controllerInput.RightJoycon.ButtonZr; + DpadUp = controllerInput.LeftJoycon.DpadUp; + DpadDown = controllerInput.LeftJoycon.DpadDown; + DpadLeft = controllerInput.LeftJoycon.DpadLeft; + DpadRight = controllerInput.LeftJoycon.DpadRight; + ButtonL = controllerInput.LeftJoycon.ButtonL; + ButtonMinus = controllerInput.LeftJoycon.ButtonMinus; + LeftButtonSl = controllerInput.LeftJoycon.ButtonSl; + LeftButtonSr = controllerInput.LeftJoycon.ButtonSr; + ButtonZl = controllerInput.LeftJoycon.ButtonZl; - DeadzoneLeft = controllerInput.DeadzoneLeft; - DeadzoneRight = controllerInput.DeadzoneRight; - RangeLeft = controllerInput.RangeLeft; - RangeRight = controllerInput.RangeRight; - TriggerThreshold = controllerInput.TriggerThreshold; + ButtonA = controllerInput.RightJoycon.ButtonA; + ButtonB = controllerInput.RightJoycon.ButtonB; + ButtonX = controllerInput.RightJoycon.ButtonX; + ButtonY = controllerInput.RightJoycon.ButtonY; + ButtonR = controllerInput.RightJoycon.ButtonR; + ButtonPlus = controllerInput.RightJoycon.ButtonPlus; + RightButtonSl = controllerInput.RightJoycon.ButtonSl; + RightButtonSr = controllerInput.RightJoycon.ButtonSr; + ButtonZr = controllerInput.RightJoycon.ButtonZr; - if (controllerInput.Motion != null) + DeadzoneLeft = controllerInput.DeadzoneLeft; + DeadzoneRight = controllerInput.DeadzoneRight; + RangeLeft = controllerInput.RangeLeft; + RangeRight = controllerInput.RangeRight; + TriggerThreshold = controllerInput.TriggerThreshold; + + if (controllerInput.Motion != null) + { + EnableMotion = controllerInput.Motion.EnableMotion; + MotionBackend = controllerInput.Motion.MotionBackend; + GyroDeadzone = controllerInput.Motion.GyroDeadzone; + Sensitivity = controllerInput.Motion.Sensitivity; + + if (controllerInput.Motion is CemuHookMotionConfigController cemuHook) { - EnableMotion = controllerInput.Motion.EnableMotion; - MotionBackend = controllerInput.Motion.MotionBackend; - GyroDeadzone = controllerInput.Motion.GyroDeadzone; - Sensitivity = controllerInput.Motion.Sensitivity; + EnableCemuHookMotion = true; + DsuServerHost = cemuHook.DsuServerHost; + DsuServerPort = cemuHook.DsuServerPort; + Slot = cemuHook.Slot; + AltSlot = cemuHook.AltSlot; + MirrorInput = cemuHook.MirrorInput; + } - if (controllerInput.Motion is CemuHookMotionConfigController cemuHook) - { - EnableCemuHookMotion = true; - DsuServerHost = cemuHook.DsuServerHost; - DsuServerPort = cemuHook.DsuServerPort; - Slot = cemuHook.Slot; - AltSlot = cemuHook.AltSlot; - MirrorInput = cemuHook.MirrorInput; - } - - if (controllerInput.Rumble != null) - { - EnableRumble = controllerInput.Rumble.EnableRumble; - WeakRumble = controllerInput.Rumble.WeakRumble; - StrongRumble = controllerInput.Rumble.StrongRumble; - } + if (controllerInput.Rumble != null) + { + EnableRumble = controllerInput.Rumble.EnableRumble; + WeakRumble = controllerInput.Rumble.WeakRumble; + StrongRumble = controllerInput.Rumble.StrongRumble; } } } diff --git a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs index 9b43ab7ec3..f35413283c 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs @@ -322,38 +322,44 @@ namespace Ryujinx.Ava.UI.Models.Input { if (config != null) { - if (config is StandardKeyboardInputConfig keyboardConfig) + Id = config.Id; + ControllerType = config.ControllerType; + PlayerIndex = config.PlayerIndex; + + if (config is not StandardKeyboardInputConfig keyboardConfig) { - LeftStickUp = keyboardConfig.LeftJoyconStick.StickUp; - LeftStickDown = keyboardConfig.LeftJoyconStick.StickDown; - LeftStickLeft = keyboardConfig.LeftJoyconStick.StickLeft; - LeftStickRight = keyboardConfig.LeftJoyconStick.StickRight; - - RightStickUp = keyboardConfig.RightJoyconStick.StickUp; - RightStickDown = keyboardConfig.RightJoyconStick.StickDown; - RightStickLeft = keyboardConfig.RightJoyconStick.StickLeft; - RightStickRight = keyboardConfig.RightJoyconStick.StickRight; - - DpadUp = keyboardConfig.LeftJoycon.DpadUp; - DpadDown = keyboardConfig.LeftJoycon.DpadDown; - DpadLeft = keyboardConfig.LeftJoycon.DpadLeft; - DpadRight = keyboardConfig.LeftJoycon.DpadRight; - ButtonL = keyboardConfig.LeftJoycon.ButtonL; - ButtonMinus = keyboardConfig.LeftJoycon.ButtonMinus; - LeftButtonSl = keyboardConfig.LeftJoycon.ButtonSl; - LeftButtonSr = keyboardConfig.LeftJoycon.ButtonSr; - ButtonZl = keyboardConfig.LeftJoycon.ButtonZl; - - ButtonA = keyboardConfig.RightJoycon.ButtonA; - ButtonB = keyboardConfig.RightJoycon.ButtonB; - ButtonX = keyboardConfig.RightJoycon.ButtonX; - ButtonY = keyboardConfig.RightJoycon.ButtonY; - ButtonR = keyboardConfig.RightJoycon.ButtonR; - ButtonPlus = keyboardConfig.RightJoycon.ButtonPlus; - RightButtonSl = keyboardConfig.RightJoycon.ButtonSl; - RightButtonSr = keyboardConfig.RightJoycon.ButtonSr; - ButtonZr = keyboardConfig.RightJoycon.ButtonZr; + return; } + + LeftStickUp = keyboardConfig.LeftJoyconStick.StickUp; + LeftStickDown = keyboardConfig.LeftJoyconStick.StickDown; + LeftStickLeft = keyboardConfig.LeftJoyconStick.StickLeft; + LeftStickRight = keyboardConfig.LeftJoyconStick.StickRight; + + RightStickUp = keyboardConfig.RightJoyconStick.StickUp; + RightStickDown = keyboardConfig.RightJoyconStick.StickDown; + RightStickLeft = keyboardConfig.RightJoyconStick.StickLeft; + RightStickRight = keyboardConfig.RightJoyconStick.StickRight; + + DpadUp = keyboardConfig.LeftJoycon.DpadUp; + DpadDown = keyboardConfig.LeftJoycon.DpadDown; + DpadLeft = keyboardConfig.LeftJoycon.DpadLeft; + DpadRight = keyboardConfig.LeftJoycon.DpadRight; + ButtonL = keyboardConfig.LeftJoycon.ButtonL; + ButtonMinus = keyboardConfig.LeftJoycon.ButtonMinus; + LeftButtonSl = keyboardConfig.LeftJoycon.ButtonSl; + LeftButtonSr = keyboardConfig.LeftJoycon.ButtonSr; + ButtonZl = keyboardConfig.LeftJoycon.ButtonZl; + + ButtonA = keyboardConfig.RightJoycon.ButtonA; + ButtonB = keyboardConfig.RightJoycon.ButtonB; + ButtonX = keyboardConfig.RightJoycon.ButtonX; + ButtonY = keyboardConfig.RightJoycon.ButtonY; + ButtonR = keyboardConfig.RightJoycon.ButtonR; + ButtonPlus = keyboardConfig.RightJoycon.ButtonPlus; + RightButtonSl = keyboardConfig.RightJoycon.ButtonSl; + RightButtonSr = keyboardConfig.RightJoycon.ButtonSr; + ButtonZr = keyboardConfig.RightJoycon.ButtonZr; } } From d224996c15ee2ecf1a7e36f0f97bdcec47434838 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 14:30:25 -0400 Subject: [PATCH 08/54] It builds --- .../Input/ControllerInputViewModel.cs | 19 ++++++------- .../UI/ViewModels/Input/InputViewModel.cs | 28 +++++++++---------- .../Input/KeyboardInputViewModel.cs | 19 ++++++------- .../UI/Views/Input/ControllerInputView.axaml | 7 ++--- .../UI/Views/Input/InputView.axaml | 12 ++++++-- .../UI/Views/Input/InputView.axaml.cs | 5 ++-- .../UI/Views/Input/KeyboardInputView.axaml | 3 +- 7 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs index eb4e485ace..7a64f82061 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -39,17 +39,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input } } - private bool _showSettings; - public bool ShowSettings - { - get => _showSettings; - set - { - _showSettings = value; - OnPropertyChanged(); - } - } - private SvgImage _image; public SvgImage Image { @@ -70,5 +59,13 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { await RumbleInputView.Show(this); } + + public ControllerInputViewModel(InputViewModel model, ControllerInputConfig config) + { + IsLeft = model.IsLeft; + IsRight = model.IsRight; + Image = model.Image; + Config = config; + } } } \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs index ec8682e192..4b9dddae47 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs @@ -47,7 +47,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input private int _controllerNumber = 0; private string _controllerImage; private int _device; - private object _configuration; + private object _configViewModel; private string _profileName; private bool _isLoaded; private readonly UserControl _owner; @@ -72,12 +72,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public bool IsModified { get; set; } - public object Configuration + public object ConfigViewModel { - get => _configuration; + get => _configViewModel; set { - _configuration = value; + _configViewModel = value; OnPropertyChanged(); } @@ -286,12 +286,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input if (Config is StandardKeyboardInputConfig keyboardInputConfig) { - Configuration = new KeyboardInputConfig(keyboardInputConfig); + ConfigViewModel = new KeyboardInputViewModel(this, new KeyboardInputConfig(keyboardInputConfig)); } if (Config is StandardControllerInputConfig controllerInputConfig) { - Configuration = new ControllerInputConfig(controllerInputConfig); + ConfigViewModel = new ControllerInputViewModel(this, new ControllerInputConfig(controllerInputConfig)); } } @@ -733,7 +733,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input return; } - if (Configuration == null) + if (ConfigViewModel == null) { return; } @@ -756,11 +756,11 @@ namespace Ryujinx.Ava.UI.ViewModels.Input if (IsKeyboard) { - config = (Configuration as KeyboardInputConfig).GetConfig(); + config = (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig(); } else if (IsController) { - config = (Configuration as ControllerInputConfig).GetConfig(); + config = (ConfigViewModel as ControllerInputViewModel).Config.GetConfig(); } config.ControllerType = Controllers[_controller].Type; @@ -825,18 +825,18 @@ namespace Ryujinx.Ava.UI.ViewModels.Input if (device.Type == DeviceType.Keyboard) { - var inputConfig = Configuration as KeyboardInputConfig; + var inputConfig = (ConfigViewModel as KeyboardInputViewModel).Config; inputConfig.Id = device.Id; } else { - var inputConfig = Configuration as ControllerInputConfig; + var inputConfig = (ConfigViewModel as ControllerInputViewModel).Config; inputConfig.Id = device.Id.Split(" ")[0]; } var config = !IsController - ? (Configuration as KeyboardInputConfig).GetConfig() - : (Configuration as ControllerInputConfig).GetConfig(); + ? (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig() + : (ConfigViewModel as ControllerInputViewModel).Config.GetConfig(); config.ControllerType = Controllers[_controller].Type; config.PlayerIndex = _playerId; @@ -867,7 +867,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public void NotifyChanges() { - OnPropertyChanged(nameof(Configuration)); + OnPropertyChanged(nameof(ConfigViewModel)); OnPropertyChanged(nameof(IsController)); OnPropertyChanged(nameof(ShowSettings)); OnPropertyChanged(nameof(IsKeyboard)); diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs index 97b3aae0ec..4025e4a3cf 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -38,17 +38,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input } } - private bool _showSettings; - public bool ShowSettings - { - get => _showSettings; - set - { - _showSettings = value; - OnPropertyChanged(); - } - } - private SvgImage _image; public SvgImage Image { @@ -59,5 +48,13 @@ namespace Ryujinx.Ava.UI.ViewModels.Input OnPropertyChanged(); } } + + public KeyboardInputViewModel(InputViewModel model, KeyboardInputConfig config) + { + IsLeft = model.IsLeft; + IsRight = model.IsRight; + Image = model.Image; + Config = config; + } } } \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml index a75b84dd34..9f4974b5e1 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml @@ -35,8 +35,7 @@ + MinHeight="450"> @@ -451,7 +450,7 @@ @@ -477,7 +476,7 @@ diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml index b56bbcb3aa..a4cc7d8ce0 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml @@ -211,7 +211,15 @@ - - + + + + + + + + + + \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs index 045f000c9d..dbca2b5819 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs @@ -27,14 +27,15 @@ namespace Ryujinx.Ava.UI.Views.Input InitializeComponent(); - foreach (ILogical visual in SettingButtons.GetLogicalDescendants()) + // TODO: Move this stuff to Controller/KeyboardInputView + /*foreach (ILogical visual in SettingButtons.GetLogicalDescendants()) { if (visual is ToggleButton button && !(visual is CheckBox)) { button.Checked += Button_Checked; button.Unchecked += Button_Unchecked; } - } + }*/ } protected override void OnPointerReleased(PointerReleasedEventArgs e) diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml index 9d09af81f1..10ae809c94 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml @@ -35,8 +35,7 @@ + MinHeight="450"> From d738da55a7cd0ccb783cfa21a056b891c2dd4fda Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 14:36:01 -0400 Subject: [PATCH 09/54] Progress --- .../ViewModels/Input/ControllerInputViewModel.cs | 15 ++++++++++++--- .../UI/ViewModels/Input/InputViewModel.cs | 2 ++ .../UI/ViewModels/Input/KeyboardInputViewModel.cs | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs index 7a64f82061..34d7ac2cf2 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -50,6 +50,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input } } + public InputViewModel parentModel; + public async void ShowMotionConfig() { await MotionInputView.Show(this); @@ -62,10 +64,17 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public ControllerInputViewModel(InputViewModel model, ControllerInputConfig config) { - IsLeft = model.IsLeft; - IsRight = model.IsRight; - Image = model.Image; + parentModel = model; + model.NotifyChangesEvent += UpdateParentModelValues; + UpdateParentModelValues(); Config = config; } + + public void UpdateParentModelValues() + { + IsLeft = parentModel.IsLeft; + IsRight = parentModel.IsRight; + Image = parentModel.Image; + } } } \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs index 4b9dddae47..0c02586795 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs @@ -71,6 +71,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public bool IsLeft { get; set; } public bool IsModified { get; set; } + public event Action NotifyChangesEvent; public object ConfigViewModel { @@ -873,6 +874,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input OnPropertyChanged(nameof(IsKeyboard)); OnPropertyChanged(nameof(IsRight)); OnPropertyChanged(nameof(IsLeft)); + NotifyChangesEvent?.Invoke(); } public void Dispose() diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs index 4025e4a3cf..6e886d0b85 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -49,12 +49,21 @@ namespace Ryujinx.Ava.UI.ViewModels.Input } } + public InputViewModel parentModel; + public KeyboardInputViewModel(InputViewModel model, KeyboardInputConfig config) { - IsLeft = model.IsLeft; - IsRight = model.IsRight; - Image = model.Image; + parentModel = model; + model.NotifyChangesEvent += UpdateParentModelValues; + UpdateParentModelValues(); Config = config; } + + public void UpdateParentModelValues() + { + IsLeft = parentModel.IsLeft; + IsRight = parentModel.IsRight; + Image = parentModel.Image; + } } } \ No newline at end of file From 355ec4036f3d04a466a1fef0c6c7d75417055df9 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 14:56:39 -0400 Subject: [PATCH 10/54] Almost there --- .../Views/Input/ControllerInputView.axaml.cs | 106 +++++++++++++++ .../UI/Views/Input/InputView.axaml | 4 +- .../UI/Views/Input/InputView.axaml.cs | 122 +----------------- .../UI/Views/Input/KeyboardInputView.axaml.cs | 105 +++++++++++++++ 4 files changed, 214 insertions(+), 123 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index e2d60c1d95..998f717ec0 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -1,12 +1,118 @@ using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.Input; +using Avalonia.Interactivity; +using Avalonia.LogicalTree; +using Ryujinx.Ava.UI.Helpers; +using Ryujinx.Ava.UI.ViewModels.Input; +using Ryujinx.Common.Configuration.Hid.Controller; +using Ryujinx.Input; +using Ryujinx.Input.Assigner; namespace Ryujinx.Ava.UI.Views.Input { public partial class ControllerInputView : UserControl { + private ButtonKeyAssigner _currentAssigner; + public ControllerInputView() { InitializeComponent(); + + foreach (ILogical visual in SettingButtons.GetLogicalDescendants()) + { + if (visual is ToggleButton button && !(visual is CheckBox)) + { + button.Checked += Button_Checked; + button.Unchecked += Button_Unchecked; + } + } + } + + protected override void OnPointerReleased(PointerReleasedEventArgs e) + { + base.OnPointerReleased(e); + + if (_currentAssigner != null && _currentAssigner.ToggledButton != null && !_currentAssigner.ToggledButton.IsPointerOver) + { + _currentAssigner.Cancel(); + } + } + + private void Button_Checked(object sender, RoutedEventArgs e) + { + if (sender is ToggleButton button) + { + if (_currentAssigner != null && button == _currentAssigner.ToggledButton) + { + return; + } + + bool isStick = button.Tag != null && button.Tag.ToString() == "stick"; + + if (_currentAssigner == null && (bool)button.IsChecked) + { + _currentAssigner = new ButtonKeyAssigner(button); + + FocusManager.Instance.Focus(this, NavigationMethod.Pointer); + + PointerPressed += MouseClick; + + IKeyboard keyboard = (IKeyboard)(DataContext as ControllerInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. + IButtonAssigner assigner = CreateButtonAssigner(isStick); + + _currentAssigner.ButtonAssigned += (sender, e) => + { + if (e.IsAssigned) + { + (DataContext as ControllerInputViewModel).parentModel.IsModified = true; + } + }; + + _currentAssigner.GetInputAndAssign(assigner, keyboard); + } + else + { + if (_currentAssigner != null) + { + ToggleButton oldButton = _currentAssigner.ToggledButton; + + _currentAssigner.Cancel(); + _currentAssigner = null; + button.IsChecked = false; + } + } + } + } + + private void Button_Unchecked(object sender, RoutedEventArgs e) + { + _currentAssigner?.Cancel(); + _currentAssigner = null; + } + + private void MouseClick(object sender, PointerPressedEventArgs e) + { + bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed; + + _currentAssigner?.Cancel(shouldUnbind); + + PointerPressed -= MouseClick; + } + + private IButtonAssigner CreateButtonAssigner(bool forStick) + { + IButtonAssigner assigner; + + assigner = new GamepadButtonAssigner((DataContext as ControllerInputViewModel).parentModel.SelectedGamepad, ((DataContext as ControllerInputViewModel).parentModel.Config as StandardControllerInputConfig).TriggerThreshold, forStick); + + return assigner; + } + + public void Dispose() + { + _currentAssigner?.Cancel(); + _currentAssigner = null; } } } \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml index a4cc7d8ce0..a1cd3ba520 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml @@ -214,10 +214,10 @@ - + - + diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs index dbca2b5819..4c0264e55b 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml.cs @@ -1,97 +1,21 @@ using Avalonia.Controls; -using Avalonia.Controls.Primitives; -using Avalonia.Input; -using Avalonia.Interactivity; -using Avalonia.LogicalTree; using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.Models; using Ryujinx.Ava.UI.ViewModels.Input; -using Ryujinx.Common.Configuration.Hid.Controller; -using Ryujinx.Input; -using Ryujinx.Input.Assigner; -using System; namespace Ryujinx.Ava.UI.Views.Input { public partial class InputView : UserControl { private bool _dialogOpen; - - private ButtonKeyAssigner _currentAssigner; - internal InputViewModel ViewModel { get; set; } + private InputViewModel ViewModel { get; set; } public InputView() { DataContext = ViewModel = new InputViewModel(this); InitializeComponent(); - - // TODO: Move this stuff to Controller/KeyboardInputView - /*foreach (ILogical visual in SettingButtons.GetLogicalDescendants()) - { - if (visual is ToggleButton button && !(visual is CheckBox)) - { - button.Checked += Button_Checked; - button.Unchecked += Button_Unchecked; - } - }*/ - } - - protected override void OnPointerReleased(PointerReleasedEventArgs e) - { - base.OnPointerReleased(e); - - if (_currentAssigner != null && _currentAssigner.ToggledButton != null && !_currentAssigner.ToggledButton.IsPointerOver) - { - _currentAssigner.Cancel(); - } - } - - private void Button_Checked(object sender, RoutedEventArgs e) - { - if (sender is ToggleButton button) - { - if (_currentAssigner != null && button == _currentAssigner.ToggledButton) - { - return; - } - - bool isStick = button.Tag != null && button.Tag.ToString() == "stick"; - - if (_currentAssigner == null && (bool)button.IsChecked) - { - _currentAssigner = new ButtonKeyAssigner(button); - - FocusManager.Instance.Focus(this, NavigationMethod.Pointer); - - PointerPressed += MouseClick; - - IKeyboard keyboard = (IKeyboard)ViewModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. - IButtonAssigner assigner = CreateButtonAssigner(isStick); - - _currentAssigner.ButtonAssigned += (sender, e) => - { - if (e.IsAssigned) - { - ViewModel.IsModified = true; - } - }; - - _currentAssigner.GetInputAndAssign(assigner, keyboard); - } - else - { - if (_currentAssigner != null) - { - ToggleButton oldButton = _currentAssigner.ToggledButton; - - _currentAssigner.Cancel(); - _currentAssigner = null; - button.IsChecked = false; - } - } - } } public void SaveCurrentProfile() @@ -99,48 +23,6 @@ namespace Ryujinx.Ava.UI.Views.Input ViewModel.Save(); } - private IButtonAssigner CreateButtonAssigner(bool forStick) - { - IButtonAssigner assigner; - - var device = ViewModel.Devices[ViewModel.Device]; - - if (device.Type == DeviceType.Keyboard) - { - assigner = new KeyboardKeyAssigner((IKeyboard)ViewModel.SelectedGamepad); - } - else if (device.Type == DeviceType.Controller) - { - assigner = new GamepadButtonAssigner(ViewModel.SelectedGamepad, (ViewModel.Config as StandardControllerInputConfig).TriggerThreshold, forStick); - } - else - { - throw new Exception("Controller not supported"); - } - - return assigner; - } - - private void Button_Unchecked(object sender, RoutedEventArgs e) - { - _currentAssigner?.Cancel(); - _currentAssigner = null; - } - - private void MouseClick(object sender, PointerPressedEventArgs e) - { - bool shouldUnbind = false; - - if (e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed) - { - shouldUnbind = true; - } - - _currentAssigner?.Cancel(shouldUnbind); - - PointerPressed -= MouseClick; - } - private async void PlayerIndexBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (ViewModel.IsModified && !_dialogOpen) @@ -173,8 +55,6 @@ namespace Ryujinx.Ava.UI.Views.Input public void Dispose() { - _currentAssigner?.Cancel(); - _currentAssigner = null; ViewModel.Dispose(); } } diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs index cdfb8edd33..46984c3884 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs @@ -1,12 +1,117 @@ using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.Input; +using Avalonia.Interactivity; +using Avalonia.LogicalTree; +using Ryujinx.Ava.UI.Helpers; +using Ryujinx.Ava.UI.ViewModels.Input; +using Ryujinx.Input; +using Ryujinx.Input.Assigner; namespace Ryujinx.Ava.UI.Views.Input { public partial class KeyboardInputView : UserControl { + private ButtonKeyAssigner _currentAssigner; + public KeyboardInputView() { InitializeComponent(); + + foreach (ILogical visual in SettingButtons.GetLogicalDescendants()) + { + if (visual is ToggleButton button && !(visual is CheckBox)) + { + button.Checked += Button_Checked; + button.Unchecked += Button_Unchecked; + } + } + } + + protected override void OnPointerReleased(PointerReleasedEventArgs e) + { + base.OnPointerReleased(e); + + if (_currentAssigner != null && _currentAssigner.ToggledButton != null && !_currentAssigner.ToggledButton.IsPointerOver) + { + _currentAssigner.Cancel(); + } + } + + private void Button_Checked(object sender, RoutedEventArgs e) + { + if (sender is ToggleButton button) + { + if (_currentAssigner != null && button == _currentAssigner.ToggledButton) + { + return; + } + + bool isStick = button.Tag != null && button.Tag.ToString() == "stick"; + + if (_currentAssigner == null && (bool)button.IsChecked) + { + _currentAssigner = new ButtonKeyAssigner(button); + + FocusManager.Instance.Focus(this, NavigationMethod.Pointer); + + PointerPressed += MouseClick; + + IKeyboard keyboard = (IKeyboard)(DataContext as KeyboardInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. + IButtonAssigner assigner = CreateButtonAssigner(isStick); + + _currentAssigner.ButtonAssigned += (sender, e) => + { + if (e.IsAssigned) + { + (DataContext as KeyboardInputViewModel).parentModel.IsModified = true; + } + }; + + _currentAssigner.GetInputAndAssign(assigner, keyboard); + } + else + { + if (_currentAssigner != null) + { + ToggleButton oldButton = _currentAssigner.ToggledButton; + + _currentAssigner.Cancel(); + _currentAssigner = null; + button.IsChecked = false; + } + } + } + } + + private void Button_Unchecked(object sender, RoutedEventArgs e) + { + _currentAssigner?.Cancel(); + _currentAssigner = null; + } + + private void MouseClick(object sender, PointerPressedEventArgs e) + { + bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed; + + _currentAssigner?.Cancel(shouldUnbind); + + PointerPressed -= MouseClick; + } + + private IButtonAssigner CreateButtonAssigner(bool forStick) + { + IButtonAssigner assigner; + + assigner = new KeyboardKeyAssigner((IKeyboard)(DataContext as KeyboardInputViewModel).parentModel.SelectedGamepad); + + return assigner; + } + + public void Dispose() + { + _currentAssigner?.Cancel(); + _currentAssigner = null; } } } \ No newline at end of file From a553b090b6112cfa34bb045e5f9e40ee028692c9 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 17:39:04 -0400 Subject: [PATCH 11/54] Fix stupid mistake --- .../UI/Models/Input/ControllerInputConfig.cs | 40 +++---- .../UI/Models/Input/KeyboardInputConfig.cs | 103 +++++++++--------- .../UI/Views/Input/ControllerInputView.axaml | 6 +- .../UI/Views/Input/KeyboardInputView.axaml | 6 +- 4 files changed, 77 insertions(+), 78 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs index fc7a5fd113..0826f92124 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs @@ -63,13 +63,13 @@ namespace Ryujinx.Ava.UI.Models.Input } } - private GamepadInputId _leftControllerStickButton; - public GamepadInputId LeftControllerStickButton + private GamepadInputId _leftStickButton; + public GamepadInputId LeftStickButton { - get => _leftControllerStickButton; + get => _leftStickButton; set { - _leftControllerStickButton = value; + _leftStickButton = value; OnPropertyChanged(); } } @@ -118,13 +118,13 @@ namespace Ryujinx.Ava.UI.Models.Input } } - private GamepadInputId _rightControllerStickButton; - public GamepadInputId RightControllerStickButton + private GamepadInputId _rightStickButton; + public GamepadInputId RightStickButton { - get => _rightControllerStickButton; + get => _rightStickButton; set { - _rightControllerStickButton = value; + _rightStickButton = value; OnPropertyChanged(); } } @@ -479,17 +479,17 @@ namespace Ryujinx.Ava.UI.Models.Input return; } - LeftJoystick = controllerInput.LeftJoyconStick.Joystick; - LeftInvertStickX = controllerInput.LeftJoyconStick.InvertStickX; - LeftInvertStickY = controllerInput.LeftJoyconStick.InvertStickY; - LeftRotate90 = controllerInput.LeftJoyconStick.Rotate90CW; - LeftControllerStickButton = controllerInput.LeftJoyconStick.StickButton; + LeftJoystick = controllerInput.LeftJoyconStick.Joystick; + LeftInvertStickX = controllerInput.LeftJoyconStick.InvertStickX; + LeftInvertStickY = controllerInput.LeftJoyconStick.InvertStickY; + LeftRotate90 = controllerInput.LeftJoyconStick.Rotate90CW; + LeftStickButton = controllerInput.LeftJoyconStick.StickButton; - RightJoystick = controllerInput.RightJoyconStick.Joystick; - RightInvertStickX = controllerInput.RightJoyconStick.InvertStickX; - RightInvertStickY = controllerInput.RightJoyconStick.InvertStickY; - RightRotate90 = controllerInput.RightJoyconStick.Rotate90CW; - RightControllerStickButton = controllerInput.RightJoyconStick.StickButton; + RightJoystick = controllerInput.RightJoyconStick.Joystick; + RightInvertStickX = controllerInput.RightJoyconStick.InvertStickX; + RightInvertStickY = controllerInput.RightJoyconStick.InvertStickY; + RightRotate90 = controllerInput.RightJoyconStick.Rotate90CW; + RightStickButton = controllerInput.RightJoyconStick.StickButton; DpadUp = controllerInput.LeftJoycon.DpadUp; DpadDown = controllerInput.LeftJoycon.DpadDown; @@ -582,7 +582,7 @@ namespace Ryujinx.Ava.UI.Models.Input InvertStickX = LeftInvertStickX, InvertStickY = LeftInvertStickY, Rotate90CW = LeftRotate90, - StickButton = LeftControllerStickButton, + StickButton = LeftStickButton, }, RightJoyconStick = new JoyconConfigControllerStick { @@ -590,7 +590,7 @@ namespace Ryujinx.Ava.UI.Models.Input InvertStickX = RightInvertStickX, InvertStickY = RightInvertStickY, Rotate90CW = RightRotate90, - StickButton = RightControllerStickButton, + StickButton = RightStickButton, }, Rumble = new RumbleConfigController { diff --git a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs index f35413283c..33ef381863 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs @@ -54,13 +54,13 @@ namespace Ryujinx.Ava.UI.Models.Input } } - private Key _leftKeyboardStickButton; - public Key LeftKeyboardStickButton + private Key _leftStickButton; + public Key LeftStickButton { - get => _leftKeyboardStickButton; + get => _leftStickButton; set { - _leftKeyboardStickButton = value; + _leftStickButton = value; OnPropertyChanged(); } } @@ -109,13 +109,13 @@ namespace Ryujinx.Ava.UI.Models.Input } } - private Key _rightKeyboardStickButton; - public Key RightKeyboardStickButton + private Key _rightStickButton; + public Key RightStickButton { - get => _rightKeyboardStickButton; + get => _rightStickButton; set { - _rightKeyboardStickButton = value; + _rightStickButton = value; OnPropertyChanged(); } } @@ -331,15 +331,17 @@ namespace Ryujinx.Ava.UI.Models.Input return; } - LeftStickUp = keyboardConfig.LeftJoyconStick.StickUp; - LeftStickDown = keyboardConfig.LeftJoyconStick.StickDown; - LeftStickLeft = keyboardConfig.LeftJoyconStick.StickLeft; - LeftStickRight = keyboardConfig.LeftJoyconStick.StickRight; + LeftStickUp = keyboardConfig.LeftJoyconStick.StickUp; + LeftStickDown = keyboardConfig.LeftJoyconStick.StickDown; + LeftStickLeft = keyboardConfig.LeftJoyconStick.StickLeft; + LeftStickRight = keyboardConfig.LeftJoyconStick.StickRight; + LeftStickButton = keyboardConfig.LeftJoyconStick.StickButton; - RightStickUp = keyboardConfig.RightJoyconStick.StickUp; - RightStickDown = keyboardConfig.RightJoyconStick.StickDown; - RightStickLeft = keyboardConfig.RightJoyconStick.StickLeft; - RightStickRight = keyboardConfig.RightJoyconStick.StickRight; + RightStickUp = keyboardConfig.RightJoyconStick.StickUp; + RightStickDown = keyboardConfig.RightJoyconStick.StickDown; + RightStickLeft = keyboardConfig.RightJoyconStick.StickLeft; + RightStickRight = keyboardConfig.RightJoyconStick.StickRight; + RightStickButton = keyboardConfig.RightJoyconStick.StickButton; DpadUp = keyboardConfig.LeftJoycon.DpadUp; DpadDown = keyboardConfig.LeftJoycon.DpadDown; @@ -371,48 +373,45 @@ namespace Ryujinx.Ava.UI.Models.Input Backend = InputBackendType.WindowKeyboard, PlayerIndex = PlayerIndex, ControllerType = ControllerType, - LeftJoycon = - new LeftJoyconCommonConfig - { - DpadUp = DpadUp, - DpadDown = DpadDown, - DpadLeft = DpadLeft, - DpadRight = DpadRight, - ButtonL = ButtonL, - ButtonMinus = ButtonMinus, - ButtonZl = ButtonZl, - ButtonSl = LeftButtonSl, - ButtonSr = LeftButtonSr, - }, - RightJoycon = - new RightJoyconCommonConfig - { - ButtonA = ButtonA, - ButtonB = ButtonB, - ButtonX = ButtonX, - ButtonY = ButtonY, - ButtonPlus = ButtonPlus, - ButtonSl = RightButtonSl, - ButtonSr = RightButtonSr, - ButtonR = ButtonR, - ButtonZr = ButtonZr - }, - LeftJoyconStick = - new JoyconConfigKeyboardStick - { - StickUp = LeftStickUp, - StickDown = LeftStickDown, - StickRight = LeftStickRight, - StickLeft = LeftStickLeft, - StickButton = LeftKeyboardStickButton - }, + LeftJoycon = new LeftJoyconCommonConfig + { + DpadUp = DpadUp, + DpadDown = DpadDown, + DpadLeft = DpadLeft, + DpadRight = DpadRight, + ButtonL = ButtonL, + ButtonMinus = ButtonMinus, + ButtonZl = ButtonZl, + ButtonSl = LeftButtonSl, + ButtonSr = LeftButtonSr, + }, + RightJoycon = new RightJoyconCommonConfig + { + ButtonA = ButtonA, + ButtonB = ButtonB, + ButtonX = ButtonX, + ButtonY = ButtonY, + ButtonPlus = ButtonPlus, + ButtonSl = RightButtonSl, + ButtonSr = RightButtonSr, + ButtonR = ButtonR, + ButtonZr = ButtonZr + }, + LeftJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = LeftStickUp, + StickDown = LeftStickDown, + StickRight = LeftStickRight, + StickLeft = LeftStickLeft, + StickButton = LeftStickButton + }, RightJoyconStick = new JoyconConfigKeyboardStick { StickUp = RightStickUp, StickDown = RightStickDown, StickLeft = RightStickLeft, StickRight = RightStickRight, - StickButton = RightKeyboardStickButton + StickButton = RightStickButton }, Version = InputConfig.CurrentVersion }; diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml index 9f4974b5e1..e96773bfad 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml @@ -142,7 +142,7 @@ TextAlignment="Center" /> @@ -560,7 +560,7 @@ - + diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml index 10ae809c94..bd5e71b6e1 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml @@ -143,7 +143,7 @@ TextAlignment="Center" /> @@ -481,7 +481,7 @@ - + From 1b037ca33dae10d81b42b9d36e4a3fef1dc8dde6 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 17:47:43 -0400 Subject: [PATCH 12/54] Fix more stupid mistakes --- .../UI/Models/Input/ControllerInputConfig.cs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs index 0826f92124..a1e27025b9 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs @@ -533,13 +533,13 @@ namespace Ryujinx.Ava.UI.Models.Input AltSlot = cemuHook.AltSlot; MirrorInput = cemuHook.MirrorInput; } + } - if (controllerInput.Rumble != null) - { - EnableRumble = controllerInput.Rumble.EnableRumble; - WeakRumble = controllerInput.Rumble.WeakRumble; - StrongRumble = controllerInput.Rumble.StrongRumble; - } + if (controllerInput.Rumble != null) + { + EnableRumble = controllerInput.Rumble.EnableRumble; + WeakRumble = controllerInput.Rumble.WeakRumble; + StrongRumble = controllerInput.Rumble.StrongRumble; } } } @@ -598,6 +598,13 @@ namespace Ryujinx.Ava.UI.Models.Input WeakRumble = WeakRumble, StrongRumble = StrongRumble }, + Motion = new MotionConfigController + { + EnableMotion = EnableMotion, + MotionBackend = MotionBackend, + GyroDeadzone = GyroDeadzone, + Sensitivity = Sensitivity, + }, Version = InputConfig.CurrentVersion, DeadzoneLeft = DeadzoneLeft, DeadzoneRight = DeadzoneRight, @@ -606,9 +613,16 @@ namespace Ryujinx.Ava.UI.Models.Input TriggerThreshold = TriggerThreshold, }; - config.Motion.Sensitivity = Sensitivity; - config.Motion.EnableMotion = EnableMotion; - config.Motion.GyroDeadzone = GyroDeadzone; + if (EnableCemuHookMotion) + { + var cemuHook = (CemuHookMotionConfigController)config.Motion; + cemuHook.DsuServerHost = DsuServerHost; + cemuHook.DsuServerPort = DsuServerPort; + cemuHook.Slot = Slot; + cemuHook.AltSlot = AltSlot; + cemuHook.MirrorInput = MirrorInput; + config.Motion = cemuHook; + } return config; } From 4a92d0b482c01b4b6f65120a0f8b6e318d51792d Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 17:54:42 -0400 Subject: [PATCH 13/54] Actually fix fuck ups --- .../UI/Models/Input/ControllerInputConfig.cs | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs index a1e27025b9..6a93237497 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs @@ -398,17 +398,6 @@ namespace Ryujinx.Ava.UI.Models.Input } } - private MotionInputBackendType _motionBackend; - public MotionInputBackendType MotionBackend - { - get => _motionBackend; - set - { - _motionBackend = value; - OnPropertyChanged(); - } - } - private double _gyroDeadzone; public double GyroDeadzone { @@ -520,7 +509,6 @@ namespace Ryujinx.Ava.UI.Models.Input if (controllerInput.Motion != null) { EnableMotion = controllerInput.Motion.EnableMotion; - MotionBackend = controllerInput.Motion.MotionBackend; GyroDeadzone = controllerInput.Motion.GyroDeadzone; Sensitivity = controllerInput.Motion.Sensitivity; @@ -598,13 +586,6 @@ namespace Ryujinx.Ava.UI.Models.Input WeakRumble = WeakRumble, StrongRumble = StrongRumble }, - Motion = new MotionConfigController - { - EnableMotion = EnableMotion, - MotionBackend = MotionBackend, - GyroDeadzone = GyroDeadzone, - Sensitivity = Sensitivity, - }, Version = InputConfig.CurrentVersion, DeadzoneLeft = DeadzoneLeft, DeadzoneRight = DeadzoneRight, @@ -615,13 +596,28 @@ namespace Ryujinx.Ava.UI.Models.Input if (EnableCemuHookMotion) { - var cemuHook = (CemuHookMotionConfigController)config.Motion; - cemuHook.DsuServerHost = DsuServerHost; - cemuHook.DsuServerPort = DsuServerPort; - cemuHook.Slot = Slot; - cemuHook.AltSlot = AltSlot; - cemuHook.MirrorInput = MirrorInput; - config.Motion = cemuHook; + config.Motion = new CemuHookMotionConfigController + { + EnableMotion = EnableMotion, + MotionBackend = MotionInputBackendType.CemuHook, + GyroDeadzone = GyroDeadzone, + Sensitivity = Sensitivity, + DsuServerHost = DsuServerHost, + DsuServerPort = DsuServerPort, + Slot = Slot, + AltSlot = AltSlot, + MirrorInput = MirrorInput + }; + } + else + { + config.Motion = new MotionConfigController + { + EnableMotion = EnableMotion, + MotionBackend = MotionInputBackendType.GamepadDriver, + GyroDeadzone = GyroDeadzone, + Sensitivity = Sensitivity + }; } return config; From c567f40531523d94ec2af5a29a0781d897d20c7e Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 18:53:51 -0400 Subject: [PATCH 14/54] Start localising --- src/Ryujinx.Ava/Assets/Locales/en_US.json | 27 ++++++++ .../UI/Helpers/KeyValueConverter.cs | 63 +++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/Ryujinx.Ava/Assets/Locales/en_US.json b/src/Ryujinx.Ava/Assets/Locales/en_US.json index 2febf90ec3..2d22b46ac7 100644 --- a/src/Ryujinx.Ava/Assets/Locales/en_US.json +++ b/src/Ryujinx.Ava/Assets/Locales/en_US.json @@ -266,6 +266,33 @@ "ControllerSettingsMotionGyroDeadzone": "Gyro Deadzone:", "ControllerSettingsSave": "Save", "ControllerSettingsClose": "Close", + "KeyUnknown": "Unknown", + "KeyShiftLeft": "Shift Left", + "KeyShiftRight": "Shift Right", + "KeyControlLeft": "Control Left", + "KeyControlRight": "Control Right", + "KeyAltLeft": "Alt Left", + "KeyAltRight": "Alt Right", + "KeyOptLeft": "⌥ Left", + "KeyOptRight": "⌥ Right", + "KeyWinLeft": "Windows Left", + "KeyWinRight": "Windows Right", + "KeyCmdLeft": "⌘ Left", + "KeyCmdRight": "⌘ Right", + "KeyMenu": "Menu", + "KeyUp": "Up", + "KeyDown": "Down", + "KeyLeft": "Left", + "KeyRight": "Right", + "KeyEnter": "Enter", + "KeyEscape": "Escape", + "KeySpace": "Space", + "KeyTab": "Tab", + "KeyBackSpace": "Backspace", + "KeyInsert": "Insert", + "KeyDelete": "Delete", + "KeyPageUp": "Page Up", + "KeyPageDown": "Page Down", "UserProfilesSelectedUserProfile": "Selected User Profile:", "UserProfilesSaveProfileName": "Save Profile Name", "UserProfilesChangeProfileImage": "Change Profile Image", diff --git a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs index 028ed6bf46..48155614b8 100644 --- a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs +++ b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs @@ -1,7 +1,10 @@ using Avalonia.Data.Converters; +using DynamicData.Kernel; +using Ryujinx.Ava.Common.Locale; using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Configuration.Hid.Controller; using System; +using System.Collections.Generic; using System.Globalization; namespace Ryujinx.Ava.UI.Helpers @@ -9,15 +12,59 @@ namespace Ryujinx.Ava.UI.Helpers internal class KeyValueConverter : IValueConverter { public static KeyValueConverter Instance = new(); + internal static readonly Dictionary KeysMap = new() + { + { Key.Unknown, LocaleKeys.KeyUnknown }, + { Key.ShiftLeft, LocaleKeys.KeyShiftLeft }, + { Key.ShiftRight, LocaleKeys.KeyShiftRight }, + { Key.ControlLeft, LocaleKeys.KeyControlLeft }, + { Key.ControlRight, LocaleKeys.KeyControlRight }, + { Key.AltLeft, OperatingSystem.IsMacOS() ? LocaleKeys.KeyOptLeft : LocaleKeys.KeyAltLeft }, + { Key.AltRight, OperatingSystem.IsMacOS() ? LocaleKeys.KeyOptRight : LocaleKeys.KeyAltRight }, + { Key.WinLeft, OperatingSystem.IsMacOS() ? LocaleKeys.KeyCmdLeft : LocaleKeys.KeyWinLeft }, + { Key.WinRight, OperatingSystem.IsMacOS() ? LocaleKeys.KeyCmdRight : LocaleKeys.KeyWinRight }, + { Key.Up, LocaleKeys.KeyUp }, + { Key.Down, LocaleKeys.KeyDown }, + { Key.Left, LocaleKeys.KeyLeft }, + { Key.Right, LocaleKeys.KeyRight }, + { Key.Enter, LocaleKeys.KeyEnter }, + { Key.Escape, LocaleKeys.KeyEscape }, + { Key.Space, LocaleKeys.KeySpace }, + { Key.Tab, LocaleKeys.KeyTab }, + { Key.BackSpace, LocaleKeys.KeyBackSpace }, + { Key.Insert, LocaleKeys.KeyInsert }, + { Key.Delete, LocaleKeys.KeyDelete }, + { Key.PageUp, LocaleKeys.KeyPageUp }, + { Key.PageDown, LocaleKeys.KeyPageDown }, + }; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value == null) + string keyString = ""; + + if (value != null) { - return null; + if (value is Key key) + { + if (KeysMap.TryGetValue(key, out LocaleKeys localeKey)) + { + keyString = LocaleManager.Instance[localeKey]; + } + else + { + keyString = key.ToString(); + } + } + else if (value is GamepadInputId gamepadInputId) + { + keyString = value.ToString(); + } + else if (value is StickInputId stickInputId) + { keyString = value.ToString(); + } } - return value.ToString(); + return keyString; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) @@ -28,7 +75,15 @@ namespace Ryujinx.Ava.UI.Helpers { if (targetType == typeof(Key)) { - key = Enum.Parse(value.ToString()); + var optionalKey = KeysMap.FirstOrOptional(x => LocaleManager.Instance[x.Value] == value.ToString()); + if (optionalKey.HasValue) + { + key = optionalKey.Value; + } + else + { + key = Enum.Parse(value.ToString()); + } } else if (targetType == typeof(GamepadInputId)) { From 920777bc4b62484c8afade08622ff11fea7c53c2 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 19:51:48 -0400 Subject: [PATCH 15/54] r/therestofthefuckingowl --- src/Ryujinx.Ava/Assets/Locales/en_US.json | 47 +++++++++++ .../UI/Helpers/KeyValueConverter.cs | 78 +++++++++++++++---- 2 files changed, 109 insertions(+), 16 deletions(-) diff --git a/src/Ryujinx.Ava/Assets/Locales/en_US.json b/src/Ryujinx.Ava/Assets/Locales/en_US.json index 2d22b46ac7..3a008af3dd 100644 --- a/src/Ryujinx.Ava/Assets/Locales/en_US.json +++ b/src/Ryujinx.Ava/Assets/Locales/en_US.json @@ -293,6 +293,53 @@ "KeyDelete": "Delete", "KeyPageUp": "Page Up", "KeyPageDown": "Page Down", + "KeyHome": "Home", + "KeyEnd": "End", + "KeyCapsLock": "Caps Lock", + "KeyScrollLock": "Scroll Lock", + "KeyPrintScreen": "Print Screen", + "KeyPause": "Pause", + "KeyNumLock": "Num Lock", + "KeyClear": "Clear", + "KeyKeypad0": "Keypad 0", + "KeyKeypad1": "Keypad 1", + "KeyKeypad2": "Keypad 2", + "KeyKeypad3": "Keypad 3", + "KeyKeypad4": "Keypad 4", + "KeyKeypad5": "Keypad 5", + "KeyKeypad6": "Keypad 6", + "KeyKeypad7": "Keypad 7", + "KeyKeypad8": "Keypad 8", + "KeyKeypad9": "Keypad 9", + "KeyKeypadDivide": "Keypad Divide", + "KeyKeypadMultiply": "Keypad Multiply", + "KeyKeypadSubtract": "Keypad Subtract", + "KeyKeypadAdd": "Keypad Add", + "KeyKeypadDecimal": "Keypad Decimal", + "KeyKeypadEnter": "Keypad Enter", + "KeyNumber0": "0", + "KeyNumber1": "1", + "KeyNumber2": "2", + "KeyNumber3": "3", + "KeyNumber4": "4", + "KeyNumber5": "5", + "KeyNumber6": "6", + "KeyNumber7": "7", + "KeyNumber8": "8", + "KeyNumber9": "9", + "KeyTilde": "~", + "KeyGrave": "`", + "KeyMinus": "-", + "KeyPlus": "+", + "KeyBracketLeft": "[", + "KeyBracketRight": "]", + "KeySemicolon": ";", + "KeyQuote": "\"", + "KeyComma": ",", + "KeyPeriod": ".", + "KeySlash": "/", + "KeyBackSlash": "\\", + "KeyUnbound": "Unbound", "UserProfilesSelectedUserProfile": "Selected User Profile:", "UserProfilesSaveProfileName": "Save Profile Name", "UserProfilesChangeProfileImage": "Change Profile Image", diff --git a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs index 48155614b8..efda8f07e7 100644 --- a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs +++ b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs @@ -12,7 +12,8 @@ namespace Ryujinx.Ava.UI.Helpers internal class KeyValueConverter : IValueConverter { public static KeyValueConverter Instance = new(); - internal static readonly Dictionary KeysMap = new() + + private static readonly Dictionary KeysMap = new() { { Key.Unknown, LocaleKeys.KeyUnknown }, { Key.ShiftLeft, LocaleKeys.KeyShiftLeft }, @@ -36,33 +37,78 @@ namespace Ryujinx.Ava.UI.Helpers { Key.Delete, LocaleKeys.KeyDelete }, { Key.PageUp, LocaleKeys.KeyPageUp }, { Key.PageDown, LocaleKeys.KeyPageDown }, + { Key.Home, LocaleKeys.KeyHome }, + { Key.End, LocaleKeys.KeyEnd }, + { Key.CapsLock, LocaleKeys.KeyCapsLock }, + { Key.ScrollLock, LocaleKeys.KeyScrollLock }, + { Key.PrintScreen, LocaleKeys.KeyPrintScreen }, + { Key.Pause, LocaleKeys.KeyPause }, + { Key.NumLock, LocaleKeys.KeyNumLock }, + { Key.Clear, LocaleKeys.KeyClear }, + { Key.Keypad0, LocaleKeys.KeyKeypad0 }, + { Key.Keypad1, LocaleKeys.KeyKeypad1 }, + { Key.Keypad2, LocaleKeys.KeyKeypad2 }, + { Key.Keypad3, LocaleKeys.KeyKeypad3 }, + { Key.Keypad4, LocaleKeys.KeyKeypad4 }, + { Key.Keypad5, LocaleKeys.KeyKeypad5 }, + { Key.Keypad6, LocaleKeys.KeyKeypad6 }, + { Key.Keypad7, LocaleKeys.KeyKeypad7 }, + { Key.Keypad8, LocaleKeys.KeyKeypad8 }, + { Key.Keypad9, LocaleKeys.KeyKeypad9 }, + { Key.KeypadDivide, LocaleKeys.KeyKeypadDivide }, + { Key.KeypadMultiply, LocaleKeys.KeyKeypadMultiply }, + { Key.KeypadSubtract, LocaleKeys.KeyKeypadSubtract }, + { Key.KeypadAdd, LocaleKeys.KeyKeypadAdd }, + { Key.KeypadDecimal, LocaleKeys.KeyKeypadDecimal }, + { Key.KeypadEnter, LocaleKeys.KeyKeypadEnter }, + { Key.Number0, LocaleKeys.KeyNumber0 }, + { Key.Number1, LocaleKeys.KeyNumber1 }, + { Key.Number2, LocaleKeys.KeyNumber2 }, + { Key.Number3, LocaleKeys.KeyNumber3 }, + { Key.Number4, LocaleKeys.KeyNumber4 }, + { Key.Number5, LocaleKeys.KeyNumber5 }, + { Key.Number6, LocaleKeys.KeyNumber6 }, + { Key.Number7, LocaleKeys.KeyNumber7 }, + { Key.Number8, LocaleKeys.KeyNumber8 }, + { Key.Number9, LocaleKeys.KeyNumber9 }, + { Key.Tilde, LocaleKeys.KeyTilde }, + { Key.Grave, LocaleKeys.KeyGrave }, + { Key.Minus, LocaleKeys.KeyMinus }, + { Key.Plus, LocaleKeys.KeyPlus }, + { Key.BracketLeft, LocaleKeys.KeyBracketLeft }, + { Key.BracketRight, LocaleKeys.KeyBracketRight }, + { Key.Semicolon, LocaleKeys.KeySemicolon }, + { Key.Quote, LocaleKeys.KeyQuote }, + { Key.Comma, LocaleKeys.KeyComma }, + { Key.Period, LocaleKeys.KeyPeriod }, + { Key.Slash, LocaleKeys.KeySlash }, + { Key.BackSlash, LocaleKeys.KeyBackSlash }, + { Key.Unbound, LocaleKeys.KeyUnbound }, }; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string keyString = ""; - if (value != null) + if (value is Key key) { - if (value is Key key) + if (KeysMap.TryGetValue(key, out LocaleKeys localeKey)) { - if (KeysMap.TryGetValue(key, out LocaleKeys localeKey)) - { - keyString = LocaleManager.Instance[localeKey]; - } - else - { - keyString = key.ToString(); - } + keyString = LocaleManager.Instance[localeKey]; } - else if (value is GamepadInputId gamepadInputId) + else { - keyString = value.ToString(); - } - else if (value is StickInputId stickInputId) - { keyString = value.ToString(); + keyString = key.ToString(); } } + else if (value is GamepadInputId gamepadInputId) + { + keyString = value.ToString(); + } + else if (value is StickInputId stickInputId) + { + keyString = value.ToString(); + } return keyString; } From 3afc37e68399392bbb4a935f94d96901425a57ac Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 19:54:32 -0400 Subject: [PATCH 16/54] Localise ButtonKeyAssigner --- src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs index 7e8ba73421..c48b83cde3 100644 --- a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs +++ b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs @@ -2,6 +2,7 @@ using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.LogicalTree; using Avalonia.Threading; +using Ryujinx.Ava.Common.Locale; using Ryujinx.Input; using Ryujinx.Input.Assigner; using System; @@ -82,7 +83,7 @@ namespace Ryujinx.Ava.UI.Helpers if (_shouldUnbind) { - SetButtonText(ToggledButton, "Unbound"); + SetButtonText(ToggledButton, LocaleManager.Instance[LocaleKeys.KeyUnbound]); } else if (pressedButton != "") { @@ -115,4 +116,4 @@ namespace Ryujinx.Ava.UI.Helpers _shouldUnbind = shouldUnbind; } } -} +} \ No newline at end of file From a5ef6580c41331a98ff06cf06e7901b793800d9a Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 20:29:31 -0400 Subject: [PATCH 17/54] Are you feeling it now mr krabs --- .../UI/Helpers/KeyValueConverter.cs | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs index efda8f07e7..fae54a9cb0 100644 --- a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs +++ b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs @@ -86,6 +86,16 @@ namespace Ryujinx.Ava.UI.Helpers { Key.Unbound, LocaleKeys.KeyUnbound }, }; + private static readonly Dictionary GamepadInputIdMap = new() + { + + }; + + private static readonly Dictionary StickInputIdMap = new() + { + + }; + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string keyString = ""; @@ -103,11 +113,25 @@ namespace Ryujinx.Ava.UI.Helpers } else if (value is GamepadInputId gamepadInputId) { - keyString = value.ToString(); + if (GamepadInputIdMap.TryGetValue(gamepadInputId, out LocaleKeys localeKey)) + { + keyString = LocaleManager.Instance[localeKey]; + } + else + { + keyString = gamepadInputId.ToString(); + } } else if (value is StickInputId stickInputId) { - keyString = value.ToString(); + if (StickInputIdMap.TryGetValue(stickInputId, out LocaleKeys localeKey)) + { + keyString = LocaleManager.Instance[localeKey]; + } + else + { + keyString = stickInputId.ToString(); + } } return keyString; @@ -133,11 +157,27 @@ namespace Ryujinx.Ava.UI.Helpers } else if (targetType == typeof(GamepadInputId)) { - key = Enum.Parse(value.ToString()); + var optionalKey = GamepadInputIdMap.FirstOrOptional(x => LocaleManager.Instance[x.Value] == value.ToString()); + if (optionalKey.HasValue) + { + key = optionalKey.Value; + } + else + { + key = Enum.Parse(value.ToString()); + } } else if (targetType == typeof(StickInputId)) { - key = Enum.Parse(value.ToString()); + var optionalKey = StickInputIdMap.FirstOrOptional(x => LocaleManager.Instance[x.Value] == value.ToString()); + if (optionalKey.HasValue) + { + key = optionalKey.Value; + } + else + { + key = Enum.Parse(value.ToString()); + } } } From 1231e1e87d98806d35d2f30d7c9c65f4487dc412 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 21:00:53 -0400 Subject: [PATCH 18/54] =?UTF-8?q?We=E2=80=99re=20done=20at=20last?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Ryujinx.Ava/Assets/Locales/en_US.json | 25 ++++++++++++++++ .../UI/Helpers/KeyValueConverter.cs | 29 +++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Ava/Assets/Locales/en_US.json b/src/Ryujinx.Ava/Assets/Locales/en_US.json index 3a008af3dd..e4c5a5ae89 100644 --- a/src/Ryujinx.Ava/Assets/Locales/en_US.json +++ b/src/Ryujinx.Ava/Assets/Locales/en_US.json @@ -340,6 +340,31 @@ "KeySlash": "/", "KeyBackSlash": "\\", "KeyUnbound": "Unbound", + "GamepadLeftStick": "Left Stick Button", + "GamepadRightStick": "Right Stick Button", + "GamepadLeftShoulder": "Left Shoulder", + "GamepadRightShoulder": "Right Shoulder", + "GamepadLeftTrigger": "Left Trigger", + "GamepadRightTrigger": "Right Trigger", + "GamepadDpadUp": "D-Pad Up", + "GamepadDpadDown": "D-Pad Down", + "GamepadDpadLeft": "D-Pad Left", + "GamepadDpadRight": "D-Pad Right", + "GamepadMinus": "Gamepad Minus", + "GamepadPlus": "Gamepad Plus", + "GamepadGuide": "Guide", + "GamepadMisc1": "Misc", + "GamepadPaddle1": "Paddle 1", + "GamepadPaddle2": "Paddle 2", + "GamepadPaddle3": "Paddle 3", + "GamepadPaddle4": "Paddle 4", + "GamepadTouchpad": "Touchpad", + "GamepadSingleLeftTrigger0": "Left Trigger 0", + "GamepadSingleRightTrigger0": "Right Trigger 0", + "GamepadSingleLeftTrigger1": "Left Trigger 1", + "GamepadSingleRightTrigger1": "Right Trigger 1", + "StickLeft": "Left Stick", + "StickRight": "Right Stick", "UserProfilesSelectedUserProfile": "Selected User Profile:", "UserProfilesSaveProfileName": "Save Profile Name", "UserProfilesChangeProfileImage": "Change Profile Image", diff --git a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs index fae54a9cb0..81e61728d7 100644 --- a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs +++ b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs @@ -88,12 +88,37 @@ namespace Ryujinx.Ava.UI.Helpers private static readonly Dictionary GamepadInputIdMap = new() { - + { GamepadInputId.LeftStick, LocaleKeys.GamepadLeftStick }, + { GamepadInputId.RightStick, LocaleKeys.GamepadRightStick }, + { GamepadInputId.LeftShoulder, LocaleKeys.GamepadLeftShoulder }, + { GamepadInputId.RightShoulder, LocaleKeys.GamepadRightShoulder }, + { GamepadInputId.LeftTrigger, LocaleKeys.GamepadLeftTrigger }, + { GamepadInputId.RightTrigger, LocaleKeys.GamepadRightTrigger }, + { GamepadInputId.DpadUp, LocaleKeys.GamepadDpadUp}, + { GamepadInputId.DpadDown, LocaleKeys.GamepadDpadDown}, + { GamepadInputId.DpadLeft, LocaleKeys.GamepadDpadLeft}, + { GamepadInputId.DpadRight, LocaleKeys.GamepadDpadRight}, + { GamepadInputId.Minus, LocaleKeys.GamepadMinus}, + { GamepadInputId.Plus, LocaleKeys.GamepadPlus}, + { GamepadInputId.Guide, LocaleKeys.GamepadGuide}, + { GamepadInputId.Misc1, LocaleKeys.GamepadMisc1}, + { GamepadInputId.Paddle1, LocaleKeys.GamepadPaddle1}, + { GamepadInputId.Paddle2, LocaleKeys.GamepadPaddle2}, + { GamepadInputId.Paddle3, LocaleKeys.GamepadPaddle3}, + { GamepadInputId.Paddle4, LocaleKeys.GamepadPaddle4}, + { GamepadInputId.Touchpad, LocaleKeys.GamepadTouchpad}, + { GamepadInputId.SingleLeftTrigger0, LocaleKeys.GamepadSingleLeftTrigger0}, + { GamepadInputId.SingleRightTrigger0, LocaleKeys.GamepadSingleRightTrigger0}, + { GamepadInputId.SingleLeftTrigger1, LocaleKeys.GamepadSingleLeftTrigger1}, + { GamepadInputId.SingleRightTrigger1, LocaleKeys.GamepadSingleRightTrigger1}, + { GamepadInputId.Unbound, LocaleKeys.KeyUnbound}, }; private static readonly Dictionary StickInputIdMap = new() { - + { StickInputId.Left, LocaleKeys.StickLeft}, + { StickInputId.Right, LocaleKeys.StickRight}, + { StickInputId.Unbound, LocaleKeys.KeyUnbound}, }; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) From 2b0fce3e9d2cd551e150275b4a1af3caf9deaae7 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 22:35:23 -0400 Subject: [PATCH 19/54] Crimes against code --- src/Ryujinx.Ava/Assets/Locales/en_US.json | 12 +-- .../UI/Helpers/ButtonKeyAssigner.cs | 25 ++---- .../UI/Helpers/KeyValueConverter.cs | 44 +--------- .../UI/Views/Input/ControllerInputView.axaml | 88 +++++++++---------- .../Views/Input/ControllerInputView.axaml.cs | 79 ++++++++++++++++- .../Assigner/GamepadButtonAssigner.cs | 8 +- src/Ryujinx.Input/Assigner/IButtonAssigner.cs | 2 +- .../Assigner/KeyboardKeyAssigner.cs | 10 +-- 8 files changed, 147 insertions(+), 121 deletions(-) diff --git a/src/Ryujinx.Ava/Assets/Locales/en_US.json b/src/Ryujinx.Ava/Assets/Locales/en_US.json index e4c5a5ae89..d5c2d8cfc6 100644 --- a/src/Ryujinx.Ava/Assets/Locales/en_US.json +++ b/src/Ryujinx.Ava/Assets/Locales/en_US.json @@ -346,12 +346,12 @@ "GamepadRightShoulder": "Right Shoulder", "GamepadLeftTrigger": "Left Trigger", "GamepadRightTrigger": "Right Trigger", - "GamepadDpadUp": "D-Pad Up", - "GamepadDpadDown": "D-Pad Down", - "GamepadDpadLeft": "D-Pad Left", - "GamepadDpadRight": "D-Pad Right", - "GamepadMinus": "Gamepad Minus", - "GamepadPlus": "Gamepad Plus", + "GamepadDpadUp": "Up", + "GamepadDpadDown": "Down", + "GamepadDpadLeft": "Left", + "GamepadDpadRight": "Right", + "GamepadMinus": "-", + "GamepadPlus": "+", "GamepadGuide": "Guide", "GamepadMisc1": "Misc", "GamepadPaddle1": "Paddle 1", diff --git a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs index c48b83cde3..a39e785c31 100644 --- a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs +++ b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs @@ -1,3 +1,5 @@ +using Avalonia; +using Avalonia.Data; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.LogicalTree; @@ -17,11 +19,13 @@ namespace Ryujinx.Ava.UI.Helpers { public ToggleButton Button { get; } public bool IsAssigned { get; } + public object Key { get; } - public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned) + public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, object key) { Button = button; IsAssigned = isAssigned; + Key = key; } } @@ -79,15 +83,11 @@ namespace Ryujinx.Ava.UI.Helpers await Dispatcher.UIThread.InvokeAsync(() => { - string pressedButton = assigner.GetPressedButton(); + object pressedButton = assigner.GetPressedButton(); if (_shouldUnbind) { - SetButtonText(ToggledButton, LocaleManager.Instance[LocaleKeys.KeyUnbound]); - } - else if (pressedButton != "") - { - SetButtonText(ToggledButton, pressedButton); + pressedButton = null; } _shouldUnbind = false; @@ -95,17 +95,8 @@ namespace Ryujinx.Ava.UI.Helpers ToggledButton.IsChecked = false; - ButtonAssigned?.Invoke(this, new ButtonAssignedEventArgs(ToggledButton, pressedButton != null)); + ButtonAssigned?.Invoke(this, new ButtonAssignedEventArgs(ToggledButton, pressedButton != null, pressedButton)); - static void SetButtonText(ToggleButton button, string text) - { - ILogical textBlock = button.GetLogicalDescendants().First(x => x is TextBlock); - - if (textBlock != null && textBlock is TextBlock block) - { - block.Text = text; - } - } }); } diff --git a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs index 81e61728d7..1d8def0b84 100644 --- a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs +++ b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs @@ -164,49 +164,7 @@ namespace Ryujinx.Ava.UI.Helpers public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - object key = null; - - if (value != null) - { - if (targetType == typeof(Key)) - { - var optionalKey = KeysMap.FirstOrOptional(x => LocaleManager.Instance[x.Value] == value.ToString()); - if (optionalKey.HasValue) - { - key = optionalKey.Value; - } - else - { - key = Enum.Parse(value.ToString()); - } - } - else if (targetType == typeof(GamepadInputId)) - { - var optionalKey = GamepadInputIdMap.FirstOrOptional(x => LocaleManager.Instance[x.Value] == value.ToString()); - if (optionalKey.HasValue) - { - key = optionalKey.Value; - } - else - { - key = Enum.Parse(value.ToString()); - } - } - else if (targetType == typeof(StickInputId)) - { - var optionalKey = StickInputIdMap.FirstOrOptional(x => LocaleManager.Instance[x.Value] == value.ToString()); - if (optionalKey.HasValue) - { - key = optionalKey.Value; - } - else - { - key = Enum.Parse(value.ToString()); - } - } - } - - return key; + throw new NotSupportedException(); } } } diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml index e96773bfad..e7c1d54ca1 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml @@ -74,9 +74,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsTriggerZL}" TextAlignment="Center" /> - + @@ -90,9 +90,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsTriggerL}" TextAlignment="Center" /> - + @@ -106,9 +106,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonMinus}" TextAlignment="Center" /> - + @@ -140,9 +140,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickButton}" TextAlignment="Center" /> - + @@ -157,9 +157,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickStick}" TextAlignment="Center" /> - + @@ -250,9 +250,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsDPadUp}" TextAlignment="Center" /> - + @@ -267,9 +267,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsDPadDown}" TextAlignment="Center" /> - + @@ -284,9 +284,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsDPadLeft}" TextAlignment="Center" /> - + @@ -301,9 +301,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsDPadRight}" TextAlignment="Center" /> - + @@ -354,9 +354,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsLeftSR}" TextAlignment="Center" /> - + @@ -372,9 +372,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsLeftSL}" TextAlignment="Center" /> - + @@ -390,9 +390,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsRightSR}" TextAlignment="Center" /> - + @@ -408,9 +408,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsRightSL}" TextAlignment="Center" /> - + @@ -516,9 +516,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsTriggerZR}" TextAlignment="Center" /> - + @@ -534,9 +534,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsTriggerR}" TextAlignment="Center" /> - + @@ -552,9 +552,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonPlus}" TextAlignment="Center" /> - + @@ -587,9 +587,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonA}" TextAlignment="Center" /> - + @@ -604,9 +604,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonB}" TextAlignment="Center" /> - + @@ -621,9 +621,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonX}" TextAlignment="Center" /> - + @@ -638,9 +638,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonY}" TextAlignment="Center" /> - + @@ -672,9 +672,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickButton}" TextAlignment="Center" /> - + @@ -690,9 +690,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickStick}" TextAlignment="Center" /> - + diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index 998f717ec0..65f32504d6 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -8,6 +8,8 @@ using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Common.Configuration.Hid.Controller; using Ryujinx.Input; using Ryujinx.Input.Assigner; +using System; +using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; namespace Ryujinx.Ava.UI.Views.Input { @@ -65,7 +67,82 @@ namespace Ryujinx.Ava.UI.Views.Input { if (e.IsAssigned) { - (DataContext as ControllerInputViewModel).parentModel.IsModified = true; + var viewModel = (DataContext as ControllerInputViewModel); + viewModel.parentModel.IsModified = true; + + // This is a crime against code but I can't think of anything better rn + switch (button.Name) + { + case "ButtonZl": + viewModel.Config.ButtonZl = (GamepadInputId)e.Key; + break; + case "ButtonL": + viewModel.Config.ButtonL = (GamepadInputId)e.Key; + break; + case "ButtonMinus": + viewModel.Config.ButtonMinus = (GamepadInputId)e.Key; + break; + case "LeftStickButton": + viewModel.Config.LeftStickButton = (GamepadInputId)e.Key; + break; + case "LeftJoystick": + viewModel.Config.LeftJoystick = (StickInputId)e.Key; + break; + case "DpadUp": + viewModel.Config.DpadUp = (GamepadInputId)e.Key; + break; + case "DpadDown": + viewModel.Config.DpadDown = (GamepadInputId)e.Key; + break; + case "DpadLeft": + viewModel.Config.DpadLeft = (GamepadInputId)e.Key; + break; + case "DpadRight": + viewModel.Config.DpadRight = (GamepadInputId)e.Key; + break; + case "LeftButtonSr": + viewModel.Config.LeftButtonSr = (GamepadInputId)e.Key; + break; + case "LeftButtonSl": + viewModel.Config.LeftButtonSl = (GamepadInputId)e.Key; + break; + case "RightButtonSr": + viewModel.Config.RightButtonSr = (GamepadInputId)e.Key; + break; + case "RightButtonSl": + viewModel.Config.RightButtonSl = (GamepadInputId)e.Key; + break; + case "ButtonZr": + viewModel.Config.ButtonZr = (GamepadInputId)e.Key; + break; + case "ButtonR": + viewModel.Config.ButtonR = (GamepadInputId)e.Key; + break; + case "ButtonPlus": + viewModel.Config.ButtonPlus = (GamepadInputId)e.Key; + break; + case "ButtonA": + viewModel.Config.ButtonA = (GamepadInputId)e.Key; + break; + case "ButtonB": + viewModel.Config.ButtonB = (GamepadInputId)e.Key; + break; + case "ButtonX": + viewModel.Config.ButtonX = (GamepadInputId)e.Key; + break; + case "ButtonY": + viewModel.Config.ButtonY = (GamepadInputId)e.Key; + break; + case "RightStickButton": + viewModel.Config.RightStickButton = (GamepadInputId)e.Key; + break; + case "RightJoystick": + viewModel.Config.RightJoystick = (StickInputId)e.Key; + break; + default: + Console.WriteLine(button.Name); + break; + } } }; diff --git a/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs b/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs index 388ebcc07a..be583508c9 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 object GetPressedButton() { IEnumerable pressedButtons = _detector.GetPressedButtons(); if (pressedButtons.Any()) { - return !_forStick ? pressedButtons.First().ToString() : ((StickInputId)pressedButtons.First()).ToString(); + return !_forStick ? pressedButtons.First() : ((StickInputId)pressedButtons.First()); } - return ""; + return null; } private void CollectButtonStats() @@ -194,4 +194,4 @@ namespace Ryujinx.Input.Assigner } } } -} +} \ No newline at end of file diff --git a/src/Ryujinx.Input/Assigner/IButtonAssigner.cs b/src/Ryujinx.Input/Assigner/IButtonAssigner.cs index 76a9fece49..27f1c6b8db 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 by the button assigner. /// /// The pressed button that was read - string GetPressedButton(); + object GetPressedButton(); } } diff --git a/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs b/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs index e52ef4a2ce..a4dde19878 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 object GetPressedButton() { - string keyPressed = ""; + object keyPressed = null; for (Key key = Key.Unknown; key < Key.Count; key++) { if (_keyboardState.IsPressed(key)) { - keyPressed = key.ToString(); + keyPressed = key; break; } } - return !ShouldCancel() ? keyPressed : ""; + return !ShouldCancel() ? keyPressed : null; } } } From 44a53e1cdfe47f5d05f911074f902c3a2a87c5a3 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 22:51:08 -0400 Subject: [PATCH 20/54] Try me in the Hague --- .../Views/Input/ControllerInputView.axaml.cs | 3 - .../UI/Views/Input/KeyboardInputView.axaml | 112 +++++++++--------- .../UI/Views/Input/KeyboardInputView.axaml.cs | 93 ++++++++++++++- 3 files changed, 148 insertions(+), 60 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index 65f32504d6..11149af0d1 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -139,9 +139,6 @@ namespace Ryujinx.Ava.UI.Views.Input case "RightJoystick": viewModel.Config.RightJoystick = (StickInputId)e.Key; break; - default: - Console.WriteLine(button.Name); - break; } } }; diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml index bd5e71b6e1..5e5348c63c 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml @@ -74,9 +74,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsTriggerZL}" TextAlignment="Center" /> - + @@ -90,9 +90,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsTriggerL}" TextAlignment="Center" /> - + @@ -106,9 +106,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonMinus}" TextAlignment="Center" /> - + @@ -141,9 +141,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickButton}" TextAlignment="Center" /> - + @@ -158,9 +158,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickUp}" TextAlignment="Center" /> - + @@ -175,9 +175,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickDown}" TextAlignment="Center" /> - + @@ -192,9 +192,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickLeft}" TextAlignment="Center" /> - + @@ -209,9 +209,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickRight}" TextAlignment="Center" /> - + @@ -245,9 +245,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsDPadUp}" TextAlignment="Center" /> - + @@ -262,9 +262,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsDPadDown}" TextAlignment="Center" /> - + @@ -279,9 +279,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsDPadLeft}" TextAlignment="Center" /> - + @@ -296,9 +296,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsDPadRight}" TextAlignment="Center" /> - + @@ -334,9 +334,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsLeftSR}" TextAlignment="Center" /> - + @@ -352,9 +352,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsLeftSL}" TextAlignment="Center" /> - + @@ -370,9 +370,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsRightSR}" TextAlignment="Center" /> - + @@ -388,9 +388,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsRightSL}" TextAlignment="Center" /> - + @@ -437,9 +437,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsTriggerZR}" TextAlignment="Center" /> - + @@ -455,9 +455,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsTriggerR}" TextAlignment="Center" /> - + @@ -473,9 +473,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonPlus}" TextAlignment="Center" /> - + @@ -508,9 +508,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonA}" TextAlignment="Center" /> - + @@ -525,9 +525,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonB}" TextAlignment="Center" /> - + @@ -542,9 +542,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonX}" TextAlignment="Center" /> - + @@ -559,9 +559,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsButtonY}" TextAlignment="Center" /> - + @@ -594,9 +594,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickButton}" TextAlignment="Center" /> - + @@ -611,9 +611,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickUp}" TextAlignment="Center" /> - + @@ -628,9 +628,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickDown}" TextAlignment="Center" /> - + @@ -645,9 +645,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickLeft}" TextAlignment="Center" /> - + @@ -662,9 +662,9 @@ VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsStickRight}" TextAlignment="Center" /> - + diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs index 46984c3884..ffbe55fe0c 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs @@ -7,6 +7,7 @@ using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Input; using Ryujinx.Input.Assigner; +using Key = Ryujinx.Common.Configuration.Hid.Key; namespace Ryujinx.Ava.UI.Views.Input { @@ -64,7 +65,97 @@ namespace Ryujinx.Ava.UI.Views.Input { if (e.IsAssigned) { - (DataContext as KeyboardInputViewModel).parentModel.IsModified = true; + var viewModel = (DataContext as KeyboardInputViewModel); + viewModel.parentModel.IsModified = true; + + // More crimes against humanity incoming + switch (button.Name) + { + case "ButtonZl": + viewModel.Config.ButtonZl = (Key)e.Key; + break; + case "ButtonL": + viewModel.Config.ButtonL = (Key)e.Key; + break; + case "ButtonMinus": + viewModel.Config.ButtonMinus = (Key)e.Key; + break; + case "LeftStickButton": + viewModel.Config.LeftStickButton = (Key)e.Key; + break; + case "LeftStickUp": + viewModel.Config.LeftStickUp = (Key)e.Key; + break; + case "LeftStickDown": + viewModel.Config.LeftStickDown = (Key)e.Key; + break; + case "LeftStickRight": + viewModel.Config.LeftStickRight = (Key)e.Key; + break; + case "LeftStickLeft": + viewModel.Config.LeftStickLeft = (Key)e.Key; + break; + case "DpadUp": + viewModel.Config.DpadUp = (Key)e.Key; + break; + case "DpadDown": + viewModel.Config.DpadDown = (Key)e.Key; + break; + case "DpadLeft": + viewModel.Config.DpadLeft = (Key)e.Key; + break; + case "DpadRight": + viewModel.Config.DpadRight = (Key)e.Key; + break; + case "LeftButtonSr": + viewModel.Config.LeftButtonSr = (Key)e.Key; + break; + case "LeftButtonSl": + viewModel.Config.LeftButtonSl = (Key)e.Key; + break; + case "RightButtonSr": + viewModel.Config.RightButtonSr = (Key)e.Key; + break; + case "RightButtonSl": + viewModel.Config.RightButtonSl = (Key)e.Key; + break; + case "ButtonZr": + viewModel.Config.ButtonZr = (Key)e.Key; + break; + case "ButtonR": + viewModel.Config.ButtonR = (Key)e.Key; + break; + case "ButtonPlus": + viewModel.Config.ButtonPlus = (Key)e.Key; + break; + case "ButtonA": + viewModel.Config.ButtonA = (Key)e.Key; + break; + case "ButtonB": + viewModel.Config.ButtonB = (Key)e.Key; + break; + case "ButtonX": + viewModel.Config.ButtonX = (Key)e.Key; + break; + case "ButtonY": + viewModel.Config.ButtonY = (Key)e.Key; + break; + case "RightStickButton": + viewModel.Config.RightStickButton = (Key)e.Key; + break; + case "RightStickUp": + viewModel.Config.RightStickUp = (Key)e.Key; + break; + case "RightStickDown": + viewModel.Config.RightStickDown = (Key)e.Key; + break; + case "RightStickRight": + viewModel.Config.RightStickRight = (Key)e.Key; + break; + case "RightStickLeft": + viewModel.Config.RightStickLeft = (Key)e.Key; + break; + } } }; From b005814c72494b8f37f99667bd5fa684e48f31c5 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 May 2023 22:55:03 -0400 Subject: [PATCH 21/54] Please be quiet --- src/Ryujinx/UI/Windows/ControllerWindow.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Ryujinx/UI/Windows/ControllerWindow.cs b/src/Ryujinx/UI/Windows/ControllerWindow.cs index 9541134432..46fd4224cc 100644 --- a/src/Ryujinx/UI/Windows/ControllerWindow.cs +++ b/src/Ryujinx/UI/Windows/ControllerWindow.cs @@ -893,7 +893,7 @@ namespace Ryujinx.UI.Windows } } - string pressedButton = assigner.GetPressedButton(); + object pressedButton = assigner.GetPressedButton(); Application.Invoke(delegate { @@ -903,7 +903,7 @@ namespace Ryujinx.UI.Windows } else if (pressedButton != "") { - button.Label = pressedButton; + button.Label = pressedButton.ToString(); } _middleMousePressed = false; @@ -1227,4 +1227,4 @@ namespace Ryujinx.UI.Windows Dispose(); } } -} +} \ No newline at end of file From 86fdd76013fdcb0bf8466bb7e7e72632602c20c9 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 19 May 2023 09:02:07 -0400 Subject: [PATCH 22/54] Crimes are here to stay --- src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs | 1 - src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs | 1 - src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs index 1d8def0b84..e066da29e2 100644 --- a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs +++ b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs @@ -1,5 +1,4 @@ using Avalonia.Data.Converters; -using DynamicData.Kernel; using Ryujinx.Ava.Common.Locale; using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Configuration.Hid.Controller; diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index 11149af0d1..d9c80cb2eb 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -70,7 +70,6 @@ namespace Ryujinx.Ava.UI.Views.Input var viewModel = (DataContext as ControllerInputViewModel); viewModel.parentModel.IsModified = true; - // This is a crime against code but I can't think of anything better rn switch (button.Name) { case "ButtonZl": diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs index ffbe55fe0c..04e76bb322 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs @@ -68,7 +68,6 @@ namespace Ryujinx.Ava.UI.Views.Input var viewModel = (DataContext as KeyboardInputViewModel); viewModel.parentModel.IsModified = true; - // More crimes against humanity incoming switch (button.Name) { case "ButtonZl": From e51c131fd7e26652cd763366d62efc1714aa0d8c Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 19 May 2023 09:27:25 -0400 Subject: [PATCH 23/54] Dispose stuff --- src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs | 4 +++- src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs | 4 +++- src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml | 2 +- src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml.cs | 2 +- src/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index d9c80cb2eb..c122b0167e 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -1,3 +1,4 @@ +using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Input; @@ -182,8 +183,9 @@ namespace Ryujinx.Ava.UI.Views.Input return assigner; } - public void Dispose() + protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) { + base.OnDetachedFromVisualTree(e); _currentAssigner?.Cancel(); _currentAssigner = null; } diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs index 04e76bb322..14f9176e0d 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs @@ -1,3 +1,4 @@ +using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Input; @@ -198,8 +199,9 @@ namespace Ryujinx.Ava.UI.Views.Input return assigner; } - public void Dispose() + protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) { + base.OnDetachedFromVisualTree(e); _currentAssigner?.Cancel(); _currentAssigner = null; } diff --git a/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml b/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml index 08b45f206b..55c2ed6e3c 100644 --- a/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml @@ -29,7 +29,7 @@ + Name="InputView" /> diff --git a/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml.cs index e75c9f0cc4..55b69af068 100644 --- a/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Settings/SettingsInputView.axaml.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Ava.UI.Views.Settings public void Dispose() { - ControllerSettings.Dispose(); + InputView.Dispose(); } } } diff --git a/src/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs b/src/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs index d7bb0b8837..314501c525 100644 --- a/src/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs +++ b/src/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs @@ -37,7 +37,7 @@ namespace Ryujinx.Ava.UI.Windows public void SaveSettings() { - InputPage.ControllerSettings?.SaveCurrentProfile(); + InputPage.InputView?.SaveCurrentProfile(); if (Owner is MainWindow window && ViewModel.DirectoryChanged) { From 7dddee597138e3a6b0737d451870a099c53047a7 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 19 May 2023 09:44:53 -0400 Subject: [PATCH 24/54] Cleanup a couple things --- .../UI/Models/Input/ControllerInputConfig.cs | 51 ++----------------- 1 file changed, 5 insertions(+), 46 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs index 6a93237497..ff81daf0b5 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs @@ -14,6 +14,11 @@ namespace Ryujinx.Ava.UI.Models.Input public int Slot { get; set; } public int AltSlot { get; set; } public bool MirrorInput { get; set; } + public int Sensitivity { get; set; } + public double GyroDeadzone { get; set; } + + public float WeakRumble { get; set; } + public float StrongRumble { get; set; } public string Id { get; set; } public ControllerType ControllerType { get; set; } @@ -398,30 +403,6 @@ namespace Ryujinx.Ava.UI.Models.Input } } - private double _gyroDeadzone; - public double GyroDeadzone - { - get => _gyroDeadzone; - set - { - _gyroDeadzone = Math.Round(value, 3); - - OnPropertyChanged(); - } - } - - private int _sensitivity; - public int Sensitivity - { - get => _sensitivity; - set - { - _sensitivity = value; - - OnPropertyChanged(); - } - } - private bool _enableRumble; public bool EnableRumble { @@ -433,28 +414,6 @@ namespace Ryujinx.Ava.UI.Models.Input } } - private float _weakRumble; - public float WeakRumble - { - get => _weakRumble; - set - { - _weakRumble = value; - OnPropertyChanged(); - } - } - - private float _strongRumble; - public float StrongRumble - { - get => _strongRumble; - set - { - _strongRumble = value; - OnPropertyChanged(); - } - } - public ControllerInputConfig(InputConfig config) { if (config != null) From b9cf223d86ae64bc6f4421d242eca1d64af2073d Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 19 May 2023 10:08:24 -0400 Subject: [PATCH 25/54] Visual fixes and improvements One weird bug --- .../Input/KeyboardInputViewModel.cs | 4 +++ .../UI/Views/Input/ControllerInputView.axaml | 22 +++++++-------- .../UI/Views/Input/KeyboardInputView.axaml | 28 +++++++++---------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs index 6e886d0b85..b9f4c8602c 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -24,6 +24,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { _isLeft = value; OnPropertyChanged(); + OnPropertyChanged(nameof(HasSides)); } } @@ -35,9 +36,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { _isRight = value; OnPropertyChanged(); + OnPropertyChanged(nameof(HasSides)); } } + public bool HasSides => IsLeft ^ IsRight; + private SvgImage _image; public SvgImage Image { diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml index e7c1d54ca1..6cf873071e 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml @@ -316,6 +316,13 @@ Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> + + - - + + + MinHeight="90" + IsVisible="{Binding HasSides}"> - - - Date: Fri, 19 May 2023 13:04:15 -0400 Subject: [PATCH 26/54] Fix rebase errors --- .../UI/ViewModels/Input/MotionInputViewModel.cs | 2 +- .../UI/Views/Input/ControllerInputView.axaml.cs | 1 - src/Ryujinx.Ava/UI/Views/Input/MotionInputView.axaml.cs | 8 +++----- src/Ryujinx.Ava/UI/Views/Input/RumbleInputView.axaml.cs | 8 +++----- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/MotionInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/MotionInputViewModel.cs index 0b12a51f6c..c9ed8f2d46 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/MotionInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/MotionInputViewModel.cs @@ -1,4 +1,4 @@ -namespace Ryujinx.Ava.UI.ViewModels +namespace Ryujinx.Ava.UI.ViewModels.Input { public class MotionInputViewModel : BaseModel { diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index c122b0167e..58f0339c9a 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -9,7 +9,6 @@ using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Common.Configuration.Hid.Controller; using Ryujinx.Input; using Ryujinx.Input.Assigner; -using System; using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; namespace Ryujinx.Ava.UI.Views.Input diff --git a/src/Ryujinx.Ava/UI/Views/Input/MotionInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/MotionInputView.axaml.cs index 1b340752b1..2304364b67 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/MotionInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/MotionInputView.axaml.cs @@ -1,9 +1,7 @@ using Avalonia.Controls; using FluentAvalonia.UI.Controls; using Ryujinx.Ava.Common.Locale; -using Ryujinx.Ava.UI.Models; -using Ryujinx.Ava.UI.ViewModels; -using Ryujinx.Common.Configuration.Hid.Controller; +using Ryujinx.Ava.UI.ViewModels.Input; using System.Threading.Tasks; namespace Ryujinx.Ava.UI.Views.Input @@ -19,7 +17,7 @@ namespace Ryujinx.Ava.UI.Views.Input public MotionInputView(ControllerInputViewModel viewModel) { - var config = viewModel.Configuration as InputConfiguration; + var config = viewModel.Config; _viewModel = new MotionInputViewModel { @@ -51,7 +49,7 @@ namespace Ryujinx.Ava.UI.Views.Input }; contentDialog.PrimaryButtonClick += (sender, args) => { - var config = viewModel.Configuration as InputConfiguration; + var config = viewModel.Config; config.Slot = content._viewModel.Slot; config.Sensitivity = content._viewModel.Sensitivity; config.GyroDeadzone = content._viewModel.GyroDeadzone; diff --git a/src/Ryujinx.Ava/UI/Views/Input/RumbleInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/RumbleInputView.axaml.cs index 9307f872c3..58a4b416b6 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/RumbleInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/RumbleInputView.axaml.cs @@ -1,9 +1,7 @@ using Avalonia.Controls; using FluentAvalonia.UI.Controls; using Ryujinx.Ava.Common.Locale; -using Ryujinx.Ava.UI.Models; -using Ryujinx.Ava.UI.ViewModels; -using Ryujinx.Common.Configuration.Hid.Controller; +using Ryujinx.Ava.UI.ViewModels.Input; using System.Threading.Tasks; namespace Ryujinx.Ava.UI.Views.Input @@ -19,7 +17,7 @@ namespace Ryujinx.Ava.UI.Views.Input public RumbleInputView(ControllerInputViewModel viewModel) { - var config = viewModel.Configuration as InputConfiguration; + var config = viewModel.Config; _viewModel = new RumbleInputViewModel { @@ -47,7 +45,7 @@ namespace Ryujinx.Ava.UI.Views.Input contentDialog.PrimaryButtonClick += (sender, args) => { - var config = viewModel.Configuration as InputConfiguration; + var config = viewModel.Config; config.StrongRumble = content._viewModel.StrongRumble; config.WeakRumble = content._viewModel.WeakRumble; }; From 71fa81017b0ffa98c79168e73cf4278c9e5c2e9c Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 19 May 2023 17:45:35 -0400 Subject: [PATCH 27/54] Fixes --- .../Input/ControllerInputViewModel.cs | 4 + .../UI/Views/Input/ControllerInputView.axaml | 112 +++++++++--------- 2 files changed, 62 insertions(+), 54 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs index 34d7ac2cf2..52e2d2c539 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -25,6 +25,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { _isLeft = value; OnPropertyChanged(); + OnPropertyChanged(nameof(HasSides)); } } @@ -36,9 +37,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { _isRight = value; OnPropertyChanged(); + OnPropertyChanged(nameof(HasSides)); } } + public bool HasSides => IsLeft ^ IsRight; + private SvgImage _image; public SvgImage Image { diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml index 6cf873071e..74827174af 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml @@ -350,76 +350,80 @@ Text="{Binding Config.TriggerThreshold, StringFormat=\{0:0.00\}}" /> - + - + IsVisible="{Binding IsLeft}" + Orientation="Horizontal"> - - - - + + + + - + IsVisible="{Binding IsLeft}" + Orientation="Horizontal"> - - - - + + + + - + IsVisible="{Binding IsRight}" + Orientation="Horizontal"> - - - - + + + + - + IsVisible="{Binding IsRight}" + Orientation="Horizontal"> - + + + + From 5e8eedae37b8386956d5408bccf093ca2a20c0ef Mon Sep 17 00:00:00 2001 From: Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com> Date: Sun, 28 May 2023 17:44:13 -0400 Subject: [PATCH 28/54] Ack Suggestions Remaining ack suggestions Update src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs Co-authored-by: Ac_K Update src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs Co-authored-by: Ac_K --- src/Ryujinx.Ava/Assets/Locales/en_US.json | 4 +- .../UI/Models/Input/ControllerInputConfig.cs | 65 +++++++++---------- .../UI/Models/Input/KeyboardInputConfig.cs | 52 +++++++-------- .../Input/ControllerInputViewModel.cs | 18 ++--- .../Input/KeyboardInputViewModel.cs | 6 +- src/Ryujinx/UI/Windows/ControllerWindow.cs | 4 +- 6 files changed, 72 insertions(+), 77 deletions(-) diff --git a/src/Ryujinx.Ava/Assets/Locales/en_US.json b/src/Ryujinx.Ava/Assets/Locales/en_US.json index d5c2d8cfc6..621a51ad7d 100644 --- a/src/Ryujinx.Ava/Assets/Locales/en_US.json +++ b/src/Ryujinx.Ava/Assets/Locales/en_US.json @@ -275,8 +275,8 @@ "KeyAltRight": "Alt Right", "KeyOptLeft": "⌥ Left", "KeyOptRight": "⌥ Right", - "KeyWinLeft": "Windows Left", - "KeyWinRight": "Windows Right", + "KeyWinLeft": "⊞ Left", + "KeyWinRight": "⊞ Right", "KeyCmdLeft": "⌘ Left", "KeyCmdRight": "⌘ Right", "KeyMenu": "Menu", diff --git a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs index ff81daf0b5..cb3e171fa4 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs @@ -14,11 +14,11 @@ namespace Ryujinx.Ava.UI.Models.Input public int Slot { get; set; } public int AltSlot { get; set; } public bool MirrorInput { get; set; } - public int Sensitivity { get; set; } + public int Sensitivity { get; set; } public double GyroDeadzone { get; set; } public float WeakRumble { get; set; } - public float StrongRumble { get; set; } + public float StrongRumble { get; set; } public string Id { get; set; } public ControllerType ControllerType { get; set; } @@ -339,7 +339,6 @@ namespace Ryujinx.Ava.UI.Models.Input set { _deadzoneLeft = MathF.Round(value, 3); - OnPropertyChanged(); } } @@ -351,7 +350,6 @@ namespace Ryujinx.Ava.UI.Models.Input set { _deadzoneRight = MathF.Round(value, 3); - OnPropertyChanged(); } } @@ -363,7 +361,6 @@ namespace Ryujinx.Ava.UI.Models.Input set { _rangeLeft = MathF.Round(value, 3); - OnPropertyChanged(); } } @@ -375,7 +372,6 @@ namespace Ryujinx.Ava.UI.Models.Input set { _rangeRight = MathF.Round(value, 3); - OnPropertyChanged(); } } @@ -387,7 +383,6 @@ namespace Ryujinx.Ava.UI.Models.Input set { _triggerThreshold = MathF.Round(value, 3); - OnPropertyChanged(); } } @@ -427,37 +422,37 @@ namespace Ryujinx.Ava.UI.Models.Input return; } - LeftJoystick = controllerInput.LeftJoyconStick.Joystick; - LeftInvertStickX = controllerInput.LeftJoyconStick.InvertStickX; - LeftInvertStickY = controllerInput.LeftJoyconStick.InvertStickY; - LeftRotate90 = controllerInput.LeftJoyconStick.Rotate90CW; - LeftStickButton = controllerInput.LeftJoyconStick.StickButton; + LeftJoystick = controllerInput.LeftJoyconStick.Joystick; + LeftInvertStickX = controllerInput.LeftJoyconStick.InvertStickX; + LeftInvertStickY = controllerInput.LeftJoyconStick.InvertStickY; + LeftRotate90 = controllerInput.LeftJoyconStick.Rotate90CW; + LeftStickButton = controllerInput.LeftJoyconStick.StickButton; - RightJoystick = controllerInput.RightJoyconStick.Joystick; + RightJoystick = controllerInput.RightJoyconStick.Joystick; RightInvertStickX = controllerInput.RightJoyconStick.InvertStickX; RightInvertStickY = controllerInput.RightJoyconStick.InvertStickY; - RightRotate90 = controllerInput.RightJoyconStick.Rotate90CW; - RightStickButton = controllerInput.RightJoyconStick.StickButton; + RightRotate90 = controllerInput.RightJoyconStick.Rotate90CW; + RightStickButton = controllerInput.RightJoyconStick.StickButton; - DpadUp = controllerInput.LeftJoycon.DpadUp; - DpadDown = controllerInput.LeftJoycon.DpadDown; - DpadLeft = controllerInput.LeftJoycon.DpadLeft; - DpadRight = controllerInput.LeftJoycon.DpadRight; - ButtonL = controllerInput.LeftJoycon.ButtonL; - ButtonMinus = controllerInput.LeftJoycon.ButtonMinus; - LeftButtonSl = controllerInput.LeftJoycon.ButtonSl; - LeftButtonSr = controllerInput.LeftJoycon.ButtonSr; - ButtonZl = controllerInput.LeftJoycon.ButtonZl; + DpadUp = controllerInput.LeftJoycon.DpadUp; + DpadDown = controllerInput.LeftJoycon.DpadDown; + DpadLeft = controllerInput.LeftJoycon.DpadLeft; + DpadRight = controllerInput.LeftJoycon.DpadRight; + ButtonL = controllerInput.LeftJoycon.ButtonL; + ButtonMinus = controllerInput.LeftJoycon.ButtonMinus; + LeftButtonSl = controllerInput.LeftJoycon.ButtonSl; + LeftButtonSr = controllerInput.LeftJoycon.ButtonSr; + ButtonZl = controllerInput.LeftJoycon.ButtonZl; - ButtonA = controllerInput.RightJoycon.ButtonA; - ButtonB = controllerInput.RightJoycon.ButtonB; - ButtonX = controllerInput.RightJoycon.ButtonX; - ButtonY = controllerInput.RightJoycon.ButtonY; - ButtonR = controllerInput.RightJoycon.ButtonR; - ButtonPlus = controllerInput.RightJoycon.ButtonPlus; + ButtonA = controllerInput.RightJoycon.ButtonA; + ButtonB = controllerInput.RightJoycon.ButtonB; + ButtonX = controllerInput.RightJoycon.ButtonX; + ButtonY = controllerInput.RightJoycon.ButtonY; + ButtonR = controllerInput.RightJoycon.ButtonR; + ButtonPlus = controllerInput.RightJoycon.ButtonPlus; RightButtonSl = controllerInput.RightJoycon.ButtonSl; RightButtonSr = controllerInput.RightJoycon.ButtonSr; - ButtonZr = controllerInput.RightJoycon.ButtonZr; + ButtonZr = controllerInput.RightJoycon.ButtonZr; DeadzoneLeft = controllerInput.DeadzoneLeft; DeadzoneRight = controllerInput.DeadzoneRight; @@ -521,7 +516,7 @@ namespace Ryujinx.Ava.UI.Models.Input ButtonSl = RightButtonSl, ButtonSr = RightButtonSr, ButtonR = ButtonR, - ButtonZr = ButtonZr, + ButtonZr = ButtonZr }, LeftJoyconStick = new JoyconConfigControllerStick { @@ -529,7 +524,7 @@ namespace Ryujinx.Ava.UI.Models.Input InvertStickX = LeftInvertStickX, InvertStickY = LeftInvertStickY, Rotate90CW = LeftRotate90, - StickButton = LeftStickButton, + StickButton = LeftStickButton }, RightJoyconStick = new JoyconConfigControllerStick { @@ -537,7 +532,7 @@ namespace Ryujinx.Ava.UI.Models.Input InvertStickX = RightInvertStickX, InvertStickY = RightInvertStickY, Rotate90CW = RightRotate90, - StickButton = RightStickButton, + StickButton = RightStickButton }, Rumble = new RumbleConfigController { @@ -550,7 +545,7 @@ namespace Ryujinx.Ava.UI.Models.Input DeadzoneRight = DeadzoneRight, RangeLeft = RangeLeft, RangeRight = RangeRight, - TriggerThreshold = TriggerThreshold, + TriggerThreshold = TriggerThreshold }; if (EnableCemuHookMotion) diff --git a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs index 33ef381863..8355f26fbf 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs @@ -331,37 +331,37 @@ namespace Ryujinx.Ava.UI.Models.Input return; } - LeftStickUp = keyboardConfig.LeftJoyconStick.StickUp; - LeftStickDown = keyboardConfig.LeftJoyconStick.StickDown; - LeftStickLeft = keyboardConfig.LeftJoyconStick.StickLeft; - LeftStickRight = keyboardConfig.LeftJoyconStick.StickRight; - LeftStickButton = keyboardConfig.LeftJoyconStick.StickButton; + LeftStickUp = keyboardConfig.LeftJoyconStick.StickUp; + LeftStickDown = keyboardConfig.LeftJoyconStick.StickDown; + LeftStickLeft = keyboardConfig.LeftJoyconStick.StickLeft; + LeftStickRight = keyboardConfig.LeftJoyconStick.StickRight; + LeftStickButton = keyboardConfig.LeftJoyconStick.StickButton; - RightStickUp = keyboardConfig.RightJoyconStick.StickUp; - RightStickDown = keyboardConfig.RightJoyconStick.StickDown; - RightStickLeft = keyboardConfig.RightJoyconStick.StickLeft; - RightStickRight = keyboardConfig.RightJoyconStick.StickRight; + RightStickUp = keyboardConfig.RightJoyconStick.StickUp; + RightStickDown = keyboardConfig.RightJoyconStick.StickDown; + RightStickLeft = keyboardConfig.RightJoyconStick.StickLeft; + RightStickRight = keyboardConfig.RightJoyconStick.StickRight; RightStickButton = keyboardConfig.RightJoyconStick.StickButton; - DpadUp = keyboardConfig.LeftJoycon.DpadUp; - DpadDown = keyboardConfig.LeftJoycon.DpadDown; - DpadLeft = keyboardConfig.LeftJoycon.DpadLeft; - DpadRight = keyboardConfig.LeftJoycon.DpadRight; - ButtonL = keyboardConfig.LeftJoycon.ButtonL; - ButtonMinus = keyboardConfig.LeftJoycon.ButtonMinus; - LeftButtonSl = keyboardConfig.LeftJoycon.ButtonSl; - LeftButtonSr = keyboardConfig.LeftJoycon.ButtonSr; - ButtonZl = keyboardConfig.LeftJoycon.ButtonZl; + DpadUp = keyboardConfig.LeftJoycon.DpadUp; + DpadDown = keyboardConfig.LeftJoycon.DpadDown; + DpadLeft = keyboardConfig.LeftJoycon.DpadLeft; + DpadRight = keyboardConfig.LeftJoycon.DpadRight; + ButtonL = keyboardConfig.LeftJoycon.ButtonL; + ButtonMinus = keyboardConfig.LeftJoycon.ButtonMinus; + LeftButtonSl = keyboardConfig.LeftJoycon.ButtonSl; + LeftButtonSr = keyboardConfig.LeftJoycon.ButtonSr; + ButtonZl = keyboardConfig.LeftJoycon.ButtonZl; - ButtonA = keyboardConfig.RightJoycon.ButtonA; - ButtonB = keyboardConfig.RightJoycon.ButtonB; - ButtonX = keyboardConfig.RightJoycon.ButtonX; - ButtonY = keyboardConfig.RightJoycon.ButtonY; - ButtonR = keyboardConfig.RightJoycon.ButtonR; - ButtonPlus = keyboardConfig.RightJoycon.ButtonPlus; + ButtonA = keyboardConfig.RightJoycon.ButtonA; + ButtonB = keyboardConfig.RightJoycon.ButtonB; + ButtonX = keyboardConfig.RightJoycon.ButtonX; + ButtonY = keyboardConfig.RightJoycon.ButtonY; + ButtonR = keyboardConfig.RightJoycon.ButtonR; + ButtonPlus = keyboardConfig.RightJoycon.ButtonPlus; RightButtonSl = keyboardConfig.RightJoycon.ButtonSl; RightButtonSr = keyboardConfig.RightJoycon.ButtonSr; - ButtonZr = keyboardConfig.RightJoycon.ButtonZr; + ButtonZr = keyboardConfig.RightJoycon.ButtonZr; } } @@ -383,7 +383,7 @@ namespace Ryujinx.Ava.UI.Models.Input ButtonMinus = ButtonMinus, ButtonZl = ButtonZl, ButtonSl = LeftButtonSl, - ButtonSr = LeftButtonSr, + ButtonSr = LeftButtonSr }, RightJoycon = new RightJoyconCommonConfig { diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs index 52e2d2c539..bf94101d4b 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -56,6 +56,14 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public InputViewModel parentModel; + public ControllerInputViewModel(InputViewModel model, ControllerInputConfig config) + { + parentModel = model; + model.NotifyChangesEvent += OnParentModelChanged; + OnParentModelChanged(); + Config = config; + } + public async void ShowMotionConfig() { await MotionInputView.Show(this); @@ -66,15 +74,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input await RumbleInputView.Show(this); } - public ControllerInputViewModel(InputViewModel model, ControllerInputConfig config) - { - parentModel = model; - model.NotifyChangesEvent += UpdateParentModelValues; - UpdateParentModelValues(); - Config = config; - } - - public void UpdateParentModelValues() + public void OnParentModelChanged() { IsLeft = parentModel.IsLeft; IsRight = parentModel.IsRight; diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs index b9f4c8602c..7b7e9bbe74 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -58,12 +58,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public KeyboardInputViewModel(InputViewModel model, KeyboardInputConfig config) { parentModel = model; - model.NotifyChangesEvent += UpdateParentModelValues; - UpdateParentModelValues(); + model.NotifyChangesEvent += OnParentModelChanged; + OnParentModelChanged(); Config = config; } - public void UpdateParentModelValues() + public void OnParentModelChanged() { IsLeft = parentModel.IsLeft; IsRight = parentModel.IsRight; diff --git a/src/Ryujinx/UI/Windows/ControllerWindow.cs b/src/Ryujinx/UI/Windows/ControllerWindow.cs index 46fd4224cc..60cb567761 100644 --- a/src/Ryujinx/UI/Windows/ControllerWindow.cs +++ b/src/Ryujinx/UI/Windows/ControllerWindow.cs @@ -893,7 +893,7 @@ namespace Ryujinx.UI.Windows } } - object pressedButton = assigner.GetPressedButton(); + string pressedButton = assigner.GetPressedButton().ToString(); Application.Invoke(delegate { @@ -903,7 +903,7 @@ namespace Ryujinx.UI.Windows } else if (pressedButton != "") { - button.Label = pressedButton.ToString(); + button.Label = pressedButton; } _middleMousePressed = false; From 02b355eebf56f65a120653f2ace52c16e67d2775 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sat, 12 Aug 2023 11:52:46 +0100 Subject: [PATCH 29/54] Formatting and error More Ava 11-ness Whoops --- .../UI/Helpers/ButtonKeyAssigner.cs | 6 +- .../UI/Models/Input/ControllerInputConfig.cs | 4 +- .../UI/Models/Input/KeyboardInputConfig.cs | 2 +- .../Input/ControllerInputViewModel.cs | 2 +- .../UI/ViewModels/Input/InputViewModel.cs | 2 +- .../Input/KeyboardInputViewModel.cs | 2 +- .../Views/Input/ControllerInputView.axaml.cs | 223 +++++++-------- .../UI/Views/Input/InputView.axaml | 12 +- .../UI/Views/Input/InputView.axaml.cs | 2 +- .../UI/Views/Input/KeyboardInputView.axaml.cs | 259 +++++++++--------- .../Assigner/GamepadButtonAssigner.cs | 2 +- src/Ryujinx/UI/Windows/ControllerWindow.cs | 2 +- 12 files changed, 260 insertions(+), 258 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs index a39e785c31..c77df81001 100644 --- a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs +++ b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs @@ -1,7 +1,7 @@ using Avalonia; -using Avalonia.Data; using Avalonia.Controls; using Avalonia.Controls.Primitives; +using Avalonia.Data; using Avalonia.LogicalTree; using Avalonia.Threading; using Ryujinx.Ava.Common.Locale; @@ -19,7 +19,7 @@ namespace Ryujinx.Ava.UI.Helpers { public ToggleButton Button { get; } public bool IsAssigned { get; } - public object Key { get; } + public object Key { get; } public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, object key) { @@ -107,4 +107,4 @@ namespace Ryujinx.Ava.UI.Helpers _shouldUnbind = shouldUnbind; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs index cb3e171fa4..4929e582e1 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs @@ -565,7 +565,7 @@ namespace Ryujinx.Ava.UI.Models.Input } else { - config.Motion = new MotionConfigController + config.Motion = new MotionConfigController { EnableMotion = EnableMotion, MotionBackend = MotionInputBackendType.GamepadDriver, @@ -577,4 +577,4 @@ namespace Ryujinx.Ava.UI.Models.Input return config; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs index 8355f26fbf..029565210c 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs @@ -419,4 +419,4 @@ namespace Ryujinx.Ava.UI.Models.Input return config; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs index bf94101d4b..0e23dfa76b 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -81,4 +81,4 @@ namespace Ryujinx.Ava.UI.ViewModels.Input Image = parentModel.Image; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs index 0c02586795..a1303372fc 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs @@ -889,4 +889,4 @@ namespace Ryujinx.Ava.UI.ViewModels.Input AvaloniaKeyboardDriver.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs index 7b7e9bbe74..a938730638 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -70,4 +70,4 @@ namespace Ryujinx.Ava.UI.ViewModels.Input Image = parentModel.Image; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index 58f0339c9a..edf7b6eba2 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -25,8 +25,7 @@ namespace Ryujinx.Ava.UI.Views.Input { if (visual is ToggleButton button && !(visual is CheckBox)) { - button.Checked += Button_Checked; - button.Unchecked += Button_Unchecked; + button.IsCheckedChanged += Button_IsCheckedChanged; } } } @@ -41,129 +40,131 @@ namespace Ryujinx.Ava.UI.Views.Input } } - private void Button_Checked(object sender, RoutedEventArgs e) + private void Button_IsCheckedChanged(object sender, RoutedEventArgs e) { if (sender is ToggleButton button) { - if (_currentAssigner != null && button == _currentAssigner.ToggledButton) + if ((bool)button.IsChecked) { - return; - } - - bool isStick = button.Tag != null && button.Tag.ToString() == "stick"; - - if (_currentAssigner == null && (bool)button.IsChecked) - { - _currentAssigner = new ButtonKeyAssigner(button); - - FocusManager.Instance.Focus(this, NavigationMethod.Pointer); - - PointerPressed += MouseClick; - - IKeyboard keyboard = (IKeyboard)(DataContext as ControllerInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. - IButtonAssigner assigner = CreateButtonAssigner(isStick); - - _currentAssigner.ButtonAssigned += (sender, e) => + if (_currentAssigner != null && button == _currentAssigner.ToggledButton) { - if (e.IsAssigned) + return; + } + + bool isStick = button.Tag != null && button.Tag.ToString() == "stick"; + + if (_currentAssigner == null && (bool)button.IsChecked) + { + _currentAssigner = new ButtonKeyAssigner(button); + + this.Focus(NavigationMethod.Pointer); + + PointerPressed += MouseClick; + + IKeyboard keyboard = (IKeyboard)(DataContext as ControllerInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. + IButtonAssigner assigner = CreateButtonAssigner(isStick); + + _currentAssigner.ButtonAssigned += (sender, e) => { - var viewModel = (DataContext as ControllerInputViewModel); - viewModel.parentModel.IsModified = true; - - switch (button.Name) + if (e.IsAssigned) { - case "ButtonZl": - viewModel.Config.ButtonZl = (GamepadInputId)e.Key; - break; - case "ButtonL": - viewModel.Config.ButtonL = (GamepadInputId)e.Key; - break; - case "ButtonMinus": - viewModel.Config.ButtonMinus = (GamepadInputId)e.Key; - break; - case "LeftStickButton": - viewModel.Config.LeftStickButton = (GamepadInputId)e.Key; - break; - case "LeftJoystick": - viewModel.Config.LeftJoystick = (StickInputId)e.Key; - break; - case "DpadUp": - viewModel.Config.DpadUp = (GamepadInputId)e.Key; - break; - case "DpadDown": - viewModel.Config.DpadDown = (GamepadInputId)e.Key; - break; - case "DpadLeft": - viewModel.Config.DpadLeft = (GamepadInputId)e.Key; - break; - case "DpadRight": - viewModel.Config.DpadRight = (GamepadInputId)e.Key; - break; - case "LeftButtonSr": - viewModel.Config.LeftButtonSr = (GamepadInputId)e.Key; - break; - case "LeftButtonSl": - viewModel.Config.LeftButtonSl = (GamepadInputId)e.Key; - break; - case "RightButtonSr": - viewModel.Config.RightButtonSr = (GamepadInputId)e.Key; - break; - case "RightButtonSl": - viewModel.Config.RightButtonSl = (GamepadInputId)e.Key; - break; - case "ButtonZr": - viewModel.Config.ButtonZr = (GamepadInputId)e.Key; - break; - case "ButtonR": - viewModel.Config.ButtonR = (GamepadInputId)e.Key; - break; - case "ButtonPlus": - viewModel.Config.ButtonPlus = (GamepadInputId)e.Key; - break; - case "ButtonA": - viewModel.Config.ButtonA = (GamepadInputId)e.Key; - break; - case "ButtonB": - viewModel.Config.ButtonB = (GamepadInputId)e.Key; - break; - case "ButtonX": - viewModel.Config.ButtonX = (GamepadInputId)e.Key; - break; - case "ButtonY": - viewModel.Config.ButtonY = (GamepadInputId)e.Key; - break; - case "RightStickButton": - viewModel.Config.RightStickButton = (GamepadInputId)e.Key; - break; - case "RightJoystick": - viewModel.Config.RightJoystick = (StickInputId)e.Key; - break; - } - } - }; + var viewModel = (DataContext as ControllerInputViewModel); + viewModel.parentModel.IsModified = true; - _currentAssigner.GetInputAndAssign(assigner, keyboard); + switch (button.Name) + { + case "ButtonZl": + viewModel.Config.ButtonZl = (GamepadInputId)e.Key; + break; + case "ButtonL": + viewModel.Config.ButtonL = (GamepadInputId)e.Key; + break; + case "ButtonMinus": + viewModel.Config.ButtonMinus = (GamepadInputId)e.Key; + break; + case "LeftStickButton": + viewModel.Config.LeftStickButton = (GamepadInputId)e.Key; + break; + case "LeftJoystick": + viewModel.Config.LeftJoystick = (StickInputId)e.Key; + break; + case "DpadUp": + viewModel.Config.DpadUp = (GamepadInputId)e.Key; + break; + case "DpadDown": + viewModel.Config.DpadDown = (GamepadInputId)e.Key; + break; + case "DpadLeft": + viewModel.Config.DpadLeft = (GamepadInputId)e.Key; + break; + case "DpadRight": + viewModel.Config.DpadRight = (GamepadInputId)e.Key; + break; + case "LeftButtonSr": + viewModel.Config.LeftButtonSr = (GamepadInputId)e.Key; + break; + case "LeftButtonSl": + viewModel.Config.LeftButtonSl = (GamepadInputId)e.Key; + break; + case "RightButtonSr": + viewModel.Config.RightButtonSr = (GamepadInputId)e.Key; + break; + case "RightButtonSl": + viewModel.Config.RightButtonSl = (GamepadInputId)e.Key; + break; + case "ButtonZr": + viewModel.Config.ButtonZr = (GamepadInputId)e.Key; + break; + case "ButtonR": + viewModel.Config.ButtonR = (GamepadInputId)e.Key; + break; + case "ButtonPlus": + viewModel.Config.ButtonPlus = (GamepadInputId)e.Key; + break; + case "ButtonA": + viewModel.Config.ButtonA = (GamepadInputId)e.Key; + break; + case "ButtonB": + viewModel.Config.ButtonB = (GamepadInputId)e.Key; + break; + case "ButtonX": + viewModel.Config.ButtonX = (GamepadInputId)e.Key; + break; + case "ButtonY": + viewModel.Config.ButtonY = (GamepadInputId)e.Key; + break; + case "RightStickButton": + viewModel.Config.RightStickButton = (GamepadInputId)e.Key; + break; + case "RightJoystick": + viewModel.Config.RightJoystick = (StickInputId)e.Key; + break; + } + } + }; + + _currentAssigner.GetInputAndAssign(assigner, keyboard); + } + else + { + if (_currentAssigner != null) + { + ToggleButton oldButton = _currentAssigner.ToggledButton; + + _currentAssigner.Cancel(); + _currentAssigner = null; + button.IsChecked = false; + } + } } else { - if (_currentAssigner != null) - { - ToggleButton oldButton = _currentAssigner.ToggledButton; - - _currentAssigner.Cancel(); - _currentAssigner = null; - button.IsChecked = false; - } + _currentAssigner?.Cancel(); + _currentAssigner = null; } } } - private void Button_Unchecked(object sender, RoutedEventArgs e) - { - _currentAssigner?.Cancel(); - _currentAssigner = null; - } - private void MouseClick(object sender, PointerPressedEventArgs e) { bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed; @@ -189,4 +190,4 @@ namespace Ryujinx.Ava.UI.Views.Input _currentAssigner = null; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml index a1cd3ba520..639de58e66 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml @@ -63,7 +63,7 @@ HorizontalAlignment="Stretch" VerticalAlignment="Center" SelectionChanged="PlayerIndexBox_OnSelectionChanged" - Items="{Binding PlayerIndexes}" + ItemsSource="{Binding PlayerIndexes}" SelectedIndex="{Binding PlayerId}"> @@ -91,14 +91,14 @@ HorizontalAlignment="Left" VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsProfile}" /> - @@ -480,7 +480,7 @@ @@ -761,4 +761,4 @@ - \ No newline at end of file + diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml index 639de58e66..ae35e0e461 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml @@ -106,7 +106,7 @@ Margin="5,0,0,0" VerticalAlignment="Center" ToolTip.Tip="{locale:Locale ControllerSettingsLoadProfileToolTip}" - Command="{ReflectionBinding LoadProfile}"> + Command="{Binding LoadProfile}"> + Command="{Binding SaveProfile}"> + Command="{Binding RemoveProfile}"> + Command="{Binding LoadDevices}"> + ItemsSource="{Binding Controllers}" + SelectedIndex="{Binding Controller}"> From a0a74d3d103e838ae8332494bb8f95b86a49d836 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 19 Sep 2023 10:50:01 -0400 Subject: [PATCH 34/54] Remove ambigious object --- .../UI/Helpers/ButtonKeyAssigner.cs | 16 ++--- .../Views/Input/ControllerInputView.axaml.cs | 46 +++++++-------- .../UI/Views/Input/KeyboardInputView.axaml.cs | 58 +++++++++---------- .../Assigner/GamepadButtonAssigner.cs | 4 +- src/Ryujinx.Input/Assigner/IButtonAssigner.cs | 2 +- .../Assigner/KeyboardKeyAssigner.cs | 6 +- src/Ryujinx.Input/ButtonValue.cs | 48 +++++++++++++++ 7 files changed, 111 insertions(+), 69 deletions(-) create mode 100644 src/Ryujinx.Input/ButtonValue.cs diff --git a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs index c77df81001..db450a9ffc 100644 --- a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs +++ b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs @@ -1,14 +1,8 @@ -using Avalonia; -using Avalonia.Controls; using Avalonia.Controls.Primitives; -using Avalonia.Data; -using Avalonia.LogicalTree; using Avalonia.Threading; -using Ryujinx.Ava.Common.Locale; using Ryujinx.Input; using Ryujinx.Input.Assigner; using System; -using System.Linq; using System.Threading.Tasks; namespace Ryujinx.Ava.UI.Helpers @@ -19,13 +13,13 @@ namespace Ryujinx.Ava.UI.Helpers { public ToggleButton Button { get; } public bool IsAssigned { get; } - public object Key { get; } + public ButtonValue? ButtonValue { get; } - public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, object key) + public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, ButtonValue? buttonValue) { Button = button; IsAssigned = isAssigned; - Key = key; + ButtonValue = buttonValue; } } @@ -83,7 +77,7 @@ namespace Ryujinx.Ava.UI.Helpers await Dispatcher.UIThread.InvokeAsync(() => { - object pressedButton = assigner.GetPressedButton(); + ButtonValue? pressedButton = assigner.GetPressedButton(); if (_shouldUnbind) { @@ -95,7 +89,7 @@ namespace Ryujinx.Ava.UI.Helpers ToggledButton.IsChecked = false; - ButtonAssigned?.Invoke(this, new ButtonAssignedEventArgs(ToggledButton, pressedButton != null, pressedButton)); + ButtonAssigned?.Invoke(this, new ButtonAssignedEventArgs(ToggledButton, pressedButton.HasValue, pressedButton)); }); } diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index 5743bfe4d1..240a930e83 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -9,7 +9,6 @@ using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Common.Configuration.Hid.Controller; using Ryujinx.Input; using Ryujinx.Input.Assigner; -using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; namespace Ryujinx.Ava.UI.Views.Input { @@ -69,75 +68,76 @@ namespace Ryujinx.Ava.UI.Views.Input if (e.IsAssigned) { var viewModel = (DataContext as ControllerInputViewModel); + var buttonValue = e.ButtonValue.Value; viewModel.parentModel.IsModified = true; switch (button.Name) { case "ButtonZl": - viewModel.Config.ButtonZl = (GamepadInputId)e.Key; + viewModel.Config.ButtonZl = buttonValue.AsGamepadButtonInputId(); break; case "ButtonL": - viewModel.Config.ButtonL = (GamepadInputId)e.Key; + viewModel.Config.ButtonL = buttonValue.AsGamepadButtonInputId(); break; case "ButtonMinus": - viewModel.Config.ButtonMinus = (GamepadInputId)e.Key; + viewModel.Config.ButtonMinus = buttonValue.AsGamepadButtonInputId(); break; case "LeftStickButton": - viewModel.Config.LeftStickButton = (GamepadInputId)e.Key; + viewModel.Config.LeftStickButton = buttonValue.AsGamepadButtonInputId(); break; case "LeftJoystick": - viewModel.Config.LeftJoystick = (StickInputId)e.Key; + viewModel.Config.LeftJoystick = buttonValue.AsGamepadStickId(); break; case "DpadUp": - viewModel.Config.DpadUp = (GamepadInputId)e.Key; + viewModel.Config.DpadUp = buttonValue.AsGamepadButtonInputId(); break; case "DpadDown": - viewModel.Config.DpadDown = (GamepadInputId)e.Key; + viewModel.Config.DpadDown = buttonValue.AsGamepadButtonInputId(); break; case "DpadLeft": - viewModel.Config.DpadLeft = (GamepadInputId)e.Key; + viewModel.Config.DpadLeft = buttonValue.AsGamepadButtonInputId(); break; case "DpadRight": - viewModel.Config.DpadRight = (GamepadInputId)e.Key; + viewModel.Config.DpadRight = buttonValue.AsGamepadButtonInputId(); break; case "LeftButtonSr": - viewModel.Config.LeftButtonSr = (GamepadInputId)e.Key; + viewModel.Config.LeftButtonSr = buttonValue.AsGamepadButtonInputId(); break; case "LeftButtonSl": - viewModel.Config.LeftButtonSl = (GamepadInputId)e.Key; + viewModel.Config.LeftButtonSl = buttonValue.AsGamepadButtonInputId(); break; case "RightButtonSr": - viewModel.Config.RightButtonSr = (GamepadInputId)e.Key; + viewModel.Config.RightButtonSr = buttonValue.AsGamepadButtonInputId(); break; case "RightButtonSl": - viewModel.Config.RightButtonSl = (GamepadInputId)e.Key; + viewModel.Config.RightButtonSl = buttonValue.AsGamepadButtonInputId(); break; case "ButtonZr": - viewModel.Config.ButtonZr = (GamepadInputId)e.Key; + viewModel.Config.ButtonZr = buttonValue.AsGamepadButtonInputId(); break; case "ButtonR": - viewModel.Config.ButtonR = (GamepadInputId)e.Key; + viewModel.Config.ButtonR = buttonValue.AsGamepadButtonInputId(); break; case "ButtonPlus": - viewModel.Config.ButtonPlus = (GamepadInputId)e.Key; + viewModel.Config.ButtonPlus = buttonValue.AsGamepadButtonInputId(); break; case "ButtonA": - viewModel.Config.ButtonA = (GamepadInputId)e.Key; + viewModel.Config.ButtonA = buttonValue.AsGamepadButtonInputId(); break; case "ButtonB": - viewModel.Config.ButtonB = (GamepadInputId)e.Key; + viewModel.Config.ButtonB = buttonValue.AsGamepadButtonInputId(); break; case "ButtonX": - viewModel.Config.ButtonX = (GamepadInputId)e.Key; + viewModel.Config.ButtonX = buttonValue.AsGamepadButtonInputId(); break; case "ButtonY": - viewModel.Config.ButtonY = (GamepadInputId)e.Key; + viewModel.Config.ButtonY = buttonValue.AsGamepadButtonInputId(); break; case "RightStickButton": - viewModel.Config.RightStickButton = (GamepadInputId)e.Key; + viewModel.Config.RightStickButton = buttonValue.AsGamepadButtonInputId(); break; case "RightJoystick": - viewModel.Config.RightJoystick = (StickInputId)e.Key; + viewModel.Config.RightJoystick = buttonValue.AsGamepadStickId(); break; } } diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs index 13dd59ee4f..59da291568 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs @@ -8,7 +8,6 @@ using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Input; using Ryujinx.Input.Assigner; -using Key = Ryujinx.Common.Configuration.Hid.Key; namespace Ryujinx.Ava.UI.Views.Input { @@ -68,93 +67,94 @@ namespace Ryujinx.Ava.UI.Views.Input if (e.IsAssigned) { var viewModel = (DataContext as KeyboardInputViewModel); + var buttonValue = e.ButtonValue.Value; viewModel.parentModel.IsModified = true; switch (button.Name) { case "ButtonZl": - viewModel.Config.ButtonZl = (Key)e.Key; + viewModel.Config.ButtonZl = buttonValue.AsKey(); break; case "ButtonL": - viewModel.Config.ButtonL = (Key)e.Key; + viewModel.Config.ButtonL = buttonValue.AsKey(); break; case "ButtonMinus": - viewModel.Config.ButtonMinus = (Key)e.Key; + viewModel.Config.ButtonMinus = buttonValue.AsKey(); break; case "LeftStickButton": - viewModel.Config.LeftStickButton = (Key)e.Key; + viewModel.Config.LeftStickButton = buttonValue.AsKey(); break; case "LeftStickUp": - viewModel.Config.LeftStickUp = (Key)e.Key; + viewModel.Config.LeftStickUp = buttonValue.AsKey(); break; case "LeftStickDown": - viewModel.Config.LeftStickDown = (Key)e.Key; + viewModel.Config.LeftStickDown = buttonValue.AsKey(); break; case "LeftStickRight": - viewModel.Config.LeftStickRight = (Key)e.Key; + viewModel.Config.LeftStickRight = buttonValue.AsKey(); break; case "LeftStickLeft": - viewModel.Config.LeftStickLeft = (Key)e.Key; + viewModel.Config.LeftStickLeft = buttonValue.AsKey(); break; case "DpadUp": - viewModel.Config.DpadUp = (Key)e.Key; + viewModel.Config.DpadUp = buttonValue.AsKey(); break; case "DpadDown": - viewModel.Config.DpadDown = (Key)e.Key; + viewModel.Config.DpadDown = buttonValue.AsKey(); break; case "DpadLeft": - viewModel.Config.DpadLeft = (Key)e.Key; + viewModel.Config.DpadLeft = buttonValue.AsKey(); break; case "DpadRight": - viewModel.Config.DpadRight = (Key)e.Key; + viewModel.Config.DpadRight = buttonValue.AsKey(); break; case "LeftButtonSr": - viewModel.Config.LeftButtonSr = (Key)e.Key; + viewModel.Config.LeftButtonSr = buttonValue.AsKey(); break; case "LeftButtonSl": - viewModel.Config.LeftButtonSl = (Key)e.Key; + viewModel.Config.LeftButtonSl = buttonValue.AsKey(); break; case "RightButtonSr": - viewModel.Config.RightButtonSr = (Key)e.Key; + viewModel.Config.RightButtonSr = buttonValue.AsKey(); break; case "RightButtonSl": - viewModel.Config.RightButtonSl = (Key)e.Key; + viewModel.Config.RightButtonSl = buttonValue.AsKey(); break; case "ButtonZr": - viewModel.Config.ButtonZr = (Key)e.Key; + viewModel.Config.ButtonZr = buttonValue.AsKey(); break; case "ButtonR": - viewModel.Config.ButtonR = (Key)e.Key; + viewModel.Config.ButtonR = buttonValue.AsKey(); break; case "ButtonPlus": - viewModel.Config.ButtonPlus = (Key)e.Key; + viewModel.Config.ButtonPlus = buttonValue.AsKey(); break; case "ButtonA": - viewModel.Config.ButtonA = (Key)e.Key; + viewModel.Config.ButtonA = buttonValue.AsKey(); break; case "ButtonB": - viewModel.Config.ButtonB = (Key)e.Key; + viewModel.Config.ButtonB = buttonValue.AsKey(); break; case "ButtonX": - viewModel.Config.ButtonX = (Key)e.Key; + viewModel.Config.ButtonX = buttonValue.AsKey(); break; case "ButtonY": - viewModel.Config.ButtonY = (Key)e.Key; + viewModel.Config.ButtonY = buttonValue.AsKey(); break; case "RightStickButton": - viewModel.Config.RightStickButton = (Key)e.Key; + viewModel.Config.RightStickButton = buttonValue.AsKey(); break; case "RightStickUp": - viewModel.Config.RightStickUp = (Key)e.Key; + viewModel.Config.RightStickUp = buttonValue.AsKey(); break; case "RightStickDown": - viewModel.Config.RightStickDown = (Key)e.Key; + viewModel.Config.RightStickDown = buttonValue.AsKey(); break; case "RightStickRight": - viewModel.Config.RightStickRight = (Key)e.Key; + viewModel.Config.RightStickRight = buttonValue.AsKey(); break; case "RightStickLeft": - viewModel.Config.RightStickLeft = (Key)e.Key; + viewModel.Config.RightStickLeft = buttonValue.AsKey(); break; } } diff --git a/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs b/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs index bb23688b5d..bf8319a6a9 100644 --- a/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs +++ b/src/Ryujinx.Input/Assigner/GamepadButtonAssigner.cs @@ -59,13 +59,13 @@ namespace Ryujinx.Input.Assigner return _gamepad == null || !_gamepad.IsConnected; } - public object GetPressedButton() + public ButtonValue? GetPressedButton() { IEnumerable pressedButtons = _detector.GetPressedButtons(); if (pressedButtons.Any()) { - return !_forStick ? pressedButtons.First() : ((StickInputId)pressedButtons.First()); + return !_forStick ? new(pressedButtons.First()) : new(((StickInputId)pressedButtons.First())); } return null; diff --git a/src/Ryujinx.Input/Assigner/IButtonAssigner.cs b/src/Ryujinx.Input/Assigner/IButtonAssigner.cs index 27f1c6b8db..6537171339 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 by the button assigner. /// /// The pressed button that was read - object GetPressedButton(); + ButtonValue? GetPressedButton(); } } diff --git a/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs b/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs index a4dde19878..c66812ba03 100644 --- a/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs +++ b/src/Ryujinx.Input/Assigner/KeyboardKeyAssigner.cs @@ -31,15 +31,15 @@ namespace Ryujinx.Input.Assigner return _keyboardState.IsPressed(Key.Escape); } - public object GetPressedButton() + public ButtonValue? GetPressedButton() { - object keyPressed = null; + ButtonValue? keyPressed = null; for (Key key = Key.Unknown; key < Key.Count; key++) { if (_keyboardState.IsPressed(key)) { - keyPressed = key; + keyPressed = new(key); break; } } diff --git a/src/Ryujinx.Input/ButtonValue.cs b/src/Ryujinx.Input/ButtonValue.cs new file mode 100644 index 0000000000..8fa447b2be --- /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 struct ButtonValue + { + public ButtonValueType Type; + public 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; + } + } +} From a6c066ea38c0f5ae45afb7aa4da8275137216fce Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 19 Sep 2023 10:52:02 -0400 Subject: [PATCH 35/54] Remove redundant property --- src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs | 6 ++---- src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs | 2 +- src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs index db450a9ffc..54e0918a50 100644 --- a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs +++ b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs @@ -12,13 +12,11 @@ namespace Ryujinx.Ava.UI.Helpers internal class ButtonAssignedEventArgs : EventArgs { public ToggleButton Button { get; } - public bool IsAssigned { get; } public ButtonValue? ButtonValue { get; } - public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, ButtonValue? buttonValue) + public ButtonAssignedEventArgs(ToggleButton button, ButtonValue? buttonValue) { Button = button; - IsAssigned = isAssigned; ButtonValue = buttonValue; } } @@ -89,7 +87,7 @@ namespace Ryujinx.Ava.UI.Helpers ToggledButton.IsChecked = false; - ButtonAssigned?.Invoke(this, new ButtonAssignedEventArgs(ToggledButton, pressedButton.HasValue, pressedButton)); + ButtonAssigned?.Invoke(this, new ButtonAssignedEventArgs(ToggledButton, pressedButton)); }); } diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index 240a930e83..52fc62389e 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -65,7 +65,7 @@ namespace Ryujinx.Ava.UI.Views.Input _currentAssigner.ButtonAssigned += (sender, e) => { - if (e.IsAssigned) + if (e.ButtonValue.HasValue) { var viewModel = (DataContext as ControllerInputViewModel); var buttonValue = e.ButtonValue.Value; diff --git a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs index 59da291568..f7024c5d1a 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/KeyboardInputView.axaml.cs @@ -64,7 +64,7 @@ namespace Ryujinx.Ava.UI.Views.Input _currentAssigner.ButtonAssigned += (sender, e) => { - if (e.IsAssigned) + if (e.ButtonValue.HasValue) { var viewModel = (DataContext as KeyboardInputViewModel); var buttonValue = e.ButtonValue.Value; From 6846f23c62dc6ae70e5f4f28cb16cf81a0ab26a6 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 19 Sep 2023 11:00:55 -0400 Subject: [PATCH 36/54] Old man yells at formatter --- src/Ryujinx.Input/ButtonValue.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Input/ButtonValue.cs b/src/Ryujinx.Input/ButtonValue.cs index 8fa447b2be..4a1f8724bf 100644 --- a/src/Ryujinx.Input/ButtonValue.cs +++ b/src/Ryujinx.Input/ButtonValue.cs @@ -6,8 +6,8 @@ namespace Ryujinx.Input public struct ButtonValue { - public ButtonValueType Type; - public uint RawValue; + private ButtonValueType Type; + private uint RawValue; public ButtonValue(Key key) { From fffe67b5c51751e8d3499c3fcdc1f0ea8b094ff1 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 19 Sep 2023 11:05:20 -0400 Subject: [PATCH 37/54] r e a d o n l y --- src/Ryujinx.Input/ButtonValue.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Ryujinx.Input/ButtonValue.cs b/src/Ryujinx.Input/ButtonValue.cs index 4a1f8724bf..f037e6b60a 100644 --- a/src/Ryujinx.Input/ButtonValue.cs +++ b/src/Ryujinx.Input/ButtonValue.cs @@ -4,45 +4,45 @@ namespace Ryujinx.Input { public enum ButtonValueType { Key, GamepadButtonInputId, StickId } - public struct ButtonValue + public readonly struct ButtonValue { - private ButtonValueType Type; - private uint RawValue; + private readonly ButtonValueType _type; + private readonly uint _rawValue; public ButtonValue(Key key) { - Type = ButtonValueType.Key; - RawValue = (uint)key; + _type = ButtonValueType.Key; + _rawValue = (uint)key; } public ButtonValue(GamepadButtonInputId gamepad) { - Type = ButtonValueType.GamepadButtonInputId; - RawValue = (uint)gamepad; + _type = ButtonValueType.GamepadButtonInputId; + _rawValue = (uint)gamepad; } public ButtonValue(StickInputId stick) { - Type = ButtonValueType.StickId; - RawValue = (uint)stick; + _type = ButtonValueType.StickId; + _rawValue = (uint)stick; } public Common.Configuration.Hid.Key AsKey() { - Debug.Assert(Type == ButtonValueType.Key); - return (Common.Configuration.Hid.Key)RawValue; + 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; + 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; + Debug.Assert(_type == ButtonValueType.StickId); + return (Common.Configuration.Hid.Controller.StickInputId)_rawValue; } } } From bc36ca697eb442fbf77be55b8fa239a2ed384392 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 19 Sep 2023 13:01:45 -0400 Subject: [PATCH 38/54] Fix profiles --- src/Ryujinx.Ava/UI/Views/Input/InputView.axaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml index ae35e0e461..b4940941cc 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml @@ -99,7 +99,7 @@ VerticalAlignment="Center" SelectedIndex="0" ItemsSource="{Binding ProfilesList}" - Text="{Binding ProfileName}" /> + Text="{Binding ProfileName, Mode=TwoWay}" />