Эх сурвалжийг харах

添加好友离线时长,根据离线时长排序

leiyasi 1 жил өмнө
parent
commit
1bc8d6e816

+ 19 - 1
GameClient/Assets/Game/HotUpdate/Data/FriendDataManager.cs

@@ -103,13 +103,31 @@ namespace GFGGame
                 _friendDic[roleId].takeGiftState = takeState;
             }
         }
+
         public void UpdateFriendList(bool sort)
         {
             // _list = _friendDic.Values.ToList<FriendInfoData>();
             if (!sort) return;
+            // 按照时间戳大->小排序,时间戳为0的(在线)置顶
             _list.Sort((long a, long b) =>
             {
-                long count = _friendDic[b].roleInfo.offlineTimeSec - _friendDic[a].roleInfo.offlineTimeSec;
+                if(_friendDic[a].roleInfo.offlineTimeSec == 0 
+                && _friendDic[b].roleInfo.offlineTimeSec == 0)
+                {
+                    return 0;
+                }
+
+                if(_friendDic[a].roleInfo.offlineTimeSec == 0)
+                {
+                    return -1;
+                }
+
+                if (_friendDic[b].roleInfo.offlineTimeSec == 0)
+                {
+                    return 1;
+                }
+
+                long count = _friendDic[a].roleInfo.offlineTimeSec - _friendDic[b].roleInfo.offlineTimeSec;
                 if (count > 0)
                 {
                     return -1;

+ 3 - 3
GameClient/Assets/Game/HotUpdate/FairyGUI/GenCode/Friend/UI_ListItem.cs

@@ -14,7 +14,7 @@ namespace UI.Friend
         public GTextField m_txtName;
         public GButton m_btnSend;
         public GLoader m_loaState;
-        public GTextField m_txtName_2;
+        public GTextField m_txtTime;
         public const string URL = "ui://wez2ujnnpdeo9";
         public const string PACKAGE_NAME = "Friend";
         public const string RES_NAME = "ListItem";
@@ -69,7 +69,7 @@ namespace UI.Friend
             m_txtName = (GTextField)comp.GetChild("txtName");
             m_btnSend = (GButton)comp.GetChild("btnSend");
             m_loaState = (GLoader)comp.GetChild("loaState");
-            m_txtName_2 = (GTextField)comp.GetChild("txtName");
+            m_txtTime = (GTextField)comp.GetChild("txtTime");
         }
         public void Dispose(bool disposeTarget = false)
         {
@@ -80,7 +80,7 @@ namespace UI.Friend
             m_txtName = null;
             m_btnSend = null;
             m_loaState = null;
-            m_txtName_2 = null;
+            m_txtTime = null;
             if(disposeTarget && target != null)
             {
                 target.RemoveFromParent();

+ 34 - 1
GameClient/Assets/Game/HotUpdate/Views/Friend/FriendView.cs

@@ -3,6 +3,7 @@ using FairyGUI;
 using UI.Friend;
 using UI.CommonGame;
 using System.Collections;
+using ET;
 
 namespace GFGGame
 {
@@ -145,6 +146,7 @@ namespace GFGGame
             _ui.m_btnSendAll.text = RedDotDataManager.Instance.GetFriendGiftRed() ? "一键领取并赠送" : "一键赠送";
             _ui.m_txtPowerCount.SetVar("value", FriendDataManager.Instance.Count.ToString()).FlushVars();
             _ui.m_txtPowerCount.SetVar("maxValue", FriendDataManager.Instance.maxGetPowerCount.ToString()).FlushVars();
+
         }
 
 
@@ -155,6 +157,15 @@ namespace GFGGame
 
             UI_ListItem item = UI_ListItem.Proxy(obj);
 
+            if(friendInfo.roleInfo.offlineTimeSec > 0)
+            {
+                item.m_txtTime.visible = true;
+                item.m_txtTime.text = UpdateFriendOfflineTime(friendInfo.roleInfo.offlineTimeSec);
+            }
+            else
+            {
+                item.m_txtTime.visible = false;
+            }
             RoleInfoManager.Instance.UpdateHead(item.m_comHead, friendInfo.roleInfo.headId, friendInfo.roleInfo.headBorderId);
             item.m_txtName.text = friendInfo.roleInfo.roleName;
             item.m_txtLvl.text = friendInfo.roleInfo.roleLv.ToString();
@@ -201,7 +212,7 @@ namespace GFGGame
         {
             if (RedDotDataManager.Instance.GetFriendGiftRed() && FriendDataManager.Instance.Count < FriendDataManager.Instance.maxGetPowerCount)
             {
-                FriendSProxy.ReqTakeGiftFromAllFriend().Coroutine();
+                FriendSProxy.ReqTakeGiftFromAllFriend().Coroutine(); 
             }
             else
             {
@@ -332,5 +343,27 @@ namespace GFGGame
             RedDotController.Instance.SetComRedDot(_ui.m_btnSendAll, RedDotDataManager.Instance.GetFriendGiftRed());
             // RefreshView();
         }
+
+        private string UpdateFriendOfflineTime(long timeMsec)
+        {
+            string timeStr = TimeUtil.FormattingTimeTo_DD_HH_mm(TimeHelper.ClientNow() - timeMsec);
+            string[] timeTipArr = { "天", "小时", "分钟"};
+            string[] timeArr = timeStr.Split(':');
+            for(int i = 0; i < timeArr.Length; i++)
+            {
+                int num = int.Parse(timeArr[i]);
+                if (i == 0 && num > 30)
+                {
+                    return "超过30天";
+                }
+                else if (num > 0)
+                {
+
+                    return num + timeTipArr[i] + "前";
+                }
+            }
+
+            return "1分钟前";
+        }
     }
 }

BIN
GameClient/Assets/ResIn/UI/Friend/Friend_fui.bytes