From 2a845f0babe52ac324b3cbe294db7dcec9346042 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期一, 22 十二月 2025 19:07:24 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.1.20:10010/r/Project_SG_scripts

---
 Main/System/Chat/ChatManager.cs |  141 ++++++++++++++++++++++++++--------------------
 1 files changed, 79 insertions(+), 62 deletions(-)

diff --git a/Main/System/Chat/ChatManager.cs b/Main/System/Chat/ChatManager.cs
index 573bab0..6630b36 100644
--- a/Main/System/Chat/ChatManager.cs
+++ b/Main/System/Chat/ChatManager.cs
@@ -17,7 +17,7 @@
     public Dictionary<int, ChatBubbleData> chatBubbles = new Dictionary<int, ChatBubbleData>();
     //<ChannelType,鏃堕棿鎴�>
     public Dictionary<int, int> chatChannelSendTime = new Dictionary<int, int>();
-    public event Action<ChatChannel, TalkData> OnUpdateTalkEvent;
+    public event Action<ChatChannel, TalkData, bool> OnUpdateTalkEvent;
     public event Action OnUpdateTalkCacheListEvent;
 
     public Dictionary<int, int> chatChannelCD = new Dictionary<int, int>();
@@ -27,7 +27,6 @@
     public Color32 areaOtherColor;
     public Dictionary<int, int[]> chatChannelBulletColorArrDict = new Dictionary<int, int[]>();
     public Dictionary<ChatChannel, Color32> chatChannelBulletColorDict = new Dictionary<ChatChannel, Color32>();
-
     public int[] defaultChannelBulletColorArr;
     public Color32 defaultChannelBulletColor;
     public int characterLimit;
@@ -48,45 +47,21 @@
 
         config = FuncConfigConfig.Get("TalkColor");
         areaMyColorArr = ConfigParse.GetMultipleStr<int>(config.Numerical1);
-        areaMyColor = new Color32()
-        {
-            r = (byte)(areaMyColorArr.Length > 0 ? areaMyColorArr[0] : 0),
-            g = (byte)(areaMyColorArr.Length > 1 ? areaMyColorArr[1] : 0),
-            b = (byte)(areaMyColorArr.Length > 2 ? areaMyColorArr[2] : 0),
-            a = (byte)(areaMyColorArr.Length > 3 ? areaMyColorArr[3] : 255),
-        };
+        areaMyColor = ParseColor32(areaMyColorArr);
 
         areaOtherColorArr = ConfigParse.GetMultipleStr<int>(config.Numerical2);
-        areaOtherColor = new Color32()
-        {
-            r = (byte)(areaOtherColorArr.Length > 0 ? areaOtherColorArr[0] : 0),
-            g = (byte)(areaOtherColorArr.Length > 1 ? areaOtherColorArr[1] : 0),
-            b = (byte)(areaOtherColorArr.Length > 2 ? areaOtherColorArr[2] : 0),
-            a = (byte)(areaOtherColorArr.Length > 3 ? areaOtherColorArr[3] : 255),
-        };
+        areaOtherColor = ParseColor32(areaOtherColorArr);
 
         chatChannelBulletColorArrDict = ConfigParse.ParseIntArrayDict(config.Numerical3);
         foreach (var kv in chatChannelBulletColorArrDict)
         {
             if (!IsValidChatChannel(kv.Key))
                 continue;
-            chatChannelBulletColorDict[(ChatChannel)kv.Key] = new Color32()
-            {
-                r = (byte)(kv.Value.Length > 0 ? kv.Value[0] : 0),
-                g = (byte)(kv.Value.Length > 1 ? kv.Value[1] : 0),
-                b = (byte)(kv.Value.Length > 2 ? kv.Value[2] : 0),
-                a = (byte)(kv.Value.Length > 3 ? kv.Value[3] : 0),
-            };
+            chatChannelBulletColorDict[(ChatChannel)kv.Key] = ParseColor32(kv.Value);
         }
 
         defaultChannelBulletColorArr = ConfigParse.GetMultipleStr<int>(config.Numerical4);
