123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- // 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
- cc.Class({
- extends: cc.Component,
- properties: {
- // foo: {
- // // ATTRIBUTES:
- // default: null, // The default value will be used only when the component attaching
- // // to a node for the first time
- // type: cc.SpriteFrame, // optional, default is typeof default
- // serializable: true, // optional, default is true
- // },
- // bar: {
- // get () {
- // return this._bar;
- // },
- // set (value) {
- // this._bar = value;
- // }
- // },
- mainMenu:{
- default:null,
- type:cc.Node
- },
- friendRank:{
- default:null,
- type:cc.Node
- },
- totalRank:{
- default:null,
- type:cc.Node
- },
- bottleStore:{
- default:null,
- type:cc.Node
- },
- arrowStore:{
- default:null,
- type:cc.Node
- },
- rankingScrollView: cc.Sprite,
- shareDialog:cc.Node,
-
- loginPage:cc.Node,
- audioManager:cc.Node,
- shareUrls:[],
- shareTitle:[],
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.loginPage.active = Global.showLoginPage;
- this.audioManager.getComponent("AudioMng").stopAll();
- this.shareUrls[0]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share1.jpg';
- this.shareUrls[1]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share2.jpg';
- this.shareUrls[2]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share3.jpg';
- this.shareUrls[3]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share1.jpg';
- this.shareUrls[4]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share2.jpg';
- this.shareUrls[5]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share3.jpg';
- this.shareTitle[0] = '这游戏怎么一玩上就停不下来呢!';
- this.shareTitle[1] = '点一下~玩一年~皮肤不用一分钱!';
- this.shareTitle[2] = '这游戏怎么一玩上就停不下来呢!';
- this.shareTitle[3] = '点一下~玩一年~皮肤不用一分钱!';
- this.shareTitle[4] = '这游戏怎么一玩上就停不下来呢!';
- this.shareTitle[5] = '点一下~玩一年~皮肤不用一分钱!';
- if(Global.showTotalRank){
- this.goTotalRank();
- Global.showTotalRank = false;
- }
- if(Global.showFriendRank){
- this.goFriendRank();
- Global.showFriendRank = false;
- }
- },
- start () {
- },
- goMainMenu(){
- this.mainMenu.active = true;
- this.friendRank.active = false;
- this.totalRank.active = false;
- this.bottleStore.active = false;
- this.arrowStore.active = false;
- },
- goArrowStore(){
- this.mainMenu.active = false;
- this.friendRank.active = false;
- this.totalRank.active = false;
- this.bottleStore.active = false;
- this.arrowStore.active = true;
- },
- goBottleStore(){
- this.mainMenu.active = false;
- this.friendRank.active = false;
- this.totalRank.active = false;
- this.bottleStore.active = true;
- this.arrowStore.active = false;
- },
- goFriendRank(){
- this.mainMenu.active = false;
- this.friendRank.active = true;
- this.totalRank.active = false;
- this.bottleStore.active = false;
- this.arrowStore.active = false;
- if (window.wx != undefined) {
- // 发消息给子域
- window.wx.postMessage({
- messageType: 1,
- MAIN_MENU_NUM: "score"
- });
- } else {
- cc.log("获取好友排行榜数据。score");
- }
- },
- goTotalRank(){
- this.mainMenu.active = false;
- this.friendRank.active = false;
- this.totalRank.active = true;
- this.bottleStore.active = false;
- this.arrowStore.active = false;
- },
- shareGame(){
- // wx.request()
- let title = this.shareTitle[Math.floor(Math.random()*6)];
- let imageUrl = this.shareUrls[Math.floor(Math.random()*6)];
- this.shareDialog.active = true;
- this.shareDialog.getComponent('ShareModal').button.on('touchend', ()=> {
- this.shareDialog.active = false;
- if(wx!=undefined){
- console.log('share uid: '+Global.user.uid);
- wx.shareAppMessage({
- title: title,
- imageUrl: imageUrl,
- query:"uid="+Global.user.uid
- })
- }
- }, this);
- },
- startGame(){
- cc.director.loadScene("Game");
- },
- friendButtonFunc(event) {
- if (window.wx != undefined) {
- // 发消息给子域
- window.wx.postMessage({
- messageType: 1,
- MAIN_MENU_NUM: "score"
- });
- } else {
- cc.log("获取好友排行榜数据。score");
- }
- },
- groupFriendButtonFunc: function (event) {
- if (window.wx != undefined) {
- window.wx.shareAppMessage({
- success: (res) => {
- if (res.shareTickets != undefined && res.shareTickets.length > 0) {
- window.wx.postMessage({
- messageType: 5,
- MAIN_MENU_NUM: "score",
- shareTicket: res.shareTickets[0]
- });
- }
- }
- });
- } else {
- cc.log("获取群排行榜数据。score");
- }
- },
- start () {
- if (window.wx != undefined) {
- // window.wx.showShareMenu({withShareTicket: true});//设置分享按钮,方便获取群id展示群排行榜
- this.tex = new cc.Texture2D();
- // var openDataContext = wx.getOpenDataContext();
- // var sharedCanvas = openDataContext.canvas;
- // if (sharedCanvas) {
- // sharedCanvas.width = cc.game.canvas.width * 2;
- // sharedCanvas.height = cc.game.canvas.height * 2;
- // }
- window.sharedCanvas.width = 1334;
- window.sharedCanvas.height = 750;
- // window.wx.postMessage({
- // messageType: 3,
- // MAIN_MENU_NUM: "score",
- // score: 10
- // });
- }
- },
-
- _updateSubDomainCanvas () {
- if (!this.tex) {
- return;
- }
- this.tex.initWithElement(sharedCanvas);
- this.tex.handleLoadedTexture();
- this.rankingScrollView.spriteFrame = new cc.SpriteFrame(this.tex);
- },
- update(dt) {
- this._updateSubDomainCanvas();
- },
- // update (dt) {},
- });
|