style: 格式化代码并修复代码风格问题
本次提交主要对HeroAttrsComp和HeroViewComp两个文件进行了代码风格统一优化: 1. 统一变量声明的空格规范,修复类型标注前后的空格问题 2. 修正函数参数默认值的空格格式 3. 调整空行和注释的排版一致性 4. 修复字符串类型标注的大小写问题 5. 新增等级变更脏标记和对应的UI显示逻辑 6. 优化了部分条件判断和逻辑代码的可读性
This commit is contained in:
@@ -70,6 +70,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
// ==================== 脏标签标记 ====================
|
||||
dirty_hp: boolean = false; // 血量变更标记
|
||||
dirty_shield: boolean = false; // 护盾变更标记
|
||||
dirty_lv: boolean = false; // 等级变更标记
|
||||
|
||||
// ==================== 技能距离缓存 ====================
|
||||
maxSkillDistance: number = 0; // 最远技能攻击距离(缓存,受MP影响)
|
||||
@@ -429,6 +430,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
// 重置脏标签
|
||||
this.dirty_hp = false;
|
||||
this.dirty_shield = false;
|
||||
this.dirty_lv = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,13 +39,14 @@ export class HeroViewComp extends CCComp {
|
||||
deadCD: number = 0
|
||||
monDeadTime: number = 0.1
|
||||
hp_height: number = 70
|
||||
boss_hp_height:number=120
|
||||
boss_hp_height: number = 140
|
||||
// 血条显示相关
|
||||
lastBarUpdateTime: number = 0; // 最后一次血条/蓝条/护盾更新时间
|
||||
// ==================== UI 节点引用 ====================
|
||||
private top_node: Node = null!;
|
||||
private topOpacity: UIOpacity = null!;
|
||||
private topBasePos: Vec3 = v3();
|
||||
private lvLabel: Label | null = null; // 等级显示文本
|
||||
private readonly barIdleOpacity: number = 153;
|
||||
private readonly barActiveOpacity: number = 255;
|
||||
private readonly idleOpacityDelay: number = 0.25;
|
||||
@@ -121,10 +122,13 @@ export class HeroViewComp extends CCComp {
|
||||
this.top_node.getChildByName("hp").active = true;
|
||||
this.top_node.getChildByName("cd").active = false;
|
||||
this.top_node.getChildByName("shield").active = false;
|
||||
this.top_node.getChildByName("lv").active = false;
|
||||
this.top_node.getChildByName("lv").active = true;
|
||||
this.top_node.active = true;
|
||||
this.setTopBarOpacity(false);
|
||||
|
||||
// 初始化等级显示
|
||||
this.lv_show();
|
||||
|
||||
// 🔥 重置血条 UI 显示状态
|
||||
if (this.model) {
|
||||
this.hp_show();
|
||||
@@ -157,6 +161,12 @@ export class HeroViewComp extends CCComp {
|
||||
|
||||
// 确保血条等UI始终在最上层显示
|
||||
this.top_node.setSiblingIndex(999);
|
||||
|
||||
// 缓存等级显示 Label(lv 节点下的 Label 子节点)
|
||||
const lvNode = this.top_node.getChildByName("lv");
|
||||
if (lvNode) {
|
||||
this.lvLabel = lvNode.getChildByName("Label")?.getComponent(Label) ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +205,11 @@ export class HeroViewComp extends CCComp {
|
||||
this.show_shield(this.model.shield);
|
||||
this.model.dirty_shield = false;
|
||||
}
|
||||
|
||||
if (this.model.dirty_lv) {
|
||||
this.lv_show();
|
||||
this.model.dirty_lv = false;
|
||||
}
|
||||
}
|
||||
|
||||
public cd_show() {
|
||||
@@ -237,6 +252,12 @@ export class HeroViewComp extends CCComp {
|
||||
return this.model.hp >= this.model.hp_max;
|
||||
}
|
||||
|
||||
/** 更新等级显示 */
|
||||
private lv_show() {
|
||||
if (!this.lvLabel || !this.model) return;
|
||||
this.lvLabel.string = String(this.model.lv);
|
||||
}
|
||||
|
||||
private setTopBarOpacity(isActive: boolean) {
|
||||
if (!this.top_node || !this.top_node.isValid) return;
|
||||
if (this.topOpacity) {
|
||||
|
||||
Reference in New Issue
Block a user