Bläddra i källkod

优化搭配赛当前排行榜数据的加载

hexiaojie 11 månader sedan
förälder
incheckning
0b83725235

+ 2 - 0
GameClient/Assets/Game/HotUpdate/Constant/ConstMessage.cs

@@ -262,5 +262,7 @@ namespace GFGGame
         public const string FieldWork_STARTCHANGE = "FieldWork_STARTCHANGE";
         //奖励界面关闭
         public const string REWARDVIEW_CLOTHER = "REWARDVIEW_CLOTHER";
+        //关卡排行榜数据加载完毕
+        public const string REQ_CURRENT_RANK = "REQ_CURRENT_RANK";
     }
 }

+ 1 - 0
GameClient/Assets/Game/HotUpdate/Controller/GameController.cs

@@ -283,6 +283,7 @@ namespace GFGGame
             ShopSProxy.ReqGetGrowthFundInfo().Coroutine();
             ActivityAfuGiftSProxy.GetSummerGiftInfo().Coroutine();
             //RoleInfoSProxy.ReqNewRoleGetSuitStatus().Coroutine();
+            MatchingCompetitionSproxy.ReqCurrentRank().Coroutine();
 
             int storageAutoPlay = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY);
             FightDataManager.Instance.autoPlay = storageAutoPlay <= 0 ? false : true;

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Data/MatchingPhotoHelper.cs

@@ -42,7 +42,7 @@ namespace GFGGame
             for (int i = 0; i < list.Count; i++)
             {
                 MatchingPhotoWorksData data = list[i];
-                if (data == null || data.Ntexture != null) continue;
+                if (data == null || data.Ntexture != null || !data.IsUp) continue;
                 int count = 0;
                 yield return DownloadPicture(data, count);
             }

+ 4 - 0
GameClient/Assets/Game/HotUpdate/Data/VO/MatchingCompetitionData.cs

@@ -44,6 +44,10 @@ namespace GFGGame
     //搭配赛作品信息
     public class MatchingPhotoWorksData
     {
+        public long RoleId { get; set; }
+
+        public bool IsUp = true;
+
         public JudgingRoundRoleInfo JudgingInfo;
         /// <summary>
         /// 照片数据

+ 70 - 8
GameClient/Assets/Game/HotUpdate/ServerProxy/MatchingCompetitionSproxy.cs

@@ -4,6 +4,7 @@ using FairyGUI;
 using UnityEngine;
 using UnityEngine.Networking;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace ET
 {
@@ -152,18 +153,78 @@ namespace GFGGame
             return true;
         }
         //获取当前排行榜
-        public static async ETTask<bool> ReqCurrentRank()
+        public static async ETTask<bool> ReqCurrentRank(bool isPushEvent = false)
         {
-            var response = (S2C_GetCurJudgingRoundRankList)await MessageHelper.SendToServer(new C2S_GetCurJudgingRoundRankList { });
+            var response =
+                (S2C_GetCurJudgingRoundRankList)await MessageHelper.SendToServer(new C2S_GetCurJudgingRoundRankList
+                    { });
             if (!(response is { Error: ErrorCode.ERR_Success })) return false;
-            MatchingCompetitionDataManager.Instance._currentRankList.Clear();
-            foreach (var item in response.JudgingRoundRoleInfoList)
+
+            //需要从缓存里清理的数据
+            List<long> delRoleIds = new List<long>();
+            foreach (var item in MatchingCompetitionDataManager.Instance._currentRankList)
             {
-                MatchingPhotoWorksData data = new MatchingPhotoWorksData();
-                data.JudgingInfo = item;
-                MatchingCompetitionDataManager.Instance._currentRankList.Add(data);
+                if (response.JudgingRoundRoleInfoList.All(a => a.RoleId != item.RoleId))
+                {
+                    delRoleIds.Add(item.RoleId);
+                }
+            }
+
+            //执行清理
+            if (delRoleIds.Count != 0)
+            {
+                foreach (var roleId in delRoleIds)
+                {
+                    var itemToRemove =
+                        MatchingCompetitionDataManager.Instance._currentRankList.FirstOrDefault(item =>
+                            item.RoleId == roleId);
+                    if (itemToRemove != null)
+                    {
+                        MatchingCompetitionDataManager.Instance._currentRankList.Remove(itemToRemove);
+                    }
+                }
+            }
+            
+            foreach (var judgingRoundRoleInfo in response.JudgingRoundRoleInfoList)
+            {
+                MatchingPhotoWorksData matchingPhotoWorksData =
+                    MatchingCompetitionDataManager.Instance._currentRankList.FirstOrDefault(a =>
+                        a.RoleId == judgingRoundRoleInfo.RoleId);
+                if (matchingPhotoWorksData == null)
+                {
+                    matchingPhotoWorksData = new MatchingPhotoWorksData
+                    {
+                        RoleId = judgingRoundRoleInfo.RoleId,
+                        JudgingInfo = judgingRoundRoleInfo
+                    };
+                    MatchingCompetitionDataManager.Instance._currentRankList.Add(matchingPhotoWorksData);
+                }
+                else
+                {
+                    int index = MatchingCompetitionDataManager.Instance._currentRankList
+                        .IndexOf(matchingPhotoWorksData);
+                    if (matchingPhotoWorksData.JudgingInfo != null)
+                    {
+                        string newTempFileName = StringUtil.GetUrlFileName(matchingPhotoWorksData.JudgingInfo.PictureTempUrl);
+                        string oldTempFileName = StringUtil.GetUrlFileName(judgingRoundRoleInfo.PictureTempUrl);
+                        matchingPhotoWorksData.IsUp = newTempFileName != oldTempFileName;
+                    }
+
+                    matchingPhotoWorksData.JudgingInfo = judgingRoundRoleInfo;
+                    matchingPhotoWorksData.RoleId = judgingRoundRoleInfo.RoleId;
+                    MatchingCompetitionDataManager.Instance._currentRankList[index] = matchingPhotoWorksData;
+                }
+            }
+
+            Timers.inst.StartCoroutine(
+                MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._currentRankList));
+
+            //推送事件
+            if (isPushEvent)
+            {
+                EventAgent.DispatchEvent(ConstMessage.REQ_CURRENT_RANK);
             }
-            Timers.inst.StartCoroutine(MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._currentRankList));
+
             return true;
         }
         //获取往期作品集
