少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, September 13, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System;
using System.Text.RegularExpressions;
 
namespace vnxbqy.UI
{
 
    public class ChatFriend : MonoBehaviour
    {
        [SerializeField] ScrollerController m_Controller;
 
        private List<ChatFriendData> chatList = null;
 
        [SerializeField] RichText destText;
        [SerializeField] RichText destSysText;
        private bool open = false;
        public bool IsOpen
        {
            get { return open; }
        }
 
        private void Awake()
        {
            m_Controller.OnGetDynamicSize += OnGetChatDynamicSize;
            ChatCtrl.Inst.SetChatFreind(this);
        }
 
        #region 计算动态宽度长度
        private bool OnGetChatDynamicSize(ScrollerDataType type, int index, out float height)
        {
            height = 90;
            if (chatList == null || index >= chatList.Count)
            {
                return false;
            }
            ChatData chat = chatList[index];
            if (type == ScrollerDataType.Extra2)
            {
                height = chat.content.Equals(string.Empty) ? 90 : 120;
            }
            else if (type == ScrollerDataType.Tail)
            {
                height = 30;
            }
            float width = 0;
            OnGetChatDynamicHeight(chat.content, ref height, ref width, type, chat.infoList);
            return true;
        }
        private void OnGetChatDynamicHeight(string content, ref float height, ref float width, ScrollerDataType type, ArrayList infoList = null)
        {
            if (type == ScrollerDataType.Tail)
            {
                destSysText.SetExtenalData(infoList);
                destSysText.text = content;
                width = destSysText.preferredWidth;
                height += Mathf.Max(0, destSysText.preferredHeight - 23);
            }
            else
            {
                destText.SetExtenalData(infoList);
                destText.text = content;
                width = destText.preferredWidth;
                height += Mathf.Max(0, destText.preferredHeight - 30);
            }
        }
        #endregion
 
        private void OnEnable()
        {
            ChatCtrl.OnRefreshPteChat += OnRefreshPteChat;
            RefreshChatInfo();
            open = true;
            ChatCtrl.Inst.lockUpdate = true;
            OnSetLock();
        }
 
        public void OnSetLock()
        {
            m_Controller.lockType = ChatCtrl.Inst.lockUpdate ? EnhanceLockType.LockVerticalBottom : EnhanceLockType.KeepVertical;
            if (ChatCtrl.Inst.lockUpdate)
            {
                m_Controller.ResetScrollPos();
            }
        }
 
        private void OnDisable()
        {
            ChatCtrl.OnRefreshPteChat -= OnRefreshPteChat;
            open = false;
        }
 
        public void RefreshChatInfo()
        {
            int id = ChatCtrl.Inst.PteChatID;
            chatList = ChatCtrl.Inst.GetChatInfo(id);
            m_Controller.Refresh();
            if (chatList != null)
            {
                for (int i = 0; i < chatList.Count; i++)
                {
                    if (chatList[i].soundTick != 0)
                    {
                        m_Controller.AddCell(ScrollerDataType.Extra2, i);
                        continue;
                    }
                    if (Regex.IsMatch(chatList[i].content, ChatCtrl.KILL_IDENTIFY))
                    {
                        m_Controller.AddCell(ScrollerDataType.Tail, i);
                        continue;
                    }
                    if (chatList[i].player == PlayerDatas.Instance.baseData.PlayerID)
                    {
                        m_Controller.AddCell(ScrollerDataType.Header, i);
                    }
                    else
                    {
                        m_Controller.AddCell(ScrollerDataType.Normal, i);
                    }
                }
            }
            m_Controller.Restart();
        }
 
        private void OnRefreshPteChat(ChatFriendData data)
        {
            if (data == null)
            {
                return;
            }
            if (data.toPlayer != ChatCtrl.Inst.PteChatID && data.player != ChatCtrl.Inst.PteChatID)
            {
                return;
            }
            if (data.player == PlayerDatas.Instance.baseData.PlayerID)
            {
 
            }
            RefreshChatInfo();
        }
    }
 
}