OfflineGrossIncome.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. }
  81. }
  82. });
  83. }
  84. } else {
  85. this.videoBtn.active = true;
  86. this.shareBtn.active = true;
  87. }
  88. },
  89. onLoad() {
  90. this.node.zIndex = this.zIndex;
  91. this._grossIncome = {"n": 0, "e": 0};
  92. },
  93. start() {
  94. this.content.scaleX = 0;
  95. this.content.scaleY = 0;
  96. this.content.runAction(cc.scaleTo(0.35, 1, 1).easing(cc.easeBackOut()));
  97. this.secretarySprite.runAction(cc.moveBy(0.3, cc.v2(325, 0)));
  98. },
  99. /**
  100. * 重置按钮状态
  101. */
  102. _resetBtn() {
  103. this.videoBtn.active = false;
  104. this.shareBtn.active = false;
  105. this.normalBtn.active = true;
  106. },
  107. dismiss() {
  108. let finish = cc.callFunc(() => {
  109. this.node.destroy();
  110. }, this);
  111. let sequence = cc.sequence(cc.scaleTo(0.2, 0, 0).easing(cc.easeBackIn()), finish);
  112. this.content.runAction(sequence);
  113. },
  114. /**
  115. * 普通关闭,获得正常收益x1
  116. */
  117. close() {
  118. GameModule.audioMng.playClickButton();
  119. this.addIncome(this._grossIncome);
  120. this.dismiss()
  121. },
  122. /**
  123. * 增加金币收入
  124. * @param {number} value 数量
  125. */
  126. addIncome(value) {
  127. // console.log("addIncome: " + value);
  128. // GameModule.userInfo.gold += parseInt(value);
  129. GameModule.userInfo.gold = taptapTool.add(GameModule.userInfo.gold, value);
  130. // GameEvent.fire(GameNotificationKey.HandleOfflineIncomeAnim)
  131. // 添加金币后立刻上报
  132. GameModule.userInfo.doReport();
  133. },
  134. /**
  135. * 看视频获取更多离线收益
  136. */
  137. watchVideo() {
  138. GameModule.audioMng.playClickButton();
  139. // Todo: 对接微信广告Api
  140. this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}));
  141. this.dismiss();
  142. },
  143. /**
  144. * 调起微信分享及后续分享逻辑
  145. */
  146. share() {
  147. GameModule.audioMng.playClickButton();
  148. if (CC_WECHATGAME) {
  149. GameEvent.on(GameNotificationKey.ShowShareAction, this, (type) => {
  150. this.shareActionCallback(type);
  151. });
  152. WeChat.shareAction(WechatShareType.OfflineIncome, () => {
  153. }, () => {
  154. console.log('分享失败或取消');
  155. });
  156. } else {
  157. this.addIncome(taptapTool.multiple(this._grossIncome, {'n': 2, 'e': 0}));
  158. this.dismiss();
  159. }
  160. },
  161. shareActionCallback(type) {
  162. if (type != WechatShareType.OfflineIncome) { return; }
  163. this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}))
  164. this.dismiss();
  165. GameEvent.off(GameNotificationKey.ShowShareAction, this);
  166. },
  167. setCoinRichText(coin) {
  168. this.coinRichText.string = `<img src='coin_small'/><outline color=#ffffff width=4><b><color=#009227> ${coin}</c></b></outline>`;
  169. },
  170. ///2倍
  171. setWatchVideoRichText(coin) {
  172. this.watchVideoRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
  173. },
  174. /// 2倍
  175. setShareVideoRichText(coin) {
  176. this.shareRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
  177. },
  178. // update (dt) {},
  179. });