| //--------------------------------------------------------  | 
| //    [Author]:           第二世界  | 
| //    [  Date ]:           Friday, September 21, 2018  | 
| //--------------------------------------------------------  | 
| using UnityEngine;  | 
| using System.Collections;  | 
| using UnityEngine.UI;  | 
|   | 
| using System;  | 
| using System.Collections.Generic;  | 
|   | 
| namespace vnxbqy.UI  | 
| {  | 
|   | 
|     public class DungenWHYJ : MonoBehaviour  | 
|     {  | 
|   | 
|         [SerializeField] Button m_WHYJButton;  | 
|         [SerializeField] GameObject m_Container_WHYJ;          | 
|         [SerializeField] ItemCell[] m_Items;  | 
|         [SerializeField] Image m_Rating;//评级  | 
|         DungeonModel model { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }  | 
|         List<int> ListRating = new List<int>();  | 
|         Dictionary<int, List<Item>> rewardItems = new Dictionary<int, List<Item>>();  | 
|         public void Init()  | 
|         {  | 
|             ListRating.Clear();  | 
|             var congfig = DungeonOpenTimeConfig.Get(51010).RewardRate;  | 
|             for (int i = 0; i < congfig.Length; i++)  | 
|             {  | 
|                 ListRating.Add(congfig[i]);  | 
|             }             | 
|             model.dungeonFightStageChangeEevent += dungeonFightStageChangeEevent;          | 
|             model.updateMissionEvent += updateMissionEvent;  | 
|             if (model.dungeonFightStage == DungeonFightStage.Prepare)  | 
|             {  | 
|                 m_Container_WHYJ.SetActive(true);  | 
|             }  | 
|             else  | 
|             {  | 
|                 m_Container_WHYJ.SetActive(false);  | 
|             }  | 
|             SetRatingImage();  | 
|             SetTranItemCell();  | 
|         }  | 
|   | 
|         public void Unit()  | 
|         {  | 
|             model.dungeonFightStageChangeEevent -= dungeonFightStageChangeEevent;  | 
|             model.updateMissionEvent -= updateMissionEvent;  | 
|         }  | 
|   | 
|         private void updateMissionEvent()  | 
|         {  | 
|             SetRatingImage();  | 
|             SetTranItemCell();  | 
|         }  | 
|   | 
|         private void Start()  | 
|         {  | 
|             m_WHYJButton.AddListener(OnClickButton);  | 
|         }  | 
|         private void OnEnable()  | 
|         {  | 
|              | 
|         }  | 
|         private void OnDisable()  | 
|         {  | 
|             | 
|         }  | 
|   | 
|         private void dungeonFightStageChangeEevent(DungeonFightStage obj)  | 
|         {  | 
|             if (obj == DungeonFightStage.Prepare)  | 
|             {  | 
|                 if (!m_Container_WHYJ.activeSelf)  | 
|                 {  | 
|                     m_Container_WHYJ.SetActive(true);  | 
|                 }  | 
|             }  | 
|             else if(obj == DungeonFightStage.Normal)  | 
|             {  | 
|                 if (m_Container_WHYJ.activeSelf)  | 
|                 {  | 
|                     m_Container_WHYJ.SetActive(false);  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         private void SetTranItemCell()  | 
|         {  | 
|             int lineID = model.mission.lineID;  | 
|   | 
|             if (!rewardItems.ContainsKey(lineID + 1))  | 
|             {  | 
|                 rewardItems.Add(lineID + 1, new List<Item>());  | 
|                 var WHYJConfig = WHYJRewardConfig.Get(lineID + 1);  | 
|                 for (int i = 0; i < WHYJConfig.Reward.Length; i++)  | 
|                 {  | 
|                     rewardItems[lineID + 1].Add(new Item()  | 
|                     {  | 
|                         id = WHYJConfig.Reward[i],  | 
|                         count = WHYJConfig.Quantity[i],  | 
|                     });  | 
|                 }  | 
|                 rewardItems[lineID + 1].Sort(Compare);  | 
|             }  | 
|   | 
|             List<Item> RewardList = rewardItems[lineID + 1];  | 
|   | 
|             for (int i = 0; i < m_Items.Length; i++)  | 
|             {  | 
|                 if (i < RewardList.Count)  | 
|                 {  | 
|                     m_Items[i].SetActive(true);  | 
|                     float value = GetRating() * RewardList[i].count;  | 
|                     ItemCellModel cellModel = new ItemCellModel(RewardList[i].id, true, (ulong)Math.Round(value,0));  | 
|                     m_Items[i].Init(cellModel);  | 
|                 }  | 
|                 else  | 
|                 {  | 
|                     m_Items[i].SetActive(false);  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         private int Compare(Item x, Item y)  | 
|         {  | 
|             var lhs_config = ItemConfig.Get(x.id);  | 
|             var rhs_config = ItemConfig.Get(y.id);  | 
|             if (lhs_config.ItemColor != rhs_config.ItemColor)  | 
|             {  | 
|                 return -lhs_config.ItemColor.CompareTo(rhs_config.ItemColor);  | 
|             }  | 
|             return 0;  | 
|         }  | 
|   | 
|         private void OnClickButton()  | 
|         {  | 
|             m_Container_WHYJ.SetActive(!m_Container_WHYJ.activeSelf);  | 
|         }  | 
|   | 
|         private float GetRating()  | 
|         {  | 
|             float Value = 1f;  | 
|             if (ListRating.Count < 4)  | 
|             {  | 
|                 return Value;  | 
|             }  | 
|             switch (model.mission.grade)  | 
|             {  | 
|                 case 1:  | 
|                     Value =(float)Math.Round((double)ListRating[4] / 100, 1);                  | 
|                     return Value;  | 
|                 case 2:  | 
|                     Value = (float)Math.Round((double)ListRating[3] / 100, 1);  | 
|                     return Value;  | 
|                 case 3:  | 
|                     Value = (float)Math.Round((double)ListRating[2] / 100, 1);  | 
|                     return Value;  | 
|                 case 4:  | 
|                     Value = (float)Math.Round((double)ListRating[1] / 100, 1);  | 
|                     return Value;  | 
|                 case 5:  | 
|                     Value = (float)Math.Round((double)ListRating[0] / 100, 1);  | 
|                     return Value;  | 
|                 default:  | 
|                     Value = (float)Math.Round((double)ListRating[0] / 100, 1);  | 
|                     return Value;  | 
|             }                | 
|         }  | 
|         private void SetRatingImage()  | 
|         {  | 
|             if (model.mission.Equals(default(DungeonMissionData)))  | 
|             {  | 
|                 return;  | 
|             }  | 
|             switch (model.mission.grade)  | 
|             {  | 
|                 case 1:  | 
|                     m_Rating.SetSprite("Rating_D");  | 
|                     break;  | 
|                 case 2:  | 
|                     m_Rating.SetSprite("Rating_C");  | 
|                     break;  | 
|                 case 3:  | 
|                     m_Rating.SetSprite("Rating_B");  | 
|                     break;  | 
|                 case 4:  | 
|                     m_Rating.SetSprite("Rating_A");  | 
|                     break;  | 
|                 case 5:  | 
|                     m_Rating.SetSprite("Rating_S");  | 
|                     break;  | 
|                 default:  | 
|                     m_Rating.SetSprite("Rating_S");  | 
|                     break;  | 
|             }  | 
|         }  | 
|     }  | 
| }  | 
|   | 
|   | 
|   |