feat: 添加英雄信息弹窗显示功能
- 在卡牌点击时打开英雄技能信息弹窗 - 为英雄头像信息组件添加点击打开弹窗功能 - 重构信息弹窗组件,支持动态显示英雄技能信息 - 调整弹窗UI布局和尺寸以适应不同数量的技能显示
This commit is contained in:
@@ -1,25 +1,13 @@
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { _decorator, Animation, AnimationClip, EventTouch, Label, Node, NodeEventType, Sprite, SpriteAtlas, Tween, tween, UIOpacity, Vec3, resources } from "cc";
|
||||
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 { CardConfig, CardType, SpecialCardList } from "../common/config/CardSet";
|
||||
import { CardUseComp } from "./CardUseComp";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('IBoxComp')
|
||||
@ecs.register('IBoxComp', false)
|
||||
export class IBoxComp extends CCComp {
|
||||
private debugMode: boolean = true;
|
||||
/** 锁定态图标节点(显示时表示本槽位锁定) */
|
||||
@property(Node)
|
||||
Line1: Node = null!
|
||||
@property(Node)
|
||||
@@ -30,24 +18,74 @@ export class IBoxComp extends CCComp {
|
||||
Line4: Node = null!
|
||||
@property(Node)
|
||||
Line5: Node = null!
|
||||
onAdded(args: any) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
}
|
||||
init(){
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user