2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

260 lines
8.9 KiB
C#

using System.Collections.Generic;
using Game.Battle;
namespace Game
{
public class PageHud : UIPageBase<ViewHud>
{
private int _targetCache = 0;
private readonly List<UIPoolItem<ViewMpItem>> _mpItemList = new List<UIPoolItem<ViewMpItem>>();
protected override void OnCreate()
{
CreateUI(true);
}
protected override void OnDestroy()
{
}
protected override void OnOpen()
{
// UIManager.instance.Open(EUIPage.BlessList);
// UIManager.instance.Open(EUIPage.Combo);
UIManager.Instance.Open(EuiPage.HeadBar);
UIManager.Instance.Open(EuiPage.Weapon);
EventManager.Instance.AddEvent<PEntityAlive>(EEvent.EntityAlive, OnEntityAlive);
EventManager.Instance.AddEvent<PEntityHit>(EEvent.EntityHit, OnEntityHit);
EventManager.Instance.AddEvent<string>(EEvent.ShowLevelName, OnShowLevelName);
}
protected override void OnClose()
{
foreach (var item in _mpItemList)
item.Destroy();
_mpItemList.Clear();
EventManager.Instance.RemoveEvent<PEntityAlive>(EEvent.EntityAlive, OnEntityAlive);
EventManager.Instance.RemoveEvent<PEntityHit>(EEvent.EntityHit, OnEntityHit);
EventManager.Instance.RemoveEvent<string>(EEvent.ShowLevelName, OnShowLevelName);
}
private void OnEntityAlive(PEntityAlive param)
{
if (_targetCache == 0)
{
return;
}
var entity = param.Entity;
if (!param.IsAlive && entity == _targetCache)
{
BindMonsterInfo(null);
}
}
private void OnEntityHit(PEntityHit param)
{
if (!param.IsSkill)
{
return;
}
var entity = Util.GetEntity(param.Target);
if (!entity.hp.IsAlive)
{
return;
}
if (entity.Team() != ETeam.Monster)
{
return;
}
if (_targetCache != param.Entity)
{
BindMonsterInfo(entity);
}
}
private void OnShowLevelName(string levelName)
{
View.m_showLevelName.selectedIndex = 1;
var uiLevelName = View.m_UI_LevelName;
uiLevelName.m_Name.text = levelName;
uiLevelName.m_showName.Play();
}
protected override void OnCreateBind()
{
var master = Util.GetMaster();
BindHp(master); //绑定血条
BindShield(master); //绑定护盾条
BindInteract(master); //绑定交互UI
}
public override void Update()
{
}
private void BindHp(GameEntity entity)
{
var hp = entity.hp;
var uiPlayer = View.m_UI_Player;
BindData(hp.HpMax, (_, now) =>
{
uiPlayer.m_bar_blood.max = now;
uiPlayer.m_t_bloodThrough.text = $"{now}";
});
BindData(hp.Hp, (_, now) =>
{
uiPlayer.m_bar_blood.value = now;
uiPlayer.m_t_blood.text = $"{now}";
});
BindData(hp.MpMax, (_, now) =>
{
for (var i = _mpItemList.Count - 1; i >= 0; i--)
{
var mpItem = _mpItemList[i];
uiPlayer.m_list_mp.RemoveChildAt(i);
mpItem.Destroy();
}
for (var i = 0; i < now; i++)
{
var mpItem = UIManager.Instance.Creator.CreateUIItem<ViewMpItem>(ViewMpItem.URL);
_mpItemList.Add(mpItem);
uiPlayer.m_list_mp.AddChild(mpItem.Component);
}
});
BindData(hp.Mp, (_, now) =>
{
for (var i = 0; i < _mpItemList.Count; i++)
{
var mpItem = _mpItemList[i];
if (i < now - 1)
{
mpItem.Component.m_c1.selectedIndex = 1;
}
else if (i == now - 1)
{
mpItem.Component.m_c1.selectedIndex = 2;
}
else
{
mpItem.Component.m_c1.selectedIndex = 0;
}
}
});
BindData(hp.SubMpMax, (_, now) => { uiPlayer.m_bar_subMp.max = now; });
BindData(hp.SubMp, (_, now) => { uiPlayer.m_bar_subMp.value = now; });
}
private void BindShield(GameEntity entity)
{
}
private void BindInteract(GameEntity entity)
{
var combo = entity.combo;
BindData(combo.TargetInteract, (_, now) => { View.m_showInteract.selectedIndex = (now != 0 ? 1 : 0); });
}
private void BindMonsterInfo(GameEntity entity)
{
var entityPre = Util.GetEntity(_targetCache);
if (entityPre != null)
{
var hp = entityPre.hp;
var buff = entityPre.buff;
UnbindData(hp.HpMax);
UnbindData(hp.Hp);
UnbindData(hp.ShieldMax);
UnbindData(hp.Shield);
UnbindData(hp.MpMax);
UnbindData(hp.Mp);
UnbindData(hp.SubMpMax);
UnbindData(hp.SubMp);
UnbindData(buff.BuffMap);
foreach (var item in buff.BuffMap)
{
var buffData = item.Value;
UnbindData(buffData.TimeLeft);
UnbindData(buffData.Level);
}
}
if (entity != null)
{
var uiMonster = View.m_UI_Monster;
var hp = entity.hp;
var buff = entity.buff;
uiMonster.m_monsterName.text = entity.iD.Data.BasicCfg.Name;
BindData(hp.HpMax, (_, now) =>
{
uiMonster.m_bloodBarEnemy.m_sub.max = now;
uiMonster.m_bloodBarEnemy.m_tween.max = now;
});
BindData(hp.Hp, (_, now) =>
{
uiMonster.m_bloodBarEnemy.m_sub.value = now;
uiMonster.m_bloodBarEnemy.m_tween.TweenValue(now - 1, 0.5f);
});
BindData(hp.ShieldMax, (_, now) =>
{
uiMonster.m_shieldBarEnemy.m_sub.max = now;
uiMonster.m_shieldBarEnemy.m_tween.max = now;
uiMonster.m_showshield.selectedIndex = now > 0 ? 1 : 0;
});
BindData(hp.Shield, (_, now) =>
{
uiMonster.m_shieldBarEnemy.m_sub.value = now;
uiMonster.m_shieldBarEnemy.m_tween.TweenValue(now - 1, 0.5f);
uiMonster.m_showshield.selectedIndex = now > 0 ? 1 : 0;
});
BindData(buff.BuffMap, (_, now) =>
{
uiMonster.m_buff.RemoveChildrenToPool();
foreach (var item in now)
{
if (!item.Value.IsShow)
{
continue;
}
var obj = uiMonster.m_buff.AddItemFromPool() as Viewc_buffItem;
var buffData = item.Value;
obj.m_buffIcon.texture = Texture(buffData.BuffCfg.Buff.Icon);
ReBindData(buffData.TimeLeft, (_, now) => { obj.m_mask.fillAmount = now / buffData.TimeMax; });
ReBindData(buffData.Level, (_, now) => { obj.m_level.text = $"{now}"; });
}
});
_targetCache = entity.ID();
}
View.m_showMonsterInfo.selectedIndex = entity == null ? 0 : 1;
}
protected override void OnInput(PPlayerInput context)
{
if (context.Action == EKeyActionType.Press)
{
if (context.Key == EFunctionKey.Test1)
{
UIManager.Instance.Open(EuiPage.SkillGm);
}
if (context.Key == EFunctionKey.Bag)
{
UIManager.Instance.Open(EuiPage.Bag);
}
if (context.Key == EFunctionKey.Menu)
{
UIManager.Instance.Open(EuiPage.GmPanel);
}
}
}
}
}