Update prevent inappropriate word
This commit is contained in:
@@ -9,6 +9,7 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using BrewMonster.Scripts;
|
||||
using BrewMonster.PerfectWorld.Scripts.Utility.ChatFilter;
|
||||
|
||||
namespace BrewMonster.UI
|
||||
{
|
||||
@@ -23,9 +24,12 @@ namespace BrewMonster.UI
|
||||
[SerializeField] private Button maleGenderButton;
|
||||
[SerializeField] private Button femaleGenderButton;
|
||||
[SerializeField] private TMP_InputField nameInputField;
|
||||
[SerializeField] private TMP_Text validationMessageText;
|
||||
[SerializeField] private Button confirmButton;
|
||||
[SerializeField] private Button cancelButton;
|
||||
[SerializeField] private Button backButton;
|
||||
[SerializeField] private CDlgMessageBox messageBoxPrefab;
|
||||
private CDlgMessageBox _messageBoxInstance;
|
||||
|
||||
private int _currentProfession = -1;
|
||||
private int _currentGender = -1;
|
||||
@@ -79,6 +83,7 @@ namespace BrewMonster.UI
|
||||
if (nameInputField != null)
|
||||
{
|
||||
nameInputField.onSubmit.AddListener((text) => { if (CanConfirm()) OnConfirmClicked(); });
|
||||
nameInputField.onValueChanged.AddListener((text) => ClearValidationError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +102,8 @@ namespace BrewMonster.UI
|
||||
nameInputField.Select();
|
||||
}
|
||||
|
||||
ClearValidationError();
|
||||
|
||||
UpdateConfirmButtonState();
|
||||
}
|
||||
|
||||
@@ -180,10 +187,8 @@ namespace BrewMonster.UI
|
||||
if (!CanConfirm())
|
||||
return;
|
||||
|
||||
string characterName = nameInputField != null ? nameInputField.text : "";
|
||||
if (string.IsNullOrWhiteSpace(characterName))
|
||||
if (!TryGetValidatedCharacterName(out string characterName))
|
||||
{
|
||||
Debug.LogWarning("Character name cannot be empty");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -214,6 +219,77 @@ namespace BrewMonster.UI
|
||||
_onCancel?.Invoke();
|
||||
}
|
||||
|
||||
private bool TryGetValidatedCharacterName(out string characterName)
|
||||
{
|
||||
characterName = nameInputField != null ? nameInputField.text.Trim() : string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(characterName))
|
||||
{
|
||||
ShowValidationError("Character name cannot be empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ChatFilterService.ContainsBadWord(characterName))
|
||||
{
|
||||
ShowValidationError("Character name contains inappropriate words.");
|
||||
return false;
|
||||
}
|
||||
|
||||
ClearValidationError();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ShowValidationError(string message)
|
||||
{
|
||||
if (validationMessageText != null)
|
||||
{
|
||||
validationMessageText.text = message;
|
||||
validationMessageText.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
var dialog = GetOrCreateMessageBoxInstance();
|
||||
if (dialog != null)
|
||||
{
|
||||
dialog.ShowMessageBoxYes("Invalid Character Name", message, null, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
CECUIManager.Instance?.ShowMessageBoxYes("Invalid Character Name", message, null, null);
|
||||
}
|
||||
Debug.LogWarning(message);
|
||||
}
|
||||
|
||||
private CDlgMessageBox GetOrCreateMessageBoxInstance()
|
||||
{
|
||||
if (_messageBoxInstance != null)
|
||||
{
|
||||
return _messageBoxInstance;
|
||||
}
|
||||
|
||||
if (messageBoxPrefab == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var canvas = GetComponentInParent<Canvas>();
|
||||
if (canvas == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_messageBoxInstance = Instantiate(messageBoxPrefab, canvas.transform);
|
||||
_messageBoxInstance.gameObject.SetActive(false);
|
||||
return _messageBoxInstance;
|
||||
}
|
||||
|
||||
private void ClearValidationError()
|
||||
{
|
||||
if (validationMessageText != null)
|
||||
{
|
||||
validationMessageText.text = string.Empty;
|
||||
validationMessageText.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanConfirm()
|
||||
{
|
||||
if (_currentProfession < 0 || _currentProfession >= (int)Profession.NUM_PROFESSION)
|
||||
|
||||
@@ -912,9 +912,11 @@ MonoBehaviour:
|
||||
maleGenderButton: {fileID: 4799972544958627575}
|
||||
femaleGenderButton: {fileID: 975101812964933518}
|
||||
nameInputField: {fileID: 5515740729786715052}
|
||||
validationMessageText: {fileID: 0}
|
||||
confirmButton: {fileID: 2058345032894912639}
|
||||
cancelButton: {fileID: 3605310658127377634}
|
||||
backButton: {fileID: 3605310658127377634}
|
||||
messageBoxPrefab: {fileID: 1069295583529170983, guid: 54cccb2c6a758a24183474cd385ccb2c, type: 3}
|
||||
--- !u!1 &2083311518824170680
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
Reference in New Issue
Block a user