113 lines
2.8 KiB
C#
113 lines
2.8 KiB
C#
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
using UnityEngine.UI;
|
|||
|
using GCGame;
|
|||
|
|
|||
|
public class ChangeNameBox : MonoBehaviour {
|
|||
|
|
|||
|
public InputField inputName;
|
|||
|
public Button ConfirmBtn;
|
|||
|
public Button CancelBtn;
|
|||
|
|
|||
|
public static ulong ItemGUID = 0;
|
|||
|
|
|||
|
public void OnConfirmBtnClick()
|
|||
|
{
|
|||
|
//判断输入的名字
|
|||
|
if (string.IsNullOrEmpty(inputName.text))
|
|||
|
{
|
|||
|
//请输入人物名称
|
|||
|
MessageBoxLogic.OpenOKBox(1281, 1000);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
string strCurName = "";
|
|||
|
// 过滤掉 0 非法字符
|
|||
|
foreach (char curChar in inputName.text)
|
|||
|
{
|
|||
|
if ((int)curChar != 0)
|
|||
|
{
|
|||
|
strCurName += curChar;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (string.IsNullOrEmpty(strCurName))
|
|||
|
{
|
|||
|
//请输入人物名称
|
|||
|
MessageBoxLogic.OpenOKBox(1281, 1000);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
int curCharNum = 0; // 英文算一个,中文算两个
|
|||
|
foreach (char curChar in strCurName)
|
|||
|
{
|
|||
|
if ((int)curChar >= 128)
|
|||
|
{
|
|||
|
|
|||
|
curCharNum += 2;
|
|||
|
}
|
|||
|
else if ((int)curChar >= 65 && (int)curChar <= 90)
|
|||
|
{
|
|||
|
curCharNum += 2;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
curCharNum++;
|
|||
|
}
|
|||
|
// curCharNum += 2;
|
|||
|
|
|||
|
if (char.IsWhiteSpace(curChar))
|
|||
|
{
|
|||
|
//名字不能包含空格
|
|||
|
MessageBoxLogic.OpenOKBox(1280, 1000);
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
if (curCharNum > 12)
|
|||
|
{
|
|||
|
// 名字过长
|
|||
|
MessageBoxLogic.OpenOKBox(1279, 1000);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (inputName.text.Contains("*"))
|
|||
|
{
|
|||
|
MessageBoxLogic.OpenOKBox(1278, 1000);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (inputName.text.Contains("*"))
|
|||
|
{
|
|||
|
MessageBoxLogic.OpenOKBox(1278, 1000);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (null == Utils.GetStrFilter(strCurName, (int)Games.GlobeDefine.GameDefine_Globe.STRFILTER_TYPE.STRFILTER_NAME))
|
|||
|
{
|
|||
|
//发协议
|
|||
|
CG_REQ_CHANGENAME reqChange = (CG_REQ_CHANGENAME)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_CHANGENAME);
|
|||
|
reqChange.SetNametype(1);
|
|||
|
reqChange.SetItemguid(ItemGUID);
|
|||
|
reqChange.SetChangename(inputName.text);
|
|||
|
|
|||
|
reqChange.SendPacket();
|
|||
|
|
|||
|
//RoleViewLogic.Instance().UpdateAttrRightView();
|
|||
|
OnCancelBtnClick();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// 包含非法字符
|
|||
|
MessageBoxLogic.OpenOKBox(1278, 1000);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void OnCancelBtnClick()
|
|||
|
{
|
|||
|
//关闭当前窗口
|
|||
|
UIManager.CloseUI(UIInfo.ChangeNameBox);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|