social.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. let highLevel =cc.sys.localStorage.getItem('highLevel')
  55. return highLevel
  56. },
  57. getHighestScore() {
  58. //let score = wx.getStorageSync('highScore')
  59. let score =cc.sys.localStorage.getItem('highScore')
  60. return score
  61. },
  62. // --------------- share ----------------
  63. onShareButton() {
  64. var self = this;
  65. wx.shareAppMessage({
  66. title: "我终于成为了" + this._controller.scoreMgr.levelData[this._controller.scoreMgr.level - 1].name + ",真是开心",
  67. // imageUrlId: 'oxEwGvClT0uldQ470pM84w',
  68. imageUrl: 'https://mmocgame.qpic.cn/wechatgame/LtJZOjH6Z9ibiaMlpqzldsOf46Q7TZiaysI1fwc4Oj1L3CkbCaJMAMoicibbHu2HUQkOib/0'
  69. })
  70. },
  71. onUsualShareButton() {
  72. wx.shareAppMessage({
  73. title: "只是个农民,现在已经做到宰相",
  74. // imageUrlId: 'oxEwGvClT0uldQ470pM84w',
  75. imageUrl: 'https://mmocgame.qpic.cn/wechatgame/LtJZOjH6Z9ibiaMlpqzldsOf46Q7TZiaysI1fwc4Oj1L3CkbCaJMAMoicibbHu2HUQkOib/0'
  76. })
  77. },
  78. onShakePhone() {
  79. wx.vibrateShort()
  80. },
  81. // ---------------分数上传---------------
  82. onGameOver(level, score) {
  83. console.log('zh:onGameOver'+level)
  84. //上传分数
  85. //打开开放域
  86. this.score = score
  87. let highLevel = level
  88. let highScore = score
  89. let self = this
  90. wx.postMessage({
  91. event: 'setScore',
  92. score: score,
  93. level: level,
  94. })
  95. highLevel = wx.getStorageSync('highLevel')
  96. highLevel = parseInt(highLevel)
  97. if (highLevel) {
  98. highLevel = highLevel < level ? level : highLevel
  99. } else {
  100. highLevel = level
  101. }
  102. highScore = wx.getStorageSync('highScore')
  103. if (highScore) {
  104. highScore = parseInt(highScore)
  105. highScore = highScore < score ? score : highScore
  106. } else {
  107. highScore = score
  108. }
  109. var highLevelName = this._controller.gameData.json.levelData[highLevel - 1].name
  110. //wx.setStorageSync('highLevel', highLevel + '')
  111. //wx.setStorageSync('highScore', highScore + '')
  112. cc.sys.localStorage.setItem('highLevel', highLevel + '');
  113. cc.sys.localStorage.setItem('highScore', highScore + '');
  114. self._controller.scoreMgr.failHighScore.string = "您的最高分:" + (highScore + '')
  115. var kvDataList = new Array()
  116. kvDataList.push({
  117. key: "highLevel",
  118. value: highLevelName,
  119. }, {
  120. key: "highScore",
  121. value: highScore + '',
  122. })
  123. },
  124. showRank() {
  125. wx.postMessage({
  126. message: 'Show',
  127. event: 'getRank',
  128. })
  129. this.display.node.active = true
  130. this._isShow = true
  131. },
  132. closeRank() {
  133. this.display.node.active = false
  134. wx.postMessage({
  135. message: 'Hide'
  136. })
  137. this._isShow = false
  138. },
  139. showGroupRank() {
  140. wx.postMessage({
  141. message: 'Show'
  142. })
  143. this.groupDisplay.node.active = true
  144. this._isShow = true
  145. },
  146. // switchRankType() {
  147. // wx.postMessage({
  148. // message: 'switchRank'
  149. // })
  150. // this._isShow = true
  151. // },
  152. closeGroupRank() {
  153. this.groupDisplay.node.active = false
  154. wx.postMessage({
  155. message: 'Hide'
  156. })
  157. this._isShow = false
  158. },
  159. createImage(sprite, url) {
  160. let image = wx.createImage();
  161. image.onload = function () {
  162. let texture = new cc.Texture2D();
  163. texture.initWithElement(image);
  164. texture.handleLoadedTexture();
  165. sprite.spriteFrame = new cc.SpriteFrame(texture);
  166. };
  167. image.src = url;
  168. },
  169. update() {
  170. if (this._isShow) {
  171. if(2>1){
  172. return;//zh
  173. }
  174. if (this.display.node.active) {
  175. this.display.node.getComponent(cc.WXSubContextView).update()
  176. }
  177. if (this.groupDisplay.node.active) {
  178. this.groupDisplay.node.getComponent(cc.WXSubContextView).update()
  179. }
  180. }
  181. },
  182. // 控制打开广告
  183. onReviveButton(type) {
  184. // 广告位
  185. let self = this
  186. this.adType = type //0表示加倍 1表示复活
  187. if (this.audioAd) {
  188. this.audioAd.show().catch(() => {
  189. // 失败重试
  190. this.audioAd.load()
  191. .then(() => this.audioAd.show())
  192. .catch(err => {
  193. console.log('激励视频 广告显示失败', err.errMsg)
  194. if (self.adType) {
  195. self._controller.game.onSkipRevive()
  196. } else {
  197. self._controller.scoreMgr.onLevelUpButton()
  198. }
  199. })
  200. })
  201. return
  202. }
  203. this.audioAd = wx.createRewardedVideoAd({
  204. adUnitId: 'adunit-482148cfeb243378'
  205. })
  206. this.audioAd.show().catch(() => {
  207. // 失败重试
  208. this.audioAd.load()
  209. .then(() => this.audioAd.show())
  210. .catch(err => {
  211. self.fakeShare()
  212. })
  213. })
  214. this.audioAd.onError(err => {
  215. self.fakeShare()
  216. })
  217. this.audioAd.onClose((res) => {
  218. if (self.adType) {
  219. if (res && res.isEnded || res === undefined) {
  220. self._controller.game.showReviveSuccess()
  221. } else {
  222. self._controller.game.askRevive()
  223. }
  224. } else {
  225. if (res && res.isEnded || res === undefined) {
  226. self._controller.scoreMgr.onLevelUpButton(2)
  227. }
  228. }
  229. })
  230. },
  231. fakeShare() {
  232. let self = this
  233. wx.shareAppMessage({
  234. title: "我已经玩到" + this._controller.scoreMgr.score + "分了,邀请你来挑战",
  235. // imageUrlId: 'oxEwGvClT0uldQ470pM84w',
  236. imageUrl: 'https://mmocgame.qpic.cn/wechatgame/LtJZOjH6Z9ibiaMlpqzldsOf46Q7TZiaysI1fwc4Oj1L3CkbCaJMAMoicibbHu2HUQkOib/0'
  237. })
  238. if (this.adType) {
  239. self._controller.game.showReviveSuccess()
  240. } else {
  241. self._controller.scoreMgr.onLevelUpButton(2)
  242. }
  243. },
  244. openBannerAdv() {
  245. // 创建 Banner 广告实例,提前初始化
  246. // let screenWidth = wx.getSystemInfoSync().screenWidth
  247. // let bannerHeight = screenWidth / 350 * 120
  248. // let screenHeight = wx.getSystemInfoSync().screenHeight - 108
  249. // let adUnitIds = [
  250. // 'adunit-510a4ec39065ef96',
  251. // 'adunit-29b0fa7a2db8e8cb',
  252. // 'adunit-4020bb9ea439e6a5'
  253. // ]
  254. // if (this.bannerAd) {
  255. // this.bannerAd.destroy()
  256. // }
  257. // this.bannerAd = wx.createBannerAd({
  258. // adUnitId: adUnitIds[Math.floor(Math.random() * 3)],
  259. // style: {
  260. // left: 0,
  261. // top: screenHeight,
  262. // width: 620,
  263. // }
  264. // })
  265. // // 在适合的场景显示 Banner 广告
  266. // this.bannerAd.onLoad(() => {
  267. // // console.log('banner 广告加载成功')
  268. // })
  269. // this.bannerAd.onError((e) => {
  270. // console.log('banner 广告加载失败', e)
  271. // })
  272. // this.bannerAd.show()
  273. // .then()
  274. },
  275. navToMiniprogram(event,custom) {
  276. console.log(custom)
  277. wx.navigateToMiniProgram({
  278. appId: custom
  279. })
  280. },
  281. closeBannerAdv() {
  282. if (this.bannerAd) {
  283. this.bannerAd.hide()
  284. }
  285. }
  286. });