-        defaultChannelBulletColor = new Color32()
-        {
-            r = (byte)(defaultChannelBulletColorArr.Length > 0 ? defaultChannelBulletColorArr[0] : 0),
-            g = (byte)(defaultChannelBulletColorArr.Length > 1 ? defaultChannelBulletColorArr[1] : 0),
-            b = (byte)(defaultChannelBulletColorArr.Length > 2 ? defaultChannelBulletColorArr[2] : 0),
-            a = (byte)(defaultChannelBulletColorArr.Length > 3 ? defaultChannelBulletColorArr[3] : 255),
-        };
+        defaultChannelBulletColor = ParseColor32(defaultChannelBulletColorArr);
 
         config = FuncConfigConfig.Get("TalkLimit");
         characterLimit = int.Parse(config.Numerical1);
@@ -94,15 +69,20 @@
         config = FuncConfigConfig.Get("TalkBubble");
         sysBubbleID = int.Parse(config.Numerical1);
         sysBubbleColorArr = ConfigParse.GetMultipleStr<int>(config.Numerical2);
-        sysBubbleColor = new Color32()
-        {
-            r = (byte)(sysBubbleColorArr.Length > 0 ? sysBubbleColorArr[0] : 0),
-            g = (byte)(sysBubbleColorArr.Length > 1 ? sysBubbleColorArr[1] : 0),
-            b = (byte)(sysBubbleColorArr.Length > 2 ? sysBubbleColorArr[2] : 0),
-            a = (byte)(sysBubbleColorArr.Length > 3 ? sysBubbleColorArr[3] : 255),
-        };
+        sysBubbleColor = ParseColor32(sysBubbleColorArr);
 
         ParseChatBubbleConfig();
+    }
+
+    public Color32 ParseColor32(int[] colorArr)
+    {
+        return new Color32()
+        {
+            r = (byte)(colorArr.Length > 0 ? colorArr[0] : 0),
+            g = (byte)(colorArr.Length > 1 ? colorArr[1] : 0),
+            b = (byte)(colorArr.Length > 2 ? colorArr[2] : 0),
+            a = (byte)(colorArr.Length > 3 ? colorArr[3] : 255),
+        };
     }
 
     public override void Release()
@@ -113,19 +93,28 @@
         GuildManager.Instance.EnterOrQuitGuildEvent -= EnterOrQuitGuildEvent;
     }
 
-    //琚涪鍑�/閫�鍑哄伐浼氭椂锛屽垏鎹㈣亰澶╅閬�
+    //琚涪鍑�/閫�鍑哄伐浼氭椂锛屽垏鎹㈣亰澶╅閬�,娓呯悊缂撳瓨鐨勬棫鍏細淇℃伅
     private void EnterOrQuitGuildEvent(bool obj)
     {
         if (!obj)
         {
             nowChatChannel = ChatChannel.World;
             nowChatTab = ChatTab.World;
+            if (talkDict.ContainsKey(ChatChannel.Guild))
+            {
+                talkDict[ChatChannel.Guild].Clear();
+            }
+            if (lastTalkDataDict.ContainsKey(ChatChannel.Guild))
+            {
+                lastTalkDataDict.Remove(ChatChannel.Guild);
+            }
         }
     }
-    
+
     private void OnBeforePlayerDataInitializeEvent()
     {
         talkDict.Clear();
+        lastTalkDataDict.Clear();
         currentDay = -1;
         nowChatChannel = ChatChannel.World;
         nowChatTab = ChatTab.World;
@@ -235,20 +224,8 @@
                 top = config.RightOffset.Length > 2 ? config.RightOffset[2] : 0,
                 bottom = config.RightOffset.Length > 3 ? config.RightOffset[3] : 0,
             };
-            bubble.myColor = new Color32()
-            {
-                r = (byte)(config.MyColor.Length > 0 ? config.MyColor[0] : 0),
-                g = (byte)(config.MyColor.Length > 1 ? config.MyColor[1] : 0),
-                b = (byte)(config.MyColor.Length > 2 ? config.MyColor[2] : 0),
-                a = (byte)(config.MyColor.Length > 3 ? config.MyColor[3] : 255),
-            };
-            bubble.otherColor = new Color32()
-            {
-                r = (byte)(config.OtherColor.Length > 0 ? config.OtherColor[0] : 0),
-                g = (byte)(config.OtherColor.Length > 1 ? config.OtherColor[1] : 0),
-                b = (byte)(config.OtherColor.Length > 2 ? config.OtherColor[2] : 0),
-                a = (byte)(config.OtherColor.Length > 3 ? config.OtherColor[3] : 255),
-            };
+            bubble.myColor = ParseColor32(config.MyColor);
+            bubble.otherColor = ParseColor32(config.OtherColor);
             bubble.top = config.Top;
             chatBubbles.Add(config.ID, bubble);
         }
