Use generic conversion method

This commit is contained in:
Isaac Marovitz 2024-02-23 20:31:12 -05:00 committed by Isaac Marovitz
parent 0f6ed5a53a
commit 584fc555fe
5 changed files with 71 additions and 81 deletions

View file

@ -9,6 +9,7 @@ using Ryujinx.Ava.UI.ViewModels.Input;
using Ryujinx.Common.Configuration.Hid.Controller; using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Input; using Ryujinx.Input;
using Ryujinx.Input.Assigner; using Ryujinx.Input.Assigner;
using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
namespace Ryujinx.Ava.UI.Views.Input namespace Ryujinx.Ava.UI.Views.Input
{ {
@ -74,70 +75,70 @@ namespace Ryujinx.Ava.UI.Views.Input
switch (button.Name) switch (button.Name)
{ {
case "ButtonZl": case "ButtonZl":
viewModel.Config.ButtonZl = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonZl = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "ButtonL": case "ButtonL":
viewModel.Config.ButtonL = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonL = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "ButtonMinus": case "ButtonMinus":
viewModel.Config.ButtonMinus = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonMinus = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "LeftStickButton": case "LeftStickButton":
viewModel.Config.LeftStickButton = buttonValue.AsGamepadButtonInputId(); viewModel.Config.LeftStickButton = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "LeftJoystick": case "LeftJoystick":
viewModel.Config.LeftJoystick = buttonValue.AsGamepadStickId(); viewModel.Config.LeftJoystick = buttonValue.AsHidType<StickInputId>();
break; break;
case "DpadUp": case "DpadUp":
viewModel.Config.DpadUp = buttonValue.AsGamepadButtonInputId(); viewModel.Config.DpadUp = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "DpadDown": case "DpadDown":
viewModel.Config.DpadDown = buttonValue.AsGamepadButtonInputId(); viewModel.Config.DpadDown = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "DpadLeft": case "DpadLeft":
viewModel.Config.DpadLeft = buttonValue.AsGamepadButtonInputId(); viewModel.Config.DpadLeft = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "DpadRight": case "DpadRight":
viewModel.Config.DpadRight = buttonValue.AsGamepadButtonInputId(); viewModel.Config.DpadRight = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "LeftButtonSr": case "LeftButtonSr":
viewModel.Config.LeftButtonSr = buttonValue.AsGamepadButtonInputId(); viewModel.Config.LeftButtonSr = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "LeftButtonSl": case "LeftButtonSl":
viewModel.Config.LeftButtonSl = buttonValue.AsGamepadButtonInputId(); viewModel.Config.LeftButtonSl = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "RightButtonSr": case "RightButtonSr":
viewModel.Config.RightButtonSr = buttonValue.AsGamepadButtonInputId(); viewModel.Config.RightButtonSr = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "RightButtonSl": case "RightButtonSl":
viewModel.Config.RightButtonSl = buttonValue.AsGamepadButtonInputId(); viewModel.Config.RightButtonSl = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "ButtonZr": case "ButtonZr":
viewModel.Config.ButtonZr = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonZr = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "ButtonR": case "ButtonR":
viewModel.Config.ButtonR = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonR = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "ButtonPlus": case "ButtonPlus":
viewModel.Config.ButtonPlus = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonPlus = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "ButtonA": case "ButtonA":
viewModel.Config.ButtonA = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonA = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "ButtonB": case "ButtonB":
viewModel.Config.ButtonB = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonB = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "ButtonX": case "ButtonX":
viewModel.Config.ButtonX = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonX = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "ButtonY": case "ButtonY":
viewModel.Config.ButtonY = buttonValue.AsGamepadButtonInputId(); viewModel.Config.ButtonY = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "RightStickButton": case "RightStickButton":
viewModel.Config.RightStickButton = buttonValue.AsGamepadButtonInputId(); viewModel.Config.RightStickButton = buttonValue.AsHidType<GamepadInputId>();
break; break;
case "RightJoystick": case "RightJoystick":
viewModel.Config.RightJoystick = buttonValue.AsGamepadStickId(); viewModel.Config.RightJoystick = buttonValue.AsHidType<StickInputId>();
break; break;
} }
} }

