From fcc2aaf0a03221697b9ef5c1d3183afc17ca116c Mon Sep 17 00:00:00 2001 From: walkpan Date: Tue, 6 Jan 2026 17:01:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=95=8C=E9=9D=A2):=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E7=89=A9=E5=93=81=E8=B4=AD=E4=B9=B0=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=B9=B6=E8=B0=83=E6=95=B4=E5=8D=A1=E7=89=87=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除MissionCardComp中与物品购买相关的代码逻辑 - 调整card.prefab的宽度和精灵图集引用 - 简化卡片选择逻辑,统一处理物品使用事件 --- assets/resources/gui/uis/bgs/card.prefab | 9 ++-- assets/script/game/map/MissionCardComp.ts | 65 +---------------------- 2 files changed, 8 insertions(+), 66 deletions(-) diff --git a/assets/resources/gui/uis/bgs/card.prefab b/assets/resources/gui/uis/bgs/card.prefab index 430a316b..59f2c813 100644 --- a/assets/resources/gui/uis/bgs/card.prefab +++ b/assets/resources/gui/uis/bgs/card.prefab @@ -851,7 +851,7 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 80, + "width": 130, "height": 80 }, "_anchorPoint": { @@ -888,7 +888,7 @@ "a": 255 }, "_spriteFrame": { - "__uuid__": "deedea09-8f2b-400f-9803-4cfd38e45d1a@eb208", + "__uuid__": "deedea09-8f2b-400f-9803-4cfd38e45d1a@c83a0", "__expectedType__": "cc.SpriteFrame" }, "_type": 0, @@ -903,7 +903,10 @@ "_fillRange": 0, "_isTrimmedMode": true, "_useGrayscale": false, - "_atlas": null, + "_atlas": { + "__uuid__": "deedea09-8f2b-400f-9803-4cfd38e45d1a", + "__expectedType__": "cc.SpriteAtlas" + }, "_id": "" }, { diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index 92168364..ca3ef86c 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -40,9 +40,6 @@ export class MissionCardComp extends CCComp { // 当前卡片类型 curCardType: CardType = CardType.Talent; - // 已购买的卡片槽位标记 (用于物品购买) - purchasedSlots: boolean[] = [false, false, false, false, false]; - // 是否处于锁定状态 private isLocked: boolean = true; @@ -119,8 +116,6 @@ export class MissionCardComp extends CCComp { if (sprite) sprite.color = new Color(255, 255, 255); } }); - // 重置购买状态 - this.purchasedSlots = [false, false, false, false, false]; } // 是否已经选择了天赋 @@ -164,11 +159,6 @@ export class MissionCardComp extends CCComp { this.hasSelected = false; this.curCardType = type; - // 仅在物品类型(商店)显示关闭按钮 - if (this.btnClose) { - this.btnClose.active = (type === CardType.Potion); - } - // 根据锁定状态显示 Lock 节点 if (this.Lock) { this.Lock.active = this.isLocked; @@ -252,10 +242,6 @@ export class MissionCardComp extends CCComp { desc = data.desc || ""; } - // 如果是物品,显示价格 - if (this.curCardType === CardType.Potion && data.price) { - desc += `\n价格: ${data.price}`; - } info.getComponent(Label)!.string = desc; } } @@ -277,55 +263,6 @@ export class MissionCardComp extends CCComp { let selectedCardNode: Node | null = (this as any)[`card${_index}`]; if (selectedData && selectedCardNode) { - // 处理物品购买逻辑 - if (this.curCardType === CardType.Potion) { - if (this.purchasedSlots[_index]) { - oops.gui.toast("该物品已购买"); - return; - } - - if (smc.vmdata.gold < selectedData.price) { - oops.gui.toast("金币不足"); - return; - } - - // 扣除金币 - smc.updateGold(-selectedData.price); - - // 发送使用物品事件 - oops.message.dispatchEvent(GameEvent.UseItemCard, selectedData.id); - - // 标记已购买 - this.purchasedSlots[_index] = true; - - // 视觉反馈 (变灰) - const sprite = selectedCardNode.getComponent(Sprite); - if (sprite) sprite.color = new Color(150, 150, 150); - - // 激活 selected 组件 - const selected = selectedCardNode.getChildByName("selected"); - if(selected) { - selected.active = true; - selected.setScale(Vec3.ZERO); - tween(selected).to(0.2, { scale: new Vec3(1, 1, 1) }, { easing: 'backOut' }).start(); - } - - oops.gui.toast("购买成功"); - - // 检查是否所有卡片都已购买,如果是则关闭 - let allPurchased = true; - // 检查当前显示的卡片是否都买了 - if (this.card1.active && !this.purchasedSlots[1]) allPurchased = false; - if (this.card2.active && !this.purchasedSlots[2]) allPurchased = false; - if (this.card3.active && !this.purchasedSlots[3]) allPurchased = false; - if (this.card4.active && !this.purchasedSlots[4]) allPurchased = false; - - if (allPurchased) { - this.close(); - } - return; - } - this.hasSelected = true; console.log("选择卡片:", selectedData.name, "类型:", this.curCardType); @@ -360,6 +297,8 @@ export class MissionCardComp extends CCComp { oops.message.dispatchEvent(GameEvent.UseSkillCard, selectedData.uuid); } else if (this.curCardType === CardType.Partner) { oops.message.dispatchEvent(GameEvent.CallFriend, { uuid: selectedData.uuid }); + } else if (this.curCardType === CardType.Potion) { + oops.message.dispatchEvent(GameEvent.UseItemCard, selectedData.id); } // 后续扩展其他类型事件 this.close();