Files
heros/assets/script/game/map/HInfoComp.ts
panw d67c63b768 refactor(gui): 优化role_controller.prefab结构和视觉表现
- 调整多个组件的__id__以规范资源引用
- 修改部分节点名称以提升可读性和管理
- 优化节点的位置、旋转和缩放参数
- 更新Sprite和Label组件的颜色及资源关联
- 替换部分SpriteFrame资源,提高图像清晰度
- 修改UITransform尺寸和锚点以匹配设计需求
- 添加新的Animation和Widget组件,完善动画与布局
- 调整光源节点的变换参数以改善光照效果
- 清理和重组节点层次结构,简化子节点管理
- 改进字体样式及视觉表现,符合设计规范
2025-10-20 16:53:35 +08:00

102 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { _decorator, Animation, AnimationClip, Component, instantiate, Label, Node, Prefab, resources, Sprite, SpriteFrame, v3 } from 'cc';
import { oops } from 'db://oops-framework/core/Oops';
import { getHeroList, HeroInfo, HType, HTypeName } from '../common/config/heroSet';
import { smc } from '../common/SingletonModuleComp';
const { ccclass, property } = _decorator;
@ccclass('HInfoComp')
export class HInfoComp extends Component {
h_uuid:number=0
name_node:any=null
type_node:any=null
ap_node:any=null
hp_node:any=null
def_node:any=null
// 重新定义节点映射,使名称更清晰
// 当前显示的英雄节点数组7个位置
heroNodes: (Node | null)[] = [null, null, null, null, null, null, null];
// 英雄位置定义
hero_pos:any={
0:v3(420,-109,0), // 不在屏幕内
1:v3(280,-109,0),
2:v3(140,-109,0),
3:v3(0,-109,0),
4:v3(-140,-109,0),
5:v3(-280,-109,0),
6:v3(-420,-109,0), // 不在屏幕内
}
// 位置索引常量
private static center_pos = 3;
start() {
this.name_node=this.node.getChildByName("hero").getChildByName("hname").getChildByName("name")
this.type_node=this.node.getChildByName("hero").getChildByName("hname").getChildByName("type")
this.ap_node=this.node.getChildByName("info").getChildByName("base").getChildByName("ap").getChildByName("num")
this.hp_node=this.node.getChildByName("info").getChildByName("base").getChildByName("hp").getChildByName("num")
this.def_node=this.node.getChildByName("info").getChildByName("base").getChildByName("def").getChildByName("num")
this.h_uuid=smc.fight_hero
this.update_data(this.h_uuid)
}
update(deltaTime: number) {
}
update_data(uuid:number){
this.h_uuid=uuid
console.log("[HInfoComp]:update_data",uuid,HeroInfo[uuid],this.node)
this.name_node.getComponent(Label).string=HeroInfo[uuid].name
this.type_node.getComponent(Label).string=HTypeName[HeroInfo[uuid].type]
this.ap_node.getComponent(Label).string=HeroInfo[uuid].ap.toString()
this.hp_node.getComponent(Label).string=HeroInfo[uuid].hp.toString()
this.def_node.getComponent(Label).string=HeroInfo[uuid].def.toString()
this.load_all_hero(uuid)
}
load_all_hero(uuid:number){
}
load_hui(uuid:number,pos_index: number){
var path = "game/heros/"+HeroInfo[uuid].path;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
HeroInfo[uuid]
let anm_path=HeroInfo[uuid].path
resources.load("game/heros/hero/"+anm_path+"/idle", AnimationClip, (err, clip) => {
node.getComponent(Animation).addClip(clip);
node.getComponent(Animation).play("idle");
});
node.setPosition(this.hero_pos[pos_index])
}
claear_hero(){
for (let i = 0; i < this.heroNodes.length; i++) {
if (this.heroNodes[i]) {
this.heroNodes[i].destroy();
this.heroNodes[i] = null;
}
}
}
next_hero(){
let heros=getHeroList()
let index = heros.indexOf(this.h_uuid);
index++
if(index==heros.length) index=0
let nextHero = heros[index];
this.update_data(nextHero)
}
prev_hero(){
let heros=getHeroList()
let index = heros.indexOf(this.h_uuid);
index--
if(index==-1) index=heros.length-1
let prevHero = heros[index];
this.update_data(prevHero)
}
close(){
oops.gui.removeByNode(this.node)
}
reset() {
this.node.destroy()
}
}