fix(英雄视图): 修复护盾显示时顶部血条隐藏的问题
调整顶部血条显示逻辑,将透明度控制改为显隐控制,确保护盾存在时血条始终可见。同时修复了护盾更新时未正确触发血条显示的问题,并优化了满血无护盾时的自动隐藏逻辑。
This commit is contained in:
@@ -115,13 +115,12 @@ export class HeroViewComp extends CCComp {
|
||||
private initUINodes() {
|
||||
this.top_node = this.node.getChildByName("top");
|
||||
this.topOpacity = this.top_node.getComponent(UIOpacity) || this.top_node.addComponent(UIOpacity);
|
||||
this.top_node.setPosition(0, 100, 0);
|
||||
this.topBasePos = this.top_node.position.clone();
|
||||
const hpNode = this.top_node.getChildByName("hp");
|
||||
if(this.model.fac==FacSet.HERO){
|
||||
hpNode.getChildByName("Bar").getComponent(Sprite).color=new Color("#2ECC71")
|
||||
}
|
||||
// let hp_y = this.node.getComponent(UITransform).height+10;
|
||||
// this.top_node.setPosition(0, hp_y, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,12 +168,11 @@ export class HeroViewComp extends CCComp {
|
||||
/** 显示护盾 */
|
||||
private show_shield(shield: number = 0, shield_max: number = 0) {
|
||||
this.lastBarUpdateTime = Date.now() / 1000;
|
||||
if(!this.top_node.active) return
|
||||
let shield_progress = shield / shield_max;
|
||||
this.node.getChildByName("shielded").active = shield > 0;
|
||||
this.top_node.getChildByName("shield").active = shield > 0;
|
||||
this.top_node.getChildByName("shield").getComponent(ProgressBar).progress = shield_progress;
|
||||
|
||||
this.setTopBarOpacity(false);
|
||||
}
|
||||
|
||||
/** 显示血量 */
|
||||
@@ -201,19 +199,24 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
|
||||
private isFullHp(): boolean {
|
||||
private isFullHpAndNoShield(): boolean {
|
||||
if (!this.model) return false;
|
||||
if (this.model.hp_max <= 0) return false;
|
||||
return this.model.hp >= this.model.hp_max;
|
||||
const isFullHp = this.model.hp >= this.model.hp_max;
|
||||
const noShield = this.model.shield <= 0;
|
||||
return isFullHp && noShield;
|
||||
}
|
||||
|
||||
private setTopBarOpacity(isActive: boolean) {
|
||||
if (!this.topOpacity || !this.topOpacity.isValid) return;
|
||||
if (isActive) {
|
||||
if (!this.top_node || !this.top_node.isValid) return;
|
||||
if (this.topOpacity) {
|
||||
this.topOpacity.opacity = this.barActiveOpacity;
|
||||
}
|
||||
if (isActive) {
|
||||
this.top_node.active = true;
|
||||
return;
|
||||
}
|
||||
this.topOpacity.opacity = this.isFullHp() ? this.barIdleOpacity : this.barActiveOpacity;
|
||||
this.top_node.active = !this.isFullHpAndNoShield();
|
||||
}
|
||||
|
||||
private activateTopBar() {
|
||||
|
||||
Reference in New Issue
Block a user