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/WenZiRes/ui/Game"; import CccGame from "../../../WordGame/gameComScript/CccGame/CccGame"; import ChaDianListScript from "../../../WordGame/gameComScript/ChaDianListScript"; import ChooseBtnLayer from "../../../WordGame/gameComScript/ChooseBtnLayer"; import logPrefabScript from "../../../WordGame/gameComScript/logPrefabScript"; const { ccclass, property } = cc._decorator; @ccclass export default class JiXianTaoSheng extends WordGameBaseComponent { @property(cc.Node) layerNode: cc.Node[] = []; @property(cc.Node) chooseLayer: cc.Node = null; //当前层级下标 curLayerIndex = 0; //当前进度 curSchedule = 0; chadianNum = 0; chadianIndex = 0; chooseIndex = -1; isOnTimer = false; timer = 0; //文本配置 titleArrayConfig: string[] = []; conclusionArrayConfig: any[] = []; topDialogConfig: string[] = []; duihuaArrayConfig: any[] = []; chooseArrayConfig: any = null; chadianListConfig: any = null; start() { super.start(); DaDianScript.userEnterDaDian(); //this.openTouchEvent(this.node.getChildByName('bg')); Common5.stopMusic(); Common5.getJsonFromBundle(Common5.selectGameInfo.bundle, 'script/JiXianTaoShengConfig', (assest) => { this.jsonData = assest.json this.initParameters(); this.initComponent(); }) } update(dt) { this.refreshTimer(dt); } //初始化参数 initParameters() { this.curLayerIndex = 0; this.curSchedule = 0; this.chadianNum = 0; this.chadianIndex = 0; this.chooseIndex = -1; this.titleArrayConfig = this.jsonData.titleArray; this.conclusionArrayConfig = this.jsonData.conclusionArray; this.duihuaArrayConfig = this.jsonData.duihuaArray; this.chooseArrayConfig = this.jsonData.chooseArray; this.chadianListConfig = this.jsonData.chadianList; this.topDialogConfig = this.jsonData.topDialog; Common.Type = 0; Common.subLevel = this.curLayerIndex; Common.GameSubTipConfigs = this.jsonData.tipsArray; Common.GameSubAnswerConfigs = this.jsonData.answersArray; EventMgr.onEvent_custom(ryw_Event.touchChaDianCheck, (data_) => { this.gameChaDianStep(data_.touchIndex); }, this); EventMgr.onEvent_custom(ryw_Event.chooseResult, (data_) => { this.chooseResultCallback(data_.touchIndex); }, this); EventMgr.onEvent_custom(ryw_Event.NormalTouchMoveCheck, (data_) => { this.normalTouchCallback(data_.targetNode); }, this); EventMgr.onEvent_custom(ryw_Event.NormalTouchEndCheck, (data_) => { this.normalTouchCallback(data_.targetNode); }, this); EventMgr.onEvent_custom(ryw_Event.DirectTouchMoveCheck, (data_) => { this.normalTouchCallback(data_.targetNode); }, this); } //初始化组件 initComponent() { for (const node of this.layerNode) { node.active = false; } this.refreshLayer(); this.timer = 180; this.isOnTimer = true; Common5.playMusicCustom(Common5.selectGameInfo.bundle, 'sound/关卡背景,需要在关卡里循环播放'); } //刷新场景 refreshLayer() { let node = this.layerNode[this.curLayerIndex]; node.active = true; Game.ins.setGameTitle(this.titleArrayConfig[this.curLayerIndex]); // let topDialog = node.getChildByName('view').getChildByName('顶部对话框'); // topDialog.getChildByName('str').getComponent(cc.Label).string = this.topDialogConfig[this.curLayerIndex]; if (this.curLayerIndex == 0) { //Common5.playMusicCustom(Common5.selectGameInfo.bundle, 'sound/场景一背景音'); this.showDuiHua(this.duihuaArrayConfig[0]); this.refreshChadian(); } else if (this.curLayerIndex == 1) { //Common5.playMusicCustom(Common5.selectGameInfo.bundle, 'sound/场景二背景音'); this.showDuiHua(this.duihuaArrayConfig[1]); this.refreshChadian(); } } //刷新茬点 refreshChadian() { let node = this.layerNode[this.curLayerIndex]; let headNodeList = node.getChildByName('HeadNodeList'); let chadianIconList = node.getChildByName('chadianIconList'); let chadianTouchList = node.getChildByName('view').getChildByName('chadianTouchList'); headNodeList.active = false; chadianIconList.active = true; chadianTouchList.active = true; let config = this.chadianListConfig[this.curLayerIndex]; if (config) { let chadianIconList = node.getChildByName('chadianIconList'); let scr: ChaDianListScript = chadianIconList.getComponent('ChaDianListScript'); scr.setChaDianData(config.chadianIconList); } this.curSchedule = 1; } //刷新结语 refreshOperate() { let node = this.layerNode[this.curLayerIndex]; let chadianIconList = node.getChildByName('chadianIconList'); let chadianTouchList = node.getChildByName('view').getChildByName('chadianTouchList'); chadianIconList.active = false; chadianTouchList.active = false; switch (this.curLayerIndex) { case 0: node.getChildByName("view").getChildByName("toolBar").active = true; break; case 1: this.showChooseLayer(0); node.getChildByName("view").getChildByName("operatedNodeList").active = true; break; default: break; } } curDt: number = 0; refreshTimer(dt: number) { if (this.isOnTimer) { this.curDt += dt; if (this.curDt >= 1) { this.curDt--; this.timer--; let Timer = this.layerNode[this.curLayerIndex].getChildByName("view").getChildByName("Timer"); let second = this.timer % 60, minute = (this.timer - second) / 60; let secondStr = second >= 10 ? "" + second : "0" + second, minuteStr = minute >= 10 ? "" + minute : "0" + minute; Timer.getComponent(cc.Label).string = minuteStr + ":" + secondStr; if (this.timer <= 0) { this.isOnTimer = false; this.endGameView(0); } } } } //茬点步骤 gameChaDianStep(touchIndex) { let config = this.chadianListConfig[this.curLayerIndex]; let chadianLog = config.chadianLog; console.log(this.chadianNum, ' this.chadianNum++='); this.showDuiHua(chadianLog[touchIndex], () => { if (this.curSchedule == 1) { this.chadianNum++; if (this.chadianNum == chadianLog.length) { this.chadianNum = 0; this.refreshOperate(); } } }); } //选择回调 chooseResultCallback(touchIndex: number) { this.node.getChildByName("inputBlock").active = true; let node = this.layerNode[this.curLayerIndex]; if (this.chooseIndex == 0) { let blackCurtain = node.getChildByName("view").getChildByName("blackCurtain"); blackCurtain.getChildByName("bar").active = false; cc.tween(blackCurtain) .call(() => { Common5.playEffectCustom(Common5.selectGameInfo.bundle, 'sound/炸弹爆炸'); CccGame.playAnimation2(node.getChildByName("view").getChildByName("爆炸"), "爆炸"); }) .delay(2) .set({ active: true, opacity: 0 }) .to(1, { opacity: 255 }) .call(() => { node.getChildByName("view").getChildByName("爆炸").active = false; let conclusion = this.conclusionArrayConfig[0]; blackCurtain.getChildByName("bar").getChildByName("text").getComponent(cc.Label).string = conclusion.str; blackCurtain.getChildByName("bar").active = true; if (conclusion.effectUrl) { Common5.playEffectCustom(Common5.selectGameInfo.bundle, conclusion.effectUrl); } }) .delay(3) .call(() => { this.endGameView(0); }) .start(); } } //触摸回调 normalTouchCallback(targetNode: cc.Node) { console.log("+++++++++++++++++++++>" + targetNode.name); let node = this.layerNode[this.curLayerIndex]; switch (targetNode.name) { case '刀': node.getChildByName("view").getChildByName("toolBar").active = false; CccGame.playAnimation2(node.getChildByName("view").getChildByName("人1"), "刀切"); Common5.playEffectCustom(Common5.selectGameInfo.bundle, 'sound/小刀割绳子'); this.nextLayer(); break; case '铁锤': node.getChildByName("view").getChildByName("toolBar").active = false; CccGame.playAnimation2(node.getChildByName("view").getChildByName("人1"), "锤子"); this.scheduleOnce(() => { Common5.playEffectCustom(Common5.selectGameInfo.bundle, 'sound/打火机,锤子惨叫'); }, 0.5); this.scheduleOnce(() => { CccGame.playAnimation2(node.getChildByName("view").getChildByName("人1"), "被打后呼吸", true); this.scheduleOnce(() => { this.endGameView(0); }, 1.5); }, 1.5); break; case '打火机': Common5.playEffectCustom(Common5.selectGameInfo.bundle, 'sound/打火机'); node.getChildByName("view").getChildByName("toolBar").active = false; CccGame.playAnimation2(node.getChildByName("view").getChildByName("火"), "animation"); this.scheduleOnce(() => { Common5.playEffectCustom(Common5.selectGameInfo.bundle, 'sound/打火机,锤子惨叫'); }, 1); this.scheduleOnce(() => { this.endGameView(0); }, 3); break; case '拆除炸弹': this.chooseLayer.active = false; let blackCurtain = node.getChildByName("view").getChildByName("blackCurtain"); blackCurtain.getChildByName("bar").active = false; cc.tween(blackCurtain) .set({ active: true, opacity: 0 }) .to(1, { opacity: 255 }) .call(() => { let conclusion = this.conclusionArrayConfig[this.curLayerIndex]; blackCurtain.getChildByName("bar").getChildByName("text").getComponent(cc.Label).string = conclusion.str; blackCurtain.getChildByName("bar").active = true; if (conclusion.effectUrl) { Common5.playEffectCustom(Common5.selectGameInfo.bundle, conclusion.effectUrl); } }) .delay(4) .call(() => { this.endGameView(1); }) .start(); break; default: break; } } //显示选项 showChooseLayer(chooseIndex: number) { this.chooseLayer.active = true; this.chooseIndex = chooseIndex; Common.GameSubChooseArray = this.chooseArrayConfig[chooseIndex]; let script_: ChooseBtnLayer = this.chooseLayer.getComponent('ChooseBtnLayer'); script_.setChooseBtnView(); } //显示对话 showDuiHua(curLog, func?) { console.log("curLog==", curLog); if (curLog.effectUrl) { Common5.playEffectCustom(Common5.selectGameInfo.bundle, curLog.effectUrl); } let string_ = curLog.str; let qiPaoPos_ = curLog.qiPaoPos; let delayTime_ = curLog.delayTime || 3; let node = this.layerNode[this.curLayerIndex].getChildByName('view'); if (qiPaoPos_ != -1) { let qiPao = node.getChildByName("qiPao").getChildByName("qiPao_" + qiPaoPos_); qiPao.stopAllActions() qiPao.getChildByName("str").getComponent(cc.Label).string = string_ cc.tween(qiPao) .set({ active: true, scale: 0 }) .to(0.2, { scale: 1 }) .delay(delayTime_) .set({ active: false }) .start(); } else { let logPrefab = this.node.getChildByName('logPrefab'); let script_: logPrefabScript = logPrefab.getComponent('logPrefabScript'); script_.setDailogShow(string_, delayTime_); } this.scheduleOnce(() => { if (func) { func(); } }, delayTime_); } //跳转场景 nextLayer() { this.curLayerIndex++; Common.subLevel = this.curLayerIndex; Game.ins.updateTishiBtn(); for (let i = 0; i < this.layerNode.length; i++) { if (this.layerNode[i].active) { cc.tween(this.layerNode[i]) .delay(1.0) .to(1, { opacity: 0 }) .call(() => { this.layerNode[i].active = false; this.refreshLayer(); }) .start(); } else { this.layerNode[i].active = false; } }; } //结束弹窗 endGameView(touchIndex) { this.node.getChildByName("inputBlock").active = true; Game.ins.stopTime(); if (touchIndex == 0) { Game.ins.showFail(); } else { Game.ins.showSuccess(); } } //解锁提示 unlockLevel(sublevel) { Game.ins.tipUnlock(sublevel) } 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; let logPrefab = this.node.getChildByName('logPrefab'); logPrefab.getChildByName('duihua').active = false; } onClick(event) { let target = event.target as cc.Node; console.log("+++++++++++++++++++++>" + target.name); Common5.playEffect("点击音效"); switch (target.name) { case "BtnAddTimes": default: break; } } }