refactor(界面): 移除物品购买逻辑并调整卡片组件
- 删除MissionCardComp中与物品购买相关的代码逻辑 - 调整card.prefab的宽度和精灵图集引用 - 简化卡片选择逻辑,统一处理物品使用事件
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user