View file

@ -8,6 +8,7 @@ using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Ava.UI.ViewModels.Input;
using Ryujinx.Input; using Ryujinx.Input;
using Ryujinx.Input.Assigner; using Ryujinx.Input.Assigner;
using Key = Ryujinx.Common.Configuration.Hid.Key;
namespace Ryujinx.Ava.UI.Views.Input namespace Ryujinx.Ava.UI.Views.Input
{ {
@ -71,88 +72,88 @@ namespace Ryujinx.Ava.UI.Views.Input
switch (button.Name) switch (button.Name)
{ {
case "ButtonZl": case "ButtonZl":
viewModel.Config.ButtonZl = buttonValue.AsKey(); viewModel.Config.ButtonZl = buttonValue.AsHidType<Key>();
break; break;
case "ButtonL": case "ButtonL":
viewModel.Config.ButtonL = buttonValue.AsKey(); viewModel.Config.ButtonL = buttonValue.AsHidType<Key>();
break; break;
case "ButtonMinus": case "ButtonMinus":
viewModel.Config.ButtonMinus = buttonValue.AsKey(); viewModel.Config.ButtonMinus = buttonValue.AsHidType<Key>();
break; break;
case "LeftStickButton": case "LeftStickButton":
viewModel.Config.LeftStickButton = buttonValue.AsKey(); viewModel.Config.LeftStickButton = buttonValue.AsHidType<Key>();
break; break;
case "LeftStickUp": case "LeftStickUp":
viewModel.Config.LeftStickUp = buttonValue.AsKey(); viewModel.Config.LeftStickUp = buttonValue.AsHidType<Key>();
break; break;
case "LeftStickDown": case "LeftStickDown":
viewModel.Config.LeftStickDown = buttonValue.AsKey(); viewModel.Config.LeftStickDown = buttonValue.AsHidType<Key>();
break; break;
case "LeftStickRight": case "LeftStickRight":
viewModel.Config.LeftStickRight = buttonValue.AsKey(); viewModel.Config.LeftStickRight = buttonValue.AsHidType<Key>();
break; break;
case "LeftStickLeft": case "LeftStickLeft":
viewModel.Config.LeftStickLeft = buttonValue.AsKey(); viewModel.Config.LeftStickLeft = buttonValue.AsHidType<Key>();
break; break;
case "DpadUp": case "DpadUp":
viewModel.Config.DpadUp = buttonValue.AsKey(); viewModel.Config.DpadUp = buttonValue.AsHidType<Key>();
break; break;
case "DpadDown": case "DpadDown":
viewModel.Config.DpadDown = buttonValue.AsKey(); viewModel.Config.DpadDown = buttonValue.AsHidType<Key>();
break; break;
case "DpadLeft": case "DpadLeft":
viewModel.Config.DpadLeft = buttonValue.AsKey(); viewModel.Config.DpadLeft = buttonValue.AsHidType<Key>();
break; break;
case "DpadRight": case "DpadRight":
viewModel.Config.DpadRight = buttonValue.AsKey(); viewModel.Config.DpadRight = buttonValue.AsHidType<Key>();
break; break;
case "LeftButtonSr": case "LeftButtonSr":
viewModel.Config.LeftButtonSr = buttonValue.AsKey(); viewModel.Config.LeftButtonSr = buttonValue.AsHidType<Key>();
break; break;
case "LeftButtonSl": case "LeftButtonSl":
viewModel.Config.LeftButtonSl = buttonValue.AsKey(); viewModel.Config.LeftButtonSl = buttonValue.AsHidType<Key>();
break; break;
case "RightButtonSr": case "RightButtonSr":
viewModel.Config.RightButtonSr = buttonValue.AsKey(); viewModel.Config.RightButtonSr = buttonValue.AsHidType<Key>();
break; break;
case "RightButtonSl": case "RightButtonSl":
viewModel.Config.RightButtonSl = buttonValue.AsKey(); viewModel.Config.RightButtonSl = buttonValue.AsHidType<Key>();
break; break;
case "ButtonZr": case "ButtonZr":
viewModel.Config.ButtonZr = buttonValue.AsKey(); viewModel.Config.ButtonZr = buttonValue.AsHidType<Key>();
break; break;
case "ButtonR": case "ButtonR":
viewModel.Config.ButtonR = buttonValue.AsKey(); viewModel.Config.ButtonR = buttonValue.AsHidType<Key>();
break; break;
case "ButtonPlus": case "ButtonPlus":
viewModel.Config.ButtonPlus = buttonValue.AsKey(); viewModel.Config.ButtonPlus = buttonValue.AsHidType<Key>();
break; break;
case "ButtonA": case "ButtonA":
viewModel.Config.ButtonA = buttonValue.AsKey(); viewModel.Config.ButtonA = buttonValue.AsHidType<Key>();
break; break;
case "ButtonB": case "ButtonB":
viewModel.Config.ButtonB = buttonValue.AsKey(); viewModel.Config.ButtonB = buttonValue.AsHidType<Key>();
break; break;
case "ButtonX": case "ButtonX":
viewModel.Config.ButtonX = buttonValue.AsKey(); viewModel.Config.ButtonX = buttonValue.AsHidType<Key>();
break; break;
case "ButtonY": case "ButtonY":
viewModel.Config.ButtonY = buttonValue.AsKey(); viewModel.Config.ButtonY = buttonValue.AsHidType<Key>();
break; break;
case "RightStickButton": case "RightStickButton":
viewModel.Config.RightStickButton = buttonValue.AsKey(); viewModel.Config.RightStickButton = buttonValue.AsHidType<Key>();
break; break;
case "RightStickUp": case "RightStickUp":
viewModel.Config.RightStickUp = buttonValue.AsKey(); viewModel.Config.RightStickUp = buttonValue.AsHidType<Key>();
break; break;
case "RightStickDown": case "RightStickDown":
viewModel.Config.RightStickDown = buttonValue.AsKey(); viewModel.Config.RightStickDown = buttonValue.AsHidType<Key>();
break; break;
case "RightStickRight": case "RightStickRight":
viewModel.Config.RightStickRight = buttonValue.AsKey(); viewModel.Config.RightStickRight = buttonValue.AsHidType<Key>();
break; break;
case "RightStickLeft": case "RightStickLeft":
viewModel.Config.RightStickLeft = buttonValue.AsKey(); viewModel.Config.RightStickLeft = buttonValue.AsHidType<Key>();
break; break;
} }
} }

