MainNavigation.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. mainMenu:{
  29. default:null,
  30. type:cc.Node
  31. },
  32. friendRank:{
  33. default:null,
  34. type:cc.Node
  35. },
  36. totalRank:{
  37. default:null,
  38. type:cc.Node
  39. },
  40. bottleStore:{
  41. default:null,
  42. type:cc.Node
  43. },
  44. arrowStore:{
  45. default:null,
  46. type:cc.Node
  47. },
  48. rankingScrollView: cc.Sprite,
  49. shareDialog:cc.Node,
  50. loginPage:cc.Node,
  51. audioManager:cc.Node,
  52. shareUrls:[],
  53. shareTitle:[],
  54. },
  55. // LIFE-CYCLE CALLBACKS:
  56. onLoad () {
  57. this.loginPage.active = Global.showLoginPage;
  58. this.audioManager.getComponent("AudioMng").stopAll();
  59. this.shareUrls[0]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share1.jpg';
  60. this.shareUrls[1]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share2.jpg';
  61. this.shareUrls[2]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share3.jpg';
  62. this.shareUrls[3]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share1.jpg';
  63. this.shareUrls[4]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share2.jpg';
  64. this.shareUrls[5]='http://pub.dwstatic.com/wxgame/dwgame01/wxshare/share3.jpg';
  65. this.shareTitle[0] = '这游戏怎么一玩上就停不下来呢!';
  66. this.shareTitle[1] = '点一下~玩一年~皮肤不用一分钱!';
  67. this.shareTitle[2] = '这游戏怎么一玩上就停不下来呢!';
  68. this.shareTitle[3] = '点一下~玩一年~皮肤不用一分钱!';
  69. this.shareTitle[4] = '这游戏怎么一玩上就停不下来呢!';
  70. this.shareTitle[5] = '点一下~玩一年~皮肤不用一分钱!';
  71. if(Global.showTotalRank){
  72. this.goTotalRank();
  73. Global.showTotalRank = false;
  74. }
  75. if(Global.showFriendRank){
  76. this.goFriendRank();
  77. Global.showFriendRank = false;
  78. }
  79. },
  80. start () {
  81. },
  82. goMainMenu(){
  83. this.mainMenu.active = true;
  84. this.friendRank.active = false;
  85. this.totalRank.active = false;
  86. this.bottleStore.active = false;
  87. this.arrowStore.active = false;
  88. },
  89. goArrowStore(){
  90. this.mainMenu.active = false;
  91. this.friendRank.active = false;
  92. this.totalRank.active = false;
  93. this.bottleStore.active = false;
  94. this.arrowStore.active = true;
  95. },
  96. goBottleStore(){
  97. this.mainMenu.active = false;
  98. this.friendRank.active = false;
  99. this.totalRank.active = false;
  100. this.bottleStore.active = true;
  101. this.arrowStore.active = false;
  102. },
  103. goFriendRank(){
  104. this.mainMenu.active = false;
  105. this.friendRank.active = true;
  106. this.totalRank.active = false;
  107. this.bottleStore.active = false;
  108. this.arrowStore.active = false;
  109. if (window.wx != undefined) {
  110. // 发消息给子域
  111. window.wx.postMessage({
  112. messageType: 1,
  113. MAIN_MENU_NUM: "score"
  114. });
  115. } else {
  116. cc.log("获取好友排行榜数据。score");
  117. }
  118. },
  119. goTotalRank(){
  120. this.mainMenu.active = false;
  121. this.friendRank.active = false;
  122. this.totalRank.active = true;
  123. this.bottleStore.active = false;
  124. this.arrowStore.active = false;
  125. },
  126. shareGame(){
  127. // wx.request()
  128. let title = this.shareTitle[Math.floor(Math.random()*6)];
  129. let imageUrl = this.shareUrls[Math.floor(Math.random()*6)];
  130. this.shareDialog.active = true;
  131. this.shareDialog.getComponent('ShareModal').button.on('touchend', ()=> {
  132. this.shareDialog.active = false;
  133. if(wx!=undefined){
  134. console.log('share uid: '+Global.user.uid);
  135. wx.shareAppMessage({
  136. title: title,
  137. imageUrl: imageUrl,
  138. query:"uid="+Global.user.uid
  139. })
  140. }
  141. }, this);
  142. },
  143. startGame(){
  144. cc.director.loadScene("Game");
  145. },
  146. friendButtonFunc(event) {
  147. if (window.wx != undefined) {
  148. // 发消息给子域
  149. window.wx.postMessage({
  150. messageType: 1,
  151. MAIN_MENU_NUM: "score"
  152. });
  153. } else {
  154. cc.log("获取好友排行榜数据。score");
  155. }
  156. },
  157. groupFriendButtonFunc: function (event) {
  158. if (window.wx != undefined) {
  159. window.wx.shareAppMessage({
  160. success: (res) => {
  161. if (res.shareTickets != undefined && res.shareTickets.length > 0) {
  162. window.wx.postMessage({
  163. messageType: 5,
  164. MAIN_MENU_NUM: "score",
  165. shareTicket: res.shareTickets[0]
  166. });
  167. }
  168. }
  169. });
  170. } else {
  171. cc.log("获取群排行榜数据。score");
  172. }
  173. },
  174. start () {
  175. if (window.wx != undefined) {
  176. // window.wx.showShareMenu({withShareTicket: true});//设置分享按钮,方便获取群id展示群排行榜
  177. this.tex = new cc.Texture2D();
  178. // var openDataContext = wx.getOpenDataContext();
  179. // var sharedCanvas = openDataContext.canvas;
  180. // if (sharedCanvas) {
  181. // sharedCanvas.width = cc.game.canvas.width * 2;
  182. // sharedCanvas.height = cc.game.canvas.height * 2;
  183. // }
  184. window.sharedCanvas.width = 1334;
  185. window.sharedCanvas.height = 750;
  186. // window.wx.postMessage({
  187. // messageType: 3,
  188. // MAIN_MENU_NUM: "score",
  189. // score: 10
  190. // });
  191. }
  192. },
  193. _updateSubDomainCanvas () {
  194. if (!this.tex) {
  195. return;
  196. }
  197. this.tex.initWithElement(sharedCanvas);
  198. this.tex.handleLoadedTexture();
  199. this.rankingScrollView.spriteFrame = new cc.SpriteFrame(this.tex);
  200. },
  201. update(dt) {
  202. this._updateSubDomainCanvas();
  203. },
  204. // update (dt) {},
  205. });