@@ -367,8 +344,36 @@
         OnDeleteTalkEvent?.Invoke(type);
     }
 
-    public int currentDay = -1;
-    public void AddTalkData(ChatChannel type, TalkData data, bool isSend)
+
+
+    //璁板綍鍚勪釜棰戦亾鏈�鍚庝竴鏉¤亰澶╄褰�
+    public Dictionary<ChatChannel, TalkData> lastTalkDataDict = new Dictionary<ChatChannel, TalkData>();
+    public bool TryGetLastTalkData(out ChatChannel type, out TalkData data)
+    {
+        type = ChatChannel.World;
+        data = null;
+        bool isFound = false;
+        foreach (var kvp in lastTalkDataDict)
+        {
+            ChatChannel channelType = kvp.Key;
+            TalkData talkData = kvp.Value;
+            bool isOpen = GetBulletSetting(channelType);
+            if (!isOpen)
+                continue;
+            if (channelType == ChatChannel.Guild && !IsTabOpen(ChatTab.Guild, false))
+                continue;
+            if (data == null || talkData.TalkTime > data.TalkTime)
+            {
+                isFound = true;
+                type = channelType;
+                data = talkData;
+            }
+        }
+        return isFound;
+    }
+
+
+    public void AddTalkData(ChatChannel type, TalkData data, bool isSendBullet)
     {
         //濡傛灉瓒呰繃闄愬埗鍏堝垹闄ゆ棫鏁版嵁
         TryDeleteTalkData(type);
@@ -377,13 +382,24 @@
             talkDict[type] = new List<TalkData>();
         }
         talkDict[type].Add(data);
-        if (isSend)
+
+        if (!lastTalkDataDict.ContainsKey(type) || lastTalkDataDict[type].TalkTime <= data.TalkTime)
         {
-            OnUpdateTalkEvent?.Invoke(type, data);
+            //灞曠ず鐨勬秷鎭笉鑳芥槸鏃ユ湡琛屽拰绯荤粺琛�
+            if (!data.isDate && !data.isSystem)
+            {
+                lastTalkDataDict[type] = data;
+            }
+        }
+
+        if (isSendBullet)
+        {
+            OnUpdateTalkEvent?.Invoke(type, data, isSendBullet);
         }
     }
 
-    public bool TryAddDate(int allSeconds, ChatChannel type, bool isSend)
+    public int currentDay = -1;
+    public bool TryAddDate(int allSeconds, ChatChannel type, bool isSendBullet)
     {
         DateTime talkTime = TimeUtility.GetTime((uint)allSeconds);
         if (talkTime.Day != currentDay)
@@ -395,17 +411,17 @@
                 isDate = true,
                 Content = Language.Get("Chat09", talkTime.Month, talkTime.Day),
                 TalkTime = (uint)allSeconds,
-            }, isSend);
+            }, isSendBullet);
             return true;
         }
         return false;
     }
 
-    public void AddSysData(string msg, ArrayList infoList, ChatChannel type, bool isSend)
+    public void AddSysData(string msg, ArrayList infoList, ChatChannel type, bool isSendBullet)
     {
         int allSeconds = TimeUtility.AllSeconds;
         // 濡傛灉闅斿ぉ,澧炲姞鏃ユ湡琛�
-        TryAddDate(allSeconds, type, isSend);
+        TryAddDate(allSeconds, type, isSendBullet);
 
         if (!talkDict.ContainsKey(type))
         {
@@ -419,7 +435,7 @@
             BubbleBox = 1,
             TalkTime = (uint)allSeconds,
             InfoList = new ArrayList(infoList),
-        }, isSend);
+        }, isSendBullet);
     }
 
     public void UpdateTalk(HB310_tagMCTalk vNetData)
@@ -592,6 +608,7 @@
 
     private Dictionary<ChatChannel, bool> bulletSettingDict = new Dictionary<ChatChannel, bool>();
 
+
     private string settingsKey { get { return StringUtility.Concat("BulletChatSettings_", PlayerDatas.Instance.PlayerId.ToString()); } }
 
     // 璁剧疆鐗瑰畾棰戦亾鐨勫脊骞曞紑鍏崇姸鎬�

--
Gitblit v1.8.0