//--------------------------------------------------------  
 | 
//    [Author]:           第二世界  
 | 
//    [  Date ]:           Tuesday, April 09, 2019  
 | 
//--------------------------------------------------------  
 | 
  
 | 
using System;  
 | 
using System.Collections;  
 | 
using System.Collections.Generic;  
 | 
using UnityEngine;  
 | 
using UnityEngine.UI;  
 | 
  
 | 
namespace vnxbqy.UI  
 | 
{  
 | 
  
 | 
    public class DungeonAdventureVictoryWin : Window  
 | 
    {  
 | 
        [SerializeField] Transform m_ContainerPoivt;  
 | 
        [SerializeField] DungeonRewardBehavour[] m_Items;  
 | 
        [SerializeField] Button m_Exit;  
 | 
        [SerializeField] Text m_ExitTimer;  
 | 
  
 | 
        const float totalTime = 8f;  
 | 
        float timer = 0f;  
 | 
        float clockTimer = 0f;  
 | 
  
 | 
        DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }  
 | 
  
 | 
        #region Built-in  
 | 
        protected override void BindController()  
 | 
        {  
 | 
        }  
 | 
  
 | 
        protected override void AddListeners()  
 | 
        {  
 | 
            m_Exit.AddListener(ExitDungeon);  
 | 
        }  
 | 
  
 | 
        protected override void OnPreOpen()  
 | 
        {  
 | 
            m_ContainerPoivt.SetActive(false);  
 | 
            timer = 0f;  
 | 
            clockTimer = 0f;  
 | 
        }  
 | 
  
 | 
        protected override void OnActived()  
 | 
        {  
 | 
            base.OnActived();  
 | 
            StartCoroutine(Co_DelayDisplay());  
 | 
        }  
 | 
  
 | 
        protected override void OnAfterOpen()  
 | 
        {  
 | 
        }  
 | 
  
 | 
        protected override void OnPreClose()  
 | 
        {  
 | 
            AdventureStage.Instance.Exit();  
 | 
        }  
 | 
  
 | 
        protected override void OnAfterClose()  
 | 
        {  
 | 
        }  
 | 
        #endregion  
 | 
  
 | 
        protected override void LateUpdate()  
 | 
        {  
 | 
            clockTimer += Time.deltaTime;  
 | 
            if (clockTimer >= 0.5f)  
 | 
            {  
 | 
                clockTimer = 0f;  
 | 
                var seconds = Mathf.CeilToInt(totalTime - timer);  
 | 
                DrawExitTimer(seconds);  
 | 
            }  
 | 
  
 | 
            timer += Time.deltaTime;  
 | 
            if (timer >= totalTime)  
 | 
            {  
 | 
                Close();  
 | 
            }  
 | 
        }  
 | 
  
 | 
        IEnumerator Co_DelayDisplay()  
 | 
        {  
 | 
            yield return WaitingForSecondConst.WaitMS3000;  
 | 
            Display();  
 | 
        }  
 | 
  
 | 
        void Display()  
 | 
        {  
 | 
            m_ContainerPoivt.SetActive(true);  
 | 
            DisplayExit();  
 | 
            DisplayItems();  
 | 
        }  
 | 
  
 | 
        void DisplayExit()  
 | 
        {  
 | 
            m_Exit.SetActive(true);  
 | 
            var seconds = Mathf.CeilToInt(totalTime - timer);  
 | 
            DrawExitTimer(seconds);  
 | 
        }  
 | 
  
 | 
        void DrawExitTimer(int seconds)  
 | 
        {  
 | 
            m_ExitTimer.text = Language.Get("DungeonVictoryWin_Btn_Exit_1", Mathf.Clamp(seconds, 0, int.MaxValue));  
 | 
        }  
 | 
  
 | 
        void DisplayItems()  
 | 
        {  
 | 
            var result = dungeonModel.dungeonResult;  
 | 
            for (int i = 0; i < m_Items.Length; i++)  
 | 
            {  
 | 
                if (result.itemInfo != null && i < result.itemInfo.Length)  
 | 
                {  
 | 
                    var serverItem = result.itemInfo[i];  
 | 
                    m_Items[i].SetActive(true);  
 | 
                    m_Items[i].Display(new Item(serverItem.ItemID, serverItem.Count));  
 | 
                }  
 | 
                else  
 | 
                {  
 | 
                    m_Items[i].SetActive(false);  
 | 
                }  
 | 
            }  
 | 
        }  
 | 
  
 | 
        private void ExitDungeon()  
 | 
        {  
 | 
            Close();  
 | 
        }  
 | 
  
 | 
    }  
 | 
  
 | 
}  
 | 
  
 | 
  
 | 
  
 | 
  
 |