hch
2 天以前 6ae4b14b7fb6640ec805f070a1f0f691941c6917
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System.Text;
using UnityEngine;
using UnityEngine.UI;
 
/// <summary>
/// 修改公告界面
/// </summary>
public class GuildChangeBroadcastWin : UIBase
{
    [SerializeField] InputField inputField;
    [SerializeField] Button okBtn;
 
    protected override void InitComponent()
    {
        okBtn.SetListener(() =>
        {
            string msg = inputField.text;
            if (!CheckLimit(msg, out int errorCode))
            {
                ShowErrorTip(errorCode);
                return;
            }
            SendPack(msg);
            CloseWindow();
        });
    }
 
    protected override void OnPreOpen()
    {
        var guildInfo = PlayerDatas.Instance.fairyData.fairy;
        if (guildInfo == null)
            return;
        inputField.placeholder.GetComponent<Text>().text = string.IsNullOrEmpty(guildInfo.Broadcast) ? Language.Get("Guild_62") : guildInfo.Broadcast; ;
        inputField.text = string.Empty;
    }
 
    private void SendPack(string msg)
    {
        CA623_tagCMChangeFamilyBroadcast pack = new CA623_tagCMChangeFamilyBroadcast();
        pack.Msg = msg;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    private bool CheckLimit(string info, out int errorCode)
    {
        errorCode = 0;
        if (string.IsNullOrEmpty(info))
        {
            errorCode = 0;
            return false;
        }
 
        if (SatisfyLength(info))
        {
            errorCode = 1;
            return false;
        }
 
        if (DirtyWordConfig.IsDirtWord(info) || UIHelper.HasSpecCheckChat(info) || DirtyNameConfig.IsDirtName(info))
        {
            errorCode = 3;
            return false;
        }
        return true;
    }
 
    private bool SatisfyLength(string name)
    {
        int length = Encoding.Default.GetBytes(name).Length;
        int maxlength = inputField.characterLimit * 3;  //纯中文字数
        return length > maxlength;
    }
 
    private void ShowErrorTip(int _errorCode)
    {
        switch (_errorCode)
        {
            case 0:
                //空
                SysNotifyMgr.Instance.ShowTip("ChatInfoNoNull");
                break;
            case 1:
                // 长度过长
                SysNotifyMgr.Instance.ShowTip("NameError2", inputField.characterLimit);
                break;
            case 3:
                // 脏字
                SysNotifyMgr.Instance.ShowTip("NameSensitive");
                break;
        }
    }
}