123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- var WxCommon = require("../WxCommon")
- var QQCommon = require("../QQCommon")
- var cfg = require("Configure")
- cc.Class({
- extends: cc.Component,
- properties: {
- gamebgMusic: {
- default: null,
- type: cc.AudioClip
- },
- buttonAudio: {
- default: null,
- type: cc.AudioClip
- },
- SignAtlas: {
- default: null,
- type: cc.SpriteAtlas,
- },
- ShareStrategyNode: { //游戏攻略图片节点
- default: null,
- type: cc.Node
- },
- GuideNode: {
- default: null,
- type: cc.Node
- },
- feiendtex: null,
- otherGamesIndex: 0,
- skinIndex: 0,
- showGuideValue: 0
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- cc.audioEngine.playMusic(this.gamebgMusic, true);
- if(CC_QQPLAY && window.GameStatusInfo) {
- GameStatusInfo.startMs = ((new Date()).getTime()).toString()
- }
- // let path = 'GameSandBox://qrcode2.png'
- // BK.QRCode.makeQRCodeToFileSync({
- // path: path,
- // content: 'hello world',
- // config: {
- // width: 256,
- // height: 256
- // }
- // });
-
- // new BK.Game({
- // onShare: function(app) {
- // var shareInfo = {
- // summary: '分享正文',
- // localPicPath: path,
- // picUrl: 'https://pub.dwstatic.com/wxgame/budingGame/share/shareImage.jpg',
- // gameName: '游戏名称'
- // }
- // return shareInfo
- // }
- // })
-
- this.showGuideValue = UserInfo.getItem('showGuide') || false;
-
- if (CC_QQPLAY) {
- // this.QQLogin();
- // this.initShare();
- UserInfo.showIndexBanner();
- try{
- BK.Script.errorAlertOpen = false;
- } catch(e) {}
- }
- },
- start() {
- this.feiendtex = new cc.Texture2D();
- this.PHB = cc.find("Canvas/PHB")
- this.rankScene = this.PHB.getComponent("RankScene");
- this.rankNode = this.PHB.getChildByName("Rank")
- this.myRankNode = this.PHB.getChildByName('MyRank')
- this.worldContentNode = this.rankNode.getChildByName('WorldContent')
- this.friendContentNode = this.rankNode.getChildByName('FriendContent')
- },
- QQLogin() {
- if(window.GameStatusInfo && window.GameStatusInfo.openId) {
- BK.Console.log('登录成功')
- }
- },
- // initShare(data) {
- // let datavalue = UserInfo.getString('allscore');
- // let key = UserInfo.getCurWeekScoreValue();
- // if (UserInfo.IsEmpty(datavalue)) {
- // UserInfo.setString('allscore', key);
- // return;
- // }
- // let datalist = datavalue.split('*');
- // let removeIndex = -1;
- // for (let index = 0; index < datalist.length; ++index) {
- // if (key == datalist[index]) {
- // // UserInfo.removeString(datalist[index]);
- // removeIndex = index;
- // }
- // }
- // if (removeIndex != -1) {
- // datalist.splice(removeIndex, 1);
- // }
- // // WxCommon.RemoveUserCloudStorage(datalist, this, this.RemoveScoreKey);
- // // this.RemoveScoreKey(datalist, true);
- // },
- // listenGame() {
- // // var date = UserInfo.GetNowFormatDate();
- // this.OnUpdateGame();
- // WxCommon.SetEnableDebug(false);
- // WxCommon.OnShow(null, this, null);
- // WxCommon.ShowShareMenu();
- // WxCommon.OnShareAppMessage(null, this, this.shareCallback);
- // WxCommon.GetSystemInfo(null, this, null);
- // },
- // OnUpdateGame() {
- // const updateManager = wx.getUpdateManager()
- // updateManager.onCheckForUpdate(function (res) {
- // // 请求完新版本信息的回调
- // console.log(res.hasUpdate)
- // })
- // updateManager.onUpdateReady(function () {
- // wx.showModal({
- // title: '更新提示',
- // content: '新版本已经准备好,是否重启应用?',
- // success: function (res) {
- // if (res.confirm) {
- // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- // updateManager.applyUpdate()
- // }
- // }
- // })
- // })
- // updateManager.onUpdateFailed(function () {
- // // 新的版本下载失败
- // })
- // },
- onRankBtn: function (event, optData) {
- cc.find("Canvas/PHB").getChildByName("BtnPHBClose").active = (optData == "true");
- cc.find("Canvas/PHB").getChildByName("emptyBtn").active = (optData == "true");
- cc.find("Canvas/PHB").getChildByName("bg").active = (optData == "true");
-
- if (this.node.active) {
- if ("true" == optData) {
- UserInfo.destroyIndexBanner();
- // this.rankScene.status = 1;
- this.showRank();
- }
- if ("false" == optData) {
- UserInfo.showIndexBanner();
- cc.find("Canvas/PHB").active = false;
- }
- } else {
- cc.find("Canvas/PHB").active = false;
- // window.accountBanner.show();
- }
- },
- showRank() {
- this.myRankNode.active = false;
-
- // if (this.rankScene.status == 1) {
- // let openDataContext = wx.getOpenDataContext();
- // let sharedCanvas = openDataContext.canvas;
- // this.feiendtex.initWithElement(sharedCanvas);
- // this.feiendtex.handleLoadedTexture();
- // this.friendContentNode.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(this.feiendtex);
- // var scale = Math.min(750 / this.feiendtex.width, 1334 / this.feiendtex.height);
- // this.friendContentNode.setContentSize(this.feiendtex.width * scale, this.feiendtex.height * scale);
- // }
- this.PHB.active = true;
- this.rankNode.active = true;
- },
- update: function () {
-
- },
- onGameStartBtn: function () {
- this.node.parent.getChildByName("SkinNode").active = false;
- UserInfo.destroyIndexBanner();
-
- if (!this.showGuideValue) {
- this.GuideNode.active = true;
- this.showGuideValue = 1;
- UserInfo.setItem('showGuide', '1')
- return false;
- } else {
- this.GuideNode && this.GuideNode.destroy();
- }
- if (this.skinIndex != UserInfo.getSkinIndex()) {
- UserInfo.setSkinIndex(this.skinIndex);
- }
- if (this.node.active) {
- // cc.audioEngine.stopMusic(this.gamebgMusic);
- this.node.parent.getComponent("SenceManager").enterSence("Home", "Game");
- } else {
- this.node.parent.getChildByName("Game").getComponent("GameSence").onRestartBtn();
- }
- },
- onSkinBtn: function (event, optData) {
- if (optData == "true") {
- this.node.parent.getChildByName("SkinNode").active = true;
- this.skinIndex = UserInfo.getSkinIndex();
- var sumScoreLabel = this.node.parent.getChildByName("SkinNode").getChildByName("SumScoreSp").getChildByName("SumScoreLabel");
- sumScoreLabel.getComponent("cc.Label").string = UserInfo.getTotalGold();
- this.updateSkinNode();
- UserInfo.destroyIndexBanner();
- } else if (optData == "false") {
- this.node.parent.getChildByName("SkinNode").active = false;
- UserInfo.showIndexBanner();
- }
- },
- updateSkinNode: function () {
- var skinNode = this.node.parent.getChildByName("SkinNode");
- if (this.skinIndex == 0) {
- skinNode.getChildByName("RightBtn").active = true;
- skinNode.getChildByName("LeftBtn").active = false;
- } else if (this.skinIndex == cfg.skinTypePath.length - 1) {
- skinNode.getChildByName("RightBtn").active = false;
- skinNode.getChildByName("LeftBtn").active = true;
- } else {
- skinNode.getChildByName("RightBtn").active = true;
- skinNode.getChildByName("LeftBtn").active = true;
- }
- var skSpine = skinNode.getChildByName("skSprite");
- skSpine.getComponent("sp.Skeleton").setSkin("p" + (this.skinIndex + 1));
- //var self = this;
- //cc.loader.loadRes(cfg.skinTypePath[self.skinIndex],cc.SpriteFrame,function(err,spriteFrame){
- //var skinsp = skinNode.getChildByName("SkinSp");
- //skinsp.getComponent("cc.Sprite").spriteFrame = spriteFrame;
- var condition1 = skinNode.getChildByName("Condition1");
- var condition2 = skinNode.getChildByName("Condition2");
- var lockerSp = skinNode.getChildByName("LockerSp");
- var playBtn = skinNode.getChildByName("PlayBtn");
- var unlockSp = skinNode.getChildByName("UnlockSp");
- UserInfo.getUserGameData((data) => {
- var historyScore = data.maxScore || UserInfo.getItem('score');
- if (this.skinIndex > 0) {
- if (cfg.skinCondition[this.skinIndex].scoreType == 0) {
- if (historyScore >= cfg.skinCondition[this.skinIndex].score) {
- condition1.active = false;
- condition2.active = false;
- unlockSp.active = true;
- lockerSp.active = false;
- playBtn.active = true;
- } else {
- condition1.active = true;
- condition2.active = false;
- unlockSp.active = false;
- lockerSp.active = true;
- playBtn.active = false;
-
- condition1.getChildByName("ConditionLabel").getComponent("cc.Label").string = historyScore + "." + cfg.skinCondition[this.skinIndex].score;
- }
-
- } else if (cfg.skinCondition[this.skinIndex].scoreType == 1) {
- var sumScore = UserInfo.getTotalGold();
- if (sumScore >= cfg.skinCondition[this.skinIndex].score) {
- condition1.active = false;
- condition2.active = false;
- unlockSp.active = true;
- lockerSp.active = false;
- playBtn.active = true;
- } else {
- condition1.active = false;
- condition2.active = true;
- unlockSp.active = false;
- lockerSp.active = true;
- playBtn.active = false;
-
- condition2.getChildByName("ConditionLabel").getComponent("cc.Label").string = cfg.skinCondition[this.skinIndex].score;
- }
- }
- } else {
- condition1.active = false;
- condition2.active = false;
- lockerSp.active = false;
- playBtn.active = true;
- unlockSp.active = true;
- }
- })
- },
- onGuideBtn: function (event) {
- this.node.parent.getChildByName("Guide").active = false;
- // UserInfo.showIndexBanner();
- },
- onNextBtn: function (event, optData) {
- if (optData == "right") {
- this.skinIndex++;
- } else if (optData = "left") {
- this.skinIndex--;
- }
- this.updateSkinNode();
- },
- onHonourBtn: function () {
- },
- onMoreBtn: function (event, optData) {
- if (CC_WECHATGAME) {
- // objSdk.openGameCenter();
- // wx.navigateToMiniProgram({
- // appId: "wx582548bc3a843fed",
- // path: "pages/index",
- // extraData: {
- // fromGame: "budinggame"
- // }
- // })
- } else {
- if (this.node.active) {
- this.node.getChildByName("GameStartBtn").getComponent("cc.Button").interactable = (optData == "false");
- this.node.getChildByName("SkinBtn").getComponent("cc.Button").interactable = (optData == "false");
- this.node.getChildByName("HonourBtn").getComponent("cc.Button").interactable = (optData == "false");
- this.node.getChildByName("RankBtn").getComponent("cc.Button").interactable = (optData == "false");
- this.node.getChildByName("MoreBtn").getComponent("cc.Button").interactable = (optData == "false");
- } else {
- this.node.parent.getChildByName("Game").getComponent("GameSence").onMoreGameBtn(optData);
- }
- this.ShareStrategyNode.active = (optData == "true");
- if (optData == "true") {
- this.createTimer();
- }
- }
- },
- onShareBtn: function () {
- if (CC_QQPLAY) {
- var data = {
- titleData: UserInfo.shareDesc,
- imgurlData: UserInfo.shareUrl
- }
- QQCommon.ShareAppMessage(data, null);
- }
- },
- createTimer: function () {
- var self = this;
- var updateOtherGames = function () {
- self.otherGamesIndex = (self.otherGamesIndex + 1 + WxCommon.otherGameCount) % WxCommon.otherGameCount;
- self.ShareStrategyNode.getChildByName("OtherGameBtn").getComponent(cc.Sprite).spriteFrame = self.SignAtlas.getSpriteFrame('games' + self.otherGamesIndex);
- self.createTimer();
- };
- if (this.ShareStrategyNode.active == true) {
- this.timerid = setTimeout(updateOtherGames, 2000);
- }
- },
- onShowOtherGame: function () {
- if (CC_WECHATGAME) {
- var path = WxCommon.otherGameMap.get(this.otherGamesIndex);
- WxCommon.PreviewImage(path, this, this.hideNode);
- }
- },
- killTimer: function () {
- if (this.timerid != null) {
- clearTimeout(this.timerid);
- this.timerid = null;
- }
- },
- hideNode: function () {
- if (this.ShareStrategyNode.active) {
- this.killTimer();
- this.ShareStrategyNode.active = false;
- if (this.node.active) {
- this.node.getChildByName("GameStartBtn").getComponent("cc.Button").interactable = true;
- this.node.getChildByName("SkinBtn").getComponent("cc.Button").interactable = true;
- this.node.getChildByName("HonourBtn").getComponent("cc.Button").interactable = true;
- this.node.getChildByName("RankBtn").getComponent("cc.Button").interactable = true;
- this.node.getChildByName("MoreBtn").getComponent("cc.Button").interactable = true;
- } else {
- this.node.parent.getChildByName("Game").getComponent("GameSence").onMoreGameBtn("false");
- }
- }
- },
- onBtnAudio: function () {
- cc.audioEngine.playEffect(this.buttonAudio);
- }
- // update (dt) {},
- });
|