//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, January 02, 2018
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
using System;
|
|
|
namespace vnxbqy.UI
|
{
|
|
public class FindPreciousBossBriefInfoBehaviour : AutoSelectScrollItem
|
{
|
|
[SerializeField] protected float m_SelectedShifting = 6f;
|
[SerializeField] protected CanvasGroup m_CanvasGroup;
|
[SerializeField] protected Button m_Select;
|
[SerializeField] protected RectTransform m_Content;
|
[SerializeField] protected Image m_BackGround;
|
[SerializeField] protected Transform m_Selected;
|
[SerializeField] protected ImageEx m_Portrait;
|
[SerializeField] protected TextEx m_BossName;
|
[SerializeField] protected TextEx m_BossLevel;
|
[SerializeField] protected RectTransform m_RealmContainer;
|
[SerializeField] protected Image m_Realm;
|
[SerializeField] protected RectTransform m_UnLockCondition;
|
[SerializeField] protected Image m_UnLockRealm;
|
[SerializeField] protected TimerBehaviour m_CoolDown;
|
[SerializeField] protected Transform m_RefreshAtOnce;
|
[SerializeField] protected Material m_NormalMaterial;
|
[SerializeField] protected Material m_GrayMaterial;
|
[SerializeField] protected FontColorSizeConfig m_BossNameFontConfig;
|
[SerializeField] protected FontColorSizeConfig m_BossLevelFontConfig;
|
|
protected int bossId = 0;
|
protected virtual int selectedBossId {
|
get;
|
set;
|
}
|
|
InteractorableState m_InteractorableState;
|
protected virtual InteractorableState interactorableState {
|
get { return m_InteractorableState; }
|
set { m_InteractorableState = value; }
|
}
|
|
protected virtual bool isRebornRightNow {
|
get {
|
if (!findPreciousModel.IsBossUnlock(bossId))
|
{
|
return false;
|
}
|
|
FindPreciousModel.BossInfo bossInfo = null;
|
if (!findPreciousModel.TryGetBossInfo(bossId, out bossInfo))
|
{
|
return false;
|
}
|
|
return !findPreciousModel.IsBossAlive(bossId) && TimeUtility.ServerNow > bossInfo.refreshTime;
|
}
|
}
|
|
protected virtual bool isUnLocked {
|
get { return findPreciousModel.IsBossUnlock(bossId); }
|
}
|
|
protected FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
|
|
public override void Display(object _data)
|
{
|
base.Display(_data);
|
bossId = (int)_data;
|
var bossInfoQuery = m_RefreshAtOnce.AddMissingComponent<RebornRightNowBossInfoQuery>();
|
bossInfoQuery.bossId = bossId;
|
findPreciousModel.bossSubscribeChangeEvent -= OnSubscribe;
|
findPreciousModel.bossSubscribeChangeEvent += OnSubscribe;
|
findPreciousModel.bossInfoUpdateEvent -= OnBossInfoUpdate;
|
findPreciousModel.bossInfoUpdateEvent += OnBossInfoUpdate;
|
}
|
|
public override void Dispose()
|
{
|
base.Dispose();
|
findPreciousModel.bossSubscribeChangeEvent -= OnSubscribe;
|
findPreciousModel.bossInfoUpdateEvent -= OnBossInfoUpdate;
|
}
|
|
protected virtual void DrawBossBaseInfo(string icon, string name, int level, int realm)
|
{
|
m_Portrait.SetSprite(icon);
|
m_Portrait.SetNativeSize();
|
this.m_BossName.text = name;
|
m_BossLevel.text = Language.Get("Z1024", level);
|
|
m_RealmContainer.SetActive(isUnLocked);
|
m_UnLockCondition.SetActive(!isUnLocked);
|
if (!isUnLocked)
|
{
|
var unLockRealm = findPreciousModel.GetBossUnLockRealm(bossId);
|
var config = RealmConfig.Get(unLockRealm);
|
m_UnLockRealm.SetSprite(config.Img);
|
}
|
else
|
{
|
if (m_Realm != null && m_RealmContainer != null)
|
{
|
if (realm > 0 && RealmConfig.Has(realm))
|
{
|
m_RealmContainer.SetActive(true);
|
var realmConfig = RealmConfig.Get(realm);
|
if (realmConfig != null)
|
{
|
m_Realm.SetSprite(realmConfig.Img);
|
}
|
}
|
else
|
{
|
m_RealmContainer.SetActive(false);
|
}
|
}
|
}
|
}
|
|
private void Awake()
|
{
|
m_Select.AddListener(SelectBoss);
|
}
|
|
private void SelectBoss()
|
{
|
//autoSelectScroll.TrySelectData(bossId);
|
selectedBossId = bossId;
|
}
|
|
protected virtual void OnSubscribe(int _bossId)
|
{
|
if (bossId != _bossId)
|
{
|
return;
|
}
|
|
}
|
|
protected virtual void UpdateBossPortrait(InteractorableState _state)
|
{
|
var isGray = _state == InteractorableState.DieOrLockedSelected || _state == InteractorableState.DieOrLockedUnSelected;
|
m_BackGround.material = isGray ? m_GrayMaterial : m_NormalMaterial;
|
m_Portrait.material = isGray ? m_GrayMaterial : m_NormalMaterial;
|
}
|
|
protected virtual void UpdateBossRebornCoolDown(bool _isUnLocked)
|
{
|
if (_isUnLocked)
|
{
|
FindPreciousModel.BossInfo bossInfo;
|
if (findPreciousModel.TryGetBossInfo(bossId, out bossInfo) && !bossInfo.IsBossAlive())
|
{
|
if (TimeUtility.ServerNow > bossInfo.refreshTime)
|
{
|
m_CoolDown.SetActive(false);
|
}
|
else
|
{
|
m_CoolDown.Begin((int)(bossInfo.refreshTime - TimeUtility.ServerNow).TotalSeconds, OnBossCoolDownCompleted);
|
}
|
}
|
else
|
{
|
m_CoolDown.SetActive(false);
|
}
|
}
|
else
|
{
|
m_CoolDown.SetActive(false);
|
}
|
}
|
|
protected void UpdateBossNameLevelFont(InteractorableState _state)
|
{
|
var selected = _state == InteractorableState.DieOrLockedSelected || _state == InteractorableState.NormalSelected;
|
m_Content.anchoredPosition = selected ? new Vector2(m_SelectedShifting, 0) : Vector2.zero;
|
if (m_CanvasGroup != null)
|
{
|
m_CanvasGroup.alpha = selected ? 1 : 0.8f;
|
}
|
|
m_Selected.SetActive(selected);
|
|
var fontPattern = string.Empty;
|
switch (_state)
|
{
|
case InteractorableState.NormalUnSelected:
|
fontPattern = "NormalUnSelected";
|
break;
|
case InteractorableState.NormalSelected:
|
fontPattern = "NormalSelected";
|
break;
|
case InteractorableState.DieOrLockedSelected:
|
fontPattern = "DieOrLockedSelected";
|
break;
|
case InteractorableState.DieOrLockedUnSelected:
|
fontPattern = "DieOrLockedUnSelected";
|
break;
|
}
|
|
var nameFontColorSize = m_BossNameFontConfig.GetColorSize(fontPattern);
|
var levelFontColorSize = m_BossLevelFontConfig.GetColorSize(fontPattern);
|
m_BossName.color = nameFontColorSize.color;
|
m_BossName.fontSize = nameFontColorSize.fontSize;
|
m_BossLevel.color = levelFontColorSize.color;
|
m_BossLevel.fontSize = levelFontColorSize.fontSize;
|
}
|
|
protected virtual void OnBossInfoUpdate(int _bossId)
|
{
|
if (bossId != _bossId)
|
{
|
return;
|
}
|
|
UpdateBossRebornCoolDown(isUnLocked);
|
UpdateBossPortrait(interactorableState);
|
}
|
|
protected virtual void OnBossCoolDownCompleted()
|
{
|
UpdateBossPortrait(interactorableState);
|
}
|
|
protected virtual void LateUpdate()
|
{
|
//if (autoSelectScroll.autoSelectable && selectedBossId != bossId && bossId > 0)
|
//{
|
// if (Mathf.Abs(centerSign.position.y - rectTransform.position.y) * 100f < rectTransform.rect.height * 0.45f)
|
// {
|
// selectedBossId = bossId;
|
// }
|
//}
|
|
if (m_RefreshAtOnce != null)
|
{
|
if (isRebornRightNow && !m_RefreshAtOnce.gameObject.activeInHierarchy)
|
{
|
m_RefreshAtOnce.SetActive(true);
|
}
|
else if (!isRebornRightNow && m_RefreshAtOnce.gameObject.activeInHierarchy)
|
{
|
m_RefreshAtOnce.SetActive(false);
|
}
|
}
|
}
|
|
public enum InteractorableState
|
{
|
NormalSelected,
|
NormalUnSelected,
|
DieOrLockedSelected,
|
DieOrLockedUnSelected,
|
}
|
|
}
|
|
}
|
|
|
|