- 在卡牌点击时打开英雄技能信息弹窗 - 为英雄头像信息组件添加点击打开弹窗功能 - 重构信息弹窗组件,支持动态显示英雄技能信息 - 调整弹窗UI布局和尺寸以适应不同数量的技能显示
92 lines
3.6 KiB
TypeScript
92 lines
3.6 KiB
TypeScript
import { _decorator, Label, Node, UITransform } from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { HeroInfo } from "../common/config/heroSet";
|
|
import { SkillSet } from "../common/config/SkillSet";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('IBoxComp')
|
|
@ecs.register('IBoxComp', false)
|
|
export class IBoxComp extends CCComp {
|
|
@property(Node)
|
|
Line1: Node = null!
|
|
@property(Node)
|
|
Line2: Node = null!
|
|
@property(Node)
|
|
Line3: Node = null!
|
|
@property(Node)
|
|
Line4: Node = null!
|
|
@property(Node)
|
|
Line5: Node = null!
|
|
private readonly baseHeight: number = 100;
|
|
private readonly extraLineHeight: number = 50;
|
|
|
|
onAdded(args: {
|
|
heroUuid?: number;
|
|
heroLv?: number;
|
|
skills?: Record<number, { uuid: number; lv: number; cd: number; ccd: number }>;
|
|
}) {
|
|
this.renderHeroInfo(args);
|
|
}
|
|
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
|
|
private renderHeroInfo(args: {
|
|
heroUuid?: number;
|
|
heroLv?: number;
|
|
skills?: Record<number, { uuid: number; lv: number; cd: number; ccd: number }>;
|
|
}) {
|
|
const heroUuid = Math.floor(args?.heroUuid ?? 0);
|
|
const heroLv = Math.max(1, Math.floor(args?.heroLv ?? 1));
|
|
const hero = HeroInfo[heroUuid];
|
|
if (!hero) {
|
|
this.applyLineTexts(["暂无技能信息"]);
|
|
return;
|
|
}
|
|
const runtimeSkills = args?.skills ? Object.values(args.skills) : [];
|
|
const sourceSkills = runtimeSkills.length > 0 ? runtimeSkills : Object.values(hero.skills ?? {});
|
|
const skillTexts = sourceSkills.map(skill => {
|
|
const skillId = Math.floor(skill?.uuid ?? 0);
|
|
if (!skillId) return "";
|
|
const config = SkillSet[skillId];
|
|
if (!config) return "";
|
|
const runtimeLv = runtimeSkills.length > 0 ? Math.max(0, Math.floor(skill.lv ?? 0)) : Math.max(0, Math.floor((skill.lv ?? 1) + heroLv - 2));
|
|
const cd = Number(skill?.cd ?? 0);
|
|
return `${config.name} Lv.${runtimeLv} CD:${cd}s ${config.info}`;
|
|
}).filter(Boolean);
|
|
this.applyLineTexts(skillTexts.length > 0 ? skillTexts : ["暂无技能信息"]);
|
|
}
|
|
|
|
private applyLineTexts(skillTexts: string[]) {
|
|
const lines = [this.Line1, this.Line2, this.Line3, this.Line4, this.Line5];
|
|
const showCount = Math.max(1, Math.min(lines.length, skillTexts.length));
|
|
for (let i = 0; i < lines.length; i++) {
|
|
const line = lines[i];
|
|
if (!line) continue;
|
|
const active = i < showCount;
|
|
line.active = active;
|
|
if (!active) continue;
|
|
const text = skillTexts[i] ?? "";
|
|
const noteNode = line.getChildByName("note");
|
|
const label = noteNode?.getComponent(Label) || noteNode?.getComponentInChildren(Label) || line.getComponentInChildren(Label);
|
|
if (label) label.string = text;
|
|
}
|
|
const targetHeight = this.baseHeight + Math.max(0, showCount - 1) * this.extraLineHeight;
|
|
this.updateIBoxHeight(targetHeight);
|
|
}
|
|
|
|
private updateIBoxHeight(height: number) {
|
|
const rootTransform = this.node.getComponent(UITransform);
|
|
if (rootTransform) {
|
|
rootTransform.setContentSize(rootTransform.contentSize.width, height);
|
|
}
|
|
const bgNode = this.node.getChildByName("Bg");
|
|
const bgTransform = bgNode?.getComponent(UITransform);
|
|
if (bgTransform) {
|
|
bgTransform.setContentSize(bgTransform.contentSize.width, height);
|
|
}
|
|
}
|
|
}
|