From e4d0b73c642c19c400bedd496b9c8bce42983d54 Mon Sep 17 00:00:00 2001
From: client_linchunjie <461730578@qq.com>
Date: 星期三, 15 八月 2018 15:50:28 +0800
Subject: [PATCH] 2562【前端】宗门试练兑换界面优化

---
 System/Dungeon/TrialExchangeWin.cs       |   30 +++++++
 System/Dungeon/TrialExchangeCell.cs      |    4 
 System/Dungeon/TrialExchangeBehaviour.cs |   18 +++-
 System/Dungeon/TrialDungeonModel.cs      |  133 ++++++++++++++++++++++++++++++--
 4 files changed, 168 insertions(+), 17 deletions(-)

diff --git a/System/Dungeon/TrialDungeonModel.cs b/System/Dungeon/TrialDungeonModel.cs
index d8d55fe..3f7b2c3 100644
--- a/System/Dungeon/TrialDungeonModel.cs
+++ b/System/Dungeon/TrialDungeonModel.cs
@@ -10,6 +10,7 @@
     {
         Dictionary<int, List<TrialExchangeConfig>> trialTokenExchangeDict = new Dictionary<int, List<TrialExchangeConfig>>();
         Dictionary<int, int> lineToTokenClassDict;
+        public Dictionary<int, List<int>> trialClassTokens = new Dictionary<int, List<int>>();
         public List<int> trialTokens = new List<int>();
         PlayerPackModel packModel { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
         DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
@@ -54,6 +55,16 @@
                 if (!trialTokens.Contains(configs[i].tokenId))
                 {
                     trialTokens.Add(configs[i].tokenId);
+                    List<int> _tokens;
+                    if (!trialClassTokens.TryGetValue(itemConfig.LV, out _tokens))
+                    {
+                        _tokens = new List<int>();
+                        trialClassTokens.Add(itemConfig.LV, _tokens);
+                    }
+                    if (!_tokens.Contains(configs[i].tokenId))
+                    {
+                        _tokens.Add(configs[i].tokenId);
+                    }
                 }
             }
             var funcConfig = ConfigManager.Instance.GetTemplate<FuncConfigConfig>("LineToItemStage");
@@ -67,6 +78,10 @@
         private void RefreshItemCountAct(PackType packType, int arg2, int itemId)
         {
             if (packType == PackType.rptItem && trialTokens.Contains(itemId))
+            {
+                UpdateRedpoint();
+            }
+            else if (packType == PackType.rptEquip)
             {
                 UpdateRedpoint();
             }
@@ -144,9 +159,14 @@
             {
                 NewBieCenter.Instance.RemoveNewBieGuide(TRIALEXCHANGE_GUIDE);
             }
-            CA32F_tagCMTrialExchange pak = new CA32F_tagCMTrialExchange();
-            pak.ID = (uint)_id;
-            GameNetSystem.Instance.SendInfo(pak);
+            var tokenConfig = ConfigManager.Instance.GetTemplate<ItemConfig>(config.tokenId);
+            ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
+                Language.Get("TokenUseConfirm", config.tokenCount, tokenConfig.ItemName, config.description), (bool isOk) =>
+                   {
+                       CA32F_tagCMTrialExchange pak = new CA32F_tagCMTrialExchange();
+                       pak.ID = (uint)_id;
+                       GameNetSystem.Instance.SendInfo(pak);
+                   });
             return true;
         }
 
@@ -182,6 +202,44 @@
             SysNotifyMgr.Instance.ShowTip("TrialExchangeLimit");
         }
 
