//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, April 04, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class HazyRegionWin : Window
|
{
|
[SerializeField] HazyRegionEntrancePanel m_EntrancePanel;
|
[SerializeField] HazyRegionIncidentPanel m_IncidentPanel;
|
|
[SerializeField] ScaleTween m_BottomScaleTween;
|
[SerializeField] UIAlphaTween m_AlphaTween;
|
|
HazyRegionStage m_Stage = HazyRegionStage.Entrance;
|
HazyRegionStage stage
|
{
|
get { return m_Stage; }
|
set
|
{
|
if (m_Stage != value)
|
{
|
switch (m_Stage)
|
{
|
case HazyRegionStage.Entrance:
|
//CloseHazyRegionEntrance();
|
break;
|
case HazyRegionStage.Playing:
|
CloseHazyRegionIncident();
|
break;
|
}
|
|
m_Stage = value;
|
|
switch (m_Stage)
|
{
|
case HazyRegionStage.Entrance:
|
OpenHazyRegionEntrance();
|
break;
|
case HazyRegionStage.Playing:
|
StartEntranceAnimation();
|
break;
|
}
|
}
|
}
|
}
|
|
HazyRegionModel model { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
|
Display();
|
|
model.onHazyRegionStateRefresh += OnHazyRegionStateRefresh;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
if (stage == HazyRegionStage.Playing)
|
{
|
StartCoroutine(Co_VerifyCompleteAllIncidents());
|
}
|
}
|
|
protected override void OnPreClose()
|
{
|
m_EntrancePanel.Dispose();
|
m_IncidentPanel.Dispose();
|
|
StopAllCoroutines();
|
|
m_BottomScaleTween.Stop();
|
m_BottomScaleTween.SetStartState();
|
m_AlphaTween.SetStartState();
|
|
model.onHazyRegionStateRefresh -= OnHazyRegionStateRefresh;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
void Display()
|
{
|
m_EntrancePanel.gameObject.SetActive(false);
|
m_IncidentPanel.gameObject.SetActive(false);
|
|
m_Stage = model.playing ? HazyRegionStage.Playing : HazyRegionStage.Entrance;
|
|
switch (stage)
|
{
|
case HazyRegionStage.Entrance:
|
OpenHazyRegionEntrance();
|
break;
|
case HazyRegionStage.Playing:
|
OpenHazyRegionIncident();
|
break;
|
}
|
}
|
|
void OpenHazyRegionEntrance()
|
{
|
m_EntrancePanel.gameObject.SetActive(true);
|
m_BottomScaleTween.Stop();
|
m_BottomScaleTween.SetStartState();
|
m_AlphaTween.SetStartState();
|
m_EntrancePanel.Dispose();
|
m_EntrancePanel.Display();
|
}
|
|
void OpenHazyRegionIncident()
|
{
|
m_IncidentPanel.gameObject.SetActive(true);
|
m_IncidentPanel.Dispose();
|
m_IncidentPanel.Display();
|
}
|
|
void CloseHazyRegionIncident()
|
{
|
m_IncidentPanel.Dispose();
|
m_IncidentPanel.gameObject.SetActive(false);
|
}
|
|
void CloseHazyRegionEntrance()
|
{
|
m_EntrancePanel.Dispose();
|
m_EntrancePanel.gameObject.SetActive(false);
|
}
|
|
void StartEntranceAnimation()
|
{
|
m_BottomScaleTween.Play();
|
m_AlphaTween.Play();
|
StartCoroutine(Co_EntranceAnimation());
|
}
|
|
IEnumerator Co_EntranceAnimation()
|
{
|
yield return WaitingForSecondConst.GetWaitForSeconds(m_AlphaTween.duration * 0.5f);
|
CloseHazyRegionEntrance();
|
yield return WaitingForSecondConst.GetWaitForSeconds(m_AlphaTween.duration * 0.2f);
|
model.requireIncidentAnimation = true;
|
OpenHazyRegionIncident();
|
}
|
|
private void OnHazyRegionStateRefresh(int state)
|
{
|
if (state == 2)
|
{
|
if ((model.playing && stage != HazyRegionStage.Playing)
|
|| (!model.playing && stage != HazyRegionStage.Entrance))
|
{
|
Display();
|
}
|
}
|
else
|
{
|
stage = state == 0 ? HazyRegionStage.Entrance : HazyRegionStage.Playing;
|
}
|
}
|
|
IEnumerator Co_VerifyCompleteAllIncidents()
|
{
|
yield return WaitingForSecondConst.WaitMS500;
|
|
var allComplete = true;
|
var incidents = model.GetAllIncidents();
|
if (incidents != null)
|
{
|
foreach (var id in incidents)
|
{
|
HazyRegionModel.Incident incident;
|
if (model.TryGetIncident(id, out incident))
|
{
|
if (incident.state != HazyRegionModel.IncidentState.Complete)
|
{
|
allComplete = false;
|
}
|
}
|
}
|
}
|
|
if (allComplete)
|
{
|
WindowCenter.Instance.Open<HazyRegionCompleteWin>();
|
}
|
}
|
|
enum HazyRegionStage
|
{
|
Entrance,
|
Playing,
|
}
|
}
|
|
}
|
|
|
|
|