Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions Assets/BossRoom/Prefabs/UI/PopupPanel.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class PopupPanel : MonoBehaviour

private const string k_DefaultConfirmText = "OK";

static readonly char[] k_InputFieldIncludeChars = new[] { '.', '_' };

/// <summary>
/// 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.
Expand Down Expand Up @@ -122,6 +124,45 @@ private void OnConfirmClick()
m_ConfirmFunction.Invoke(m_InputField.text, portNum, m_NameDisplay.GetCurrentName(), (OnlineMode)m_OnlineModeDropdown.value);
}

/// <summary>
/// Sanitize user port InputField box allowing only alphanumerics, plus any matching chars, if provided.
/// </summary>
/// <param name="dirtyString"> string to sanitize. </param>
/// <param name="includeChars"> Array of chars to include. </param>
/// <returns> Sanitized text string. </returns>
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();
}

/// <summary>
/// Added to the InputField component's OnValueChanged callback for the Room/IP UI text.
/// </summary>
public void SanitizeInputText()
{
var inputFieldText = Sanitize(m_InputField.text, k_InputFieldIncludeChars);
m_InputField.text = inputFieldText;
}

/// <summary>
/// Added to the InputField component's OnValueChanged callback for the Port UI text.
/// </summary>
public void SanitizePortText()
{
var inputFieldText = Sanitize(m_PortInputField.text);
m_PortInputField.text = inputFieldText;
}

/// <summary>
/// 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.
Expand Down