+        public int EquipCompare(int _itemId)
+        {
+            var config = ConfigManager.Instance.GetTemplate<ItemConfig>(_itemId);
+            var equipPlace = config.EquipPlace;
+            if (equipPlace == 0)
+            {
+                return 0;
+            }
+            var singlepack = packModel.GetSinglePackModel(PackType.rptEquip);
+            if (singlepack == null)
+            {
+                return 1;
+            }
+            var equipItem = singlepack.GetItemModelByIndex(equipPlace);
+            if (equipItem == null)
+            {
+                return 1;
+            }
+            var compareConfig = ConfigManager.Instance.GetTemplate<ItemConfig>(equipItem.itemId);
+            if (compareConfig == null)
+            {
+                return 1;
+            }
+            if (compareConfig.ItemColor != config.ItemColor)
+            {
+                return compareConfig.ItemColor > config.ItemColor ? -1 : 1;
+            }
+            if (compareConfig.StarLevel != config.StarLevel)
+            {
+                return compareConfig.StarLevel > config.StarLevel ? -1 : 1;
+            }
+            if (compareConfig.LV != config.LV)
+            {
+                return compareConfig.LV > config.LV ? -1 : 1;
+            }
+            return 0;
+        }
+
         #region 绾㈢偣
         void UpdateRedpoint()
         {
@@ -199,22 +257,77 @@
 
         public bool TryGetSatisfyExchange(out int maxClass)
         {
-            var configs = ConfigManager.Instance.GetAllValues<TrialExchangeConfig>();
             maxClass = 0;
-            for (int i = 0; i < configs.Count; i++)
+            foreach (var _class in trialTokenExchangeDict.Keys)
             {
-                var count = GetTrialTokenCount(configs[i].tokenId);
-                if (count >= configs[i].tokenCount)
+                List<TrialExchangeConfig> list;
+                if (TryGetTrialExchanges(_class, out list))
                 {
-                    var itemConfig = ConfigManager.Instance.GetTemplate<ItemConfig>(configs[i].tokenId);
-                    if (itemConfig.LV > maxClass)
+                    for (int i = 0; i < list.Count; i++)
                     {
-                        maxClass = itemConfig.LV;
+                        if (SatisfyExchangeBetter(list[i].id))
+                        {
+                            var itemConfig = ConfigManager.Instance.GetTemplate<ItemConfig>(list[i].tokenId);
+                            if (itemConfig.LV > maxClass)
+                            {
+                                maxClass = itemConfig.LV;
+                            }
+                            break;
+                        }
                     }
                 }
             }
             return maxClass != 0;
         }
+
+        public bool SatisfyExchangeBetter(int _id)
+        {
+            var config = ConfigManager.Instance.GetTemplate<TrialExchangeConfig>(_id);
+            if (config == null)
+            {
+                return false;
+            }
+            var count = GetTrialTokenCount(config.tokenId);
+            if (count < config.tokenCount)
+            {
+                return false;
+            }
+            var exchangeItemConfig = ConfigManager.Instance.GetTemplate<ItemConfig>(config.exchangeItemID);
+            if (exchangeItemConfig.EquipPlace == 0)
+            {
+                return true;
+            }
+            if (EquipCompare(config.exchangeItemID) == 1)
+            {
+                return true;
+            }
+            return false;
+        }
+
+        public bool IsAnySatisfyExchangeBetterEquip(int _class, out int _id)
+        {
+            _id = -1;
+            List<TrialExchangeConfig> list;
+            if (TryGetTrialExchanges(_class, out list))
+            {
+                for (int i = 0; i < list.Count; i++)
+                {
+                    var itemConfig = ConfigManager.Instance.GetTemplate<ItemConfig>(list[i].exchangeItemID);
+                    if (SatisfyExchangeBetter(list[i].id) && itemConfig.EquipPlace != 0)
+                    {
+                        _id = list[i].id;
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        public bool IsAnySatisfyExchangeBetter()
+        {
+            int _class = 0;
+            return TryGetSatisfyExchange(out _class);
+        }
         #endregion
     }
 }
diff --git a/System/Dungeon/TrialExchangeBehaviour.cs b/System/Dungeon/TrialExchangeBehaviour.cs
index f374abb..64bdc8a 100644
--- a/System/Dungeon/TrialExchangeBehaviour.cs
+++ b/System/Dungeon/TrialExchangeBehaviour.cs
@@ -14,8 +14,12 @@
         [SerializeField] ItemBehaviour m_Token;
         [SerializeField] Button m_Exchange;
         [SerializeField] Image m_Redpoint;
+        [SerializeField] Image m_Up;
+        [SerializeField] Image m_Down;
         TrialDungeonModel model { get { return ModelCenter.Instance.GetModel<TrialDungeonModel>(); } }
         DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
+
+        PlayerPackModel packModel { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
 
         int trialExchangeId = 0;
         private void Awake()
@@ -38,12 +42,11 @@
                             ModelCenter.Instance.GetModel<GetItemPathModel>().SetChinItemModel(config.tokenId);
                         }
                     }
-                    model.ProcessTrialError(error);
                 }
             }
         }
 
