feat(hero-info): 实现自动生成英雄技能描述文本

新增HeroSkillDesc工具类动态生成技能描述字符串
修正heroSet.ts中的技能触发器描述文本
优化HInfoComp组件替换硬编码的英雄信息
完善hnode预制体的info标签配置与样式
This commit is contained in:
panw
2026-05-25 17:01:04 +08:00
parent 3386ccc68c
commit e846e6408c
5 changed files with 164 additions and 25 deletions

View File

@@ -54,18 +54,18 @@
],
"_active": true,
"_components": [
{
"__id__": 444
},
{
"__id__": 446
},
{
"__id__": 448
},
{
"__id__": 450
}
],
"_prefab": {
"__id__": 450
"__id__": 452
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -9594,18 +9594,18 @@
],
"_active": true,
"_components": [
{
"__id__": 437
},
{
"__id__": 439
},
{
"__id__": 441
},
{
"__id__": 443
}
],
"_prefab": {
"__id__": 443
"__id__": 445
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -9827,10 +9827,13 @@
"_components": [
{
"__id__": 434
},
{
"__id__": 436
}
],
"_prefab": {
"__id__": 436
"__id__": 438
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -9889,6 +9892,74 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "e5AR/R3blDqZJioB55xQMd"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 433
},
"_enabled": true,
"__prefab": {
"__id__": 437
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_string": "label",
"_horizontalAlign": 0,
"_verticalAlign": 1,
"_actualFontSize": 21,
"_fontSize": 20,
"_fontFamily": "Arial",
"_lineHeight": 40,
"_overflow": 2,
"_enableWrapText": true,
"_font": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_isItalic": false,
"_isBold": true,
"_isUnderline": false,
"_underlineHeight": 2,
"_cacheMode": 0,
"_enableOutline": true,
"_outlineColor": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_outlineWidth": 2,
"_enableShadow": false,
"_shadowColor": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_shadowOffset": {
"__type__": "cc.Vec2",
"x": 2,
"y": 2
},
"_shadowBlur": 2,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "a4aoaDD+FBU6Rtemm9p9yx"
},
{
"__type__": "cc.PrefabInfo",
"root": {
@@ -9912,7 +9983,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 438
"__id__": 440
},
"_contentSize": {
"__type__": "cc.Size",
@@ -9940,7 +10011,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 440
"__id__": 442
},
"_alignFlags": 0,
"_target": null,
@@ -9976,7 +10047,7 @@
},
"_enabled": false,
"__prefab": {
"__id__": 442
"__id__": 444
},
"_resizeMode": 1,
"_layoutType": 3,
@@ -10027,7 +10098,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 445
"__id__": 447
},
"_contentSize": {
"__type__": "cc.Size",
@@ -10055,7 +10126,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 447
"__id__": 449
},
"icon_node": {
"__id__": 105
@@ -10100,7 +10171,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 449
"__id__": 451
},
"_alignFlags": 44,
"_target": null,

View 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");
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "de462338-a674-4ccf-b621-bb67d0d9b901",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -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]: "复活时",
}
/**

View File

@@ -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;