Bladeren bron

好友报错

zhaoyang 2 jaren geleden
bovenliggende
commit
b713834b75

+ 10 - 7
GameClient/Assets/Game/HotUpdate/Data/FriendDataManager.cs

@@ -34,8 +34,8 @@ namespace GFGGame
         }
 
         private Dictionary<long, FriendInfoData> _friendDic = new Dictionary<long, FriendInfoData>();//好友列表
-        private List<FriendInfoData> _list = new List<FriendInfoData>();
-        public List<FriendInfoData> FriendDatas
+        private List<long> _list = new List<long>();
+        public List<long> FriendDatas
         {
             get
             {
@@ -49,14 +49,17 @@ namespace GFGGame
         }
         public void AddFriend(FriendInfoData roleInfo)
         {
-            if (_friendDic.ContainsKey(roleInfo.roleInfo.roleId)) return;
+            long roleId = roleInfo.roleInfo.roleId;
+            if (_list.IndexOf(roleId) >= 0) return;
+            _list.Add(roleId);
             _friendDic.Add(roleInfo.roleInfo.roleId, roleInfo);
             UpdateFriendList(true);
         }
         public void RemoveFriend(long roleId)
         {
-            if (_friendDic.ContainsKey(roleId))
+            if (_list.IndexOf(roleId) >= 0)
             {
+                _list.Remove(roleId);
                 _friendDic.Remove(roleId);
                 UpdateFriendList(true);
             }
@@ -102,11 +105,11 @@ namespace GFGGame
         }
         public void UpdateFriendList(bool sort)
         {
-            _list = _friendDic.Values.ToList<FriendInfoData>();
+            // _list = _friendDic.Values.ToList<FriendInfoData>();
             if (!sort) return;
-            _list.Sort((FriendInfoData a, FriendInfoData b) =>
+            _list.Sort((long a, long b) =>
             {
-                long count = b.roleInfo.offlineTimeSec - a.roleInfo.offlineTimeSec;
+                long count = _friendDic[b].roleInfo.offlineTimeSec - _friendDic[b].roleInfo.offlineTimeSec;
                 if (count > 0)
                 {
                     return -1;

+ 3 - 2
GameClient/Assets/Game/HotUpdate/Data/RedDotDataManager.cs

@@ -144,10 +144,11 @@ namespace GFGGame
         {
             if (FriendDataManager.Instance.Count >= FriendDataManager.Instance.maxGetPowerCount) return false;
 
-            List<FriendInfoData> friendInfos = FriendDataManager.Instance.FriendDatas;
+            List<long> friendInfos = FriendDataManager.Instance.FriendDatas;
             for (int i = 0; i < friendInfos.Count; i++)
             {
-                if (friendInfos[i].takeGiftState == ConstBonusStatus.CAN_GET)
+                FriendInfoData friendInfo = FriendDataManager.Instance.GetFriendDataById(friendInfos[i]);
+                if (friendInfo.takeGiftState == ConstBonusStatus.CAN_GET)
                 {
                     return true;
                 }

+ 9 - 7
GameClient/Assets/Game/HotUpdate/Views/Friend/FriendView.cs

@@ -85,7 +85,7 @@ namespace GFGGame
                 {
                     for (int i = 0; i < FriendDataManager.Instance.FriendDatas.Count; i++)
                     {
-                        if (_friendRoleId == FriendDataManager.Instance.FriendDatas[i].roleInfo.roleId)
+                        if (_friendRoleId == FriendDataManager.Instance.FriendDatas[i])
                         {
                             _ui.m_list.selectedIndex = i;
                             _ui.m_list.ScrollToView(i);
@@ -144,7 +144,8 @@ namespace GFGGame
 
         private void RenderListItem(int index, GObject obj)
         {
-            FriendInfoData friendInfo = FriendDataManager.Instance.FriendDatas[index];
+            long roleId = FriendDataManager.Instance.FriendDatas[index];
+            FriendInfoData friendInfo = FriendDataManager.Instance.GetFriendDataById(roleId);
 
             UI_ListItem item = UI_ListItem.Proxy(obj);
 
@@ -157,7 +158,7 @@ namespace GFGGame
             {
                 item.m_btnSend.onClick.Add(OnClickBtnSend);
             }
-            item.m_btnSend.data = friendInfo;
+            item.m_btnSend.data = roleId;
             item.target.data = index;
 
             UI_ListItem.ProxyEnd();
@@ -213,7 +214,7 @@ namespace GFGGame
             AlertUI.Show("是否删除好友?").SetLeftButton(true).SetRightButton(true, "确定", (object data) =>
             {
                 int index = _ui.m_list.selectedIndex;
-                long roleId = FriendDataManager.Instance.FriendDatas[index].roleInfo.roleId;
+                long roleId = FriendDataManager.Instance.FriendDatas[index];
                 FriendSProxy.ReqDeleteFriend(roleId).Coroutine();
             });
         }
@@ -245,9 +246,10 @@ namespace GFGGame
             if (_ui.m_list.numItems > 0)
             {
                 int childIndex = _ui.m_list.ItemIndexToChildIndex(_ui.m_list.selectedIndex);
+                if (childIndex < 0) return;
                 GButton item = _ui.m_list.GetChildAt(childIndex).asButton.GetChild("btnSend").asButton;
-                FriendInfoData friendInfo = item.data as FriendInfoData;
-                selectedIndex = FriendDataManager.Instance.FriendDatas.IndexOf(friendInfo);
+                long roleId = (long)item.data;
+                selectedIndex = FriendDataManager.Instance.FriendDatas.IndexOf(roleId);
             }
             _ui.m_list.numItems = FriendDataManager.Instance.FriendDatas.Count;
             _ui.m_list.selectedIndex = selectedIndex;
@@ -260,7 +262,7 @@ namespace GFGGame
         {
             if (index >= 0)
             {
-                _friendRoleId = FriendDataManager.Instance.FriendDatas[index].roleInfo.roleId;
+                _friendRoleId = FriendDataManager.Instance.FriendDatas[index];
 
                 OtherRoleInfoDetailData roleInfoDetail = await RoleInfoSProxy.ReqOtherRoleDetailInfo(_friendRoleId);
                 if (roleInfoDetail != null)