View file

@ -8,6 +8,7 @@ using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.ViewModels; using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Input; using Ryujinx.Input;
using Ryujinx.Input.Assigner; using Ryujinx.Input.Assigner;
using Key = Ryujinx.Common.Configuration.Hid.Key;
namespace Ryujinx.Ava.UI.Views.Settings namespace Ryujinx.Ava.UI.Views.Settings
{ {
@ -81,31 +82,31 @@ namespace Ryujinx.Ava.UI.Views.Settings
switch (button.Name) switch (button.Name)
{ {
case "ToggleVsync": case "ToggleVsync":
viewModel.KeyboardHotkeys.ToggleVsync = buttonValue.AsKey(); viewModel.KeyboardHotkeys.ToggleVsync = buttonValue.AsHidType<Key>();
break; break;
case "Screenshot": case "Screenshot":
viewModel.KeyboardHotkeys.Screenshot = buttonValue.AsKey(); viewModel.KeyboardHotkeys.Screenshot = buttonValue.AsHidType<Key>();
break; break;
case "ShowUI": case "ShowUI":
viewModel.KeyboardHotkeys.ShowUI = buttonValue.AsKey(); viewModel.KeyboardHotkeys.ShowUI = buttonValue.AsHidType<Key>();
break; break;
case "Pause": case "Pause":
viewModel.KeyboardHotkeys.Pause = buttonValue.AsKey(); viewModel.KeyboardHotkeys.Pause = buttonValue.AsHidType<Key>();
break; break;
case "ToggleMute": case "ToggleMute":
viewModel.KeyboardHotkeys.ToggleMute = buttonValue.AsKey(); viewModel.KeyboardHotkeys.ToggleMute = buttonValue.AsHidType<Key>();
break; break;
case "ResScaleUp": case "ResScaleUp":
viewModel.KeyboardHotkeys.ResScaleUp = buttonValue.AsKey(); viewModel.KeyboardHotkeys.ResScaleUp = buttonValue.AsHidType<Key>();
break; break;
case "ResScaleDown": case "ResScaleDown":
viewModel.KeyboardHotkeys.ResScaleDown = buttonValue.AsKey(); viewModel.KeyboardHotkeys.ResScaleDown = buttonValue.AsHidType<Key>();
break; break;
case "VolumeUp": case "VolumeUp":
viewModel.KeyboardHotkeys.VolumeUp = buttonValue.AsKey(); viewModel.KeyboardHotkeys.VolumeUp = buttonValue.AsHidType<Key>();
break; break;
case "VolumeDown": case "VolumeDown":
viewModel.KeyboardHotkeys.VolumeDown = buttonValue.AsKey(); viewModel.KeyboardHotkeys.VolumeDown = buttonValue.AsHidType<Key>();
break; break;
} }
} }

