style: 优化MissionCardComp代码格式与细节

调整变量类型声明的空格、代码缩进与空行规范,修复部分UI更新逻辑,修正卡牌位置数组的空格格式,统一代码书写风格
This commit is contained in:
pan
2026-05-29 15:30:50 +08:00
parent 62a92ab9b6
commit 8b1f61014b
2 changed files with 1206 additions and 6170 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -81,35 +81,35 @@ export class MissionCardComp extends CCComp {
/** 卡牌面板根节点(战斗阶段收起,准备阶段展开) */ /** 卡牌面板根节点(战斗阶段收起,准备阶段展开) */
@property(Node) @property(Node)
cards_node:Node = null! cards_node: Node = null!
/** 卡牌槽位 1 节点 */ /** 卡牌槽位 1 节点 */
@property(Node) @property(Node)
card1:Node = null! card1: Node = null!
/** 卡牌槽位 2 节点 */ /** 卡牌槽位 2 节点 */
@property(Node) @property(Node)
card2:Node = null! card2: Node = null!
/** 卡牌槽位 3 节点 */ /** 卡牌槽位 3 节点 */
@property(Node) @property(Node)
card3:Node = null! card3: Node = null!
/** 卡牌槽位 4 节点 */ /** 卡牌槽位 4 节点 */
@property(Node) @property(Node)
card4:Node = null! card4: Node = null!
/** 抽卡(刷新)按钮节点 */ /** 抽卡(刷新)按钮节点 */
@property(Node) @property(Node)
cards_chou:Node = null! cards_chou: Node = null!
/** 卡池升级按钮节点 */ /** 卡池升级按钮节点 */
@property(Node) @property(Node)
cards_up:Node = null! cards_up: Node = null!
/** 金币显示节点(含 icon + num 子节点) */ /** 金币显示节点(含 icon + num 子节点) */
@property(Node) @property(Node)
coins_node:Node = null! coins_node: Node = null!
/** 卡池等级显示节点 */ /** 卡池等级显示节点 */
@property(Node) @property(Node)
pool_lv_node:Node = null! pool_lv_node: Node = null!
/** 英雄数量显示节点(含 icon + num 子节点) */ /** 英雄数量显示节点(含 icon + num 子节点) */
@property(Node) @property(Node)
hero_num_node:Node=null! hero_num_node: Node = null!
// ======================== 运行时状态 ======================== // ======================== 运行时状态 ========================
/** 当前是否为战斗阶段 */ /** 当前是否为战斗阶段 */
@@ -128,7 +128,7 @@ export class MissionCardComp extends CCComp {
/** 卡牌面板收起态缩放scale=0 隐藏) */ /** 卡牌面板收起态缩放scale=0 隐藏) */
private cardsHideScale: Vec3 = new Vec3(0, 0, 1); private cardsHideScale: Vec3 = new Vec3(0, 0, 1);
/** 卡牌原始定位点 */ /** 卡牌原始定位点 */
private cardsPos = [-260,-75,108,260] private cardsPos = [-260, -75, 108, 260]
// ======================== 生命周期 ======================== // ======================== 生命周期 ========================
@@ -164,10 +164,10 @@ export class MissionCardComp extends CCComp {
} }
/** 外部初始化入口(由 CardController 调用) */ /** 外部初始化入口(由 CardController 调用) */
init(){ init() {
this.onMissionStart(); this.onMissionStart();
} }
/** /**
* 任务开始: * 任务开始:
* 1. 进入准备阶段(展开卡牌面板)。 * 1. 进入准备阶段(展开卡牌面板)。
@@ -188,12 +188,12 @@ export class MissionCardComp extends CCComp {
missionData.hero_max_num = FightSet.HERO_MAX_NUM; missionData.hero_max_num = FightSet.HERO_MAX_NUM;
missionData.hero_extend_max_num = FightSet.HERO_MAX_NUM + 1; missionData.hero_extend_max_num = FightSet.HERO_MAX_NUM + 1;
} }
// 确保卡牌组件列表已被正确缓存 // 确保卡牌组件列表已被正确缓存
if (!this.cardComps || this.cardComps.length === 0) { if (!this.cardComps || this.cardComps.length === 0) {
this.cacheCardComps(); this.cacheCardComps();
} }
this.layoutCardSlots(); this.layoutCardSlots();
this.clearAllCards(); this.clearAllCards();
// if (this.cards_up) { // if (this.cards_up) {
@@ -276,7 +276,7 @@ export class MissionCardComp extends CCComp {
* 金币变化事件回调: * 金币变化事件回调:
* 仅负责 UI 更新和动画表现。数据更新已由 MissionEconomy 统一处理。 * 仅负责 UI 更新和动画表现。数据更新已由 MissionEconomy 统一处理。
*/ */
private onCoinAdd(event: string, args: any){ private onCoinAdd(event: string, args: any) {
const payload = args ?? event; const payload = args ?? event;
const v = typeof payload === 'number' ? payload : (payload?.delta ?? payload?.value ?? 0); const v = typeof payload === 'number' ? payload : (payload?.delta ?? payload?.value ?? 0);
this.updateCoinAndCostUI(); this.updateCoinAndCostUI();
@@ -300,21 +300,21 @@ export class MissionCardComp extends CCComp {
private onCardPoolUpgrade(event: string, args: any) { private onCardPoolUpgrade(event: string, args: any) {
const targetLv = args?.targetLv; const targetLv = args?.targetLv;
if (!targetLv) return; if (!targetLv) return;
if (targetLv > CARD_POOL_MAX_LEVEL) { if (targetLv > CARD_POOL_MAX_LEVEL) {
this.poolLv = CARD_POOL_MAX_LEVEL; this.poolLv = CARD_POOL_MAX_LEVEL;
} else { } else {
this.poolLv = targetLv; this.poolLv = targetLv;
} }
mLogger.log(this.debugMode, "MissionCardComp", "onCardPoolUpgrade", { mLogger.log(this.debugMode, "MissionCardComp", "onCardPoolUpgrade", {
targetLv, targetLv,
poolLv: this.poolLv poolLv: this.poolLv
}); });
// 提示卡池升级 // 提示卡池升级
oops.gui.toast(`卡池已升至${this.poolLv}`); oops.gui.toast(`卡池已升至${this.poolLv}`);
// 更新UI // 更新UI
this.updatePoolLvUI(); this.updatePoolLvUI();
} }
@@ -332,7 +332,7 @@ export class MissionCardComp extends CCComp {
const cards = this.buildDrawCards(); const cards = this.buildDrawCards();
this.dispatchCardsToSlots(cards); this.dispatchCardsToSlots(cards);
} }
/** 解除按钮监听,避免节点销毁后回调泄漏 */ /** 解除按钮监听,避免节点销毁后回调泄漏 */
private unbindEvents() { private unbindEvents() {
oops.message.off(GameEvent.CoinAdd, this.onCoinAdd, this); oops.message.off(GameEvent.CoinAdd, this.onCoinAdd, this);
@@ -360,9 +360,9 @@ export class MissionCardComp extends CCComp {
const payload = args ?? event; const payload = args ?? event;
const eid = Number(payload?.eid ?? 0); const eid = Number(payload?.eid ?? 0);
const model = payload?.model as HeroAttrsComp | undefined; const model = payload?.model as HeroAttrsComp | undefined;
mLogger.log(this.debugMode, "MissionCardComp", "onMasterCalled received payload:", { eid, hasModel: !!model }); mLogger.log(this.debugMode, "MissionCardComp", "onMasterCalled received payload:", { eid, hasModel: !!model });
if (!eid || !model) return; if (!eid || !model) return;
const before = this.getAliveHeroCount(); const before = this.getAliveHeroCount();
const after = this.getAliveHeroCount(); const after = this.getAliveHeroCount();
@@ -388,7 +388,7 @@ export class MissionCardComp extends CCComp {
private onUseHeroCard(event: string, args: any) { private onUseHeroCard(event: string, args: any) {
const payload = args ?? event; const payload = args ?? event;
if (!payload) return; if (!payload) return;
if (this.isBattlePhase) { if (this.isBattlePhase) {
payload.cancel = true; payload.cancel = true;
payload.reason = "battle_phase"; payload.reason = "battle_phase";
@@ -448,7 +448,7 @@ export class MissionCardComp extends CCComp {
* @returns { needCount: 合成所需数量, maxLv: 最大合成等级 } * @returns { needCount: 合成所需数量, maxLv: 最大合成等级 }
*/ */
private getMergeRule(): { needCount: number, maxLv: number } { private getMergeRule(): { needCount: number, maxLv: number } {
let needCount = FightSet.MERGE_NEED ? FightSet.MERGE_NEED:2 let needCount = FightSet.MERGE_NEED ? FightSet.MERGE_NEED : 2
let maxLv = Math.max(1, Math.floor(FightSet.MERGE_MAX ?? 3)); let maxLv = Math.max(1, Math.floor(FightSet.MERGE_MAX ?? 3));
ecs.query(ecs.allOf(MissionHeroComp)).forEach((entity: ecs.Entity) => { ecs.query(ecs.allOf(MissionHeroComp)).forEach((entity: ecs.Entity) => {
const comp = entity.get(MissionHeroComp); const comp = entity.get(MissionHeroComp);
@@ -550,7 +550,7 @@ export class MissionCardComp extends CCComp {
}); });
return; return;
} }
mLogger.log(this.debugMode, "MissionCardComp", "click draw", { mLogger.log(this.debugMode, "MissionCardComp", "click draw", {
poolLv: this.poolLv, poolLv: this.poolLv,
cost, cost,
@@ -637,7 +637,7 @@ export class MissionCardComp extends CCComp {
targetType = [CardType.Hero, CardType.SpecialRefresh]; targetType = [CardType.Hero, CardType.SpecialRefresh];
} }
const cards = getCardsByLv(this.poolLv, targetType); const cards = getCardsByLv(this.poolLv, targetType);
/** 正常情况下直接取前3 */ /** 正常情况下直接取前3 */
if (cards.length >= 3) return cards.slice(0, 3); if (cards.length >= 3) return cards.slice(0, 3);
/** 兜底当返回不足3张时循环补齐保证分发不缺位 */ /** 兜底当返回不足3张时循环补齐保证分发不缺位 */
@@ -765,24 +765,21 @@ export class MissionCardComp extends CCComp {
if (this.pool_lv_node) { if (this.pool_lv_node) {
this.pool_lv_node.active = true; this.pool_lv_node.active = true;
const lv = Math.max(CARD_POOL_INIT_LEVEL, Math.min(CARD_POOL_MAX_LEVEL, Math.floor(this.poolLv))); const lv = Math.max(CARD_POOL_INIT_LEVEL, Math.min(CARD_POOL_MAX_LEVEL, Math.floor(this.poolLv)));
const poolLvStr = `lv${lv}`; const lvNode = this.pool_lv_node.getChildByName("lv");
this.pool_lv_node.children.forEach(child => { if (lvNode) {
if (child.name === "light") { const label = lvNode.getComponent(Label);
child.active = false; if (label) {
} else if (child.name === "bg") { label.string = `lv.${lv}`;
child.active = true;
} else {
child.active = (child.name === poolLvStr);
} }
}); }
const widget = this.pool_lv_node.getComponent(Widget); const widget = this.pool_lv_node.getComponent(Widget);
if (widget) widget.updateAlignment(); if (widget) widget.updateAlignment();
this.pool_lv_node.children.forEach(child => { this.pool_lv_node.children.forEach(child => {
const childWidget = child.getComponent(Widget); const childWidget = child.getComponent(Widget);
if (childWidget) childWidget.updateAlignment(); if (childWidget) childWidget.updateAlignment();
}); });
const peak = 1.2 const peak = 1.2
this.playHeroNumNodePop( this.pool_lv_node, peak); this.playHeroNumNodePop(this.pool_lv_node, peak);
} }
mLogger.log(this.debugMode, "MissionCardComp", "pool lv ui update", { mLogger.log(this.debugMode, "MissionCardComp", "pool lv ui update", {
poolLv: this.poolLv, poolLv: this.poolLv,
@@ -811,10 +808,10 @@ export class MissionCardComp extends CCComp {
private playCoinChangeAnim(isIncrease: boolean) { private playCoinChangeAnim(isIncrease: boolean) {
if (!this.coins_node || !this.coins_node.isValid) return; if (!this.coins_node || !this.coins_node.isValid) return;
const icon = this.coins_node.getChildByName("icon"); const icon = this.coins_node.getChildByName("icon");
if (!icon || !icon.isValid ) return; if (!icon || !icon.isValid) return;
const peak = isIncrease ? 1.2 : 1.2; const peak = isIncrease ? 1.2 : 1.2;
this.playHeroNumNodePop(icon, peak); this.playHeroNumNodePop(icon, peak);
const num= this.coins_node.getChildByName("num"); const num = this.coins_node.getChildByName("num");
if (!num || !num.isValid) return; if (!num || !num.isValid) return;
this.playHeroNumNodePop(num, peak); this.playHeroNumNodePop(num, peak);
} }
@@ -854,7 +851,7 @@ export class MissionCardComp extends CCComp {
let count = 0; let count = 0;
ecs.query(ecs.allOf(HeroAttrsComp)).forEach((entity: ecs.Entity) => { ecs.query(ecs.allOf(HeroAttrsComp)).forEach((entity: ecs.Entity) => {
const model = entity.get(HeroAttrsComp); const model = entity.get(HeroAttrsComp);
if (model && model.fac === FacSet.HERO ) { if (model && model.fac === FacSet.HERO) {
count++; count++;
} }
}); });
@@ -979,7 +976,7 @@ export class MissionCardComp extends CCComp {
private getMissionHeroMaxNum(): number { private getMissionHeroMaxNum(): number {
return FightSet.HERO_MAX_NUM return FightSet.HERO_MAX_NUM
} }
@@ -994,7 +991,7 @@ export class MissionCardComp extends CCComp {
reset() { reset() {
this.resetButtonScale(this.cards_chou); this.resetButtonScale(this.cards_chou);
// this.resetButtonScale(this.cards_up); // this.resetButtonScale(this.cards_up);
// 关键:在 reset/销毁 时将 Map 置空,彻底切断引用 // 关键:在 reset/销毁 时将 Map 置空,彻底切断引用
this.cardComps = [] as any; this.cardComps = [] as any;