//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, December 07, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
|
using System;
|
using System.Collections.Generic;
|
using LitJson;
|
|
namespace Snxxz.UI
|
{
|
|
public class TreasureCollectBriefInfoBehaviour : MonoBehaviour
|
{
|
[SerializeField] Transform m_ContainerUnknown;
|
|
[SerializeField] Transform m_ContainerCollect;
|
[SerializeField] Image m_Icon;
|
[SerializeField] Image m_TreasureName;
|
|
[SerializeField] Transform m_ContainerCollecting;
|
[SerializeField] Text m_Progress;
|
[SerializeField] Slider m_TaskSlider;
|
|
[SerializeField] Transform m_ContainerChallenge;
|
[SerializeField] UIEffect m_ChallengeEffect;
|
|
[SerializeField] Button m_Goto;
|
|
bool dirty = false;
|
|
int m_DisplayId = 0;
|
int displayId {
|
get { return m_DisplayId; }
|
set {
|
if (m_DisplayId != value)
|
{
|
m_DisplayId = value;
|
dirty = true;
|
}
|
}
|
}
|
|
TreasureModel model { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
|
public void Display()
|
{
|
displayId = GetLatestCollectingTreasure();
|
|
model.treasureStateChangeEvent += TreasureStateChangeEvent;
|
model.treasureCollectProgressRefresh += TreasureCollectProgressRefresh;
|
|
dirty = false;
|
DisplayBase();
|
|
m_Goto.SetListener(OnGoto);
|
}
|
|
private void TreasureStateChangeEvent(int id)
|
{
|
displayId = GetLatestCollectingTreasure();
|
}
|
|
private void TreasureCollectProgressRefresh(int id)
|
{
|
if (id == displayId)
|
{
|
DisplayProgress();
|
}
|
}
|
|
void DisplayBase()
|
{
|
m_ContainerUnknown.gameObject.SetActive(displayId == 0);
|
m_ContainerCollect.gameObject.SetActive(displayId != 0);
|
if (displayId != 0)
|
{
|
DisplayTreasureInfo();
|
DisplayProgress();
|
}
|
}
|
|
void DisplayTreasureInfo()
|
{
|
if (displayId != 0)
|
{
|
var config = TreasureConfig.Get(displayId);
|
m_Icon.SetSprite(config.Icon);
|
m_TreasureName.SetSprite(config.NameIcon);
|
m_TreasureName.SetNativeSize();
|
}
|
}
|
|
void DisplayProgress()
|
{
|
m_ChallengeEffect.StopImediatly();
|
|
if (displayId != 0)
|
{
|
var satisfyChallenge = model.SatisfyChallenge(displayId);
|
|
m_ContainerChallenge.gameObject.SetActive(satisfyChallenge);
|
m_ContainerCollecting.gameObject.SetActive(!satisfyChallenge);
|
if (!satisfyChallenge)
|
{
|
var progress = 1f;
|
|
List<int> tasks;
|
if (model.TryGetTreasureTasks(displayId, out tasks))
|
{
|
var count = model.GetCompleteTaskCount(displayId);
|
progress = Mathf.Clamp01((float)count / tasks.Count);
|
}
|
|
m_TaskSlider.value = progress;
|
m_Progress.text = StringUtility.Contact((int)(progress * 100), "%");
|
}
|
else
|
{
|
m_ChallengeEffect.Play();
|
}
|
}
|
}
|
|
int GetLatestCollectingTreasure()
|
{
|
var treasureIds = model.GetTreasureCategory(TreasureCategory.Human);
|
foreach (var id in treasureIds)
|
{
|
Treasure treasure;
|
if (model.TryGetTreasure(id, out treasure))
|
{
|
if (treasure.state == TreasureState.Collecting)
|
{
|
return id;
|
}
|
}
|
}
|
|
return 0;
|
}
|
|
bool IsAllCompleted()
|
{
|
var treasureIds = model.GetTreasureCategory(TreasureCategory.Human);
|
foreach (var id in treasureIds)
|
{
|
Treasure treasure;
|
if (model.TryGetTreasure(id, out treasure))
|
{
|
if (treasure.state != TreasureState.Collected)
|
{
|
return false;
|
}
|
}
|
}
|
return true;
|
}
|
|
private void LateUpdate()
|
{
|
if (dirty)
|
{
|
dirty = false;
|
DisplayBase();
|
}
|
}
|
|
public void Dispose()
|
{
|
model.treasureStateChangeEvent -= TreasureStateChangeEvent;
|
model.treasureCollectProgressRefresh -= TreasureCollectProgressRefresh;
|
}
|
|
private void OnGoto()
|
{
|
if (displayId == 0)
|
{
|
return;
|
}
|
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
if (model.IsRequireUnlockAnim(TreasureCategory.Human) == displayId)
|
{
|
model.treasureGotoId = displayId;
|
model.currentCategory = TreasureCategory.Human;
|
WindowCenter.Instance.Open<TreasureSelectWin>();
|
}
|
else
|
{
|
var config = TreasureConfig.Get(displayId);
|
model.selectedTreasure = displayId;
|
model.currentCategory = (TreasureCategory)config.Category;
|
WindowCenter.Instance.Open<TreasureBaseWin>();
|
}
|
}
|
|
}
|
|
|
}
|
|
|
|