aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs
diff options
context:
space:
mode:
authorIsaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com>2023-10-21 07:26:51 -0400
committerGitHub <noreply@github.com>2023-10-21 13:26:51 +0200
commit49b37550cae6b3c69f59a9c7a44b17e3c12a813b (patch)
tree0cc8e6a3bfd65a876270b682effdb8f9505ff929 /src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs
parenta42f0bbb87b890d4f16b1148f9398210a5bfedfa (diff)
Ava UI: Input Menu Refactor (#4998)1.1.1058
* So much boilerplate * Slow and steady * Restructure + Ack suggestions * Restructure + Ack suggestions * Restructure * Clean * Propogate those fields i forgot about * It builds * Progress * Almost there * Fix stupid mistake * Fix more stupid mistakes * Actually fix fuck ups * Start localising * r/therestofthefuckingowl * Localise ButtonKeyAssigner * Are you feeling it now mr krabs * We’re done at last * Crimes against code * Try me in the Hague * Please be quiet * Crimes are here to stay * Dispose stuff * Cleanup a couple things * Visual fixes and improvements One weird bug * Fix rebase errors * Fixes * Ack Suggestions Remaining ack suggestions Update src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> Update src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> * Formatting and error More Ava 11-ness Whoops * Code style fixes * Style fixes * Analyzer fix * Remove all ReflectionBindings * Remove ambigious object * Remove redundant property * Old man yells at formatter * r e a d o n l y * Fix profiles * Use new Sliders --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
Diffstat (limited to 'src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs')
-rw-r--r--src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs157
1 files changed, 140 insertions, 17 deletions
diff --git a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs
index 028ed6bf..1c4aa7b2 100644
--- a/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs
+++ b/src/Ryujinx.Ava/UI/Helpers/KeyValueConverter.cs
@@ -1,7 +1,9 @@
using Avalonia.Data.Converters;
+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
@@ -10,37 +12,158 @@ namespace Ryujinx.Ava.UI.Helpers
{
public static KeyValueConverter Instance = new();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ private static readonly Dictionary<Key, LocaleKeys> _keysMap = new()
{
- if (value == null)
- {
- return null;
- }
+ { 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 },
+ { 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 },
+ };
- return value.ToString();
- }
+ private static readonly Dictionary<GamepadInputId, LocaleKeys> _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},
+ };
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ private static readonly Dictionary<StickInputId, LocaleKeys> _stickInputIdMap = new()
{
- object key = null;
+ { StickInputId.Left, LocaleKeys.StickLeft},
+ { StickInputId.Right, LocaleKeys.StickRight},
+ { StickInputId.Unbound, LocaleKeys.KeyUnbound},
+ };
- if (value != null)
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ string keyString = "";
+
+ if (value is Key key)
{
- if (targetType == typeof(Key))
+ if (_keysMap.TryGetValue(key, out LocaleKeys localeKey))
{
- key = Enum.Parse<Key>(value.ToString());
+ keyString = LocaleManager.Instance[localeKey];
}
- else if (targetType == typeof(GamepadInputId))
+ else
{
- key = Enum.Parse<GamepadInputId>(value.ToString());
+ keyString = key.ToString();
}
- else if (targetType == typeof(StickInputId))
+ }
+ else if (value is GamepadInputId gamepadInputId)
+ {
+ if (_gamepadInputIdMap.TryGetValue(gamepadInputId, out LocaleKeys localeKey))
{
- key = Enum.Parse<StickInputId>(value.ToString());
+ keyString = LocaleManager.Instance[localeKey];
+ }
+ else
+ {
+ keyString = gamepadInputId.ToString();
}
}
+ else if (value is StickInputId stickInputId)
+ {
+ if (_stickInputIdMap.TryGetValue(stickInputId, out LocaleKeys localeKey))
+ {
+ keyString = LocaleManager.Instance[localeKey];
+ }
+ else
+ {
+ keyString = stickInputId.ToString();
+ }
+ }
+
+ return keyString;
+ }
- return key;
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotSupportedException();
}
}
}