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.

208 lines
7.3 KiB
C#

using Game.Battle;
namespace Game
{
public class PageHud : UIPageBase<ViewHud>
{
public int TargetCache = 0;
public PageHud()
{
}
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()
{
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.Hp, (_, now) =>
{
uiPlayer.m_bar_blood.value = now;
uiPlayer.m_t_blood.text = $"{now}";
});
BindData(hp.HpMax, (_, now) =>
{
uiPlayer.m_bar_blood.max = now;
uiPlayer.m_t_bloodThrough.text = $"{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(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);
}
}
}
}
}