diff --git a/src/OWML.Common/Interfaces/Menus/IOWMLPopupInputMenu.cs b/src/OWML.Common/Interfaces/Menus/IOWMLPopupInputMenu.cs index 1115e085..4ba6edf9 100644 --- a/src/OWML.Common/Interfaces/Menus/IOWMLPopupInputMenu.cs +++ b/src/OWML.Common/Interfaces/Menus/IOWMLPopupInputMenu.cs @@ -1,12 +1,15 @@ -using UnityEngine.UI; +using System; +using UnityEngine.UI; namespace OWML.Common.Interfaces.Menus { public interface IOWMLPopupInputMenu { - public delegate bool InputPopupValidateCharEvent(string input, int charIndex, char addedChar); + [Obsolete("Use OnValidateChar instead.")] + public event PopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar; - public event InputPopupValidateCharEvent OnInputPopupValidateChar; + public delegate bool InputPopupValidateCharEvent(string input, int charIndex, char addedChar); + public event InputPopupValidateCharEvent OnValidateChar; public void EnableMenu(bool value); diff --git a/src/OWML.ModHelper.Menus/CustomInputs/OWMLPopupInputMenu.cs b/src/OWML.ModHelper.Menus/CustomInputs/OWMLPopupInputMenu.cs index 65f9b74a..8a58beb1 100644 --- a/src/OWML.ModHelper.Menus/CustomInputs/OWMLPopupInputMenu.cs +++ b/src/OWML.ModHelper.Menus/CustomInputs/OWMLPopupInputMenu.cs @@ -15,7 +15,10 @@ public class OWMLPopupInputMenu : PopupMenu, IOWMLPopupInputMenu protected bool _virtualKeyboardOpen; public event PopupInputMenu.InputPopupTextChangedEvent OnInputPopupTextChanged; - public event IOWMLPopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar; + public event IOWMLPopupInputMenu.InputPopupValidateCharEvent OnValidateChar; + + [Obsolete("Use OnValidateChar instead.")] + public event PopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar; public override void Awake() { @@ -152,20 +155,32 @@ private void OnTextFieldChanged() private char OnValidateInput(string input, int charIndex, char addedChar) { - bool flag = true; - if (this.OnInputPopupValidateChar != null) + var isValidCharacter = true; + if (OnInputPopupValidateChar != null) + { + var invocationList = OnInputPopupValidateChar.GetInvocationList(); + for (var i = 0; i < invocationList.Length; i++) + { + var flag2 = (bool)invocationList[i].DynamicInvoke(new object[] { addedChar }); + isValidCharacter = isValidCharacter && flag2; + } + } + + if (OnValidateChar != null && isValidCharacter) { - Delegate[] invocationList = this.OnInputPopupValidateChar.GetInvocationList(); - for (int i = 0; i < invocationList.Length; i++) + var invocationList = OnValidateChar.GetInvocationList(); + for (var i = 0; i < invocationList.Length; i++) { - bool flag2 = (bool)invocationList[i].DynamicInvoke(new object[] { input, charIndex, addedChar }); - flag = flag && flag2; + var flag2 = (bool)invocationList[i].DynamicInvoke(new object[] { input, charIndex, addedChar }); + isValidCharacter = isValidCharacter && flag2; } } - if (flag) + + if (isValidCharacter) { return addedChar; } + return '\0'; } diff --git a/src/OWML.ModHelper.Menus/NewMenuSystem/OptionsMenuManager.cs b/src/OWML.ModHelper.Menus/NewMenuSystem/OptionsMenuManager.cs index 688573c7..d4e3315b 100644 --- a/src/OWML.ModHelper.Menus/NewMenuSystem/OptionsMenuManager.cs +++ b/src/OWML.ModHelper.Menus/NewMenuSystem/OptionsMenuManager.cs @@ -717,7 +717,13 @@ public IOWMLTextEntryElement AddTextEntryInput(Menu menu, string label, string i if (isNumeric) { - textInputPopup.OnInputPopupValidateChar += (string input, int charIndex, char addedChar) => + textInputPopup.OnInputPopupValidateChar += c => + { + var text = textInputPopup.GetInputText() + c; + return Regex.IsMatch(text, @"^\d*[,.]?\d*$"); + }; + + textInputPopup.OnValidateChar += (string input, int charIndex, char addedChar) => { var text = input.Insert(charIndex, addedChar.ToString()); return Regex.IsMatch(text, @"^-?\d*[,.]?\d*$");