import { _decorator, tween, v3 } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { GameEvent } from "../common/config/GameEvent"; import { CardComp } from "./CardComp"; import { cardType, getRandomCardsByType } from "../common/config/CardSet"; import { smc } from "../common/SingletonModuleComp"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('CardsCompComp') @ecs.register('CardsComp', false) export class CardsCompComp extends CCComp { card1:any=null card2:any=null card3:any=null card4:any=null card1c:CardComp=null card2c:CardComp=null card3c:CardComp=null card4c:CardComp=null /** 卡牌展示队列 */ private cardQueue: Array<{type: GameEvent, data?: any}> = []; /** 是否正在展示卡牌 */ private isShowing: boolean = false; /** 视图层逻辑代码分离演示 */ onLoad() { // var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象 this.on(GameEvent.HeroSkillSelect, this.addToQueue, this); this.on(GameEvent.HeroSelect, this.addToQueue, this); this.on(GameEvent.CardRefresh, this.addToQueue, this); this.on(GameEvent.HeroSkillSelectEnd, this.close_cards, this); this.on(GameEvent.HeroSelectEnd, this.close_cards, this); this.on(GameEvent.CardRefreshEnd, this.close_cards, this); this.on(GameEvent.CardsClose, this.close_cards, this); this.card1=this.node.getChildByName("card1") this.card2=this.node.getChildByName("card2") this.card3=this.node.getChildByName("card3") this.card4=this.node.getChildByName("card4") this.card1c=this.card1.getComponent(CardComp) this.card2c=this.card2.getComponent(CardComp) this.card3c=this.card3.getComponent(CardComp) this.card4c=this.card4.getComponent(CardComp) } hero_select(){ let list=getRandomCardsByType(cardType.HERO,4) console.log("英雄选择卡牌列表",list) this.card1c.hero_select(list[0]) this.card2c.hero_select(list[1]) this.card3c.hero_select(list[2]) this.card4c.hero_select(list[3]) } hero_skill_select(){ let list=getRandomCardsByType(cardType.SKILL,4) console.log("技能选择卡牌列表",list) this.card1c.hero_skill_select(list[0]) this.card2c.hero_skill_select(list[1]) this.card3c.hero_skill_select(list[2]) this.card4c.hero_skill_select(list[3]) } equip_select(){ let list=getRandomCardsByType(cardType.EQUIP,4) console.log("装备选择卡牌列表",list) this.card1c.equip_select(list[0]) this.card2c.equip_select(list[1]) this.card3c.equip_select(list[2]) this.card4c.equip_select(list[3]) } func_select(){ console.log("功能选择卡牌") } random_select(){ this.card1c.random_select() this.card2c.random_select() this.card3c.random_select() this.card4c.random_select() } /** 添加卡牌展示到队列 */ private addToQueue(e: GameEvent, data?: any) { console.log("添加卡牌到队列", e); this.cardQueue.push({type: e, data: data}); this.processQueue(); } /** 处理卡牌队列 */ private processQueue() { if (this.isShowing || this.cardQueue.length === 0) { return; } const nextCard = this.cardQueue.shift(); this.isShowing = true; this.show_cards(nextCard.type, nextCard.data); } show_cards(e:GameEvent,data:any){ this.node.getChildByName("Button").active=false switch(e){ case GameEvent.HeroSelect: console.log("显示英雄选择卡牌") this.hero_select() break case GameEvent.HeroSkillSelect: console.log("显示技能选择卡牌") this.hero_skill_select() break case GameEvent.CardRefresh: console.log("显示随机刷新卡牌") this.node.getChildByName("Button").active=true this.random_select() break } this.show() } close_cards(e:GameEvent,data:any){ switch(e){ case GameEvent.HeroSelect: console.log("关闭英雄选择卡牌") break case GameEvent.HeroSkillSelect: console.log("关闭技能选择卡牌") break case GameEvent.CardRefresh: console.log("关闭随机刷新卡牌") break case GameEvent.CardsClose: console.log("关闭所有卡牌") break } this.hide() } show(){ // 设置初始状态 smc.mission.pause=true this.node.setPosition(v3(0, 0, 0)); this.node.setScale(v3(0, 0, 1)); // 使用缓动动画放大和移动 tween(this.node) .parallel( tween().to(0.3, { scale: v3(1, 1, 1) }, { easing: 'backOut' }), tween().to(0.3, { position: v3(0, 640, 0) }, { easing: 'backOut' }) ) .start(); } hide(){ smc.mission.pause=false tween(this.node) .parallel( tween().to(0.3, { scale: v3(0, 0, 1) }, { easing: 'backIn' }), tween().to(0.3, { position: v3(0, 0, 0) }, { easing: 'backIn' }) ) .call(()=>{ this.node.setPosition(v3(0, -1000, 0)); this.isShowing = false; this.processQueue(); // 处理队列中的下一个卡牌 }) .start(); } //放弃选择 give_up_select(){ this.hide() let mission_data=smc.vmdata.mission_data mission_data.gold+=(mission_data.back_gold+mission_data.buff_back_gold) //返还金币 } /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.cardQueue = []; this.isShowing = false; this.node.destroy(); } }