social.js 8.2 KB

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