diff --git a/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab b/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab index 20dc6316c..9f7ec8952 100644 --- a/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab +++ b/Assets/BossRoom/Prefabs/UI/PopupPanel.prefab @@ -733,7 +733,19 @@ MonoBehaviour: m_Calls: [] m_OnValueChanged: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 2699227445768669173} + m_TargetAssemblyTypeName: BossRoom.Visual.PopupPanel, BossRoom.Client + m_MethodName: SanitizePortText + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} m_CustomCaretColor: 0 m_SelectionColor: {r: 0.65882355, g: 0.80784315, b: 1, a: 0.7529412} @@ -968,7 +980,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 21.55 + m_fontSize: 18 m_fontSizeBase: 32 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -2069,7 +2081,19 @@ MonoBehaviour: m_Calls: [] m_OnValueChanged: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 2699227445768669173} + m_TargetAssemblyTypeName: BossRoom.Visual.PopupPanel, BossRoom.Client + m_MethodName: SanitizeInputText + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} m_CustomCaretColor: 0 m_SelectionColor: {r: 0.65882355, g: 0.80784315, b: 1, a: 0.7529412} @@ -2637,7 +2661,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 30.35 + m_fontSize: 35.05 m_fontSizeBase: 32 m_fontWeight: 400 m_enableAutoSizing: 1 diff --git a/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs b/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs index d3da238c6..13ddba261 100644 --- a/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs +++ b/Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs @@ -59,6 +59,8 @@ public class PopupPanel : MonoBehaviour private const string k_DefaultConfirmText = "OK"; + static readonly char[] k_InputFieldIncludeChars = new[] { '.', '_' }; + /// /// Setup this panel to be a panel view to have the player enter the game, complete with the ability for the player to /// cancel their input and requests. @@ -122,6 +124,45 @@ private void OnConfirmClick() m_ConfirmFunction.Invoke(m_InputField.text, portNum, m_NameDisplay.GetCurrentName(), (OnlineMode)m_OnlineModeDropdown.value); } + /// + /// Sanitize user port InputField box allowing only alphanumerics, plus any matching chars, if provided. + /// + /// string to sanitize. + /// Array of chars to include. + /// Sanitized text string. + static string Sanitize(string dirtyString, char[] includeChars = null) + { + var result = new StringBuilder(dirtyString.Length); + foreach (char c in dirtyString) + { + if (char.IsLetterOrDigit(c) || + (includeChars != null && Array.Exists(includeChars, includeChar => includeChar == c))) + { + result.Append(c); + } + } + + return result.ToString(); + } + + /// + /// Added to the InputField component's OnValueChanged callback for the Room/IP UI text. + /// + public void SanitizeInputText() + { + var inputFieldText = Sanitize(m_InputField.text, k_InputFieldIncludeChars); + m_InputField.text = inputFieldText; + } + + /// + /// Added to the InputField component's OnValueChanged callback for the Port UI text. + /// + public void SanitizePortText() + { + var inputFieldText = Sanitize(m_PortInputField.text); + m_PortInputField.text = inputFieldText; + } + /// /// Called when the user clicks on the cancel button when in a mode where the player is expecting to input something. /// Primary responsibility for this method is to reset the UI state.