OfflineGrossIncome.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. const DWTool = require('../utils/DWTool');
  2. const { GameNotificationKey } = require("../utils/GameEnum");
  3. const GameModule = require('../utils/GameModule');
  4. const WeChat = require('../net/WeChat');
  5. const Api = require('../net/Api');
  6. const taptapTool = require('../utils/TapTapTool');
  7. const SkillApi = require("../net/SkillApi");
  8. cc.Class({
  9. extends: cc.Component,
  10. properties: {
  11. content: cc.Node,
  12. coinRichText: cc.RichText,
  13. watchVideoRichText: cc.RichText,
  14. shareRichText: cc.RichText,
  15. secretarySprite: cc.Node,
  16. videoBtn: {
  17. tooltip: '观看视频按钮',
  18. default: null,
  19. type: cc.Node
  20. },
  21. shareBtn: {
  22. tooltip: '分享按钮',
  23. default: null,
  24. type: cc.Node
  25. },
  26. normalBtn: {
  27. tooltip: '普通确认按钮',
  28. default: null,
  29. type: cc.Node
  30. },
  31. grossIncome: {
  32. get() {
  33. return this._grossIncome;
  34. },
  35. set(value) {
  36. this._grossIncome = value;
  37. this.setCoinRichText(taptapTool.parseToString(value));
  38. this.setWatchVideoRichText(taptapTool.parseToString(taptapTool.multiple(value, {"n": 2, "e": 0})));
  39. this.setShareVideoRichText(taptapTool.parseToString(taptapTool.multiple(value, {"n": 2, "e": 0})));
  40. }
  41. },
  42. zIndex: {
  43. default: 0,
  44. notify(oldValue) {
  45. //减少无效赋值
  46. if (oldValue === this.zIndex) {
  47. return;
  48. }
  49. this.node.zIndex = this.zIndex;
  50. }
  51. }
  52. },
  53. // LIFE-CYCLE CALLBACKS:
  54. init(grossIncome) {
  55. this.grossIncome = grossIncome;
  56. this._resetBtn();
  57. if (CC_WECHATGAME) {
  58. //判断是否是正在审核的版本,是的话将隐藏分享到群的按钮
  59. if (Global.isCheck) {
  60. this.videoBtn.active = false;
  61. this.shareBtn.active = false;
  62. this.normalBtn.active = true;
  63. } else {
  64. let url = Global.debug ? 'https://pub.dwstatic.com/wxgame/taptapstar_test/sheet/offlineIncome.json' : 'https://pub.dwstatic.com/wxgame/taptapstar/sheet/offlineIncome.json';
  65. wx.request({
  66. url: url,
  67. success: (res) => {
  68. console.log(res.data);
  69. if (res.data.video) {
  70. this.videoBtn.active = true;
  71. }
  72. if (res.data.share) {
  73. this.shareBtn.active = true;
  74. }
  75. if (res.data.normal) {
  76. this.normalBtn.active = true;
  77. }
  78. }
  79. });
  80. }
  81. } else {
  82. this.videoBtn.active = true;
  83. this.shareBtn.active = true;
  84. }
  85. },
  86. onLoad() {
  87. this.node.zIndex = this.zIndex;
  88. this._grossIncome = {"n": 0, "e": 0};
  89. },
  90. start() {
  91. this.content.scaleX = 0;
  92. this.content.scaleY = 0;
  93. this.content.runAction(cc.scaleTo(0.35, 1, 1).easing(cc.easeBackOut()));
  94. this.secretarySprite.runAction(cc.moveBy(0.3, cc.v2(325, 0)));
  95. },
  96. /**
  97. * 重置按钮状态
  98. */
  99. _resetBtn() {
  100. this.videoBtn.active = false;
  101. this.shareBtn.active = false;
  102. this.normalBtn.active = false;
  103. },
  104. dismiss() {
  105. let finish = cc.callFunc(() => {
  106. this.node.destroy();
  107. }, this);
  108. let sequence = cc.sequence(cc.scaleTo(0.2, 0, 0).easing(cc.easeBackIn()), finish);
  109. this.content.runAction(sequence);
  110. },
  111. /**
  112. * 普通关闭,获得正常收益x1
  113. */
  114. close() {
  115. GameModule.audioMng.playClickButton();
  116. this.addIncome(this._grossIncome);
  117. this.dismiss()
  118. },
  119. /**
  120. * 增加金币收入
  121. * @param {number} value 数量
  122. */
  123. addIncome(value) {
  124. // console.log("addIncome: " + value);
  125. // GameModule.userInfo.gold += parseInt(value);
  126. GameModule.userInfo.gold = taptapTool.add(GameModule.userInfo.gold, value);
  127. // GameEvent.fire(GameNotificationKey.HandleOfflineIncomeAnim)
  128. // 添加金币后立刻上报
  129. GameModule.userInfo.doReport();
  130. },
  131. /**
  132. * 看视频获取更多离线收益
  133. */
  134. watchVideo() {
  135. GameModule.audioMng.playClickButton();
  136. // Todo: 对接微信广告Api
  137. this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}));
  138. this.dismiss();
  139. },
  140. /**
  141. * 调起微信分享及后续分享逻辑
  142. */
  143. share() {
  144. GameModule.audioMng.playClickButton();
  145. if (CC_WECHATGAME) {
  146. WeChat.shareAction( () => {
  147. this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}))
  148. this.dismiss();
  149. }, () => {
  150. console.log('分享失败或取消');
  151. });
  152. } else {
  153. this.addIncome(taptapTool.multiple(this._grossIncome, {'n': 2, 'e': 0}));
  154. this.dismiss();
  155. }
  156. },
  157. setCoinRichText(coin) {
  158. this.coinRichText.string = `<img src='coin_small'/><outline color=#ffffff width=4><b><color=#009227> ${coin}</c></b></outline>`;
  159. },
  160. ///2倍
  161. setWatchVideoRichText(coin) {
  162. this.watchVideoRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
  163. },
  164. /// 2倍
  165. setShareVideoRichText(coin) {
  166. this.shareRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
  167. },
  168. // update (dt) {},
  169. });