// Learn cc.Class: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html // Learn Attribute: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html var Main = require("Main"); var Util = require("Utils"); var NetManage = require("NetManage") var playerData = require("playerData"); var gameConfig = require("gameConfig") var ncfg = require("newbieConfig") var NewbieConfig = ncfg.cfg var NewbieEnum = ncfg.enu var toulanConfig = ncfg.toulan cc.Class({ extends: cc.Component, // LIFE-CYCLE CALLBACKS: properties: { newbieblack: { default: null, type: cc.Node, }, newbieHand: { default: null, type: cc.Node, }, newbieLabelNode: { default: null, type: cc.Node, }, newbieLabel: { default: null, type: cc.Label, }, }, start() { //playerData.newbieData = []//test cc.newbieManage = this; for (var k in NewbieConfig) { var step = NewbieConfig[k].step; var needcg = false for (var i = 0, len = step.length; i < len; i++) { if (step[i][0] == NewbieEnum.toulan) { needcg = true break } } if (needcg) { NewbieConfig[k].step = [] for (var i = 0, len = step.length; i < len; i++) { if (step[i][0] != NewbieEnum.toulan) { NewbieConfig[k].step.push(step[i]) }else{ var tlsteps = toulanConfig[step[i][1]] for(var j=0;j= this.stepCfg.length) { this.scpArr = {}; this.step = 0; this.newbieid = 0; this.newbieHand.active = false; // this.newbieHand2.active = false; this.newbieLabelNode.active = false; this.node.active = false; // this.sprite.active = false; this.newbieblack.active = true; this.newbieblack.opacity = 180; if (this.stepCfg[this.stepCfg.length - 1][0] != NewbieEnum.notrecheck) { cc.director.emit('NEWBIERECHECK', this.overemit); } console.log('over'); return; } var data = this.stepCfg[this.step]; var type = data[0]; this.functionTb[type](data); }, waitforUI() { var data = this.stepCfg[this.step]; var path = data[1]; this.btn = cc.find(path); if (this.btn) { this.unschedule(this.waitforUI); this.touchStep1(); } }, waitforUI2() { var data = this.stepCfg[this.step]; var temp = this.btn.getChildren()[data[2]]; if (temp) { if (data[3]) { temp = cc.find(data[3], temp); } this.btn = temp; this.unschedule(this.waitforUI2); this.touchStep2(); } }, onTouchBg(event) { if (this.btn == null) { this.newbieblack._touchListener.setSwallowTouches(true); return; } let point = event.getLocation(); let retWord = this.btn.getBoundingBoxToWorld(); let space = 0; retWord.width -= space; retWord.width = retWord.width <= 0 ? 0 : retWord.width; retWord.height -= space; retWord.height = retWord.height <= 0 ? 0 : retWord.height; if (retWord.contains(point)) { this.newbieblack._touchListener.setSwallowTouches(false); } else { this.newbieblack._touchListener.setSwallowTouches(true); } }, upz(data) { var path = data[1]; var btn = cc.find(path); let pos2 = btn.parent.convertToWorldSpaceAR(btn); var pos3 = this.node.convertToNodeSpaceAR(pos2); btn.oldparent = btn.parent btn.oldpostion = cc.v2(btn.x, btn.y) btn.removeFromParent(false) this.node.addChild(btn) btn.position = pos3 this.upnode = btn this.step++; this.doNext(); }, downz(data) { var btn = this.upnode btn.removeFromParent(false) btn.oldparent.addChild(btn) btn.position = btn.oldpostion this.upnode = null this.step++; this.doNext(); }, touchStep2() { // var pos1 = this.btn.getBoundingBoxToWorld(); // var pos2 = this.node.convertToNodeSpaceAR(cc.v2(pos1.x,pos1.y)); // pos2.x= pos2.x+this.btn.width/2; // this.btn.groupIndex = CMASK; // this.newbieHand.setPosition(cc.v2(pos2.x+this.hdx,pos2.y+this.hdy)); // this.hdx = this.hdy = 0; let pos2 = this.btn.parent.convertToWorldSpaceAR(this.btn); var pos3 = this.node.convertToNodeSpaceAR(pos2); this.btn.oldparent = this.btn.parent this.btn.oldpostion = new cc.v2(this.btn.x, this.btn.y) this.btn.removeFromParent(false) this.node.addChild(this.btn) this.btn.position = pos3 this.newbieHand.setPosition(cc.v2(pos3.x + this.hdx, pos3.y + this.hdy)); this.hdx = this.hdy = 0; this.newbieHand.opacity = 255 // this.newbieHand2.setPosition(cc.v2(pos2.x,pos2.y)); //this.newbieLabelNode.setPosition(cc.v2(0,0)); // this.newbieLabelNode.opacity = 255 // this.hsx = this.hsy = 0; this.btn.on(cc.Node.EventType.TOUCH_END, this.btnTouchEnd, this); }, touchStep1() { var data = this.stepCfg[this.step]; if (data[2] != null) { var temp = this.btn.getChildren()[data[2]]; if (temp) { if (data[3]) { temp = cc.find(data[3], temp); } this.btn = temp; this.touchStep2(); } else { this.schedule(this.waitforUI2, 0.1); } } else { this.touchStep2(); } }, setScrollViewTouch(data) { var path = data[1]; var ScrollView = cc.find(path); ScrollView.getComponent(cc.ScrollView).vertical = data[2]; this.step++; this.doNext(); }, ntouch(data) { console.log('nbtn'); // var path = data[1]; // this.btn = cc.find(path); // if(this.btn){ // this.touchStep1(); // } // else{ // this.schedule(this.waitforUI, 0.1); // } this.schedule(this.waitforUI, 0.2); }, btnTouchEnd() { // this.btn.groupIndex = 0; this.btn.removeFromParent(false) this.btn.oldparent.addChild(this.btn) this.btn.position = this.btn.oldpostion this.btn.off(cc.Node.EventType.TOUCH_END, this.btnTouchEnd, this); this.btn = null; this.step++; this.doNext(); }, nsave() { playerData.newbieData.push(this.newbieid) this.step++; this.doNext(); }, serversave() { NetManage.saveNewbie(this.newbieid) this.step++; this.doNext(); }, waitForNotice(data) { var self = this; cc.director.once(data[1], function(event) { self.step++; console.log('waitForNotice '); self.doNext(); }); }, ntalk() { }, ndelay(data) { var self = this; this.scheduleOnce(function() { self.step++; console.log('ndelay '); self.doNext(); }, data[1]); }, nemit(data) { cc.director.emit(data[1], data[2]); this.step++; this.doNext(); }, bgOpacity(data) { if (data[1] == 0) { this.newbieblack.active = false; } else { this.newbieblack.active = true; } this.newbieblack.opacity = data[1]; this.step++; this.doNext(); }, bindUI(data) { if (this.scpArr[data[1]]) { this.currentUI = this.scpArr[data[1]]; this.step++; this.doNext(); } else { this.schedule(this.bindSchedule, 0.1); } }, bindSchedule() { console.log('1'); var data = this.stepCfg[this.step]; if (this.scpArr[data[1]]) { this.unschedule(this.bindSchedule); this.currentUI = this.scpArr[data[1]]; this.step++; this.doNext(); } }, isInNewbie() { return this.newbieid != 0; }, doclean(){ this.unscheduleAllCallbacks(); if(this.upnode){ this.upnode.removeFromParent() this.upnode = null } if(this.btn){ this.btn.removeFromParent() this.btn = null } this.newbieid = 0; this.step = 0; this.newbieblack.active = true; this.newbieblack.opacity = 180; this.node.active = false; this.newbieHand.active = false; this.newbieLabelNode.active = false; this.newbieHand.zIndex = 1 this.hsx = 0; this.hsy =0; this.hdx = 0; this.hdy =0; this.scpArr = {}; } // update (dt) {}, });