This commit is contained in:
Isaac Marovitz 2023-10-22 23:46:11 -04:00 committed by Isaac Marovitz
parent 54d8d5b1e9
commit f3548fc6b8
3 changed files with 175 additions and 17 deletions

View file

@ -6,42 +6,42 @@ namespace Ryujinx.Input
public readonly struct ButtonValue
{
private readonly ButtonValueType _type;
public readonly ButtonValueType Type;
private readonly uint _rawValue;
public ButtonValue(Key key)
{
_type = ButtonValueType.Key;
Type = ButtonValueType.Key;
_rawValue = (uint)key;
}
public ButtonValue(GamepadButtonInputId gamepad)
{
_type = ButtonValueType.GamepadButtonInputId;
Type = ButtonValueType.GamepadButtonInputId;
_rawValue = (uint)gamepad;
}
public ButtonValue(StickInputId stick)
{
_type = ButtonValueType.StickId;
Type = ButtonValueType.StickId;
_rawValue = (uint)stick;
}
public Common.Configuration.Hid.Key AsKey()
{
Debug.Assert(_type == ButtonValueType.Key);
Debug.Assert(Type == ButtonValueType.Key);
return (Common.Configuration.Hid.Key)_rawValue;
}
public Common.Configuration.Hid.Controller.GamepadInputId AsGamepadButtonInputId()
{
Debug.Assert(_type == ButtonValueType.GamepadButtonInputId);
Debug.Assert(Type == ButtonValueType.GamepadButtonInputId);
return (Common.Configuration.Hid.Controller.GamepadInputId)_rawValue;
}
public Common.Configuration.Hid.Controller.StickInputId AsGamepadStickId()
{
Debug.Assert(_type == ButtonValueType.StickId);
Debug.Assert(Type == ButtonValueType.StickId);
return (Common.Configuration.Hid.Controller.StickInputId)_rawValue;
}
}

View file

@ -0,0 +1,157 @@
using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Input;
using System;
using System.Collections.Generic;
using Key = Ryujinx.Common.Configuration.Hid.Key;
using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
namespace Ryujinx.Ui.Helper
{
public static class ButtonValueHelper
{
private static readonly Dictionary<Key, string> _keysMap = new()
{
{ Key.Unknown, "Unknown" },
{ Key.ShiftLeft, "ShiftLeft" },
{ Key.ShiftRight, "ShiftRight" },
{ Key.ControlLeft, "CtrlLeft" },
{ Key.ControlRight, "CtrlRight" },
{ Key.AltLeft, OperatingSystem.IsMacOS() ? "OptLeft" : "AltLeft" },
{ Key.AltRight, OperatingSystem.IsMacOS() ? "OptRight" : "AltRight" },
{ Key.WinLeft, OperatingSystem.IsMacOS() ? "CmdLeft" : "WinLeft" },
{ Key.WinRight, OperatingSystem.IsMacOS() ? "CmdRight" : "WinRight" },
{ Key.Up, "Up" },
{ Key.Down, "Down" },
{ Key.Left, "Left" },
{ Key.Right, "Right" },
{ Key.Enter, "Enter" },
{ Key.Escape, "Escape" },
{ Key.Space, "Space" },
{ Key.Tab, "Tab" },
{ Key.BackSpace, "Backspace" },
{ Key.Insert, "Insert" },
{ Key.Delete, "Delete" },
{ Key.PageUp, "PageUp" },
{ Key.PageDown, "PageDown" },
{ Key.Home, "Home" },
{ Key.End, "End" },
{ Key.CapsLock, "CapsLock" },
{ Key.ScrollLock, "ScrollLock" },
{ Key.PrintScreen, "PrintScreen" },
{ Key.Pause, "Pause" },
{ Key.NumLock, "NumLock" },
{ Key.Clear, "Clear" },
{ Key.Keypad0, "Keypad0" },
{ Key.Keypad1, "Keypad1" },
{ Key.Keypad2, "Keypad2" },
{ Key.Keypad3, "Keypad3" },
{ Key.Keypad4, "Keypad4" },
{ Key.Keypad5, "Keypad5" },
{ Key.Keypad6, "Keypad6" },
{ Key.Keypad7, "Keypad7" },
{ Key.Keypad8, "Keypad8" },
{ Key.Keypad9, "Keypad9" },
{ Key.KeypadDivide, "KeypadDivide" },
{ Key.KeypadMultiply, "KeypadMultiply" },
{ Key.KeypadSubtract, "KeypadSubtract" },
{ Key.KeypadAdd, "KeypadAdd" },
{ Key.KeypadDecimal, "KeypadDecimal" },
{ Key.KeypadEnter, "KeypadEnter" },
{ Key.Number0, "0" },
{ Key.Number1, "1" },
{ Key.Number2, "2" },
{ Key.Number3, "3" },
{ Key.Number4, "4" },
{ Key.Number5, "5" },
{ Key.Number6, "6" },
{ Key.Number7, "7" },
{ Key.Number8, "8" },
{ Key.Number9, "9" },
{ Key.Tilde, "~" },
{ Key.Grave, "`" },
{ Key.Minus, "-" },
{ Key.Plus, "+" },
{ Key.BracketLeft, "[" },
{ Key.BracketRight, "]" },
{ Key.Semicolon, ";" },
{ Key.Quote, "'" },
{ Key.Comma, "," },
{ Key.Period, "." },
{ Key.Slash, "/" },
{ Key.BackSlash, "\\" },
{ Key.Unbound, "Unbound" },
};
private static readonly Dictionary<GamepadInputId, string> _gamepadInputIdMap = new()
{
{ GamepadInputId.LeftStick, "LeftStick" },
{ GamepadInputId.RightStick, "RightStick" },
{ GamepadInputId.LeftShoulder, "LeftShoulder" },
{ GamepadInputId.RightShoulder, "RightShoulder" },
{ GamepadInputId.LeftTrigger, "LeftTrigger" },
{ GamepadInputId.RightTrigger, "RightTrigger" },
{ GamepadInputId.DpadUp, "DpadUp" },
{ GamepadInputId.DpadDown, "DpadDown" },
{ GamepadInputId.DpadLeft, "DpadLeft" },
{ GamepadInputId.DpadRight, "DpadRight" },
{ GamepadInputId.Minus, "Minus" },
{ GamepadInputId.Plus, "Plus" },
{ GamepadInputId.Guide, "Guide" },
{ GamepadInputId.Misc1, "Misc1" },
{ GamepadInputId.Paddle1, "Paddle1" },
{ GamepadInputId.Paddle2, "Paddle2" },
{ GamepadInputId.Paddle3, "Paddle3" },
{ GamepadInputId.Paddle4, "Paddle4" },
{ GamepadInputId.Touchpad, "Touchpad" },
{ GamepadInputId.SingleLeftTrigger0, "SingleLeftTrigger0" },
{ GamepadInputId.SingleRightTrigger0, "SingleRightTrigger0" },
{ GamepadInputId.SingleLeftTrigger1, "SingleLeftTrigger1" },
{ GamepadInputId.SingleRightTrigger1, "SingleRightTrigger1" },
{ GamepadInputId.Unbound, "Unbound" },
};
private static readonly Dictionary<StickInputId, string> _stickInputIdMap = new()
{
{ StickInputId.Left, "StickLeft" },
{ StickInputId.Right, "StickRight" },
{ StickInputId.Unbound, "Unbound" },
};
public static string ToString(ButtonValue buttonValue)
{
string keyString = "";
if (buttonValue.Type == ButtonValueType.Key)
{
var key = buttonValue.AsKey();
if (!_keysMap.TryGetValue(buttonValue.AsKey(), out keyString))
{
keyString = key.ToString();
}
}
if (buttonValue.Type == ButtonValueType.GamepadButtonInputId)
{
var gamepadButton = buttonValue.AsGamepadButtonInputId();
if (!_gamepadInputIdMap.TryGetValue(buttonValue.AsGamepadButtonInputId(), out keyString))
{
keyString = gamepadButton.ToString();
}
}
if (buttonValue.Type == ButtonValueType.StickId)
{
var stickInput = buttonValue.AsGamepadStickId();
if (!_stickInputIdMap.TryGetValue(buttonValue.AsGamepadStickId(), out keyString))
{
keyString = stickInput.ToString();
}
}
return keyString;
}
}
}

