Skip to content

Commit

Permalink
Allow for negative numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Sep 26, 2024
1 parent 4238d94 commit 42b3093
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/OWML.Common/Interfaces/Menus/IOWMLPopupInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ namespace OWML.Common.Interfaces.Menus
{
public interface IOWMLPopupInputMenu
{
public event PopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar;
public delegate bool InputPopupValidateCharEvent(string input, int charIndex, char addedChar);

public event InputPopupValidateCharEvent OnInputPopupValidateChar;

public void EnableMenu(bool value);

Expand Down
4 changes: 2 additions & 2 deletions src/OWML.ModHelper.Menus/CustomInputs/OWMLPopupInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class OWMLPopupInputMenu : PopupMenu, IOWMLPopupInputMenu
protected bool _virtualKeyboardOpen;

public event PopupInputMenu.InputPopupTextChangedEvent OnInputPopupTextChanged;
public event PopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar;
public event IOWMLPopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar;

public override void Awake()
{
Expand Down Expand Up @@ -158,7 +158,7 @@ private char OnValidateInput(string input, int charIndex, char addedChar)
Delegate[] invocationList = this.OnInputPopupValidateChar.GetInvocationList();
for (int i = 0; i < invocationList.Length; i++)
{
bool flag2 = (bool)invocationList[i].DynamicInvoke(new object[] { addedChar });
bool flag2 = (bool)invocationList[i].DynamicInvoke(new object[] { input, charIndex, addedChar });
flag = flag && flag2;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OWML.ModHelper.Menus/ModInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private bool OnValidateNumber() =>
float.TryParse(_inputMenu.GetInputText(), out _);

private bool OnValidateCharNumber(char c) =>
"0123456789.".Contains("" + c);
"0123456789.-".Contains(c.ToString());

protected override void OnPopupConfirm()
{
Expand Down
6 changes: 3 additions & 3 deletions src/OWML.ModHelper.Menus/NewMenuSystem/OptionsMenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,10 @@ public IOWMLTextEntryElement AddTextEntryInput(Menu menu, string label, string i

if (isNumeric)
{
textInputPopup.OnInputPopupValidateChar += c =>
textInputPopup.OnInputPopupValidateChar += (string input, int charIndex, char addedChar) =>
{
var text = textInputPopup.GetInputText() + c;
return Regex.IsMatch(text, @"^\d*[,.]?\d*$");
var text = input.Insert(charIndex, addedChar.ToString());
return Regex.IsMatch(text, @"^-?\d*[,.]?\d*$");
};
}

Expand Down

0 comments on commit 42b3093

Please sign in to comment.