diff --git a/Assets/Resources/Prefabs/UI/PRF_InputTopicItem.prefab b/Assets/Resources/Prefabs/UI/PRF_InputTopicItem.prefab index c93805cb..d739036b 100644 --- a/Assets/Resources/Prefabs/UI/PRF_InputTopicItem.prefab +++ b/Assets/Resources/Prefabs/UI/PRF_InputTopicItem.prefab @@ -251,6 +251,7 @@ GameObject: - component: {fileID: 6549079342170574329} - component: {fileID: 8772786093202997941} - component: {fileID: 8501740602063653259} + - component: {fileID: 1292074844791121958} m_Layer: 0 m_Name: InputField_Topic m_TagString: Untagged @@ -417,6 +418,19 @@ MonoBehaviour: isAlert: 0 m_InputValidator: {fileID: 0} m_ShouldActivateOnSelect: 1 +--- !u!114 &1292074844791121958 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5041442594409627906} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5cfbc3180aa0867408d6521529e5cac4, type: 3} + m_Name: + m_EditorClassIdentifier: + inputField: {fileID: 0} --- !u!1 &5562854965458769467 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Prefabs/UI/PRF_MQTTConnectionItem.prefab b/Assets/Resources/Prefabs/UI/PRF_MQTTConnectionItem.prefab index eec069f9..ad888827 100644 --- a/Assets/Resources/Prefabs/UI/PRF_MQTTConnectionItem.prefab +++ b/Assets/Resources/Prefabs/UI/PRF_MQTTConnectionItem.prefab @@ -942,6 +942,7 @@ GameObject: - component: {fileID: 1294127454145776225} - component: {fileID: 451971561218025839} - component: {fileID: 4531525069399822389} + - component: {fileID: 3782032704331303633} m_Layer: 0 m_Name: InputField_Port m_TagString: Untagged @@ -1108,6 +1109,19 @@ MonoBehaviour: isAlert: 0 m_InputValidator: {fileID: 0} m_ShouldActivateOnSelect: 1 +--- !u!114 &3782032704331303633 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2436487502178914535} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6f95cd07bc2246945965157693796194, type: 3} + m_Name: + m_EditorClassIdentifier: + inputField: {fileID: 0} --- !u!1 &3156314644122750241 GameObject: m_ObjectHideFlags: 0 @@ -2566,6 +2580,7 @@ GameObject: - component: {fileID: 6749344978886352018} - component: {fileID: 2032036743421240120} - component: {fileID: 7558723559091652677} + - component: {fileID: 8720815484175462745} m_Layer: 0 m_Name: InputField_Domain m_TagString: Untagged @@ -2732,3 +2747,16 @@ MonoBehaviour: isAlert: 0 m_InputValidator: {fileID: 0} m_ShouldActivateOnSelect: 1 +--- !u!114 &8720815484175462745 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8829135613240903342} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 318ad98d4b818194da00221ee69745cd, type: 3} + m_Name: + m_EditorClassIdentifier: + inputField: {fileID: 0} diff --git a/Assets/Scripts/Studio/UI/Elements/UI_MQTTConnection.cs b/Assets/Scripts/Studio/UI/Elements/UI_MQTTConnection.cs index d1d00857..45eee9e5 100644 --- a/Assets/Scripts/Studio/UI/Elements/UI_MQTTConnection.cs +++ b/Assets/Scripts/Studio/UI/Elements/UI_MQTTConnection.cs @@ -60,13 +60,23 @@ namespace Studio.UI onMQTTTest?.Invoke(); var domain = InputField_Domain.text; - var port = int.Parse(InputField_Port.text); + if (string.IsNullOrWhiteSpace(domain)) + { + return; + } + if (!int.TryParse(InputField_Port.text, out var port)) + { + return; + } List topics = new(); foreach (UI_InputTopicItem item in inputTopicItems) { var topic = item.InputField_Topic.text; - topics.Add(topic); + if (!string.IsNullOrWhiteSpace(topic)) + { + topics.Add(topic); + } } var tmpClient = new TemporaryMQTTClient(domain, port, topics, OnTopicTest, OnConnectedClient, OnErrorClient); panel_MQTTTestResult.Open(domain, port.ToString()); diff --git a/Assets/Scripts/Studio/UI/InputField.meta b/Assets/Scripts/Studio/UI/InputField.meta new file mode 100644 index 00000000..e0272e9f --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 01921bb75417df441acf53da6992d294 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs b/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs new file mode 100644 index 00000000..262b38dc --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs @@ -0,0 +1,15 @@ +namespace Studio.UI +{ + public class EnglishInputFieldValidator : InputFieldValidator + { + protected override char ValidateInput(string text, int charIndex, char addedChar) + { + if ((addedChar >= 'A' && addedChar <= 'Z') || (addedChar >= 'a' && addedChar <= 'z')) + { + return addedChar; + } + + return '\0'; + } + } +} diff --git a/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs.meta b/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs.meta new file mode 100644 index 00000000..eacd99c4 --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 5cfbc3180aa0867408d6521529e5cac4 \ No newline at end of file diff --git a/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs b/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs new file mode 100644 index 00000000..be493a07 --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs @@ -0,0 +1,20 @@ +using TMPro; +using UnityEngine; +using XRLib.UI; + +namespace Studio.UI +{ + [RequireComponent(typeof(TMP_InputField))] + public abstract class InputFieldValidator : UIBase + { + public TMP_InputField inputField; + + void Awake() + { + inputField = GetComponent(); + inputField.onValidateInput += ValidateInput; + } + + protected abstract char ValidateInput(string text, int charIndex, char addedChar); + } +} diff --git a/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs.meta b/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs.meta new file mode 100644 index 00000000..4adf497b --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 03b149247b27102428968cb5df010774 \ No newline at end of file diff --git a/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs b/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs new file mode 100644 index 00000000..bd325dff --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs @@ -0,0 +1,15 @@ +namespace Studio.UI +{ + public class NumericDotInputFieldValidator : InputFieldValidator + { + protected override char ValidateInput(string text, int charIndex, char addedChar) + { + if (char.IsDigit(addedChar) || addedChar == '.') + { + return addedChar; + } + + return '\0'; + } + } +} diff --git a/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs.meta b/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs.meta new file mode 100644 index 00000000..2339ace3 --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 318ad98d4b818194da00221ee69745cd \ No newline at end of file diff --git a/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs b/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs new file mode 100644 index 00000000..1fb91d1c --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs @@ -0,0 +1,15 @@ +namespace Studio.UI +{ + public class NumericInputFieldValidator : InputFieldValidator + { + protected override char ValidateInput(string text, int charIndex, char addedChar) + { + if (char.IsDigit(addedChar)) + { + return addedChar; + } + + return '\0'; + } + } +} diff --git a/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs.meta b/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs.meta new file mode 100644 index 00000000..a28da226 --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 6f95cd07bc2246945965157693796194 \ No newline at end of file