pubgv3/assets/scripts/newbie/newbieManage.js
zhuguoqing c21cd97580 udpate
2022-05-26 14:48:21 +08:00

649 lines
19 KiB
JavaScript

// 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<tlsteps.length;j++){
NewbieConfig[k].step.push(tlsteps[j])
}
}
}
}
}
var NewbieInClude = {};
for (var k in NewbieConfig) {
var step = NewbieConfig[k].step;
for (var i = 0; i < step.length; i++) {
if (step[i][0] == NewbieEnum.bindUI) {
if (NewbieInClude[step[i][1]] == null) {
NewbieInClude[step[i][1]] = [Number(k)];
} else {
if (!Util.contains(NewbieInClude[step[i][1]], Number(k))) {
NewbieInClude[step[i][1]].push(Number(k));
}
}
}
}
}
this.NewbieInClude = NewbieInClude;
this.newbieid = 0;
this.step = 0;
this.initFunction();
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 = {};
},
initFunction() {
this.functionTb = {};
this.functionTb[NewbieEnum.bindUI] = this.bindUI.bind(this);
this.functionTb[NewbieEnum.touch] = this.ntouch.bind(this);
this.functionTb[NewbieEnum.talk] = this.ntalk.bind(this);
this.functionTb[NewbieEnum.delay] = this.ndelay.bind(this);
this.functionTb[NewbieEnum.save] = this.nsave.bind(this);
this.functionTb[NewbieEnum.serversave] = this.serversave.bind(this);
this.functionTb[NewbieEnum.waitForNotice] = this.waitForNotice.bind(this);
this.functionTb[NewbieEnum.bgOpacity] = this.bgOpacity.bind(this);
this.functionTb[NewbieEnum.emit] = this.nemit.bind(this);
this.functionTb[NewbieEnum.showHand] = this.showHand.bind(this);
this.functionTb[NewbieEnum.hideHand] = this.hideHand.bind(this);
this.functionTb[NewbieEnum.setText] = this.setText.bind(this);
this.functionTb[NewbieEnum.setScrollViewTouch] = this.setScrollViewTouch.bind(this);
// this.functionTb[NewbieEnum.showHand2] = this.showHand2.bind(this);
// this.functionTb[NewbieEnum.hideHand2] = this.hideHand2.bind(this);
this.functionTb[NewbieEnum.upz] = this.upz.bind(this);
this.functionTb[NewbieEnum.downz] = this.downz.bind(this);
this.functionTb[NewbieEnum.sprite] = this.showSprite.bind(this);
this.functionTb[NewbieEnum.handPosAndRotation] = this.sethandPosAndRotation.bind(this);
this.functionTb[NewbieEnum.tipsPosAndRotation] = this.settipsPosAndRotation.bind(this);
this.functionTb[NewbieEnum.alpha] = this.setalpha.bind(this);
this.functionTb[NewbieEnum.showTips] = this.showTips.bind(this);
this.functionTb[NewbieEnum.hideTips] = this.hideTips.bind(this);
this.functionTb[NewbieEnum.notrecheck] = this.notrecheck.bind(this);
this.functionTb[NewbieEnum.checkswitch] = this.checkswitch.bind(this);
this.functionTb[NewbieEnum.nd_alpha] = this.nd_alpha.bind(this);
this.functionTb[NewbieEnum.callPrefab] = this.callPrefab.bind(this);
},
checkConditon(nid) {
var condition = NewbieConfig[nid.toString()].conditon;
if (condition.preId && (!Util.contains(playerData.newbieData, condition.preId))) {
return false;
}
if (condition.battlecount != undefined && playerData.game_times != condition.battlecount) {
return false;
}
if (condition.isview != undefined && playerData.randnew == condition.isview) {
return false;
}
if (condition.huchi && (Util.contains(playerData.newbieData, condition.huchi))) {
return false;
}
if (condition.coin_num != undefined && playerData.coin_num < condition.coin_num) {
return false;
}
if (condition.view_times != undefined && playerData.vip_score < condition.view_times) {
return false;
}
if (condition.item != undefined) {
var item = playerData.getBagItem(condition.item.id)
if (!item) {
return false;
}
if (item.num < condition.item.num) {
return false;
}
}
if (condition.equip != undefined) {
var equip = playerData.getBagItem(condition.equip.id)
if (!equip) {
return false
}
if (Number(equip.lv) != condition.equip.lv) {
return false;
}
}
return true;
},
check(v) {
//Main.config.mainConfig.openNewbie = false
if (Main.config.mainConfig.openNewbie == false) {
return false;
}
var arr = this.NewbieInClude[v]; //{'aaa':[1,2]}
if (arr == null) {
return false;
}
if (this.newbieid != 0) {
if (Util.contains(arr, this.newbieid)) {
return true;
} else {
return false;
}
}
this.scpArr = {};
this.step = 0;
var newSave = playerData.newbieData;
for (var i = 0; i < arr.length; i++) {
if (!Util.contains(newSave, arr[i]) && this.checkConditon(arr[i])) {
this.newbieid = arr[i];
return true;
}
}
return false;
},
bindNewbie(v, isfirst) {
var res = v.node.name;
var last = this.newbieid;
if (this.check(res)) {
this.scpArr[res] = v.node;
console.log('check true');
console.log(this.newbieid);
if (last == 0) {
if (isfirst == null) {
isfirst = true;
}
this.startNewbie(res, isfirst);
}
} else {
console.log('check false');
}
},
removeNewbie(v) {
var res = v.node.name;
if (this.scpArr[res]) {
this.scpArr[res] = null;
}
},
setText(data) {
if (data[1] == "") {
this.newbieLabelNode.active = false;
this.step++;
this.doNext();
} else {
this.newbieLabelNode.active = true;
this.newbieLabel.string = data[1];
if (data[2] == true) {
this.newbieblack.on(cc.Node.EventType.TOUCH_END, this.onTouchText, this);
} else {
this.step++;
this.doNext();
}
this.newbieLabel.node.opacity = 0
this.newbieLabel.node.runAction(cc.fadeIn(0.2));
}
},
onTouchText() {
this.newbieLabelNode.active = false;
this.newbieblack.off(cc.Node.EventType.TOUCH_END, this.onTouchText, this);
this.step++;
this.doNext();
},
showSprite(data) {
this.sprite.active = data[1];
this.step++;
this.doNext();
},
checkswitch(data) {
if (parseInt(gameConfig.parameterConfig[data[1]].param_value) != 0) {
this.step++;
this.doNext();
} else {
this.step += data[2];
this.step++
this.doNext();
}
},
nd_alpha(data) {
var path = data[1];
this.btn = cc.find(path);
this.btn.opacity = data[2]
this.step++;
this.doNext();
},
callPrefab(data) {
cc.Notifier.emit('newcallprefab', data[1])
this.step++;
this.doNext();
},
sethandPosAndRotation(data) {
this.hdx = data[1];
this.hdy = data[2];
this.newbieHand.rotation = data[3];
this.step++;
this.doNext();
},
notrecheck() {
this.step++;
this.doNext();
},
settipsPosAndRotation(data) {
var height = this.newbieLabelNode.height / 2
this.newbieLabelNode.x = data[1];
this.newbieLabelNode.y = data[2];
if (this.newbieLabelNode.y < -this.node.height / 2 + height) {
this.newbieLabelNode.y = -this.node.height / 2 + height
}
this.step++;
this.doNext();
},
setalpha(data) {
this.newbieblack.opacity = data[1]
this.step++;
this.doNext();
},
showHand(data) {
if (data[1] != null) {
this.newbieHand.position = data[1];
}
this.newbieHand.active = true;
this.newbieHand.opacity = 0
this.step++;
this.doNext();
},
hideHand() {
this.newbieHand.active = false;
this.step++;
this.doNext();
},
showTips() {
this.newbieLabelNode.opacity = 255
this.step++;
this.doNext();
},
hideTips() {
this.newbieLabelNode.opacity = 0
this.step++;
this.doNext();
},
startNewbie(res, first) {
this.node.active = true;
this.newbieblack.opacity = 180;
this.stepCfg = NewbieConfig[this.newbieid.toString()].step;
this.overemit = NewbieConfig[this.newbieid.toString()].msg;
if (this.stepCfg[0][1] != res && first) {
this.stepCfg = NewbieConfig[this.newbieid.toString()].stepSave;
}
this.doNext();
},
doNext() {
if (this.step >= 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) {},
});