From f2fb9f313c976bbb6bac5500ab34eb70a9ca02f0 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Mon, 15 Apr 2024 19:07:33 -0400 Subject: [PATCH] Use switches --- src/Ryujinx.Gtk3/UI/Helper/ButtonHelper.cs | 45 +++++------ src/Ryujinx/UI/Helpers/KeyValueConverter.cs | 85 +++++++++++---------- 2 files changed, 66 insertions(+), 64 deletions(-) diff --git a/src/Ryujinx.Gtk3/UI/Helper/ButtonHelper.cs b/src/Ryujinx.Gtk3/UI/Helper/ButtonHelper.cs index c3afcaa49f..5a8ca96a19 100644 --- a/src/Ryujinx.Gtk3/UI/Helper/ButtonHelper.cs +++ b/src/Ryujinx.Gtk3/UI/Helper/ButtonHelper.cs @@ -121,34 +121,35 @@ namespace Ryujinx.UI.Helper { string keyString = ""; - if (button.Type == ButtonType.Key) + switch (button.Type) { - var key = button.AsHidType(); + case ButtonType.Key: + var key = button.AsHidType(); - if (!_keysMap.TryGetValue(button.AsHidType(), out keyString)) - { - keyString = key.ToString(); - } - } + if (!_keysMap.TryGetValue(button.AsHidType(), out keyString)) + { + keyString = key.ToString(); + } - if (button.Type == ButtonType.GamepadButtonInputId) - { - var gamepadButton = button.AsHidType(); + break; + case ButtonType.GamepadButtonInputId: + var gamepadButton = button.AsHidType(); - if (!_gamepadInputIdMap.TryGetValue(button.AsHidType(), out keyString)) - { - keyString = gamepadButton.ToString(); - } - } + if (!_gamepadInputIdMap.TryGetValue(button.AsHidType(), out keyString)) + { + keyString = gamepadButton.ToString(); + } - if (button.Type == ButtonType.StickId) - { - var stickInput = button.AsHidType(); + break; + case ButtonType.StickId: + var stickInput = button.AsHidType(); - if (!_stickInputIdMap.TryGetValue(button.AsHidType(), out keyString)) - { - keyString = stickInput.ToString(); - } + if (!_stickInputIdMap.TryGetValue(button.AsHidType(), out keyString)) + { + keyString = stickInput.ToString(); + } + + break; } return keyString; diff --git a/src/Ryujinx/UI/Helpers/KeyValueConverter.cs b/src/Ryujinx/UI/Helpers/KeyValueConverter.cs index 3d199fa8f6..cbcf16ab32 100644 --- a/src/Ryujinx/UI/Helpers/KeyValueConverter.cs +++ b/src/Ryujinx/UI/Helpers/KeyValueConverter.cs @@ -123,53 +123,54 @@ namespace Ryujinx.Ava.UI.Helpers public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string keyString = ""; + LocaleKeys localeKey; - if (value is Key key) + switch (value) { - if (_keysMap.TryGetValue(key, out LocaleKeys localeKey)) - { - if (OperatingSystem.IsMacOS()) + case Key key: + if (_keysMap.TryGetValue(key, out localeKey)) { - localeKey = localeKey switch + if (OperatingSystem.IsMacOS()) { - LocaleKeys.KeyControlLeft => LocaleKeys.KeyMacControlLeft, - LocaleKeys.KeyControlRight => LocaleKeys.KeyMacControlRight, - LocaleKeys.KeyAltLeft => LocaleKeys.KeyMacAltLeft, - LocaleKeys.KeyAltRight => LocaleKeys.KeyMacAltRight, - LocaleKeys.KeyWinLeft => LocaleKeys.KeyMacWinLeft, - LocaleKeys.KeyWinRight => LocaleKeys.KeyMacWinRight, - _ => localeKey - }; - } + localeKey = localeKey switch + { + LocaleKeys.KeyControlLeft => LocaleKeys.KeyMacControlLeft, + LocaleKeys.KeyControlRight => LocaleKeys.KeyMacControlRight, + LocaleKeys.KeyAltLeft => LocaleKeys.KeyMacAltLeft, + LocaleKeys.KeyAltRight => LocaleKeys.KeyMacAltRight, + LocaleKeys.KeyWinLeft => LocaleKeys.KeyMacWinLeft, + LocaleKeys.KeyWinRight => LocaleKeys.KeyMacWinRight, + _ => localeKey + }; + } - keyString = LocaleManager.Instance[localeKey]; - } - else - { - keyString = key.ToString(); - } - } - else if (value is GamepadInputId gamepadInputId) - { - if (_gamepadInputIdMap.TryGetValue(gamepadInputId, out LocaleKeys localeKey)) - { - 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(); - } + keyString = LocaleManager.Instance[localeKey]; + } + else + { + keyString = key.ToString(); + } + break; + case GamepadInputId gamepadInputId: + if (_gamepadInputIdMap.TryGetValue(gamepadInputId, out localeKey)) + { + keyString = LocaleManager.Instance[localeKey]; + } + else + { + keyString = gamepadInputId.ToString(); + } + break; + case StickInputId stickInputId: + if (_stickInputIdMap.TryGetValue(stickInputId, out localeKey)) + { + keyString = LocaleManager.Instance[localeKey]; + } + else + { + keyString = stickInputId.ToString(); + } + break; } return keyString;