yyl
17 小时以前 5d3366f2e0f687995eb7ad2107c4379fe7acd4e8
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
    
    public class ChatBubbleManager : GameSystemManager<ChatBubbleManager>
    {
        public Dictionary<int, ChatBubble> chatBubbles = new Dictionary<int, ChatBubble>();
 
        public event Action chatBubbleStateRefresh;
 
        bool serverInited = false;
        public override void Init()
        {
            PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
        }
 
        public override void Release()
        {
            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            bubblesIfo.Clear();
            serverInited = false;
        }
 
        public void OnPlayerLoginOk()
        {
            serverInited = true;
        }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
        {
            if (refreshType == PlayerDataType.ExAttr10 && serverInited)
            {
                SysNotifyMgr.Instance.ShowTip("ChangeBubbleSuccess");
            }
        }
 
        public bool TryGetBubble(int id, out ChatBubble bubble)
        {
            return chatBubbles.TryGetValue(id, out bubble);
        }
 
        public bool IsBubbleGot(int id)
        {
            ChatBubble bubble;
            if (TryGetBubble(id, out bubble))
            {
                // var config = ChatBubbleBoxConfig.Get(id);
                bool got = false;
 
                if (bubblesIfo.ContainsKey(id) && bubblesIfo[id].State == 1)
                {
                    got = true;
                }
                // if (!got && config.NeedLV != 0)
                // {
                //     return PlayerDatas.Instance.baseData.LV >= config.NeedLV;
                // }
                return got;
            }
            return false;
        }
 
        #region 服务端数据
 
        //聊天气泡框
        public struct BubbleBox
        {
            public int State;        //是否已激活
            public int EndTime;        //到期时间戳,0为永久
            public int Star;        //星级
        }
 
        public Dictionary<int, BubbleBox> bubblesIfo = new Dictionary<int, BubbleBox>();
 
        public void UpdateBubbleState(HA717_tagMCChatBubbleBoxState package)
        {
            List<int> list = null;
            if (serverInited)
            {
                list = new List<int>();
                foreach (var id in chatBubbles.Keys)
                {
                    if (!IsBubbleGot(id))
                    {
                        list.Add(id);
                    }
                }
            }
 
            for (int i = 0; i < package.Count; i++)
            {
                var info = package.BoxList[i];
                bubblesIfo[info.BoxID] = new BubbleBox()
                {
                    State = info.State,
                    EndTime = (int)info.EndTime,
                    Star = info.Star,
                };
            }
 
            if (serverInited)
            {
                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (IsBubbleGot(list[i]))
                        {
                            SendUseBubble(list[i]);
                            break;
                        }
                    }
                }
            }
            if (chatBubbleStateRefresh != null)
            {
                chatBubbleStateRefresh();
            }
        }
 
        public void SendUseBubble(int id)
        {
            if (!IsBubbleGot(id))
            {
                return;
            }
            if (id == PlayerDatas.Instance.baseData.bubbleId)
            {
                return;
            }
            CA230_tagCMSetChatBubbleBox pak = new CA230_tagCMSetChatBubbleBox();
            pak.BubbleBoxType = (byte)id;
            GameNetSystem.Instance.SendInfo(pak);
        }
        #endregion
 
        public struct ChatBubble
        {
            public int id;
            public RectOffset leftPadding;
            public RectOffset rifhtPadding;
            public Color32 color;
 
            public string GetBubbleIcon(bool left, ref bool isFlip)
            {
                return string.Empty;
                // var config = ChatBubbleBoxConfig.Get(id);
                // isFlip = false;
                // if (left)
                // {
                //     if (string.IsNullOrEmpty(config.leftBubbleIcon))
                //     {
                //         isFlip = true;
                //         return config.rightBubbleIcon;
                //     }
                //     return config.leftBubbleIcon;
                // }
                // else
                // {
                //     if (string.IsNullOrEmpty(config.rightBubbleIcon))
                //     {
                //         isFlip = true;
                //         return config.leftBubbleIcon;
                //     }
                //     return config.rightBubbleIcon;
                // }
            }
        }
    }