//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, April 04, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace Snxxz.UI
|
{
|
|
public class RuneTowerSweepResultWin : Window
|
{
|
[SerializeField] Button m_Skip;
|
[SerializeField] Text m_Title;
|
[SerializeField] ScrollRect m_ResultScrollRect;
|
[SerializeField] Button m_Close;
|
[SerializeField] Button m_Continue;
|
[SerializeField] VerticalLayoutGroup m_VerticalLayoutGroup;
|
|
RuneTowerSweepResultTotalBehaviour resultTotalBehaviour;
|
List<RuneTowerSweepResultBehaviour> resultBehavioursBuf = new List<RuneTowerSweepResultBehaviour>();
|
RuneTowerModel runeTowerModel { get { return ModelCenter.Instance.GetModel<RuneTowerModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
|
|
float floorHeight = 0;
|
float totalResultHeight = 0;
|
bool skip = false;
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_Close.AddListener(CloseClick);
|
m_Continue.AddListener(Continue);
|
m_Skip.AddListener(Skip);
|
}
|
|
protected override void OnPreOpen()
|
{
|
skip = false;
|
m_Close.SetActive(false);
|
m_Continue.SetActive(false);
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
StopAllCoroutines();
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
ShowResults();
|
}
|
|
#endregion
|
|
private void ShowResults()
|
{
|
m_Title.text = Language.Get("RuneTowerSweepText9");
|
GenerateSweepResultBehaviours(m_ResultScrollRect.content, runeTowerModel.towerSweepResults.Count);
|
for (int i = 0; i < resultBehavioursBuf.Count; i++)
|
{
|
var behaviour = resultBehavioursBuf[i];
|
if (i < runeTowerModel.towerSweepResults.Count)
|
{
|
behaviour.SetActive(true);
|
behaviour.Display(runeTowerModel.towerSweepResults[i]);
|
}
|
else
|
{
|
behaviour.SetActive(false);
|
}
|
}
|
|
if (resultTotalBehaviour == null)
|
{
|
var instance = UIUtility.CreateWidget("RuneTowerSweepResultTotalBehaviour", "RuneTowerSweepResultTotalBehaviour");
|
resultTotalBehaviour = instance.GetComponent<RuneTowerSweepResultTotalBehaviour>();
|
resultTotalBehaviour.transform.SetParentEx(m_ResultScrollRect.content, Vector3.zero, Vector3.zero, Vector3.one);
|
}
|
|
resultTotalBehaviour.ShowSweepTotalResult();
|
resultTotalBehaviour.transform.SetAsLastSibling();
|
|
StartCoroutine("Co_ShowResultTowerByTower");
|
}
|
|
private void GenerateSweepResultBehaviours(Transform _parent, int _needCount)
|
{
|
var currentCount = resultBehavioursBuf.Count;
|
if (_needCount > currentCount)
|
{
|
var gap = _needCount - currentCount;
|
for (int i = 0; i < gap; i++)
|
{
|
var instance = UIUtility.CreateWidget("RuneTowerSweepResultBehaviour", "RuneTowerSweepResultBehaviour");
|
var behaviour = instance.GetComponent<RuneTowerSweepResultBehaviour>();
|
behaviour.transform.SetParentEx(_parent, Vector3.zero, Vector3.zero, Vector3.one);
|
|
floorHeight = ((RectTransform)behaviour.transform).rect.height;
|
resultBehavioursBuf.Add(behaviour);
|
}
|
}
|
}
|
|
IEnumerator Co_ShowResultTowerByTower()
|
{
|
var raycastFilter = m_ResultScrollRect.AddMissingComponent<CanvasRaycastFilter>();
|
raycastFilter.raycastTarget = false;
|
|
foreach (var behaviour in resultBehavioursBuf)
|
{
|
behaviour.interactable = false;
|
}
|
|
resultTotalBehaviour.transform.localScale = Vector3.zero;
|
resultTotalBehaviour.interactable = false;
|
|
m_ResultScrollRect.verticalNormalizedPosition = 1f;
|
foreach (var behaviour in resultBehavioursBuf)
|
{
|
behaviour.transform.localScale = Vector3.zero;
|
}
|
|
var count = runeTowerModel.towerSweepResults.Count;
|
var height = 1 / (float)count;
|
var theoryStart = -((RectTransform)m_ResultScrollRect.transform).rect.height;
|
|
var timer = 0f;
|
var duration = 0.7f;
|
var start = 0f;
|
var end = 0f;
|
|
for (int i = 0; i < count; i++)
|
{
|
resultBehavioursBuf[i].transform.localScale = Vector3.one;
|
timer = 0f;
|
start = theoryStart + i * floorHeight + m_VerticalLayoutGroup.spacing * i;
|
end = start + floorHeight + m_VerticalLayoutGroup.spacing;
|
while (timer < duration)
|
{
|
timer += Time.deltaTime;
|
var t = Mathf.Clamp01(timer / duration);
|
var y = Mathf.Lerp(start, end, t);
|
if (y > m_ResultScrollRect.content.anchoredPosition.y)
|
{
|
m_ResultScrollRect.content.anchoredPosition = m_ResultScrollRect.content.anchoredPosition.SetY(y);
|
}
|
yield return null;
|
}
|
|
if (end > m_ResultScrollRect.content.anchoredPosition.y)
|
{
|
m_ResultScrollRect.content.anchoredPosition = m_ResultScrollRect.content.anchoredPosition.SetY(end);
|
}
|
|
if (skip)
|
{
|
break;
|
}
|
|
yield return WaitingForSecondConst.WaitMS500;
|
}
|
|
for (int i = 0; i < count; i++)
|
{
|
resultBehavioursBuf[i].transform.localScale = Vector3.one;
|
}
|
|
if (!skip)
|
{
|
yield return null;
|
}
|
|
resultTotalBehaviour.transform.localScale = Vector3.one;
|
resultTotalBehaviour.UpdateSizeAndPosition();
|
|
timer = 0f;
|
totalResultHeight = ((RectTransform)resultTotalBehaviour.transform).rect.height;
|
start = theoryStart + count * floorHeight + m_VerticalLayoutGroup.spacing * count;
|
end = start + totalResultHeight;
|
|
while (timer < duration)
|
{
|
timer += Time.deltaTime;
|
var t = Mathf.Clamp01(timer / duration);
|
var y = Mathf.Lerp(start, end, t);
|
if (y > m_ResultScrollRect.content.anchoredPosition.y)
|
{
|
m_ResultScrollRect.content.anchoredPosition = m_ResultScrollRect.content.anchoredPosition.SetY(y);
|
}
|
|
if (skip)
|
{
|
break;
|
}
|
|
yield return null;
|
}
|
|
yield return null;
|
|
m_ResultScrollRect.content.anchoredPosition = m_ResultScrollRect.content.anchoredPosition.SetY(end);
|
foreach (var behaviour in resultBehavioursBuf)
|
{
|
behaviour.interactable = true;
|
}
|
|
resultTotalBehaviour.interactable = true;
|
raycastFilter.raycastTarget = true;
|
|
m_Close.SetActive(true);
|
var dailyQuestState = dailyQuestModel.GetQuestState((int)DailyQuestType.RuneTowerSweep);
|
m_Continue.SetActive(dailyQuestState != DailyQuestModel.DailyQuestState.Completed);
|
}
|
|
private void Continue()
|
{
|
WindowCenter.Instance.Close<RuneTowerSweepResultWin>();
|
WindowCenter.Instance.Open<RuneTowerSweepBuyWin>();
|
}
|
|
private void Skip()
|
{
|
skip = true;
|
}
|
|
}
|
|
}
|
|
|
|
|