//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, December 07, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
|
using System;
|
using System.Collections.Generic;
|
using LitJson;
|
|
namespace vnxbqy.UI
|
{
|
|
public class TreasureCollectBriefInfoBehaviour : MonoBehaviour
|
{
|
[SerializeField] Transform m_ContainerDisplay;
|
|
[SerializeField] Transform m_ContainerUnknown;
|
[SerializeField] Text m_UnknownDescription;
|
|
[SerializeField] Transform m_ContainerCollect;
|
[SerializeField] Image m_Icon;
|
[SerializeField] Image m_TreasureName;
|
|
[SerializeField] Transform m_ContainerCollecting;
|
[SerializeField] Text m_Progress;
|
[SerializeField] SmoothSlider m_TaskSlider;
|
|
[SerializeField] Transform m_ContainerChallenge;
|
[SerializeField] UIEffect m_ChallengeEffect;
|
|
[SerializeField] UIEffect m_ProgressEffect;
|
|
[SerializeField] Button m_Goto;
|
[SerializeField] Button m_GotoAward;
|
[SerializeField] UIEffect m_AwardEffect;
|
|
bool dirty = false;
|
|
int m_DisplayId = 0;
|
int displayId {
|
get { return m_DisplayId; }
|
set {
|
if (m_DisplayId != value)
|
{
|
m_DisplayId = value;
|
dirty = true;
|
}
|
}
|
}
|
|
bool m_FullProgress = false;
|
bool fullProgress
|
{
|
get { return m_FullProgress; }
|
set
|
{
|
if (m_FullProgress != value)
|
{
|
m_FullProgress = value;
|
DisplayProgress();
|
}
|
}
|
}
|
|
Coroutine m_CacheCoroutine = null;
|
|
TreasureModel model { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
TaskModel taskModel { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
|
RoleModel roleModel { get { return ModelCenter.Instance.GetModel<RoleModel>(); } }
|
|
public void Display()
|
{
|
m_UnknownDescription.text = Language.Get("FabaoState_Text_7");
|
|
displayId = GetLatestCollectingTreasure();
|
|
model.treasureStateChangeEvent += TreasureStateChangeEvent;
|
model.treasureCollectProgressRefresh += TreasureCollectProgressRefresh;
|
WindowCenter.Instance.windowAfterOpenEvent += WindowAfterOpenEvent;
|
WindowCenter.Instance.windowAfterCloseEvent += WindowBeforeCloseEvent;
|
|
dirty = false;
|
DisplayBase();
|
|
m_Goto.SetListener(OnGoto);
|
m_GotoAward.SetActive(model.m_jumpAwardID != -1);
|
m_GotoAward.AddListener(() => {
|
if (model.m_jumpAwardID == -1)
|
return;
|
|
if (model.quickGetAward)
|
{
|
roleModel.GetCustomAward(model.m_jumpAwardID);
|
m_AwardEffect.Play();
|
return;
|
}
|
var info = model.GetFabaoAwardInfo(model.m_jumpAwardID);
|
model.gotoAwardClue = info.y;
|
model.selectedTreasure = info.x;
|
model.currentCategory = TreasureCategory.Human;
|
WindowCenter.Instance.Open<TreasureBaseWin>(true);
|
model.quickGetAward = true;
|
});
|
}
|
|
private void OnEnable()
|
{
|
m_ContainerDisplay.SetActive(false);
|
StartCoroutine(Co_Display());
|
roleModel.OnCustomAwardsEvent += RoleModel_OnCustomAwardsEvent;
|
}
|
|
private void RoleModel_OnCustomAwardsEvent()
|
{
|
m_GotoAward.SetActive(model.m_jumpAwardID != -1);
|
}
|
|
private void OnDisable()
|
{
|
roleModel.OnCustomAwardsEvent -= RoleModel_OnCustomAwardsEvent;
|
}
|
|
IEnumerator Co_Display()
|
{
|
yield return null;
|
m_ContainerDisplay.SetActive(true);
|
}
|
|
private void TreasureStateChangeEvent(int id)
|
{
|
displayId = GetLatestCollectingTreasure();
|
}
|
|
private void TreasureCollectProgressRefresh(int id)
|
{
|
if (id == displayId && model.isServerReady)
|
{
|
m_ProgressEffect.Play();
|
if (m_CacheCoroutine != null)
|
{
|
StopCoroutine(m_CacheCoroutine);
|
m_CacheCoroutine = null;
|
}
|
if (gameObject.activeInHierarchy)
|
{
|
taskModel.taskWait.Push(TaskModel.TaskWaitType.TreasureProgress);
|
m_CacheCoroutine = StartCoroutine(Co_StopEffect());
|
}
|
}
|
}
|
|
IEnumerator Co_StopEffect()
|
{
|
yield return WaitingForSecondConst.WaitMS800;
|
m_ProgressEffect.StopImediatly();
|
DisplayProgress(true);
|
}
|
|
void DisplayBase()
|
{
|
bool isChapterOpen = model.treasureChapterId != 0;
|
|
m_ContainerUnknown.SetActive(displayId == 0 || isChapterOpen);
|
m_ContainerCollect.SetActive(displayId != 0 && !isChapterOpen);
|
if (displayId != 0)
|
{
|
DisplayTreasureInfo();
|
DisplayProgress();
|
}
|
else
|
{
|
var id = GetLostTreasure();
|
var chapterConfig = TreasureChapterConfig.Get(id);
|
if (chapterConfig != null)
|
{
|
m_UnknownDescription.text = chapterConfig.unknown;
|
}
|
else
|
{
|
m_UnknownDescription.text = Language.Get("FabaoState_Text_7");
|
}
|
}
|
}
|
|
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(bool animationStep = false)
|
{
|
m_ChallengeEffect.StopImediatly();
|
|
if (displayId != 0)
|
{
|
var progress = 1f;
|
Dictionary<int, List<int>> clues;
|
if (model.TryGetTreasureClues(displayId, out clues))
|
{
|
var count = model.GetCompleteTaskCount(displayId);
|
progress = Mathf.Clamp01((float)count / clues.Count);
|
}
|
m_TaskSlider.value = progress;
|
if (!animationStep)
|
{
|
m_TaskSlider.ResetValue(progress);
|
}
|
|
var satisfyChallenge = model.SatisfyChallenge(displayId) && fullProgress;
|
|
m_ContainerChallenge.SetActive(satisfyChallenge);
|
m_ContainerCollecting.SetActive(!satisfyChallenge);
|
if (!satisfyChallenge)
|
{
|
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;
|
}
|
|
int GetLostTreasure()
|
{
|
var treasureIds = model.GetTreasureCategory(TreasureCategory.Human);
|
|
var latestTask = taskModel.GetLatestMainTaskId();
|
|
foreach (var id in treasureIds)
|
{
|
List<int> tasks;
|
if (model.TryGetTreasureTasks(id, out tasks))
|
{
|
var lastTask = tasks[tasks.Count - 1];
|
if (latestTask <= lastTask)
|
{
|
return id;
|
}
|
}
|
}
|
return 0;
|
}
|
|
private void WindowAfterOpenEvent(Window window)
|
{
|
if (window is TreasureChapterWin)
|
{
|
DisplayBase();
|
}
|
}
|
|
private void WindowBeforeCloseEvent(Window window)
|
{
|
if (window is TreasureChapterWin)
|
{
|
DisplayBase();
|
}
|
}
|
|
private void LateUpdate()
|
{
|
if (dirty)
|
{
|
dirty = false;
|
DisplayBase();
|
}
|
|
fullProgress = m_TaskSlider.slider.value >= 0.98f;
|
}
|
|
public void Dispose()
|
{
|
model.treasureStateChangeEvent -= TreasureStateChangeEvent;
|
model.treasureCollectProgressRefresh -= TreasureCollectProgressRefresh;
|
WindowCenter.Instance.windowAfterOpenEvent -= WindowAfterOpenEvent;
|
WindowCenter.Instance.windowAfterCloseEvent -= WindowBeforeCloseEvent;
|
if (m_CacheCoroutine != null)
|
{
|
StopCoroutine(m_CacheCoroutine);
|
m_CacheCoroutine = null;
|
}
|
}
|
|
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>(true);
|
}
|
else
|
{
|
var config = TreasureConfig.Get(displayId);
|
model.selectedTreasure = displayId;
|
model.currentCategory = (TreasureCategory)config.Category;
|
WindowCenter.Instance.Open<TreasureBaseWin>(true);
|
}
|
}
|
|
}
|
|
|
}
|
|
|
|