From 12cbacffca7b04a7f377e8fdf09ce78445351913 Mon Sep 17 00:00:00 2001
From: Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com>
Date: Fri, 1 Sep 2023 19:08:42 +0100
Subject: [PATCH] Fix numeric SWKB validation (#5627)
* Fix numeric swkbd validation
* GTK
---
src/Ryujinx.Ava/Assets/Locales/en_US.json | 2 +-
.../UI/Applet/SwkbdAppletDialog.axaml.cs | 6 +++---
.../Applets/SoftwareKeyboard/KeyboardMode.cs | 4 ++--
.../NumericCharacterValidation.cs | 17 +++++++++++++++++
src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs | 6 +++---
5 files changed, 26 insertions(+), 9 deletions(-)
create mode 100644 src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/NumericCharacterValidation.cs
diff --git a/src/Ryujinx.Ava/Assets/Locales/en_US.json b/src/Ryujinx.Ava/Assets/Locales/en_US.json
index efd3187ad..35a69b8f5 100644
--- a/src/Ryujinx.Ava/Assets/Locales/en_US.json
+++ b/src/Ryujinx.Ava/Assets/Locales/en_US.json
@@ -544,7 +544,7 @@
"SwkbdMinCharacters": "Must be at least {0} characters long",
"SwkbdMinRangeCharacters": "Must be {0}-{1} characters long",
"SoftwareKeyboard": "Software Keyboard",
- "SoftwareKeyboardModeNumbersOnly": "Must be numbers only",
+ "SoftwareKeyboardModeNumeric": "Must be 0-9 or '.' only",
"SoftwareKeyboardModeAlphabet": "Must be non CJK-characters only",
"SoftwareKeyboardModeASCII": "Must be ASCII text only",
"DialogControllerAppletMessagePlayerRange": "Application requests {0} player(s) with:\n\nTYPES: {1}\n\nPLAYERS: {2}\n\n{3}Please open Settings and reconfigure Input now or press Close.",
diff --git a/src/Ryujinx.Ava/UI/Applet/SwkbdAppletDialog.axaml.cs b/src/Ryujinx.Ava/UI/Applet/SwkbdAppletDialog.axaml.cs
index 210fc9a2b..5a4cd855f 100644
--- a/src/Ryujinx.Ava/UI/Applet/SwkbdAppletDialog.axaml.cs
+++ b/src/Ryujinx.Ava/UI/Applet/SwkbdAppletDialog.axaml.cs
@@ -136,10 +136,10 @@ namespace Ryujinx.Ava.UI.Controls
string localeText;
switch (mode)
{
- case KeyboardMode.NumbersOnly:
- localeText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.SoftwareKeyboardModeNumbersOnly);
+ case KeyboardMode.Numeric:
+ localeText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.SoftwareKeyboardModeNumeric);
validationInfoText = string.IsNullOrEmpty(validationInfoText) ? localeText : string.Join("\n", validationInfoText, localeText);
- _checkInput = text => text.All(char.IsDigit);
+ _checkInput = text => text.All(NumericCharacterValidation.IsNumeric);
break;
case KeyboardMode.Alphabet:
localeText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.SoftwareKeyboardModeAlphabet);
diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMode.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMode.cs
index 917e1f9e1..c2dfc31a3 100644
--- a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMode.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/KeyboardMode.cs
@@ -11,9 +11,9 @@
Default = 0,
///
- /// Only numbers allowed.
+ /// Only 0-9 or '.' allowed.
///
- NumbersOnly = 1,
+ Numeric = 1,
///
/// Only ASCII characters allowed.
diff --git a/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/NumericCharacterValidation.cs b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/NumericCharacterValidation.cs
new file mode 100644
index 000000000..d72b68eae
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/NumericCharacterValidation.cs
@@ -0,0 +1,17 @@
+using System.Text.RegularExpressions;
+
+namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
+{
+ public static partial class NumericCharacterValidation
+ {
+ public static bool IsNumeric(char value)
+ {
+ Regex regex = NumericRegex();
+
+ return regex.IsMatch(value.ToString());
+ }
+
+ [GeneratedRegex("[0-9]|.")]
+ private static partial Regex NumericRegex();
+ }
+}
diff --git a/src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs b/src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs
index 1ed08250f..c1f3d77c1 100644
--- a/src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs
+++ b/src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs
@@ -90,9 +90,9 @@ namespace Ryujinx.Ui.Applet
switch (mode)
{
- case KeyboardMode.NumbersOnly:
- _validationInfoText += "Must be numbers only.";
- _checkInput = text => text.All(char.IsDigit);
+ case KeyboardMode.Numeric:
+ _validationInfoText += "Must be 0-9 or '.' only.";
+ _checkInput = text => text.All(NumericCharacterValidation.IsNumeric);
break;
case KeyboardMode.Alphabet:
_validationInfoText += "Must be non CJK-characters only.";