-        public void Display(int id)
+        public void Display(int id, bool equipBetter = true)
         {
             trialExchangeId = id;
             var config = ConfigManager.Instance.GetTemplate<TrialExchangeConfig>(id);
@@ -58,16 +61,19 @@
             m_Item.Init(cellModel);
             m_Item.cellBtn.AddListener(() =>
             {
-                ItemAttrData itemAttrData = new ItemAttrData(config.exchangeItemID, true, (ulong)config.exchangeItemCount, -1, config.exchangeItemIsBind);
+                ItemAttrData itemAttrData = new ItemAttrData(config.exchangeItemID, true, (ulong)config.exchangeItemCount, -1, config.exchangeItemIsBind, true);
                 ModelCenter.Instance.GetModel<ItemTipsModel>().SetItemTipsModel(itemAttrData);
             });
             m_Description.text = config.description;
             m_Token.SetItem(config.tokenId, config.tokenCount);
             var count = model.GetTrialTokenCount(config.tokenId);
-            m_Token.count.color = UIHelper.GetUIColor(count >= config.tokenCount ? TextColType.Green : TextColType.Red, true);
+            m_Token.count.color = UIHelper.GetUIColor(count >= config.tokenCount ? TextColType.Green : TextColType.NavyBrown, true);
+            var equipCompare = model.EquipCompare(config.exchangeItemID);
+            m_Up.gameObject.SetActive(equipCompare == 1);
+            m_Down.gameObject.SetActive(equipCompare == -1);
 
-            m_Redpoint.gameObject.SetActive(count >= config.tokenCount
-                && dailyQuestModel.trialExchangeRedpoint.state == RedPointState.Simple);
+            var exchangeItemConfig = ConfigManager.Instance.GetTemplate<ItemConfig>(config.exchangeItemID);
+            m_Redpoint.gameObject.SetActive(count >= config.tokenCount && (equipBetter || exchangeItemConfig.EquipPlace == 0));
         }
     }
 }
diff --git a/System/Dungeon/TrialExchangeCell.cs b/System/Dungeon/TrialExchangeCell.cs
index 2d7b86e..f48d3f1 100644
--- a/System/Dungeon/TrialExchangeCell.cs
+++ b/System/Dungeon/TrialExchangeCell.cs
@@ -17,13 +17,15 @@
             {
                 return;
             }
+            int _betterEquipId = -1;
+            model.IsAnySatisfyExchangeBetterEquip(_class, out _betterEquipId);
             for (int i = 0; i < m_TrialExchanges.Length; i++)
             {
                 var index = _line * 4 + i;
                 if (index < list.Count)
                 {
                     m_TrialExchanges[i].gameObject.SetActive(true);
-                    m_TrialExchanges[i].Display(list[index].id);
+                    m_TrialExchanges[i].Display(list[index].id, _betterEquipId == list[index].id);
                 }
                 else
                 {
diff --git a/System/Dungeon/TrialExchangeWin.cs b/System/Dungeon/TrialExchangeWin.cs
index 92f6a4a..d2404fd 100644
--- a/System/Dungeon/TrialExchangeWin.cs
+++ b/System/Dungeon/TrialExchangeWin.cs
@@ -18,6 +18,8 @@
         [SerializeField] Text m_SelectClass;
         [SerializeField] Button m_SelectClassUp;
         [SerializeField] TrialSelectClassBehaviour m_SelectClassBehaviour;
+        [SerializeField] ItemBehaviour[] m_Tokens;
+        [SerializeField] Text[] m_TokenCounts;
         [SerializeField] Button m_Close;
 
         TrialDungeonModel model { get { return ModelCenter.Instance.GetModel<TrialDungeonModel>(); } }
@@ -128,6 +130,7 @@
         {
             DisplayTrialExchanges();
             DisplaySelectClass();
+            DisplayTokens();
         }
 
         void DisplayTrialExchanges()
@@ -170,6 +173,11 @@
             if (packtype == PackType.rptItem && model.trialTokens.Contains(itemId))
             {
                 m_Controller.m_Scorller.RefreshActiveCellViews();
+                DisplayTokens();
+            }
+            else if (packtype == PackType.rptEquip)
+            {
+                m_Controller.m_Scorller.RefreshActiveCellViews();
             }
         }
 
@@ -179,10 +187,32 @@
                 Language.Get("EquipSuitLV", Language.Get(StringUtility.Contact("Num_CHS_", model.selectEquipClass)));
         }
 
+        void DisplayTokens()
+        {
+            var list = model.trialClassTokens.ContainsKey(model.selectEquipClass) ? model.trialClassTokens[model.selectEquipClass] : null;
+            for (int i = 0; i < m_Tokens.Length; i++)
+            {
+                if (list != null && i < list.Count)
+                {
+                    m_Tokens[i].gameObject.SetActive(model.selectEquipClass != 1);
+                    if (model.selectEquipClass != 1)
+                    {
+                        m_Tokens[i].SetItem(list[i], 0);
+                        m_TokenCounts[i].text = model.GetTrialTokenCount(list[i]).ToString();
+                    }
+                }
+                else
+                {
+                    m_Tokens[i].gameObject.SetActive(false);
+                }
+            }
+        }
+
         private void SelectEquipClassEvent()
         {
             DisplayTrialExchanges();
             DisplaySelectClass();
+            DisplayTokens();
             bool _up = m_SelectClassBehaviour.gameObject.activeSelf;
             m_SelectClassUp.transform.localEulerAngles = Vector3.zero.SetZ(_up ? 0 : 180);
         }

--
Gitblit v1.8.0