View file

@ -9,8 +9,9 @@ using Ryujinx.Common.Utilities;
using Ryujinx.Input;
using Ryujinx.Input.Assigner;
using Ryujinx.Input.GTK3;
using Ryujinx.UI.Common.Configuration;
using Ryujinx.UI.Widgets;
using Ryujinx.Ui.Common.Configuration;
using Ryujinx.Ui.Helper;
using Ryujinx.Ui.Widgets;
using System;
using System.Collections.Generic;
using System.IO;
@ -22,7 +23,7 @@ using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInpu
using GUI = Gtk.Builder.ObjectAttribute;
using Key = Ryujinx.Common.Configuration.Hid.Key;
namespace Ryujinx.UI.Windows
namespace Ryujinx.Ui.Windows
{
public class ControllerWindow : Window
{
@ -117,7 +118,7 @@ namespace Ryujinx.UI.Windows
private static readonly InputConfigJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
public ControllerWindow(MainWindow mainWindow, PlayerIndex controllerId) : this(mainWindow, new Builder("Ryujinx.UI.Windows.ControllerWindow.glade"), controllerId) { }
public ControllerWindow(MainWindow mainWindow, PlayerIndex controllerId) : this(mainWindow, new Builder("Ryujinx.Ui.Windows.ControllerWindow.glade"), controllerId) { }
private ControllerWindow(MainWindow mainWindow, Builder builder, PlayerIndex controllerId) : base(builder.GetRawOwnedObject("_controllerWin"))
{
@ -127,7 +128,7 @@ namespace Ryujinx.UI.Windows
// 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...
_gtk3KeyboardDriver = new GTK3KeyboardDriver(this);
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.UI.Common.Resources.Logo_Ryujinx.png");
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png");
builder.Autoconnect(this);
@ -377,10 +378,10 @@ namespace Ryujinx.UI.Windows
{
_controllerImage.Pixbuf = _controllerType.ActiveId switch
{
"ProController" => new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.UI.Common.Resources.Controller_ProCon.svg", 400, 400),
"JoyconLeft" => new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.UI.Common.Resources.Controller_JoyConLeft.svg", 400, 500),
"JoyconRight" => new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.UI.Common.Resources.Controller_JoyConRight.svg", 400, 500),
_ => new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.UI.Common.Resources.Controller_JoyConPair.svg", 400, 500),
"ProController" => new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Controller_ProCon.svg", 400, 400),
"JoyconLeft" => new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Controller_JoyConLeft.svg", 400, 500),
"JoyconRight" => new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Controller_JoyConRight.svg", 400, 500),
_ => new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Controller_JoyConPair.svg", 400, 500),
};
}
}
@ -893,7 +894,7 @@ namespace Ryujinx.UI.Windows
}
}
string pressedButton = assigner.GetPressedButton().ToString();
string pressedButton = ButtonValueHelper.ToString(assigner.GetPressedButton() ?? new ButtonValue(Input.Key.Unknown));
Application.Invoke(delegate
{