refactor(mission): 重构卡牌组件内部状态管理

- 将金币数据从全局 vmdata 移至组件内部私有属性
- 重命名 coins 节点引用为 coins_node 以保持一致性
- 优化卡牌预制体布局,调整名称背景位置和缩放
- 更新数值标签的字体样式和阴影效果
- 修复卡池等级UI更新逻辑,确保正确显示当前等级
This commit is contained in:
panw
2026-03-25 15:35:50 +08:00
parent 2a50e79c01
commit 4ac9f5c06f
7 changed files with 2078 additions and 7783 deletions

View File

@@ -31,7 +31,7 @@ export class MissionCardComp extends CCComp {
@property(Node)
cards_up:Node = null!
@property(Node)
coins:Node = null!
coins_node:Node = null!
@property(Node)
pool_lv_node:Node = null!
// @property(Node)
@@ -42,6 +42,7 @@ export class MissionCardComp extends CCComp {
private cardComps: CardComp[] = [];
/** 当前卡池等级(仅影响抽卡来源,不直接改卡槽现有内容) */
private poolLv: number = CARD_POOL_INIT_LEVEL;
private coin: number = CardInitCoins;
onLoad() {
/** 绑定事件 -> 缓存子控制器 -> 初始化UI状态 */
this.bindEvents();
@@ -64,7 +65,7 @@ export class MissionCardComp extends CCComp {
/** 任务开始时重置卡池等级、清空4槽、显示面板 刷新一次卡池*/
onMissionStart() {
this.poolLv = CARD_POOL_INIT_LEVEL;
smc.vmdata.mission_data.coin=CardInitCoins //这里负责卡牌相关数据舒适化
this.coin = CardInitCoins
this.layoutCardSlots();
this.clearAllCards();
if (this.cards_up) {
@@ -109,6 +110,8 @@ export class MissionCardComp extends CCComp {
this.cards_up?.on(NodeEventType.TOUCH_END, this.onClickUpgrade, this);
}
private onCoinAdd(args:any){
const v = typeof args === 'number' ? args : (args?.delta ?? args?.value ?? 0);
this.coin = Math.max(0, (this.coin ?? 0) + v);
this.updatePoolLvUI();
this.updateCoinUI();
}
@@ -144,7 +147,7 @@ export class MissionCardComp extends CCComp {
return;
}
const cost = this.getUpgradeCost(this.poolLv);
const currentCoin = smc.vmdata.mission_data.coin ?? 0;
const currentCoin = this.coin ?? 0;
if (currentCoin < cost) {
oops.gui.toast(`金币不足,升级需要${cost}`);
this.updatePoolLvUI();
@@ -155,14 +158,14 @@ export class MissionCardComp extends CCComp {
});
return;
}
smc.vmdata.mission_data.coin = currentCoin - cost;
this.coin = currentCoin - cost;
this.poolLv += 1;
this.updateCoinUI();
this.updatePoolLvUI();
mLogger.log(this.debugMode, "MissionCardComp", "pool level up", {
poolLv: this.poolLv,
cost,
leftCoin: smc.vmdata.mission_data.coin
leftCoin: this.coin
});
}
@@ -214,7 +217,7 @@ export class MissionCardComp extends CCComp {
}
private canUpPool() {
if (this.poolLv >= CARD_POOL_MAX_LEVEL) return false;
const currentCoin = smc.vmdata.mission_data.coin ?? 0;
const currentCoin = this.coin ?? 0;
return currentCoin >= this.getUpgradeCost(this.poolLv);
}
/** 更新升级按钮上的等级文案,反馈当前卡池层级 */
@@ -231,6 +234,12 @@ export class MissionCardComp extends CCComp {
} else {
label.string = `${this.getUpgradeCost(this.poolLv)}`;
}
if (this.pool_lv_node) {
for (let i = 1; i <= CARD_POOL_MAX_LEVEL; i++) {
const n = this.pool_lv_node.getChildByName(`lv${i}`);
if (n) n.active = i === this.poolLv;
}
}
mLogger.log(this.debugMode, "MissionCardComp", "pool lv ui update", {
poolLv: this.poolLv,
cost: this.getUpgradeCost(this.poolLv)
@@ -238,10 +247,10 @@ export class MissionCardComp extends CCComp {
}
private updateCoinUI() {
if (!this.coins) return;
const label = this.coins.getChildByName("num")?.getComponent(Label);
if (!this.coins_node) return;
const label = this.coins_node.getChildByName("num")?.getComponent(Label);
if (!label) return;
label.string = `${smc.vmdata.mission_data.coin ?? 0}`;
label.string = `${this.coin ?? 0}`;
}
private getUpgradeCost(lv: number): number {