| //--------------------------------------------------------  | 
| //    [Author]:           第二世界  | 
| //    [  Date ]:           Wednesday, September 20, 2017  | 
| //--------------------------------------------------------  | 
|   | 
| using System;  | 
| using System.Collections;  | 
| using System.Collections.Generic;  | 
| using UnityEngine;  | 
| using UnityEngine.UI;  | 
|   | 
|   | 
| namespace vnxbqy.UI  | 
| {  | 
|   | 
|     public class TrialDungeonSelectWin : Window, SecondWindowInterface  | 
|     {  | 
|   | 
|         [SerializeField]  | 
|         CyclicScroll m_BossSelect;  | 
|         [SerializeField]  | 
|         Text trialChallengeCntTxt;  | 
|         [SerializeField] Button m_BuyTimes;  | 
|   | 
|         public event Action<Dungeon> dungeonSelectEvent;  | 
|         Dungeon m_CurrentSelectDungeon;  | 
|         public Dungeon currentSelectDungeon {  | 
|             get {  | 
|                 return m_CurrentSelectDungeon;  | 
|             }  | 
|             set {  | 
|                 if (m_CurrentSelectDungeon != value)  | 
|                 {  | 
|                     m_CurrentSelectDungeon = value;  | 
|                     if (dungeonSelectEvent != null)  | 
|                     {  | 
|                         dungeonSelectEvent(m_CurrentSelectDungeon);  | 
|                     }  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         List<Dungeon> dungeons = new List<Dungeon>();  | 
|   | 
|         DungeonModel model { get { return  ModelCenter.Instance.GetModel<DungeonModel>(); } }  | 
|         DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }  | 
|   | 
|         #region Built-in  | 
|         public Button close { get; set; }  | 
|   | 
|         protected override void BindController() | 
|         {  | 
|             if (this is SecondWindowInterface)  | 
|             {  | 
|                 var frame = this.GetComponentInChildren<SecondFrameLoader>();  | 
|                 frame.Create();  | 
|                 close = frame.GetComponentInChildren<Button>();  | 
|             } | 
|         }  | 
|   | 
|         protected override void AddListeners()  | 
|         {  | 
|             close.AddListener(CloseClick);  | 
|             m_BuyTimes.AddListener(BuyTimes);  | 
|         }  | 
|   | 
|         protected override void OnPreOpen()  | 
|         {  | 
|             model.dungeonRecordChangeEvent += UpdateDungeonTimes;  | 
|             model.updateDungeonBuyCnt += UpdateDungeonBuyCnt;  | 
|   | 
|             ParseTrials();  | 
|             DisplayTrialChallengeCount();  | 
|         }  | 
|   | 
|         protected override void OnActived()  | 
|         {  | 
|             base.OnActived();  | 
|             ShowAllTrialDungeons();  | 
|         }  | 
|   | 
|         protected override void OnAfterOpen()  | 
|         {  | 
|         }  | 
|   | 
|         protected override void OnPreClose()  | 
|         {  | 
|             model.dungeonRecordChangeEvent -= UpdateDungeonTimes;  | 
|             model.updateDungeonBuyCnt -= UpdateDungeonBuyCnt;  | 
|         }  | 
|   | 
|         protected override void OnAfterClose()  | 
|         {  | 
|             dungeons.Clear();  | 
|         }  | 
|         #endregion  | 
|   | 
|         private void ShowAllTrialDungeons()  | 
|         {  | 
|             m_BossSelect.Init(dungeons);  | 
|         }  | 
|   | 
|         private void ParseTrials()  | 
|         {  | 
|             foreach (var mapID in model.GetDungeonIds(model.currentDungeon.mapId)) {  | 
|                 DungeonConfig _tagDungeonModel = DungeonConfig.Get(mapID);  | 
|                 dungeons.Add(new Dungeon(model.currentDungeon.mapId, _tagDungeonModel.LineID));  | 
|             }  | 
|             currentSelectDungeon = dungeons.Count > 0 ? dungeons[0] : default(Dungeon);  | 
|         }  | 
|   | 
|         private void UpdateDungeonTimes(int mapID)  | 
|         {  | 
|             int trialMapID = model.GetTrialMaps()[0];  | 
|             if (trialMapID != mapID)  | 
|             {  | 
|                 return;  | 
|             }  | 
|             DisplayTrialChallengeCount();  | 
|         }  | 
|   | 
|         private void UpdateDungeonBuyCnt()  | 
|         {  | 
|             DisplayTrialChallengeCount();  | 
|         }  | 
|   | 
|         private void DisplayTrialChallengeCount()  | 
|         {  | 
|             var mapID = model.GetTrialMaps()[0];  | 
|             DungeonOpenTimeConfig dungeonOpenTimeModel = DungeonOpenTimeConfig.Get(mapID);  | 
|             var completedTimes = dailyQuestModel.GetDailyQuestCompletedTimes((int)DailyQuestType.Trial);  | 
|             var totalTimes = dailyQuestModel.GetDailyQuestTotalTimes((int)DailyQuestType.Trial);  | 
|             trialChallengeCntTxt.text = Language.Get("TrialChallengeCnt", UIHelper.AppendColor(completedTimes >= totalTimes ?  | 
|                 TextColType.Red : TextColType.NavyBrown, completedTimes.ToString(), true), totalTimes);  | 
|         }  | 
|   | 
|         private void BuyTimes()  | 
|         {  | 
|             WindowCenter.Instance.Open<DungeonBuyTimesWin>();  | 
|         }  | 
|   | 
|         //private void Exchange()  | 
|         //{  | 
|         //    if (!trialDungeonModel.CompleteTrialFloor(0))  | 
|         //    {  | 
|         //        trialDungeonModel.ProcessOpenTrialExchangeError();  | 
|         //        return;  | 
|         //    }  | 
|         //    WindowCenter.Instance.Open<TrialExchangeWin>();  | 
|         //}  | 
|   | 
|     }  | 
|   | 
| }  | 
|   | 
|   | 
|   | 
|   |