123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- /*
- 商城
- */
- //var planeInfo = require('PlaneInfoJS');
- var prisonInfo = require('PrisonerInfo');
- var WxCommon = require("../extra/WxCommon")
- cc.Class({
- extends: cc.Component,
- properties: {
- sceneManager: {
- default: null,
- type: cc.Node
- },
- gold: { //玩家分数
- default: null,
- type: cc.Label
- },
- characterName: { //人物名字
- default: null,
- type: cc.Label
- },
- price: { //人物价格展示
- default: null,
- type: cc.Label
- },
- introduceLabel: { //人物介绍
- default: null,
- type: cc.Label
- },
- lockedLabel : { //解锁提示
- default: null,
- type: cc.Label
- },
- chaDisplay: { //人物展示图片
- default: null,
- type: cc.Node
- },
- buy: { //购买按钮
- default: null,
- type: cc.Node
- },
- // lockPlay: { //锁,开始节点
- // default: null,
- // type: cc.Node
- // },
- // lockPlaySPFArr: { //锁、开始图片数组
- // default: [],
- // type: [cc.SpriteFrame]
- // },
- characrerSPFArr: { //展示人物节点数组
- default: [],
- type: [cc.Prefab]
- },
- },
- onLoad: function() {
-
- this._planeLevelIndex = UserInfo.getString("isLock1") == "true" ? UserInfo.getCurrentPrison()-1 : 1; //当前选中的飞机下标
- this.chaDisplay.removeAllChildren();
- var prisonNode = cc.instantiate(this.characrerSPFArr[this._planeLevelIndex]);
- this.chaDisplay.addChild(prisonNode);
- var prisonersk = prisonNode.getComponent(sp.Skeleton);
- prisonersk.setAnimation(0, "a1", true);
- this.price.string = prisonInfo[this._planeLevelIndex].price;
- this.introduceLabel.string = prisonInfo[this._planeLevelIndex].introduce;
- this.gold.string = ""+UserInfo.getGold();
- this.characterName.string = prisonInfo[this._planeLevelIndex].name;
- this.node.getChildByName("ChaPrice").active = this._planeLevelIndex != 1;
- //this.node.getChildByName("ShareTip").active = this._planeLevelIndex == 1;
- this.node.getChildByName("ShareTip").active = false;
- this.isShowBuyButton();
- this.isShowShareButton();
- },
- onEnable: function() {
- this.chaDisplay.removeAllChildren();
- var prisonNode = cc.instantiate(this.characrerSPFArr[this._planeLevelIndex]);
- this.chaDisplay.addChild(prisonNode);
- var prisonersk = prisonNode.getComponent(sp.Skeleton);
- prisonersk.setAnimation(0, "a1", true);
- this.price.string = prisonInfo[this._planeLevelIndex].price;
- this.introduceLabel.string = prisonInfo[this._planeLevelIndex].introduce;
- this.gold.string = ""+UserInfo.getGold();
- this.characterName.string = prisonInfo[this._planeLevelIndex].name;
- this.node.getChildByName("ChaPrice").active = this._planeLevelIndex != 1;
- //this.node.getChildByName("ShareTip").active = this._planeLevelIndex == 1;
- this.node.getChildByName("ShareTip").active = false;
- this.isShowBuyButton();
- this.isShowShareButton();
- },
- onGoMain: function() {
- this._planeLevelIndex = UserInfo.getString("isLock1") == "true" ? this._planeLevelIndex : 1;
- this.sceneManager.getComponent('SceneManager').changeCanvasByName('Main');
- },
- onGoGame: function() {
- this._planeLevelIndex = UserInfo.getString("isLock1") == "true" ? this._planeLevelIndex : 1;
- //this.sceneManager.getComponent('SceneManager').changeCanvasByName('Game');
- // if (parseInt(UserInfo.getString("course")) == 1) {
- // UserInfo.setString("course", '0');
- // this.sceneManager.getComponent('SceneManager').changeCanvasByName('Guide');
- // } else {
- this.sceneManager.getComponent('SceneManager').changeCanvasByName('Game');
- //}
- },
- onLeft: function() {
- this._planeLevelIndex--;
- if (this._planeLevelIndex < 0) this._planeLevelIndex = prisonInfo.length-1;
- this.chaDisplay.removeAllChildren();
- var prisonNode = cc.instantiate(this.characrerSPFArr[this._planeLevelIndex]);
- this.chaDisplay.addChild(prisonNode);
- var prisonersk = prisonNode.getComponent(sp.Skeleton);
- prisonersk.setAnimation(0, "a1", true);
- this.price.string = prisonInfo[this._planeLevelIndex].price;
- this.characterName.string = prisonInfo[this._planeLevelIndex].name;
- this.introduceLabel.string = prisonInfo[this._planeLevelIndex].introduce;
- this.node.getChildByName("ChaPrice").active = this._planeLevelIndex != 1;
- //this.node.getChildByName("ShareTip").active = this._planeLevelIndex == 1;
- this.isShowBuyButton();
- this.isShowShareButton();
- },
- onRight: function() {
- this._planeLevelIndex++;
- if (this._planeLevelIndex == prisonInfo.length) this._planeLevelIndex = 0;
-
- this.chaDisplay.removeAllChildren();
- var prisonNode = cc.instantiate(this.characrerSPFArr[this._planeLevelIndex]);
- this.chaDisplay.addChild(prisonNode);
- var prisonersk = prisonNode.getComponent(sp.Skeleton);
- prisonersk.setAnimation(0, "a1", true);
-
- this.price.string = prisonInfo[this._planeLevelIndex].price;
- this.characterName.string = prisonInfo[this._planeLevelIndex].name;
- this.introduceLabel.string = prisonInfo[this._planeLevelIndex].introduce;
- this.node.getChildByName("ChaPrice").active = this._planeLevelIndex != 1;
- //this.node.getChildByName("ShareTip").active = this._planeLevelIndex == 1;
- this.isShowBuyButton();
- this.isShowShareButton();
- },
- onBuy: function() {
- let playerGold = UserInfo.getGold();
- let chaPrice = parseInt(this.price.string);
- if (playerGold >= chaPrice) { //够钱买飞机
- let lastGold = playerGold - chaPrice;
- this.gold.string = ""+lastGold;
- UserInfo.setGold(lastGold);
- UserInfo.setString("isLock"+this._planeLevelIndex, "true");
- this.isShowBuyButton();
- this.isShowShareButton();
- } else { //不够
- if (UserInfo.platform == 1) {
- wx.showModal({
- title:'温馨提示',
- content:'您的金币不足,无法购买',
- showCancel:false,
- cancelText:'取消',
- cancelColor:'#000000',
- confirmText:'确认',
- confirmColor:'#3cc51f',
- success: function(res) {
- cc.vv.isAlreadyShow = true;
- }
- })
- }
- return;
- }
- },
- isShowBuyButton: function() {
- this.node.getChildByName("btnShare").active = false;
- this.buy.active = false;
- if (this.checkPlaneLock()) {
- //this.lockPlay.getComponent(cc.Button).enabled = true;
- //this.lockPlay.getComponent(cc.Sprite).spriteFrame = this.lockPlaySPFArr[1];
- this.price.node.parent.active = false;
- this.lockedLabel.node.active = true;
- } else {
- this.buy.active = true;
- //this.lockPlay.getComponent(cc.Button).enabled = false;
- //this.lockPlay.getComponent(cc.Sprite).spriteFrame = this.lockPlaySPFArr[0];
- this.price.node.parent.active = true;
- this.lockedLabel.node.active = false;
- }
- //设置开始按钮能否点击
- },
- isShowShareButton: function() {
- // if (this._planeLevelIndex == 1) {
- // if (!this.checkPlaneLock()) {
- // this.buy.active = false;
- // this.node.getChildByName("btnShare").active = false;
- // this.node.getChildByName("ChaPrice").active = false;
- // this.node.getChildByName("ShareTip").active = false;
-
- // // this.lockPlay.getComponent(cc.Button).enabled = false;
- // // this.lockPlay.getComponent(cc.Sprite).spriteFrame = this.lockPlaySPFArr[0];
- // } else {
- // this.node.getChildByName("ShareTip").active = false;
- // this.lockedLabel.node.active = true;
- // }
- // }
- },
- onShare: function() {
- var self = this;
- var Ok = function() {
- UserInfo.setString("isLock"+self._planeLevelIndex, "true");
- // this.lockPlay.getComponent(cc.Button).enabled = true;
- // this.lockPlay.getComponent(cc.Sprite).spriteFrame = this.lockPlaySPFArr[1];
- self.isShowBuyButton();
- self.isShowShareButton();
- }
- var data = {titleData:UserInfo.shareDesc,imgurlData:UserInfo.shareUrl,queryData:'pp=pp'}
- WxCommon.ShareAppMessage(data, this, Ok);
- },
- //检测当前选中飞机有没有解锁
- checkPlaneLock: function() {
- let currentIsLockKey = "isLock"+this._planeLevelIndex;
- let isLock = UserInfo.getString(currentIsLockKey);
- if (isLock == "true") {//解锁
- UserInfo.setCurrentPrison(this._planeLevelIndex+1);
- } else {//没有解锁
- if (this._planeLevelIndex == 0) { //如果是0号飞机,不需要解锁
- isLock = "true";
- UserInfo.setString(currentIsLockKey, "true");
- }
- }
- return isLock == "true" ? true : false;
- },
- });
|