OfflineGrossIncome.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. const DWTool = require('../utils/DWTool');
  2. const {GameNotificationKey, WechatShareType } = 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. onDestroy() {
  55. GameEvent.off(GameNotificationKey.ShowShareAction, this);
  56. },
  57. init(grossIncome) {
  58. this.grossIncome = grossIncome;
  59. this._resetBtn();
  60. if (CC_WECHATGAME) {
  61. //判断是否是正在审核的版本,是的话将隐藏分享到群的按钮
  62. if (Global.isCheck) {
  63. this.videoBtn.active = false;
  64. this.shareBtn.active = false;
  65. this.normalBtn.active = true;
  66. } else {
  67. let url = Global.debug ? 'https://pub.dwstatic.com/wxgame/taptapstar_test/sheet/offlineIncome.json' : 'https://pub.dwstatic.com/wxgame/taptapstar/sheet/offlineIncome.json';
  68. wx.request({
  69. url: url,
  70. success: (res) => {
  71. console.log(res.data);
  72. if (res.data.video) {
  73. this.videoBtn.active = true;
  74. }
  75. if (res.data.share) {
  76. this.shareBtn.active = true;
  77. }
  78. if (res.data.normal) {
  79. this.normalBtn.active = true;
  80. } else {
  81. this.normalBtn.active = false;
  82. }
  83. }
  84. });
  85. }
  86. } else {
  87. this.videoBtn.active = true;
  88. this.shareBtn.active = true;
  89. this.normalBtn.active = false;
  90. }
  91. },
  92. onLoad() {
  93. this.node.zIndex = this.zIndex;
  94. this._grossIncome = {"n": 0, "e": 0};
  95. },
  96. start() {
  97. this.content.scaleX = 0;
  98. this.content.scaleY = 0;
  99. this.content.runAction(cc.scaleTo(0.35, 1, 1).easing(cc.easeBackOut()));
  100. this.secretarySprite.runAction(cc.moveBy(0.3, cc.v2(325, 0)));
  101. },
  102. /**
  103. * 重置按钮状态
  104. */
  105. _resetBtn() {
  106. this.videoBtn.active = false;
  107. this.shareBtn.active = false;
  108. this.normalBtn.active = true;
  109. },
  110. dismiss() {
  111. let finish = cc.callFunc(() => {
  112. this.node.destroy();
  113. }, this);
  114. let sequence = cc.sequence(cc.scaleTo(0.2, 0, 0).easing(cc.easeBackIn()), finish);
  115. this.content.runAction(sequence);
  116. },
  117. /**
  118. * 普通关闭,获得正常收益x1
  119. */
  120. close() {
  121. GameModule.audioMng.playClickButton();
  122. this.addIncome(this._grossIncome);
  123. this.dismiss()
  124. },
  125. /**
  126. * 增加金币收入
  127. * @param {number} value 数量
  128. */
  129. addIncome(value) {
  130. // console.log("addIncome: " + value);
  131. // GameModule.userInfo.gold += parseInt(value);
  132. GameModule.userInfo.gold = taptapTool.add(GameModule.userInfo.gold, value);
  133. // GameEvent.fire(GameNotificationKey.HandleOfflineIncomeAnim)
  134. // 添加金币后立刻上报
  135. GameModule.userInfo.doReport();
  136. },
  137. /**
  138. * 看视频获取更多离线收益
  139. */
  140. watchVideo() {
  141. GameModule.audioMng.playClickButton();
  142. // Todo: 对接微信广告Api
  143. this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}));
  144. this.dismiss();
  145. },
  146. /**
  147. * 调起微信分享及后续分享逻辑
  148. */
  149. share() {
  150. GameModule.audioMng.playClickButton();
  151. if (CC_WECHATGAME) {
  152. GameEvent.on(GameNotificationKey.ShowShareAction, this, (type) => {
  153. this.shareActionCallback(type);
  154. });
  155. WeChat.shareAction(WechatShareType.OfflineIncome, () => {
  156. }, () => {
  157. console.log('分享失败或取消');
  158. });
  159. } else {
  160. this.addIncome(taptapTool.multiple(this._grossIncome, {'n': 2, 'e': 0}));
  161. this.dismiss();
  162. }
  163. },
  164. shareActionCallback(type) {
  165. if (type != WechatShareType.OfflineIncome) { return; }
  166. this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}))
  167. this.dismiss();
  168. GameEvent.off(GameNotificationKey.ShowShareAction, this);
  169. },
  170. setCoinRichText(coin) {
  171. this.coinRichText.string = `<img src='coin_small'/><outline color=#ffffff width=4><b><color=#009227> ${coin}</c></b></outline>`;
  172. },
  173. ///2倍
  174. setWatchVideoRichText(coin) {
  175. this.watchVideoRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
  176. },
  177. /// 2倍
  178. setShareVideoRichText(coin) {
  179. this.shareRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
  180. },
  181. // update (dt) {},
  182. });