feat(英雄视图): 添加血条显示计时功能

新增血条显示持续时间配置和计时器,修改血条显示逻辑:
1. 添加 hpBarShowTime 和 hpBarShowCD 字段控制血条显示时间
2. 初始隐藏血条,仅在受到攻击时显示并开始计时
3. 移除满血自动隐藏逻辑,改为仅更新进度条
4. 重置状态时清除血条计时器
This commit is contained in:
2025-11-03 23:40:43 +08:00
parent 8152523e10
commit 4670b12330

View File

@@ -34,6 +34,9 @@ export class HeroViewComp extends CCComp {
useMp:boolean = false; useMp:boolean = false;
realDeadTime:number=10 realDeadTime:number=10
deadCD:number=0 deadCD:number=0
// 血条显示相关
hpBarShowTime:number = 5; // 血条显示持续时间(秒)
hpBarShowCD:number = 0; // 血条显示计时器
// ==================== UI 节点引用 ==================== // ==================== UI 节点引用 ====================
private top_node: Node = null!; private top_node: Node = null!;
@@ -89,6 +92,8 @@ export class HeroViewComp extends CCComp {
this.useMp=HeroInfo[this.model.hero_uuid].type==HType.mage||HeroInfo[this.model.hero_uuid].type==HType.remote||HeroInfo[this.model.hero_uuid].type==HType.support; this.useMp=HeroInfo[this.model.hero_uuid].type==HType.mage||HeroInfo[this.model.hero_uuid].type==HType.remote||HeroInfo[this.model.hero_uuid].type==HType.support;
this.top_node.getChildByName("pow").active = this.usePower; this.top_node.getChildByName("pow").active = this.usePower;
this.top_node.getChildByName("mp").active = this.useMp; this.top_node.getChildByName("mp").active = this.useMp;
// 初始隐藏血条(被攻击后才显示)
this.top_node.active = false;
} }
/** 初始化 UI 节点引用 */ /** 初始化 UI 节点引用 */
@@ -119,6 +124,17 @@ export class HeroViewComp extends CCComp {
} }
return return
} ; } ;
// 处理血条显示计时
if (this.hpBarShowCD > 0) {
this.hpBarShowCD -= dt;
if (this.hpBarShowCD <= 0) {
// 时间到,隐藏血条
this.top_node.active = false;
this.hpBarShowCD = 0;
}
}
// ✅ View 层职责:处理表现相关的逻辑 // ✅ View 层职责:处理表现相关的逻辑
this.processDamageQueue(); // 伤害数字显示队列 this.processDamageQueue(); // 伤害数字显示队列
@@ -144,11 +160,9 @@ export class HeroViewComp extends CCComp {
/** 显示血量 */ /** 显示血量 */
private hp_show(hp: number, hp_max: number) { private hp_show(hp: number, hp_max: number) {
if(hp==hp_max) { // 不再基于血量是否满来决定显示状态,只更新进度条
this.top_node.active=false; if(!this.top_node.active) return;
return
}
this.top_node.active=true
let hp_progress = hp / hp_max; let hp_progress = hp / hp_max;
this.top_node.getChildByName("hp").getComponent(ProgressBar).progress = hp_progress; this.top_node.getChildByName("hp").getComponent(ProgressBar).progress = hp_progress;
this.scheduleOnce(() => { this.scheduleOnce(() => {
@@ -292,6 +306,7 @@ export class HeroViewComp extends CCComp {
this.status_change("idle"); this.status_change("idle");
this.model.hp =this.model.Attrs[Attrs.HP_MAX]*50/100; this.model.hp =this.model.Attrs[Attrs.HP_MAX]*50/100;
this.top_node.active=false this.top_node.active=false
this.hpBarShowCD=0
} }
/** /**
@@ -334,7 +349,12 @@ export class HeroViewComp extends CCComp {
} }
do_atked(damage:number,isCrit:boolean,s_uuid:number){ do_atked(damage:number,isCrit:boolean,s_uuid:number){
// 受到攻击时显示血条并设置显示时间即使伤害为0也显示
this.top_node.active = true;
this.hpBarShowCD = this.hpBarShowTime;
if (damage <= 0) return; if (damage <= 0) return;
// 视图层表现 // 视图层表现
let SConf=SkillSet[s_uuid] let SConf=SkillSet[s_uuid]
this.back() this.back()
@@ -448,6 +468,7 @@ export class HeroViewComp extends CCComp {
collider.off(Contact2DType.BEGIN_CONTACT); collider.off(Contact2DType.BEGIN_CONTACT);
} }
this.deadCD=0 this.deadCD=0
this.hpBarShowCD=0
// 清理伤害队列 // 清理伤害队列
this.damageQueue.length = 0; this.damageQueue.length = 0;