refactor(hero system): 重构英雄升级与卡片展示逻辑
1. 重构英雄升级方法,移除外部传入所需碎片参数,改为从配置表自动读取 2. 简化CardLiteComp.setHeroByUuid,移除卡池等级参数,直接读取英雄静态配置 3. 新增ChipComp.setHeroIconByUuid,重构英雄图标渲染逻辑 4. 新增英雄详情面板的升级功能与碎片展示 5. 新增英雄成长变化的事件监听与面板刷新逻辑
This commit is contained in:
@@ -25,8 +25,12 @@ import { mLogger } from "../common/Logger";
|
||||
import { HeroInfo, HeroList } from "../common/config/heroSet";
|
||||
import { buildSkillDesc } from "../common/config/HeroSkillDesc";
|
||||
import { CKind } from "../common/config/CardSet";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { HERO_UPGRADE_NEED_FRAGMENTS } from "../common/config/GameSet";
|
||||
import { CardBgComp } from "./CardBgComp";
|
||||
import { CardLiteComp } from "./CardLiteComp";
|
||||
import { ChipComp } from "./ChipComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
const { property, ccclass } = _decorator;
|
||||
|
||||
@@ -41,6 +45,9 @@ export class HerosListComp extends CCComp {
|
||||
@property(Node)
|
||||
ap_node = null!
|
||||
|
||||
@property(Node)
|
||||
def_node = null!
|
||||
|
||||
@property(Node)
|
||||
hp_node = null!
|
||||
|
||||
@@ -69,6 +76,18 @@ export class HerosListComp extends CCComp {
|
||||
@property(Node)
|
||||
type_node = null!
|
||||
|
||||
/** 升级按钮节点 */
|
||||
@property(Node)
|
||||
upgrade_btn = null!
|
||||
|
||||
/** 碎片数量显示节点(Label) */
|
||||
@property(Node)
|
||||
fragment_node = null!
|
||||
|
||||
/** 碎片图标节点(挂载 ChipComp 用于渲染碎片图标) */
|
||||
@property(Node)
|
||||
chip_node = null!
|
||||
|
||||
// ======================== 运行时状态 ========================
|
||||
|
||||
huuid: number = 0
|
||||
@@ -84,15 +103,49 @@ export class HerosListComp extends CCComp {
|
||||
}
|
||||
|
||||
protected onEnable(): void {
|
||||
oops.message.on(GameEvent.HERO_GROWTH_UPDATE, this.onGrowthUpdate, this)
|
||||
if (this.cards_node && this.cards_node.children.length > 0) {
|
||||
this.onCardSelect(this.huuid || HeroList[0])
|
||||
}
|
||||
}
|
||||
|
||||
protected onDisable(): void {
|
||||
oops.message.off(GameEvent.HERO_GROWTH_UPDATE, this.onGrowthUpdate, this)
|
||||
}
|
||||
|
||||
private onGrowthUpdate() {
|
||||
if (this.huuid) {
|
||||
this.updateHeroDetail(this.huuid)
|
||||
}
|
||||
}
|
||||
|
||||
closeHeros() {
|
||||
this.node.active = false
|
||||
}
|
||||
|
||||
/**
|
||||
* 升级按钮点击回调
|
||||
* 消耗碎片提升英雄局外等级,成功后刷新详情面板
|
||||
*/
|
||||
onUpgradeClick() {
|
||||
const uuid = this.huuid
|
||||
if (!uuid) return
|
||||
|
||||
const success = smc.upgradeHero(uuid)
|
||||
if (success) {
|
||||
mLogger.log(this.debugMode, "HerosListComp", `英雄 ${uuid} 升级成功`)
|
||||
this.updateHeroDetail(uuid)
|
||||
} else {
|
||||
const growth = smc.getHeroGrowth(uuid)
|
||||
const need = HERO_UPGRADE_NEED_FRAGMENTS[growth.lv + 1]
|
||||
mLogger.log(this.debugMode, "HerosListComp", `英雄 ${uuid} 升级失败`, {
|
||||
currentLv: growth.lv,
|
||||
fragments: growth.fragments,
|
||||
needFragments: need ?? "MAX",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== 卡片列表 ========================
|
||||
|
||||
private initCardList() {
|
||||
@@ -136,7 +189,7 @@ export class HerosListComp extends CCComp {
|
||||
})
|
||||
|
||||
const comp = cardNode.getComponent(CardLiteComp) || cardNode.addComponent(CardLiteComp)
|
||||
comp.setHeroByUuid(uuid, hero.card_lv ?? 1)
|
||||
comp.setHeroByUuid(uuid)
|
||||
comp.onClickCallback = (cardComp: CardLiteComp) => {
|
||||
this.onCardSelect(uuid)
|
||||
this.highlightCard(cardNode)
|
||||
@@ -197,6 +250,7 @@ export class HerosListComp extends CCComp {
|
||||
const suffix = heroLv >= 2 ? "★".repeat(heroLv - 1) : ""
|
||||
this.setLabelText(this.name_node, `${suffix}${hero.name || ""}${suffix}`)
|
||||
this.setLabelText(this.ap_node, `${(hero.ap ?? 0) * heroLv}`)
|
||||
this.setLabelText(this.def_node, `${(hero.def ?? 0) * heroLv}`)
|
||||
this.setLabelText(this.hp_node, `${(hero.hp ?? 0) * heroLv}`)
|
||||
|
||||
this.updateCdDisplay(hero)
|
||||
@@ -213,6 +267,7 @@ export class HerosListComp extends CCComp {
|
||||
this.updateLvDisplay(hero)
|
||||
this.updateTypeDisplay(hero)
|
||||
this.updateHeroAnimation(uuid)
|
||||
this.updateGrowthPanel(uuid)
|
||||
}
|
||||
|
||||
private updatePoolLvBg(poolLv: number) {
|
||||
@@ -261,6 +316,38 @@ export class HerosListComp extends CCComp {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新局外成长面板:碎片数量与升级按钮状态
|
||||
* @param uuid 英雄模板 uuid
|
||||
*/
|
||||
private updateGrowthPanel(uuid: number) {
|
||||
const growth = smc.getHeroGrowth(uuid)
|
||||
const needFragments = HERO_UPGRADE_NEED_FRAGMENTS[growth.lv + 1]
|
||||
const isMaxLv = needFragments === undefined
|
||||
|
||||
// 碎片数量显示:当前拥有 / 下一级所需(满级时显示 MAX)
|
||||
if (this.fragment_node) {
|
||||
const fragmentText = isMaxLv
|
||||
? `${growth.fragments} / MAX`
|
||||
: `${growth.fragments} / ${needFragments}`
|
||||
this.setLabelText(this.fragment_node, fragmentText)
|
||||
}
|
||||
|
||||
// 碎片图标:使用 ChipComp 渲染英雄图标(自动读取 HeroInfo 配置)
|
||||
if (this.chip_node) {
|
||||
const chipComp = this.chip_node.getComponent(ChipComp) || this.chip_node.addComponent(ChipComp)
|
||||
chipComp.setHeroIconByUuid(uuid)
|
||||
}
|
||||
|
||||
// 升级按钮状态:未满级且碎片足够时可用
|
||||
if (this.upgrade_btn) {
|
||||
const canUpgrade = !isMaxLv && growth.fragments >= needFragments
|
||||
this.upgrade_btn.active = true
|
||||
const btnComp = this.upgrade_btn.getComponent("cc.Button") as import("cc").Button | null
|
||||
if (btnComp) btnComp.interactable = canUpgrade
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== 英雄动画 ========================
|
||||
|
||||
private updateHeroAnimation(uuid: number) {
|
||||
|
||||
Reference in New Issue
Block a user