//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Friday, September 21, 2018 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using TableConfig; using System; using System.Collections.Generic; namespace Snxxz.UI { public class DungenWHYJ : MonoBehaviour { [SerializeField] Button m_WHYJButton; [SerializeField] GameObject m_Container_WHYJ; [SerializeField] Transform m_Horizontal; [SerializeField] Image m_Rating;//评级 DungeonModel model { get { return ModelCenter.Instance.GetModel(); } } List ListRating = new List(); public void Init() { ListRating.Clear(); var congfig = Config.Instance.Get(51010).RewardRate; for (int i = 0; i < congfig.Length; i++) { ListRating.Add(congfig[i]); } model.dungeonFightStageChangeEevent -= dungeonFightStageChangeEevent; model.dungeonFightStageChangeEevent += dungeonFightStageChangeEevent; model.updateMissionEvent -= updateMissionEvent; model.updateMissionEvent += updateMissionEvent; if (model.dungeonFightStage == DungeonFightStage.Prepare) { m_Container_WHYJ.SetActive(true); } else { m_Container_WHYJ.SetActive(false); } SetRatingImage(); SetTranItemCell(); } 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; var WHYJConfig = Config.Instance.Get(lineID+1); int[] RewardList = ConfigParse.GetMultipleStr(WHYJConfig.Reward); int[] QuantityList = ConfigParse.GetMultipleStr(WHYJConfig.Quantity); for (int i = 0; i < m_Horizontal.childCount; i++) { if (i < RewardList.Length) { m_Horizontal.GetChild(i).gameObject.SetActive(true); ItemCell ItemCell = m_Horizontal.GetChild(i).GetComponent(); float value = GetRating() * QuantityList[i]; ItemCellModel cellModel = new ItemCellModel(RewardList[i], true, (ulong)Math.Round(value,0), 0); ItemCell.Init(cellModel); } else { m_Horizontal.GetChild(i).gameObject.SetActive(false); } } } 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() { 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; } } } }