refactor(game/map): 使用事件队列管理卡片显示逻辑
将直接显示卡片的逻辑改为事件队列处理,避免多个卡片显示请求冲突
This commit is contained in:
@@ -89,28 +89,38 @@ export class MissionCardComp extends CCComp {
|
|||||||
// 是否已经选择了天赋
|
// 是否已经选择了天赋
|
||||||
private hasSelected: boolean = false;
|
private hasSelected: boolean = false;
|
||||||
|
|
||||||
|
// 事件队列
|
||||||
|
private eventQueue: CardType[] = [];
|
||||||
|
|
||||||
private onShopOpen(event: string, args: any) {
|
private onShopOpen(event: string, args: any) {
|
||||||
this.node.active = true;
|
this.eventQueue.push(CardType.Potion);
|
||||||
this.hasSelected = false;
|
this.checkQueue();
|
||||||
this.curCardType = CardType.Potion;
|
|
||||||
this.resetCardStates();
|
|
||||||
this.refCards();
|
|
||||||
this.playShowAnimation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private onTalentSelect(event: string, args: any) {
|
private onTalentSelect(event: string, args: any) {
|
||||||
this.node.active = true;
|
this.eventQueue.push(CardType.Talent);
|
||||||
this.hasSelected = false; // 重置选择状态
|
this.checkQueue();
|
||||||
this.curCardType = CardType.Talent; // 记录当前类型为天赋
|
|
||||||
this.resetCardStates(); // 每次刷新前重置卡片状态
|
|
||||||
this.refCards();
|
|
||||||
this.playShowAnimation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private onHeroSkillSelect(event: string, args: any) {
|
private onHeroSkillSelect(event: string, args: any) {
|
||||||
|
this.eventQueue.push(CardType.Skill);
|
||||||
|
this.checkQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private checkQueue() {
|
||||||
|
if (this.node.active) return;
|
||||||
|
if (this.eventQueue.length === 0) return;
|
||||||
|
|
||||||
|
const type = this.eventQueue.shift();
|
||||||
|
if (type) {
|
||||||
|
this.showCardType(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private showCardType(type: CardType) {
|
||||||
this.node.active = true;
|
this.node.active = true;
|
||||||
this.hasSelected = false;
|
this.hasSelected = false;
|
||||||
this.curCardType = CardType.Skill;
|
this.curCardType = type;
|
||||||
this.resetCardStates();
|
this.resetCardStates();
|
||||||
this.refCards();
|
this.refCards();
|
||||||
this.playShowAnimation();
|
this.playShowAnimation();
|
||||||
@@ -336,6 +346,7 @@ export class MissionCardComp extends CCComp {
|
|||||||
*/
|
*/
|
||||||
close() {
|
close() {
|
||||||
this.node.active = false;
|
this.node.active = false;
|
||||||
|
this.checkQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||||
|
|||||||
Reference in New Issue
Block a user