using FL.Battle; using FL.Battle.Buffs; using UnityEngine; using UnityEngine.UI; using XGame.Framework.Map; namespace FL.Map.UI { public interface IEntityBattleInfoView : IEntityView { ITarget Master { get; set; } bool IsMoveable { get; set; } void RefreshHp(); void RefreshBuffs(); } public interface IEntityBattleInfoVM { Image HpImg { get; } Image ShieldImg { get; } BattleInfoBuffList BuffList { get; } } public abstract class EntityBattleInfoView : EntityView, IEntityBattleInfoView where TViewModel : class, IEntityViewModel, IEntityBattleInfoVM { private ITarget _master; public ITarget Master { get => _master; set { _master = value; RefreshHp(); } } private Vector2 _hpImgSize; /// /// 是否可以移动 /// boss的血条位置固定 /// public bool IsMoveable { get; set; } protected override void OnInited() { //if (_hpImgSize == Vector2.zero) _hpImgSize = VM.HpImg.rectTransform.sizeDelta; //Log.Debug($"EntityBattleInfoView size:{_hpImgSize}"); } protected override void OnDispose() { VM.HpImg.rectTransform.sizeDelta = _hpImgSize; _master = null; } public void RefreshHp() { var hpImg = VM.HpImg; var shieldImg = VM.ShieldImg; var totalShield = Master.Buffs.TotalShieldVal; shieldImg.gameObject.SetActive(totalShield > 0); var totalHp = _master.Entity.Attr.HpLimit + totalShield; var curHp = _master.Entity.Attr.CurrentHp; if (hpImg.type == Image.Type.Filled) { hpImg.fillAmount = (float)curHp / totalHp; if (totalShield > 0) { shieldImg.fillAmount = (float)(curHp + totalShield) / totalHp; } } else { var size = _hpImgSize; size.x = size.x * curHp / totalHp; hpImg.rectTransform.sizeDelta = size; if (totalShield > 0) { size = _hpImgSize; size.x = size.x * (curHp + totalShield) / totalHp; shieldImg.rectTransform.sizeDelta = size; } } } public void RefreshBuffs() { if (Master.Buffs.IsShieldDirty) { Master.Buffs.IsShieldDirty = false; RefreshHp(); } if (VM.BuffList == null || Master.Buffs.IsDirty == false) return; Master.Buffs.IsDirty = false; var buffs = Master.Buffs.GetBuffs(); VM.BuffList.Refresh(buffs, Context); XGame.Framework.ListPool.Recycle(buffs); } } }