121 lines
2.8 KiB
C#
121 lines
2.8 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Gameplay;
|
|
using Gameplay.Net;
|
|
using Gameplay.Utils;
|
|
using PhxhSDK;
|
|
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Object = UnityEngine.Object;
|
|
|
|
/// <summary>
|
|
/// 改名UI
|
|
/// </summary>
|
|
public class UI_WriteNameController : UIWindow
|
|
{
|
|
/// <summary>
|
|
/// 打开改名界面
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static async UniTask<UIWindow> Open()
|
|
{
|
|
CommonUtils.CaptureScreenshot(); // 截取当前屏幕截图
|
|
|
|
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_WriteName);
|
|
}
|
|
|
|
#region UI
|
|
/// <summary>
|
|
/// 高斯模糊遮罩
|
|
/// </summary>
|
|
private RawImage rawImageGaussianBlurMask;
|
|
/// <summary>
|
|
/// 确定按钮
|
|
/// </summary>
|
|
private Button buttonConfirm;
|
|
/// <summary>
|
|
/// 输入框
|
|
/// </summary>
|
|
private TMP_InputField inputField;
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 最大长度
|
|
/// </summary>
|
|
private const int MAX_LENGT = 8;
|
|
|
|
public override void OnInit()
|
|
{
|
|
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
|
|
buttonConfirm = GetComponent<Button>("Image_BG/Button_Confirm");
|
|
inputField = GetComponent<TMP_InputField>("Image_BG/InputField (TMP)");
|
|
|
|
rawImageGaussianBlurMask.texture = CommonUtils.screenTexture;
|
|
|
|
BindButton(buttonConfirm, OnConfirm);
|
|
}
|
|
|
|
protected override void OnShowWindow(object data = null)
|
|
{
|
|
base.OnShowWindow(data);
|
|
}
|
|
|
|
protected override void OnHideWindow()
|
|
{
|
|
|
|
|
|
base.OnHideWindow();
|
|
}
|
|
|
|
public override void OnRelease()
|
|
{
|
|
base.OnRelease();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置名字
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
private void SetName(string name)
|
|
{
|
|
NetHelper.SetPlayerName(name);
|
|
OnClose();
|
|
}
|
|
|
|
#region 回调方法
|
|
/// <summary>
|
|
/// 关闭
|
|
/// </summary>
|
|
private void OnClose()
|
|
{
|
|
CloseWindow();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 确定选择
|
|
/// </summary>
|
|
private void OnConfirm()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(inputField.text))
|
|
{
|
|
UITipsManager.ShowConfirmOne("提示", "输入名字无效", null);
|
|
return;
|
|
}
|
|
|
|
if (inputField.text.Length > MAX_LENGT)
|
|
{
|
|
UITipsManager.ShowConfirmOne("提示", $"长度在1-{MAX_LENGT}个字符", null);
|
|
return;
|
|
}
|
|
|
|
if (!MaskWord.Check(inputField.text)) // 屏蔽字校验
|
|
{
|
|
UITipsManager.ShowConfirmOne("提示", "输入的名字含有屏蔽字", null);
|
|
return;
|
|
}
|
|
|
|
UITipsManager.ShowConfirmTwo("tis", $"确定取名'{inputField.text}'吗?", (Action)(() => { SetName(inputField.text); }), null);
|
|
}
|
|
#endregion
|
|
} |