//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, April 18, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class AlchemyResultWin : Window
|
{
|
[SerializeField] UIAlphaTween m_DisplayAlphaTween;
|
[SerializeField] Transform m_ContainerSucc;
|
[SerializeField] Transform m_ContainerDefeat;
|
[SerializeField] Text m_StoveLevel;
|
[SerializeField] Text m_StoveExp;
|
[SerializeField] IntensifySmoothSlider m_Slider;
|
[SerializeField] ScrollRect m_Scroller;
|
[SerializeField] List<ItemBehaviour> m_Item;
|
[SerializeField] Text m_CloseTip;
|
[SerializeField] Image m_FairyStove;
|
[SerializeField] Image m_NormalStove;
|
[SerializeField] UIEffect m_LevelUpEffect;
|
[SerializeField] Button m_Close;
|
|
public static Item displayItem;
|
public static int lastLevel = 0;
|
|
int recordLevel = 0;
|
|
DateTime openTime = DateTime.Now;
|
|
AlchemyModel model { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_Close.AddListener(OnClose);
|
}
|
|
protected override void OnPreOpen()
|
{
|
Display();
|
|
m_DisplayAlphaTween.SetStartState();
|
m_CloseTip.gameObject.SetActive(false);
|
openTime = DateTime.Now;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
if ((DateTime.Now - openTime).TotalSeconds > 2f && !m_CloseTip.gameObject.activeSelf)
|
{
|
m_CloseTip.gameObject.SetActive(true);
|
}
|
|
if (m_Slider.CurrentStage != recordLevel)
|
{
|
recordLevel = m_Slider.CurrentStage;
|
m_LevelUpEffect.Play();
|
}
|
}
|
#endregion
|
|
void Display()
|
{
|
CreateItems(1);
|
|
DisplayStove();
|
|
m_ContainerDefeat.gameObject.SetActive(displayItem.count == 0);
|
m_ContainerSucc.gameObject.SetActive(displayItem.count > 0);
|
|
if (displayItem.count > 0)
|
{
|
DisplayItem();
|
}
|
}
|
|
void DisplayStove()
|
{
|
m_FairyStove.gameObject.SetActive(model.selectAlchemyType == AlchemyType.Fairy);
|
m_NormalStove.gameObject.SetActive(model.selectAlchemyType == AlchemyType.Normal);
|
|
m_StoveLevel.text = StringUtility.Contact("Lv.", model.stoveLevel);
|
var isMax = !RefineStoveConfig.Has(model.stoveLevel + 1);
|
var stoveConfig = RefineStoveConfig.Get(model.stoveLevel);
|
|
recordLevel = lastLevel;
|
|
m_Slider.stage = lastLevel;
|
m_Slider.ResetStage();
|
|
if (isMax)
|
{
|
m_StoveExp.text = Language.Get("L1055");
|
m_Slider.delay = 0;
|
m_Slider.value = 1;
|
}
|
else
|
{
|
m_Slider.stage = model.stoveLevel;
|
m_StoveExp.text = StringUtility.Contact(model.stoveExp, "/", stoveConfig.Exp);
|
var progress = Mathf.Clamp01((float)model.stoveExp / stoveConfig.Exp);
|
m_Slider.value = progress;
|
}
|
}
|
|
void DisplayItem()
|
{
|
m_Scroller.horizontalNormalizedPosition = 0f;
|
for (int i = 0; i < m_Item.Count; i++)
|
{
|
m_Item[i].gameObject.SetActive(i < 1);
|
if (i < 1)
|
{
|
m_Item[i].SetItem(displayItem.id, displayItem.count);
|
}
|
}
|
}
|
|
void CreateItems(int count)
|
{
|
if (count > m_Item.Count)
|
{
|
var delta = count - m_Item.Count;
|
for (int i = 0; i < delta; i++)
|
{
|
var go = GameObject.Instantiate(m_Item[0]);
|
go.transform.SetParent(m_Scroller.content);
|
go.transform.localScale = Vector3.one;
|
var instance = go.GetComponent<ItemBehaviour>();
|
m_Item.Add(instance);
|
}
|
}
|
}
|
|
private void OnClose()
|
{
|
if ((DateTime.Now - openTime).TotalSeconds < 2f)
|
{
|
return;
|
}
|
CloseClick();
|
}
|
}
|
|
}
|
|
|
|
|