refactor(map): 统一使用事件驱动的小提示替代硬编码toast
将多处分散的金币不足、英雄已满等提示逻辑,统一替换为通过GameEvent.ShowSmallTip事件触发的通用小提示组件,替换原有的oops.gui.toast调用,新增通用提示显示逻辑与事件监听
This commit is contained in:
@@ -310,7 +310,7 @@ export class CardComp extends CCComp {
|
||||
// 使用统一经济管理入口消费金币
|
||||
const success = MissionEconomy.spendCoin(cardCost);
|
||||
if (!success) {
|
||||
oops.gui.toast(`金币不足,召唤需要${cardCost}`);
|
||||
oops.message.dispatchEvent(GameEvent.ShowSmallTip, "buy_coin");
|
||||
this.playReboundAnim();
|
||||
mLogger.log(this.debugMode, "CardComp", "use card coin not enough", {
|
||||
uuid: this.cardData.uuid,
|
||||
|
||||
@@ -292,6 +292,7 @@ export class MissionCardComp extends CCComp {
|
||||
oops.message.on(GameEvent.UseSkillCard, this.onUseSkillCard, this);
|
||||
oops.message.on(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
|
||||
oops.message.on(GameEvent.CardPoolUpgrade, this.onCardPoolUpgrade, this);
|
||||
oops.message.on(GameEvent.ShowSmallTip, this.onShowSmallTip, this);
|
||||
|
||||
/** 按钮触控事件:抽卡与卡池升级 */
|
||||
this.cards_chou?.on(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
|
||||
@@ -358,12 +359,48 @@ export class MissionCardComp extends CCComp {
|
||||
});
|
||||
|
||||
// 提示卡池升级
|
||||
oops.gui.toast(`卡池已升至${this.poolLv}级`);
|
||||
this.showSmallTip("pool_upgrade");
|
||||
|
||||
// 更新UI
|
||||
this.updatePoolLvUI();
|
||||
}
|
||||
|
||||
private onShowSmallTip(event: string, args: any) {
|
||||
const type = args as string;
|
||||
this.showSmallTip(type as any);
|
||||
}
|
||||
|
||||
public showSmallTip(type: "refresh_coin" | "pool_upgrade" | "buy_coin" | "hero_full") {
|
||||
let targetNode: Node | null = null;
|
||||
switch (type) {
|
||||
case "refresh_coin":
|
||||
targetNode = this.cards_chou;
|
||||
break;
|
||||
case "pool_upgrade":
|
||||
targetNode = this.pool_lv_node;
|
||||
break;
|
||||
case "buy_coin":
|
||||
targetNode = this.coins_node;
|
||||
break;
|
||||
case "hero_full":
|
||||
targetNode = this.hero_num_node;
|
||||
break;
|
||||
}
|
||||
if (targetNode && targetNode.isValid) {
|
||||
const tipNode = targetNode.getChildByName("smalltip");
|
||||
if (tipNode) {
|
||||
tipNode.active = true;
|
||||
Tween.stopAllByTarget(tipNode);
|
||||
tween(tipNode)
|
||||
.delay(2)
|
||||
.call(() => {
|
||||
if (tipNode && tipNode.isValid) tipNode.active = false;
|
||||
})
|
||||
.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private onPhasePrepareStart() {
|
||||
this.updateHeroNumUI(true, true);
|
||||
}
|
||||
@@ -469,6 +506,7 @@ export class MissionCardComp extends CCComp {
|
||||
oops.message.off(GameEvent.UseSkillCard, this.onUseSkillCard, this);
|
||||
oops.message.off(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
|
||||
oops.message.off(GameEvent.CardPoolUpgrade, this.onCardPoolUpgrade, this);
|
||||
oops.message.off(GameEvent.ShowSmallTip, this.onShowSmallTip, this);
|
||||
if (this.cards_chou && this.cards_chou.isValid) {
|
||||
this.cards_chou.off(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
|
||||
this.cards_chou.off(NodeEventType.TOUCH_END, this.onDrawTouchEnd, this);
|
||||
@@ -558,7 +596,7 @@ export class MissionCardComp extends CCComp {
|
||||
}
|
||||
payload.cancel = true;
|
||||
payload.reason = "hero_limit";
|
||||
oops.gui.toast(`英雄已满 (${current}/${heroMax})`);
|
||||
this.showSmallTip("hero_full");
|
||||
this.playHeroNumDeniedAnim();
|
||||
}
|
||||
}
|
||||
@@ -678,7 +716,7 @@ export class MissionCardComp extends CCComp {
|
||||
const cost = MissionEconomy.getRefreshCost(this.refreshCost);
|
||||
const success = MissionEconomy.executeRefresh(this.refreshCost);
|
||||
if (!success) {
|
||||
oops.gui.toast(`金币不足,刷新需要${cost}`);
|
||||
this.showSmallTip("refresh_coin");
|
||||
return;
|
||||
}
|
||||
const cards = this.buildSkillDrawCards();
|
||||
@@ -735,7 +773,7 @@ export class MissionCardComp extends CCComp {
|
||||
const cost = MissionEconomy.getRefreshCost(this.refreshCost);
|
||||
const success = MissionEconomy.executeRefresh(this.refreshCost);
|
||||
if (!success) {
|
||||
oops.gui.toast(`金币不足,刷新需要${cost}`);
|
||||
this.showSmallTip("refresh_coin");
|
||||
this.updateCoinAndCostUI();
|
||||
mLogger.log(this.debugMode, "MissionCardComp", "draw coin not enough", {
|
||||
currentCoin: MissionEconomy.getCoin(),
|
||||
|
||||
@@ -96,7 +96,7 @@ export class SCardComp extends CCComp {
|
||||
|
||||
const success = MissionEconomy.spendCoin(cardCost);
|
||||
if (!success) {
|
||||
oops.gui.toast(`金币不足,需要${cardCost}`);
|
||||
oops.message.dispatchEvent(GameEvent.ShowSmallTip, "buy_coin");
|
||||
this.playReboundAnim();
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user