social.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /**
  2. * @author heyuchang
  3. * @file 排行榜组件
  4. * @description 用户点击查看排行榜才检查授权,如果此时用户没有授权则进入授权界面
  5. */
  6. //电子邮件puhalskijsemen@gmail.com
  7. //源码网站 开vpn全局模式打开 http://web3incubators.com/
  8. //电报https://t.me/gamecode999
  9. //网页客服 http://web3incubators.com/kefu.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. display: cc.Sprite,
  14. groupDisplay: cc.Sprite,
  15. _isShow: false,
  16. // score: 0
  17. },
  18. init(c) {
  19. this._controller = c
  20. wx.showShareMenu({
  21. withShareTicket: true
  22. })
  23. wx.onShareAppMessage(function () {
  24. return {
  25. title: "开局只是个农民,现在已经做到宰相",
  26. imageUrl: 'https://mmocgame.qpic.cn/wechatgame/LtJZOjH6Z9ibiaMlpqzldsOf46Q7TZiaysI1fwc4Oj1L3CkbCaJMAMoicibbHu2HUQkOib/0'
  27. }
  28. })
  29. // 监听
  30. wx.onAudioInterruptionEnd(() => {
  31. c.musicManager.pauseBg()
  32. c.musicManager.resumeBg()
  33. })
  34. wx.onShow((options) => {
  35. if (options.scene == 1044) {
  36. wx.postMessage({
  37. message: 'group',
  38. shareTicket: options.shareTicket
  39. })
  40. c.openGroupRank()
  41. this.display.node.active = false
  42. c.totalRank.active = false
  43. }
  44. cc.director.resume()
  45. })
  46. wx.onHide(() => {
  47. cc.director.pause()
  48. })
  49. // 获取最高官阶
  50. this.getHighestLevel()
  51. },
  52. getHighestLevel() {
  53. let highLevel = wx.getStorageSync('highLevel')
  54. return highLevel
  55. },
  56. getHighestScore() {
  57. let score = wx.getStorageSync('highScore')
  58. return score
  59. },
  60. // --------------- share ----------------
  61. onShareButton() {
  62. var self = this;
  63. wx.shareAppMessage({
  64. title: "我终于成为了" + this._controller.scoreMgr.levelData[this._controller.scoreMgr.level - 1].name + ",真是开心",
  65. // imageUrlId: 'oxEwGvClT0uldQ470pM84w',
  66. imageUrl: 'https://mmocgame.qpic.cn/wechatgame/LtJZOjH6Z9ibiaMlpqzldsOf46Q7TZiaysI1fwc4Oj1L3CkbCaJMAMoicibbHu2HUQkOib/0'
  67. })
  68. },
  69. onUsualShareButton() {
  70. wx.shareAppMessage({
  71. title: "只是个农民,现在已经做到宰相",
  72. // imageUrlId: 'oxEwGvClT0uldQ470pM84w',
  73. imageUrl: 'https://mmocgame.qpic.cn/wechatgame/LtJZOjH6Z9ibiaMlpqzldsOf46Q7TZiaysI1fwc4Oj1L3CkbCaJMAMoicibbHu2HUQkOib/0'
  74. })
  75. },
  76. onShakePhone() {
  77. wx.vibrateShort()
  78. },
  79. // ---------------分数上传---------------
  80. onGameOver(level, score) {
  81. console.log('zh:onGameOver'+level)
  82. //上传分数
  83. //打开开放域
  84. this.score = score
  85. let highLevel = level
  86. let highScore = score
  87. let self = this
  88. wx.postMessage({
  89. event: 'setScore',
  90. score: score,
  91. level: level,
  92. })
  93. highLevel = wx.getStorageSync('highLevel')
  94. highLevel = parseInt(highLevel)
  95. if (highLevel) {
  96. highLevel = highLevel < level ? level : highLevel
  97. } else {
  98. highLevel = level
  99. }
  100. highScore = wx.getStorageSync('highScore')
  101. if (highScore) {
  102. highScore = parseInt(highScore)
  103. highScore = highScore < score ? score : highScore
  104. } else {
  105. highScore = score
  106. }
  107. var highLevelName = this._controller.gameData.json.levelData[highLevel - 1].name
  108. wx.setStorageSync('highLevel', highLevel + '')
  109. wx.setStorageSync('highScore', highScore + '')
  110. self._controller.scoreMgr.failHighScore.string = "您的最高分:" + (highScore + '')
  111. var kvDataList = new Array()
  112. kvDataList.push({
  113. key: "highLevel",
  114. value: highLevelName,
  115. }, {
  116. key: "highScore",
  117. value: highScore + '',
  118. })
  119. },
  120. showRank() {
  121. wx.postMessage({
  122. message: 'Show',
  123. event: 'getRank',
  124. })
  125. this.display.node.active = true
  126. this._isShow = true
  127. },
  128. closeRank() {
  129. this.display.node.active = false
  130. wx.postMessage({
  131. message: 'Hide'
  132. })
  133. this._isShow = false
  134. },
  135. showGroupRank() {
  136. wx.postMessage({
  137. message: 'Show'
  138. })
  139. this.groupDisplay.node.active = true
  140. this._isShow = true
  141. },
  142. // switchRankType() {
  143. // wx.postMessage({
  144. // message: 'switchRank'
  145. // })
  146. // this._isShow = true
  147. // },
  148. closeGroupRank() {
  149. this.groupDisplay.node.active = false
  150. wx.postMessage({
  151. message: 'Hide'
  152. })
  153. this._isShow = false
  154. },
  155. createImage(sprite, url) {
  156. let image = wx.createImage();
  157. image.onload = function () {
  158. let texture = new cc.Texture2D();
  159. texture.initWithElement(image);
  160. texture.handleLoadedTexture();
  161. sprite.spriteFrame = new cc.SpriteFrame(texture);
  162. };
  163. image.src = url;
  164. },
  165. update() {
  166. if (this._isShow) {
  167. if(2>1){
  168. return;//zh
  169. }
  170. if (this.display.node.active) {
  171. this.display.node.getComponent(cc.WXSubContextView).update()
  172. }
  173. if (this.groupDisplay.node.active) {
  174. this.groupDisplay.node.getComponent(cc.WXSubContextView).update()
  175. }
  176. }
  177. },
  178. // 控制打开广告
  179. onReviveButton(type) {
  180. // 广告位
  181. let self = this
  182. this.adType = type //0表示加倍 1表示复活
  183. if (this.audioAd) {
  184. this.audioAd.show().catch(() => {
  185. // 失败重试
  186. this.audioAd.load()
  187. .then(() => this.audioAd.show())
  188. .catch(err => {
  189. console.log('激励视频 广告显示失败', err.errMsg)
  190. if (self.adType) {
  191. self._controller.game.onSkipRevive()
  192. } else {
  193. self._controller.scoreMgr.onLevelUpButton()
  194. }
  195. })
  196. })
  197. return
  198. }
  199. this.audioAd = wx.createRewardedVideoAd({
  200. adUnitId: 'adunit-482148cfeb243378'
  201. })
  202. this.audioAd.show().catch(() => {
  203. // 失败重试
  204. this.audioAd.load()
  205. .then(() => this.audioAd.show())
  206. .catch(err => {
  207. self.fakeShare()
  208. })
  209. })
  210. this.audioAd.onError(err => {
  211. self.fakeShare()
  212. })
  213. this.audioAd.onClose((res) => {
  214. if (self.adType) {
  215. if (res && res.isEnded || res === undefined) {
  216. self._controller.game.showReviveSuccess()
  217. } else {
  218. self._controller.game.askRevive()
  219. }
  220. } else {
  221. if (res && res.isEnded || res === undefined) {
  222. self._controller.scoreMgr.onLevelUpButton(2)
  223. }
  224. }
  225. })
  226. },
  227. fakeShare() {
  228. let self = this
  229. wx.shareAppMessage({
  230. title: "我已经玩到" + this._controller.scoreMgr.score + "分了,邀请你来挑战",
  231. // imageUrlId: 'oxEwGvClT0uldQ470pM84w',
  232. imageUrl: 'https://mmocgame.qpic.cn/wechatgame/LtJZOjH6Z9ibiaMlpqzldsOf46Q7TZiaysI1fwc4Oj1L3CkbCaJMAMoicibbHu2HUQkOib/0'
  233. })
  234. if (this.adType) {
  235. self._controller.game.showReviveSuccess()
  236. } else {
  237. self._controller.scoreMgr.onLevelUpButton(2)
  238. }
  239. },
  240. openBannerAdv() {
  241. // 创建 Banner 广告实例,提前初始化
  242. // let screenWidth = wx.getSystemInfoSync().screenWidth
  243. // let bannerHeight = screenWidth / 350 * 120
  244. // let screenHeight = wx.getSystemInfoSync().screenHeight - 108
  245. // let adUnitIds = [
  246. // 'adunit-510a4ec39065ef96',
  247. // 'adunit-29b0fa7a2db8e8cb',
  248. // 'adunit-4020bb9ea439e6a5'
  249. // ]
  250. // if (this.bannerAd) {
  251. // this.bannerAd.destroy()
  252. // }
  253. // this.bannerAd = wx.createBannerAd({
  254. // adUnitId: adUnitIds[Math.floor(Math.random() * 3)],
  255. // style: {
  256. // left: 0,
  257. // top: screenHeight,
  258. // width: 620,
  259. // }
  260. // })
  261. // // 在适合的场景显示 Banner 广告
  262. // this.bannerAd.onLoad(() => {
  263. // // console.log('banner 广告加载成功')
  264. // })
  265. // this.bannerAd.onError((e) => {
  266. // console.log('banner 广告加载失败', e)
  267. // })
  268. // this.bannerAd.show()
  269. // .then()
  270. },
  271. navToMiniprogram(event,custom) {
  272. console.log(custom)
  273. wx.navigateToMiniProgram({
  274. appId: custom
  275. })
  276. },
  277. closeBannerAdv() {
  278. if (this.bannerAd) {
  279. this.bannerAd.hide()
  280. }
  281. }
  282. });