View file

@ -1,4 +1,4 @@
using System.Diagnostics; using System;
namespace Ryujinx.Input namespace Ryujinx.Input
{ {
@ -27,22 +27,9 @@ namespace Ryujinx.Input
_rawValue = (uint)stick; _rawValue = (uint)stick;
} }
public Common.Configuration.Hid.Key AsKey() public T AsHidType<T>() where T : Enum
{ {
Debug.Assert(Type == ButtonValueType.Key); return (T)Enum.ToObject(typeof(T), _rawValue);
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;
} }
} }
} }

View file

@ -123,9 +123,9 @@ namespace Ryujinx.UI.Helper
if (buttonValue.Type == ButtonValueType.Key) if (buttonValue.Type == ButtonValueType.Key)
{ {
var key = buttonValue.AsKey(); var key = buttonValue.AsHidType<Key>();
if (!_keysMap.TryGetValue(buttonValue.AsKey(), out keyString)) if (!_keysMap.TryGetValue(buttonValue.AsHidType<Key>(), out keyString))
{ {
keyString = key.ToString(); keyString = key.ToString();
} }
@ -133,9 +133,9 @@ namespace Ryujinx.UI.Helper
if (buttonValue.Type == ButtonValueType.GamepadButtonInputId) if (buttonValue.Type == ButtonValueType.GamepadButtonInputId)
{ {
var gamepadButton = buttonValue.AsGamepadButtonInputId(); var gamepadButton = buttonValue.AsHidType<GamepadInputId>();
if (!_gamepadInputIdMap.TryGetValue(buttonValue.AsGamepadButtonInputId(), out keyString)) if (!_gamepadInputIdMap.TryGetValue(buttonValue.AsHidType<GamepadInputId>(), out keyString))
{ {
keyString = gamepadButton.ToString(); keyString = gamepadButton.ToString();
} }
@ -143,9 +143,9 @@ namespace Ryujinx.UI.Helper
if (buttonValue.Type == ButtonValueType.StickId) if (buttonValue.Type == ButtonValueType.StickId)
{ {
var stickInput = buttonValue.AsGamepadStickId(); var stickInput = buttonValue.AsHidType<StickInputId>();
if (!_stickInputIdMap.TryGetValue(buttonValue.AsGamepadStickId(), out keyString)) if (!_stickInputIdMap.TryGetValue(buttonValue.AsHidType<StickInputId>(), out keyString))
{ {
keyString = stickInput.ToString(); keyString = stickInput.ToString();
} }