NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_EditIntroductionControll...

127 lines
2.9 KiB
C#
Raw Normal View History

2024-10-11 16:04:28 +08:00
using Cysharp.Threading.Tasks;
2024-10-11 18:17:51 +08:00
using Framework;
2024-10-11 16:04:28 +08:00
using Gameplay;
2024-10-11 18:17:51 +08:00
using Gameplay.Net;
2024-10-11 16:04:28 +08:00
using TMPro;
using UnityEngine.UI;
using static UnityEngine.Rendering.DebugUI;
2024-10-11 16:04:28 +08:00
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
public class UI_EditIntroductionController : UIWindow
{
//UI GameObj
///Auto Gen Start///
public Image Image_Bg;
public Button Button_Close;
public TMP_Text Text_Title;
public TMP_InputField InputField_Introduction;
public TMP_Text Text_Tip;
public Button Button_Confirm;
public RawImage rawImageGaussianBlurMask;
2024-10-11 19:15:56 +08:00
///Auto Gen End///
2024-10-11 16:04:28 +08:00
private int signMaxLen = 100;
public int maxNewlines = 1; // 最大换行符数量
// deal with input data
public override void PreLoad(object data = null)
2024-10-11 19:15:56 +08:00
{
}
2024-10-11 16:04:28 +08:00
public static async UniTask<UIWindow> Open()
{
2024-10-11 19:15:56 +08:00
CommonUtils.CaptureScreenshot(); // 截取当前屏幕截图
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_EditIntroduction);
2024-10-11 16:04:28 +08:00
}
2024-10-11 19:15:56 +08:00
2024-10-11 16:04:28 +08:00
// Use this for initialization
public override void OnInit()
{
//bind UI GameObj
UI_EditIntroductionBinder.GetComponents(this);
2024-10-11 19:15:56 +08:00
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
rawImageGaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
2024-10-11 16:04:28 +08:00
2024-10-11 19:15:56 +08:00
EventManager.Instance.Register(EventManager.EventName.PlayerInfoUpdate, OnChangeInfo);
2024-10-11 16:04:28 +08:00
InputField_Introduction.characterLimit = signMaxLen;
InputField_Introduction.onValueChanged.AddListener(ValidateInput);
2024-10-11 19:15:56 +08:00
BindButton(Button_Close, OnCloseClick);
2024-10-11 16:04:28 +08:00
BindButton(Button_Confirm, OnConfirmClick);
}
//invoke when open window
protected override void OnShowWindow(object data = null)
{
2024-10-11 19:15:56 +08:00
2024-10-11 16:04:28 +08:00
}
2024-10-11 19:15:56 +08:00
2024-10-11 16:04:28 +08:00
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
2024-10-11 19:15:56 +08:00
2024-10-11 16:04:28 +08:00
}
2024-10-11 19:15:56 +08:00
2024-10-11 16:04:28 +08:00
//invoke when close window
protected override void OnHideWindow()
{
2024-10-11 19:15:56 +08:00
2024-10-11 16:04:28 +08:00
}
2024-10-11 19:15:56 +08:00
2024-10-11 16:04:28 +08:00
//invoke when destroy
public override void OnRelease()
{
2024-10-11 19:15:56 +08:00
base.OnRelease();
2024-10-11 18:17:51 +08:00
EventManager.Instance.Unregister(EventManager.EventName.PlayerInfoUpdate, OnChangeInfo);
InputField_Introduction.onValueChanged.RemoveListener(ValidateInput);
}
2024-10-11 16:04:28 +08:00
2024-10-11 19:15:56 +08:00
protected override void OnCloseClick()
{
base.OnCloseClick();
2024-10-11 16:04:28 +08:00
CloseWindow();
2024-10-11 19:15:56 +08:00
}
void OnConfirmClick()
{
2024-10-11 16:04:28 +08:00
DebugUtil.Log("修改个性签名:" + InputField_Introduction.text);
2024-10-11 18:17:51 +08:00
NetHelper.SetPlayerIntroduction(InputField_Introduction.text);
2024-10-11 19:15:56 +08:00
}
2024-10-11 18:17:51 +08:00
void ValidateInput(string input)
{
int newlineCount = 0;
string sanitizedInput = "";
foreach (char c in input)
{
if (c == '\n' || c == '\r')
{
if (newlineCount < maxNewlines)
{
sanitizedInput += c;
newlineCount++;
}
}
else
{
sanitizedInput += c;
}
}
if (input != sanitizedInput)
{
InputField_Introduction.text = sanitizedInput;
}
}
void OnChangeInfo()
2024-10-11 18:17:51 +08:00
{
CloseWindow();
}
2024-10-11 16:04:28 +08:00
}