feat(hero-info): 实现自动生成英雄技能描述文本
新增HeroSkillDesc工具类动态生成技能描述字符串 修正heroSet.ts中的技能触发器描述文本 优化HInfoComp组件替换硬编码的英雄信息 完善hnode预制体的info标签配置与样式
This commit is contained in:
45
assets/script/game/common/config/HeroSkillDesc.ts
Normal file
45
assets/script/game/common/config/HeroSkillDesc.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { heroInfo, SkillTriggerName, SkillTriggerType } from "./heroSet";
|
||||
import { FieldSkillSet, SkillSet } from "./SkillSet";
|
||||
|
||||
const TRIGGER_KEYS: SkillTriggerType[] = [
|
||||
SkillTriggerType.Call,
|
||||
SkillTriggerType.Dead,
|
||||
SkillTriggerType.FStart,
|
||||
SkillTriggerType.FEnd,
|
||||
SkillTriggerType.Atking,
|
||||
SkillTriggerType.Atked,
|
||||
];
|
||||
|
||||
export function buildSkillDesc(hero: heroInfo): string {
|
||||
const lines: string[] = [];
|
||||
|
||||
for (const key of TRIGGER_KEYS) {
|
||||
const arr = hero[key] as { s_uuid: number; t_num: number }[] | undefined;
|
||||
if (!arr?.length) continue;
|
||||
const triggerName = SkillTriggerName[key] ?? key;
|
||||
for (const item of arr) {
|
||||
const skill = SkillSet[item.s_uuid];
|
||||
if (!skill) continue;
|
||||
const suffix = item.t_num > 1 ? ` (每${item.t_num}次触发)` : "";
|
||||
lines.push(`${triggerName}: ${skill.name}${suffix}`);
|
||||
}
|
||||
}
|
||||
|
||||
const fieldUuids = hero[SkillTriggerType.Field] as number[] | undefined;
|
||||
if (fieldUuids?.length) {
|
||||
const triggerName = SkillTriggerName[SkillTriggerType.Field] ?? "光环";
|
||||
for (const uuid of fieldUuids) {
|
||||
const fs = FieldSkillSet[uuid];
|
||||
if (fs) lines.push(`${triggerName}: ${fs.info}`);
|
||||
}
|
||||
}
|
||||
|
||||
const revive = hero[SkillTriggerType.Revive] as { s_uuid: number; r_num: number; upr: number } | undefined;
|
||||
if (revive) {
|
||||
const triggerName = SkillTriggerName[SkillTriggerType.Revive] ?? "复活";
|
||||
const skill = SkillSet[revive.s_uuid];
|
||||
if (skill) lines.push(`${triggerName}: ${skill.name}`);
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
9
assets/script/game/common/config/HeroSkillDesc.ts.meta
Normal file
9
assets/script/game/common/config/HeroSkillDesc.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "de462338-a674-4ccf-b621-bb67d0d9b901",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -100,14 +100,14 @@ export const SkillTriggerName = {
|
||||
}
|
||||
|
||||
export const SkillTriggerDesc = {
|
||||
[SkillTriggerType.Call]: "召唤时:",
|
||||
[SkillTriggerType.Dead]: "死亡时:",
|
||||
[SkillTriggerType.FStart]: "战斗开始时:",
|
||||
[SkillTriggerType.FEnd]: "战斗结束时:",
|
||||
[SkillTriggerType.Field]: "驻场时:",
|
||||
[SkillTriggerType.Atking]: "攻击后时:",
|
||||
[SkillTriggerType.Atked]: "受击后时:",
|
||||
[SkillTriggerType.Revive]: "复活时:",
|
||||
[SkillTriggerType.Call]: "召唤时",
|
||||
[SkillTriggerType.Dead]: "死亡时",
|
||||
[SkillTriggerType.FStart]: "战斗开始时",
|
||||
[SkillTriggerType.FEnd]: "战斗结束时",
|
||||
[SkillTriggerType.Field]: "场上存活",
|
||||
[SkillTriggerType.Atking]: "攻击n次",
|
||||
[SkillTriggerType.Atked]: "受击n次",
|
||||
[SkillTriggerType.Revive]: "复活时",
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@ import { smc } from "../common/SingletonModuleComp";
|
||||
import { TalentType } from "../common/config/TalentSet";
|
||||
import { Hero } from "../hero/Hero";
|
||||
import { FieldSkillType } from "../common/config/SkillSet";
|
||||
import { buildSkillDesc } from "../common/config/HeroSkillDesc";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
@@ -176,6 +177,10 @@ export class HInfoComp extends CCComp {
|
||||
this.hpLabel.string = `${hp}`;
|
||||
if (this.hpPlusLabel) this.hpPlusLabel.node.active = false;
|
||||
}
|
||||
|
||||
if (this.infoLabel) {
|
||||
this.infoLabel.string = buildSkillDesc(hero);
|
||||
}
|
||||
}
|
||||
|
||||
/** 是否正在关闭中,防止重复调用 remove */
|
||||
@@ -277,7 +282,7 @@ export class HInfoComp extends CCComp {
|
||||
// ---- 技能信息标签 ----
|
||||
if (this.infoLabel) {
|
||||
const heroData = HeroInfo[heroUuid];
|
||||
this.infoLabel.string = heroData?.info ?? "";
|
||||
this.infoLabel.string = heroData ? buildSkillDesc(heroData) : "";
|
||||
}
|
||||
|
||||
// ---- 数值标签 ----
|
||||
@@ -327,7 +332,16 @@ export class HInfoComp extends CCComp {
|
||||
this.nameLabel = this.Name_node.getComponent(Label) || this.Name_node.getComponentInChildren(Label);
|
||||
}
|
||||
if (!this.infoLabel && this.info_node) {
|
||||
this.infoLabel = this.info_node.getComponent(Label) || this.info_node.getComponentInChildren(Label);
|
||||
this.infoLabel = this.info_node.getComponentInChildren(Label);
|
||||
if (!this.infoLabel) {
|
||||
const child = this.info_node.children[0] || this.info_node;
|
||||
this.infoLabel = child.getComponent(Label) || child.addComponent(Label);
|
||||
this.infoLabel.fontSize = 20;
|
||||
this.infoLabel.lineHeight = 28;
|
||||
this.infoLabel.overflow = Label.Overflow.SHRINK;
|
||||
this.infoLabel.horizontalAlign = Label.HorizontalAlign.LEFT;
|
||||
this.infoLabel.verticalAlign = Label.VerticalAlign.TOP;
|
||||
}
|
||||
}
|
||||
if (!this.apLabel && this.ap_node) {
|
||||
this.apLabel = this.ap_node.getChildByName("val")?.getComponent(Label) || null;
|
||||
|
||||
Reference in New Issue
Block a user