import DaDianScript from "../../../FrameWork/Base/DaDianScript"; import WordGameBaseComponent from "../../../FrameWork/Base/WordGameBaseComptent"; import { ryw_Event } from "../../../FrameWork/Event/EventEnum"; import EventMgr from "../../../FrameWork/Event/EventMgr"; import Common from "../../../FrameWork/Util/Common"; import Common5 from "../../../Platform/th/Common5"; import Game from "../../../Scripts/Game"; import TouchRoleNode from "../../../WordGame/gameComScript/BaoXiao/TouchRoleNode"; import logPrefabScript from "../../../WordGame/gameComScript/logPrefabScript"; // import BaoXiaoDaKaConfig from "./BaoXiaoDaKaConfig"; const { ccclass, property } = cc._decorator; @ccclass export default class BaoXiaoDaKaScript extends WordGameBaseComponent { @property(cc.Node) roleBackList: cc.Node = null; @property(cc.Node) touchRoleNode: cc.Node = null; //当前层级下标 curLayerIndex = 0; //当前进度 curSchedule: number = 0; fireNodeInfoArray: any[] = null; //文本配置 titleArrayConfig: string[] = []; duihuaArrayConfig: any[] = []; roleFormListConfig: any[] = []; start() { super.start(); DaDianScript.userEnterDaDian(); this.openTouchEvent(this.node.getChildByName('bg')); Common5.stopMusic() Common5.getJsonFromBundle(Common5.selectGameInfo.bundle,'script/BaoXiaoDaKaConfig',(assest)=>{ //this.jsonData = JSON.stringify(assest.json) this.jsonData =assest.json this.initParameters(); this.initComponent(); }) } //初始化参数 initParameters() { this.curSchedule = 0; this.fireNodeInfoArray = []; this.titleArrayConfig = this.jsonData.titleArray//BaoXiaoDaKaConfig.getInstance().getGameConfig('titleArray') as string[]; this.duihuaArrayConfig = this.jsonData.duihuaArray//BaoXiaoDaKaConfig.getInstance().getGameConfig('duihuaArray') as any[]; this.roleFormListConfig = this.jsonData.roleFormList//BaoXiaoDaKaConfig.getInstance().getGameConfig('roleFormList') as any[]; Common.Type = 0; Common.subLevel = 0; Common.GameSubTipConfigs = this.jsonData.tipsArray//BaoXiaoDaKaConfig.getInstance().getGameConfig('tipsArray'); Common.GameSubAnswerConfigs = this.jsonData.answersArray//BaoXiaoDaKaConfig.getInstance().getGameConfig('answersArray'); EventMgr.onEvent_custom(ryw_Event.roleNodeTouchCheck, (data_) => { this.roleNodeTouchCheckCallback(data_.targetNode); }, this); EventMgr.onEvent_custom(ryw_Event.timeOut, (tab) => { this.endGameView(0); }, this); } //初始化组件 initComponent() { let lab = this.node.getChildByName("标题").getChildByName("lab"); lab.getComponent(cc.Label).string = this.titleArrayConfig[0]; let title = this.titleArrayConfig[0]; Game.ins.setGameTitle(title) this.touchRoleNode.active = false; this.refreshSchedule(); } refreshSchedule() { for (let index = 0; index < this.roleFormListConfig.length; index++) { let fireNodeInfo: any = {}; fireNodeInfo.bandleName = 'baoxiaodaka' fireNodeInfo.roleName = this.roleFormListConfig[index].roleName; fireNodeInfo.roleFormArray = this.roleFormListConfig[index].formArray; fireNodeInfo.checkNode = this.roleBackList.children[index]; fireNodeInfo.correctFormIndex = this.roleFormListConfig[index].correctFormIndex; fireNodeInfo.roleIndex = index; this.fireNodeInfoArray.push(fireNodeInfo); } for (let index = 0; index < this.fireNodeInfoArray.length; index++) { let aInt = Math.trunc(Math.random() * this.fireNodeInfoArray.length); let random = this.fireNodeInfoArray[aInt]; this.fireNodeInfoArray[aInt] = this.fireNodeInfoArray[index]; this.fireNodeInfoArray[index] = random; } } fireRoleNode(target) { if (this.fireNodeInfoArray.length <= 0) { target.active = false; return; } let roleNode = cc.instantiate(this.touchRoleNode); roleNode.active = true; roleNode.setParent(this.node.getChildByName("roleTouchList")); let scr = roleNode.getComponent(TouchRoleNode); let fireNodeInfo = this.fireNodeInfoArray.pop(); scr.setFormArray(fireNodeInfo); cc.tween(roleNode) .set({ active: true, scale: 0.1 }) .to(0.5, { position: cc.v3(0, 200), scale: 1 }) .start(); } roleNodeTouchCheckCallback(targetNode: any) { this.curSchedule++; console.log("roleIndex===================>" + targetNode.roleIndex); let roleForm = this.roleFormListConfig[targetNode.roleIndex]; if (roleForm.effectUrl) { Common5.playEffectCustom("baoxiaodaka", roleForm.effectUrl); } if (this.curSchedule == this.roleFormListConfig.length) { this.scheduleOnce(() => { this.endGameView(1); }, 3); } } showQiPao(curLog, func?) { console.log("curLog==", curLog); if (curLog.effectUrl) { Common5.playEffectCustom("baoxiaodaka", curLog.effectUrl); } let string_ = curLog.str let qiPaoPos_ = curLog.qiPaoPos if (qiPaoPos_ != -1) { let qiPao = this.node.getChildByName("qiPao").getChildByName("qiPao_" + qiPaoPos_); qiPao.stopAllActions() qiPao.getChildByName("str").getComponent(cc.Label).string = string_ qiPao.active = true qiPao.scale = 0 cc.tween(qiPao) .to(0.2, { scale: 1 }) .delay(3) .call(() => { qiPao.active = false if (func) { func(); } }) .start(); } else { let logPrefab = this.node.getChildByName('logPrefab') let script_: logPrefabScript = logPrefab.getComponent('logPrefabScript') script_.setDailogShow(string_) this.scheduleOnce(() => { if (func) { func(); } }, 3); } } endGameView(touchIndex) { Game.ins.stopTime(); this.node.getChildByName("mask").active = true; if (touchIndex == 0) { this.scheduleOnce(()=>{ Game.ins.showFail(); },3.0) } else { this.scheduleOnce(()=>{ Game.ins.showSuccess(); },3.0) } } openTouchEvent(node) { node.on(cc.Node.EventType.TOUCH_START, this.touchStartNode, this) node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this) node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this) node.on(cc.Node.EventType.TOUCH_END, this.touchEndNode, this) } closeTouchEvent(node: cc.Node) { node.off(cc.Node.EventType.TOUCH_START, this.touchStartNode, this) node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this) node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this) node.off(cc.Node.EventType.TOUCH_END, this.touchEndNode, this) } touchStartNode(event) { let target = event.target; console.log('touchStartNode'); } touchMoveNode(event) { } touchEndNode(event) { let target = event.target; } onClick(event) { let buttonName = event.target.name; Common5.playEffect("点击音效"); switch (buttonName) { case "相机": this.fireRoleNode(event.target); break; default: break; } } //update(dt) { } }