@@ -190,6 +251,7 @@ namespace GFGGame
             foreach (var item in response.JudgingRoundRoleInfoList)
             {
                 MatchingPhotoWorksData data = new MatchingPhotoWorksData();
+                data.RoleId = item.RoleId;
                 data.JudgingInfo = item;
                 MatchingCompetitionDataManager.Instance._BeforeRankList.Add(data);
             }

+ 29 - 0
GameClient/Assets/Game/HotUpdate/Utils/StringUtil.cs

@@ -66,6 +66,35 @@ namespace GFGGame
             return posValue;
 
         }
+
+        /// <summary>
+        /// 获取下载地址的文件名, 包含后缀
+        /// </summary>
+        /// <param name="url"></param>
+        /// <returns></returns>
+        public static string GetUrlFileName(string url)
+        {
+            try
+            {
+                // 创建一个 Uri 对象
+                Uri uri = new Uri(url);
+
+                // 获取 URL 的路径部分
+                string path = uri.AbsolutePath;
+
+                // 从路径中提取文件名
+                string fileName = System.IO.Path.GetFileName(path);
+
+                // // 获取不包含扩展名的文件名
+                // string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName);
+                return fileName;
+            }
+            catch
+            {
+                //增加容错
+                return url;
+            }
+        }
     }
 }
 

+ 2 - 0
GameClient/Assets/Game/HotUpdate/Views/MatchingCompetition/MatchingCompetitionRankView.cs

@@ -53,11 +53,13 @@ namespace GFGGame
         {
             base.AddEventListener();
             EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateView);
+            EventAgent.AddEventListener(ConstMessage.REQ_CURRENT_RANK, UpdateView);
         }
         protected override void RemoveEventListener()
         {
             base.RemoveEventListener();
             EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH, UpdateView);
+            EventAgent.RemoveEventListener(ConstMessage.REQ_CURRENT_RANK, UpdateView);
         }
         private void UpdateView()
         {

+ 16 - 5
GameClient/Assets/Game/HotUpdate/Views/MatchingCompetition/MatchingCompetitionUpLoadView.cs

@@ -264,14 +264,25 @@ namespace GFGGame
         }
         private async void OnClickBtnRank()
         {
-            bool result = await MatchingCompetitionSproxy.ReqCurrentRank();
-            if(result)
+            if (MatchingCompetitionDataManager.Instance._currentRankList.Count == 0)
             {
-                ViewManager.Show<MatchingCompetitionRankView>();
-            }   
+                //缓存里面不存在数据的话就进行同步加载数据
+                bool result = await MatchingCompetitionSproxy.ReqCurrentRank();
+                if (result)
+                {
+                    ViewManager.Show<MatchingCompetitionRankView>();
+                }
+                else
+                {
+                    PromptController.Instance.ShowFloatTextPrompt("暂无玩家上榜!");
+                }
+            }
             else
             {
-                PromptController.Instance.ShowFloatTextPrompt("暂无玩家上榜!");
+                //缓存里面存在数据,那也要再次请求服务器进行更新数据,只是用协程的形式,接着处理完数据后抛出事件
+                MatchingCompetitionSproxy.ReqCurrentRank(true).Coroutine();
+                //那就直接显示界面
+                ViewManager.Show<MatchingCompetitionRankView>();
             }
         }
         private async void OnClickBtnExchange()