feat(英雄信息组件): 添加技能图标显示功能并调整缩放比例
- 新增技能图标显示功能,从图集加载并显示对应技能图标 - 调整英雄信息卡片的缩放比例参数 - 优化信息显示逻辑,移除冗余的位置设置代码
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
import { _decorator, Animation, AnimationClip, Component, instantiate, Label, Node, Prefab, resources, Sprite, SpriteFrame, v3, tween, Vec3, ProgressBar } from 'cc';
|
||||
import { _decorator, Animation, AnimationClip, Component, instantiate, Label, Node, Prefab, resources, Sprite, SpriteFrame, v3, tween, Vec3, ProgressBar, SpriteAtlas } from 'cc';
|
||||
import { oops } from 'db://oops-framework/core/Oops';
|
||||
import { getHeroList, getPreAttr, HeroConf, HeroInfo, HType, HTypeName } from '../common/config/heroSet';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
@@ -12,6 +12,7 @@ const { ccclass, property } = _decorator;
|
||||
@ecs.register('HInfoComp', false)
|
||||
export class HInfoComp extends CCComp {
|
||||
h_uuid:number=0
|
||||
private uiconsAtlas: SpriteAtlas | null = null;
|
||||
name_node:any=null
|
||||
type_node:any=null
|
||||
ap_node:any=null
|
||||
@@ -54,11 +55,11 @@ export class HInfoComp extends CCComp {
|
||||
switch(posIndex) {
|
||||
case 2:
|
||||
case 4:
|
||||
return v3(-1.5, 1.5, 1); // 2、4位置:1.5倍缩放
|
||||
return v3(-2.2, 2.2, 1); // 2、4位置:1.5倍缩放
|
||||
case 3:
|
||||
return v3(-3, 3, 1); // 3位置(中心):1.5倍缩放
|
||||
return v3(-2.9, 2.9, 1); // 3位置(中心):1.5倍缩放
|
||||
default:
|
||||
return v3(-1.5, 1.5, 1); // 其他位置:1.8倍缩放
|
||||
return v3(-2.2, 2.2, 1); // 其他位置:1.8倍缩放
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +75,7 @@ export class HInfoComp extends CCComp {
|
||||
this.h_uuid=smc.fight_hero
|
||||
this.update_data(this.h_uuid)
|
||||
this.load_all_hero(this.h_uuid)
|
||||
this.showInfo()
|
||||
}
|
||||
update(deltaTime: number) {
|
||||
|
||||
@@ -95,7 +97,51 @@ export class HInfoComp extends CCComp {
|
||||
this.hp_node.getChildByName("bar").getComponent(ProgressBar).progress=bar_num.hp
|
||||
this.def_node.getChildByName("bar").getComponent(ProgressBar).progress=bar_num.def
|
||||
this.mp_node.getChildByName("bar").getComponent(ProgressBar).progress=bar_num.mp
|
||||
|
||||
// 更新技能图标
|
||||
this.updateSkillIcon(this.skill1_node, skill1.icon);
|
||||
this.updateSkillIcon(this.skill2_node, skill2.icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新技能图标
|
||||
* @param node 技能节点
|
||||
* @param iconId 图标ID
|
||||
*/
|
||||
private updateSkillIcon(node: Node, iconId: string) {
|
||||
if (!node || !iconId) return;
|
||||
console.log("iconId",iconId)
|
||||
const iconNode = node.getChildByName("icon");
|
||||
console.log("iconNode",iconNode)
|
||||
if (!iconNode) return;
|
||||
const sprite = iconNode.getComponent(Sprite);
|
||||
console.log("sprite",sprite)
|
||||
if (!sprite) return;
|
||||
if (this.uiconsAtlas) {
|
||||
console.log("this.uiconsAtlas",this.uiconsAtlas)
|
||||
const frame = this.uiconsAtlas.getSpriteFrame(iconId);
|
||||
if (frame) {
|
||||
sprite.spriteFrame = frame;
|
||||
}
|
||||
} else {
|
||||
// 加载图集
|
||||
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
|
||||
if (err) {
|
||||
console.error("[HInfoComp] Failed to load uicons atlas", err);
|
||||
return;
|
||||
}
|
||||
this.uiconsAtlas = atlas;
|
||||
console.log("atlas",atlas)
|
||||
const frame = atlas.getSpriteFrame(iconId);
|
||||
if (frame) {
|
||||
sprite.spriteFrame = frame;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
load_all_hero(uuid:number){
|
||||
// 清除之前的英雄节点
|
||||
this.claear_hero();
|
||||
@@ -172,13 +218,11 @@ export class HInfoComp extends CCComp {
|
||||
}
|
||||
showInfo(){
|
||||
this.node.getChildByName("info").active=smc.data.showInfo
|
||||
if(smc.data.showInfo){
|
||||
this.node.getChildByName("info").setPosition(this.node.getChildByName("info").position.x,0)
|
||||
}
|
||||
this.node.getChildByName("hname").getChildByName("more").getChildByName("no").active=smc.data.showInfo
|
||||
}
|
||||
btnShowInfo(){
|
||||
smc.data.showInfo=!smc.data.showInfo
|
||||
this.showInfo()
|
||||
smc.data.showInfo=!smc.data.showInfo
|
||||
this.showInfo()
|
||||
}
|
||||
claear_hero(){
|
||||
for (let i = 0; i < this.heroNodes.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user