using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class FairyGrabBossBehaviour : AutoSelectScrollItem
|
{
|
[SerializeField] RectTransform m_ContainerSelect;
|
[SerializeField] RectTransform m_ContainerKilling;
|
[SerializeField] RectTransform m_ContainerKilled;
|
[SerializeField] RectTransform m_ContainerMapName;
|
[SerializeField] Image m_BossPortrait;
|
[SerializeField] Text m_MapName;
|
[SerializeField] Text m_BossType;
|
[SerializeField] Text m_BossName;
|
[SerializeField] protected Material m_NormalMaterial;
|
[SerializeField] protected Material m_GrayMaterial;
|
[SerializeField] Image m_RealmIcon;
|
[SerializeField] Text m_Progress;
|
[SerializeField] Button m_Select;
|
public int bossId { get; private set; }
|
|
FairyGrabBossModel model { get { return ModelCenter.Instance.GetModel<FairyGrabBossModel>(); } }
|
|
private void Awake()
|
{
|
m_Select.AddListener(SelectBoss);
|
}
|
|
private void SelectBoss()
|
{
|
autoSelectScroll.TrySelectData(bossId);
|
}
|
|
public override void Display(object _data)
|
{
|
base.Display(_data);
|
bossId = (int)_data;
|
|
DrawBossBaseInfo();
|
DisplayProgress();
|
OnSelected(model.selectBoss);
|
|
model.bossSelectedEvent -= OnSelected;
|
model.bossSelectedEvent += OnSelected;
|
model.bossProgressUpdate -= BossProgressUpdate;
|
model.bossProgressUpdate += BossProgressUpdate;
|
model.stateUpdate -= StateUpdate;
|
model.stateUpdate += StateUpdate;
|
}
|
|
public override void Dispose()
|
{
|
base.Dispose();
|
model.bossSelectedEvent -= OnSelected;
|
model.bossProgressUpdate -= BossProgressUpdate;
|
model.stateUpdate -= StateUpdate;
|
}
|
|
private void OnSelected(int _bossId)
|
{
|
m_ContainerSelect.gameObject.SetActive(model.selectBoss == bossId);
|
}
|
|
void DrawBossBaseInfo()
|
{
|
var config = FairyGrabBossConfig.Get(bossId);
|
var bossInfoConfig = BossInfoConfig.Get(bossId);
|
var mapConfig = MapConfig.Get(bossInfoConfig.MapID);
|
var npcConfig = NPCConfig.Get(bossId);
|
m_BossPortrait.SetSprite(config.PortraitID);
|
m_MapName.text = mapConfig.Name;
|
m_BossName.text = npcConfig.charName;
|
|
var petConfig = PetInfoConfig.Get(config.petId);
|
m_BossType.text = string.Empty;
|
if (petConfig != null)
|
{
|
m_BossType.text = Language.Get("FairyGrabPet");
|
m_BossName.color = UIHelper.GetUIColor(petConfig.Quality, true);
|
}
|
var horseConfig = HorseConfig.Get(config.horseId);
|
if (horseConfig != null)
|
{
|
m_BossType.text = Language.Get("FairyGrabHorse");
|
m_BossName.color = UIHelper.GetUIColor(horseConfig.Quality, true);
|
}
|
|
var realmConfig = RealmConfig.Get(npcConfig.ClientRealm);
|
if (realmConfig != null)
|
{
|
m_RealmIcon.SetSprite(realmConfig.Img);
|
m_RealmIcon.SetNativeSize();
|
}
|
}
|
|
private void BossProgressUpdate(int _bossId)
|
{
|
if (_bossId == bossId)
|
{
|
DisplayProgress();
|
}
|
}
|
|
private void StateUpdate()
|
{
|
DisplayProgress();
|
}
|
|
void DisplayProgress()
|
{
|
FairyGrabBossModel.BossProgressInfo bossProgress;
|
bool killed = false;
|
bool opened = model.InActivityTime;
|
if (model.TryGetBossProgress(bossId, out bossProgress))
|
{
|
var progress = 1 - (float)bossProgress.currentHp / bossProgress.totalHp;
|
m_Progress.text = StringUtility.Contact((int)(progress * 100), "%");
|
killed = progress >= 1;
|
}
|
else
|
{
|
m_Progress.text = StringUtility.Contact(0, "%");
|
}
|
m_ContainerKilled.gameObject.SetActive(killed && opened);
|
m_ContainerKilling.gameObject.SetActive(!killed && opened);
|
m_BossPortrait.material = opened && !killed ? m_NormalMaterial : m_GrayMaterial;
|
m_ContainerMapName.gameObject.SetActive(!opened);
|
}
|
|
protected virtual void LateUpdate()
|
{
|
if (autoSelectScroll.autoSelectable && model.selectBoss != bossId && bossId > 0)
|
{
|
if (Mathf.Abs(centerSign.position.y - rectTransform.position.y) * 100f < rectTransform.rect.height * 0.45f)
|
{
|
model.selectBoss = bossId;
|
}
|
}
|
}
|
}
|
}
|