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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 161 KiB

View File

@@ -1,42 +0,0 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "3932da53-985d-4500-8c24-f7c822a4ea46",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "3932da53-985d-4500-8c24-f7c822a4ea46@6c48a",
"displayName": "ubtns",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "repeat",
"wrapModeT": "repeat",
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0,
"isUuid": true,
"imageUuidOrDatabaseUri": "3932da53-985d-4500-8c24-f7c822a4ea46",
"visible": false
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "texture",
"hasAlpha": true,
"fixAlphaTransparencyArtifacts": false,
"redirect": "3932da53-985d-4500-8c24-f7c822a4ea46@6c48a"
}
}

View File

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