diff --git a/BizHawk.MultiClient/BizHawk.MultiClient.csproj b/BizHawk.MultiClient/BizHawk.MultiClient.csproj index 629a487558..ca0a3ef6f9 100644 --- a/BizHawk.MultiClient/BizHawk.MultiClient.csproj +++ b/BizHawk.MultiClient/BizHawk.MultiClient.csproj @@ -335,6 +335,9 @@ Component + + Component + Form diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index c319d6a8f1..906325b995 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -1798,7 +1798,7 @@ namespace BizHawk.MultiClient return (int)label.Handle; } - public int forms_textbox(object form_handle, object caption = null, object width = null, object height = null, object X = null, object Y = null) + public int forms_textbox(object form_handle, object caption = null, object width = null, object height = null, object boxtype = null, object X = null, object Y = null) { LuaWinform form = GetForm(form_handle); if (form == null) @@ -1806,10 +1806,30 @@ namespace BizHawk.MultiClient return 0; } - TextBox textbox = new TextBox(); + LuaTextBox textbox = new LuaTextBox(); SetText(textbox, caption); SetLocation(textbox, X, Y); SetSize(textbox, X, Y); + if (boxtype != null) + { + switch (boxtype.ToString().ToUpper()) + { + case "HEX": + case "HEXADECIMAL": + textbox.SetType(BoxType.HEX); + break; + case "UNSIGNED": + case "UINT": + textbox.SetType(BoxType.UNSIGNED); + break; + case "NUMBER": + case "NUM": + case "SIGNED": + case "INT": + textbox.SetType(BoxType.SIGNED); + break; + } + } form.Controls.Add(textbox); return (int)textbox.Handle; } diff --git a/BizHawk.MultiClient/tools/LuaTextBox.cs b/BizHawk.MultiClient/tools/LuaTextBox.cs new file mode 100644 index 0000000000..f5294bd158 --- /dev/null +++ b/BizHawk.MultiClient/tools/LuaTextBox.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace BizHawk.MultiClient.tools +{ + enum BoxType { ALL, SIGNED, UNSIGNED, HEX }; + class LuaTextBox : TextBox + { + private BoxType boxType = BoxType.ALL; + + public void SetType(BoxType type) + { + boxType = type; + if (type != BoxType.ALL) + { + CharacterCasing = CharacterCasing.Upper; + } + else + { + CharacterCasing = CharacterCasing.Normal; + } + } + + protected override void OnKeyPress(KeyPressEventArgs e) + { + SpecificValueBox_KeyPress(this, e); + base.OnKeyPress(e); + } + + private void SpecificValueBox_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == '\b') return; + + switch (boxType) + { + case BoxType.UNSIGNED: + if (!InputValidate.IsValidUnsignedNumber(e.KeyChar)) + e.Handled = true; + break; + case BoxType.SIGNED: + if (!InputValidate.IsValidSignedNumber(e.KeyChar)) + e.Handled = true; + break; + case BoxType.HEX: + if (!InputValidate.IsValidHexNumber(e.KeyChar)) + e.Handled = true; + break; + } + } + } +}