refactor(map): 统一使用事件驱动的小提示替代硬编码toast
将多处分散的金币不足、英雄已满等提示逻辑,统一替换为通过GameEvent.ShowSmallTip事件触发的通用小提示组件,替换原有的oops.gui.toast调用,新增通用提示显示逻辑与事件监听
This commit is contained in:
@@ -74,6 +74,7 @@ export enum GameEvent {
|
|||||||
UpdateMissionGet = "UpdateMissionGet",
|
UpdateMissionGet = "UpdateMissionGet",
|
||||||
GlobalAttrChange = "GlobalAttrChange",
|
GlobalAttrChange = "GlobalAttrChange",
|
||||||
CoinAdd = "CoinAdd",
|
CoinAdd = "CoinAdd",
|
||||||
|
ShowSmallTip = "ShowSmallTip",
|
||||||
CardPoolUpgrade = "CardPoolUpgrade",
|
CardPoolUpgrade = "CardPoolUpgrade",
|
||||||
TriggerSkill = "TriggerSkill", // 瞬间触发施法事件
|
TriggerSkill = "TriggerSkill", // 瞬间触发施法事件
|
||||||
RemoveSkillBox = "RemoveSkillBox", // 技能盒销毁事件
|
RemoveSkillBox = "RemoveSkillBox", // 技能盒销毁事件
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ export class CardComp extends CCComp {
|
|||||||
// 使用统一经济管理入口消费金币
|
// 使用统一经济管理入口消费金币
|
||||||
const success = MissionEconomy.spendCoin(cardCost);
|
const success = MissionEconomy.spendCoin(cardCost);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
oops.gui.toast(`金币不足,召唤需要${cardCost}`);
|
oops.message.dispatchEvent(GameEvent.ShowSmallTip, "buy_coin");
|
||||||
this.playReboundAnim();
|
this.playReboundAnim();
|
||||||
mLogger.log(this.debugMode, "CardComp", "use card coin not enough", {
|
mLogger.log(this.debugMode, "CardComp", "use card coin not enough", {
|
||||||
uuid: this.cardData.uuid,
|
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.UseSkillCard, this.onUseSkillCard, this);
|
||||||
oops.message.on(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
|
oops.message.on(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
|
||||||
oops.message.on(GameEvent.CardPoolUpgrade, this.onCardPoolUpgrade, 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);
|
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
|
// 更新UI
|
||||||
this.updatePoolLvUI();
|
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() {
|
private onPhasePrepareStart() {
|
||||||
this.updateHeroNumUI(true, true);
|
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.UseSkillCard, this.onUseSkillCard, this);
|
||||||
oops.message.off(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
|
oops.message.off(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
|
||||||
oops.message.off(GameEvent.CardPoolUpgrade, this.onCardPoolUpgrade, 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) {
|
if (this.cards_chou && this.cards_chou.isValid) {
|
||||||
this.cards_chou.off(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
|
this.cards_chou.off(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
|
||||||
this.cards_chou.off(NodeEventType.TOUCH_END, this.onDrawTouchEnd, this);
|
this.cards_chou.off(NodeEventType.TOUCH_END, this.onDrawTouchEnd, this);
|
||||||
@@ -558,7 +596,7 @@ export class MissionCardComp extends CCComp {
|
|||||||
}
|
}
|
||||||
payload.cancel = true;
|
payload.cancel = true;
|
||||||
payload.reason = "hero_limit";
|
payload.reason = "hero_limit";
|
||||||
oops.gui.toast(`英雄已满 (${current}/${heroMax})`);
|
this.showSmallTip("hero_full");
|
||||||
this.playHeroNumDeniedAnim();
|
this.playHeroNumDeniedAnim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -678,7 +716,7 @@ export class MissionCardComp extends CCComp {
|
|||||||
const cost = MissionEconomy.getRefreshCost(this.refreshCost);
|
const cost = MissionEconomy.getRefreshCost(this.refreshCost);
|
||||||
const success = MissionEconomy.executeRefresh(this.refreshCost);
|
const success = MissionEconomy.executeRefresh(this.refreshCost);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
oops.gui.toast(`金币不足,刷新需要${cost}`);
|
this.showSmallTip("refresh_coin");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const cards = this.buildSkillDrawCards();
|
const cards = this.buildSkillDrawCards();
|
||||||
@@ -735,7 +773,7 @@ export class MissionCardComp extends CCComp {
|
|||||||
const cost = MissionEconomy.getRefreshCost(this.refreshCost);
|
const cost = MissionEconomy.getRefreshCost(this.refreshCost);
|
||||||
const success = MissionEconomy.executeRefresh(this.refreshCost);
|
const success = MissionEconomy.executeRefresh(this.refreshCost);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
oops.gui.toast(`金币不足,刷新需要${cost}`);
|
this.showSmallTip("refresh_coin");
|
||||||
this.updateCoinAndCostUI();
|
this.updateCoinAndCostUI();
|
||||||
mLogger.log(this.debugMode, "MissionCardComp", "draw coin not enough", {
|
mLogger.log(this.debugMode, "MissionCardComp", "draw coin not enough", {
|
||||||
currentCoin: MissionEconomy.getCoin(),
|
currentCoin: MissionEconomy.getCoin(),
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export class SCardComp extends CCComp {
|
|||||||
|
|
||||||
const success = MissionEconomy.spendCoin(cardCost);
|
const success = MissionEconomy.spendCoin(cardCost);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
oops.gui.toast(`金币不足,需要${cardCost}`);
|
oops.message.dispatchEvent(GameEvent.ShowSmallTip, "buy_coin");
|
||||||
this.playReboundAnim();
|
this.playReboundAnim();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user