using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChatBubbleManager : GameSystemManager { public Dictionary chatBubbles = new Dictionary(); 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 bubblesIfo = new Dictionary(); public void UpdateBubbleState(HA717_tagMCChatBubbleBoxState package) { List list = null; if (serverInited) { list = new List(); 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; // } } } }