OfflineGrossIncome.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. const ADVideo = require('../utils/ADVideo');
  9. cc.Class({
  10. extends: cc.Component,
  11. properties: {
  12. content: cc.Node,
  13. coinRichText: cc.RichText,
  14. watchVideoRichText: cc.RichText,
  15. shareRichText: cc.RichText,
  16. secretarySprite: cc.Node,
  17. videoBtn: {
  18. tooltip: '观看视频按钮',
  19. default: null,
  20. type: cc.Node
  21. },
  22. shareBtn: {
  23. tooltip: '分享按钮',
  24. default: null,
  25. type: cc.Node
  26. },
  27. shareLabel: cc.Label,
  28. normalBtn: {
  29. tooltip: '普通确认按钮',
  30. default: null,
  31. type: cc.Node
  32. },
  33. grossIncome: {
  34. get() {
  35. return this._grossIncome;
  36. },
  37. set(value) {
  38. this._grossIncome = value;
  39. this.setCoinRichText(taptapTool.parseToString(value));
  40. this.setWatchVideoRichText(taptapTool.parseToString(taptapTool.multiple(value, {"n": 2, "e": 0})));
  41. this.setShareVideoRichText(taptapTool.parseToString(taptapTool.multiple(value, {"n": 2, "e": 0})));
  42. }
  43. },
  44. zIndex: {
  45. default: 0,
  46. notify(oldValue) {
  47. //减少无效赋值
  48. if (oldValue === this.zIndex) {
  49. return;
  50. }
  51. this.node.zIndex = this.zIndex;
  52. }
  53. }
  54. },
  55. // LIFE-CYCLE CALLBACKS:
  56. onDestroy() {
  57. GameEvent.off(GameNotificationKey.ShowShareAction, this);
  58. GameEvent.off(GameNotificationKey.AdUpdateStateNotification, this);
  59. },
  60. init(grossIncome) {
  61. this.grossIncome = grossIncome;
  62. this._resetBtn();
  63. if (CC_WECHATGAME || window.tt != undefined || CC_QQPLAY) {
  64. //判断是否是正在审核的版本,是的话将隐藏分享到群的按钮
  65. if (GameGlobal.isCheck) {
  66. this.videoBtn.active = false;
  67. this.shareBtn.active = false;
  68. this.normalBtn.active = true;
  69. } else {
  70. this.initAd();
  71. }
  72. } else {
  73. this.videoBtn.active = true;
  74. this.shareBtn.active = true;
  75. this.normalBtn.active = false;
  76. }
  77. },
  78. onLoad() {
  79. this.node.zIndex = this.zIndex;
  80. this._grossIncome = {"n": 0, "e": 0};
  81. GameEvent.on(GameNotificationKey.AdUpdateStateNotification, this, (adState, callBack) => {
  82. if (callBack != undefined && callBack == 'offlineIncome') {
  83. if (adState === 3) {
  84. this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}));
  85. this.dismiss();
  86. } else {
  87. this.addIncome(this._grossIncome);
  88. this.dismiss();
  89. }
  90. }
  91. if (adState === 0 || adState === 1) {
  92. this.initAd();
  93. }
  94. this.videoBtn.getComponent(cc.Button).interactable = true;
  95. });
  96. if (window.tt != undefined) {
  97. this.shareLabel.string = "分享获得2倍";
  98. }
  99. },
  100. initAd() {
  101. if (!CC_WECHATGAME || window.tt == undefined) {
  102. return;
  103. }
  104. //// 说明有广告
  105. if (GameGlobal._adVideoState == 0) {
  106. this.videoBtn.active = true;
  107. this.shareBtn.active = false;
  108. } else if (GameGlobal._adVideoState === 1) {
  109. this.videoBtn.active = false;
  110. this.shareBtn.active = true;
  111. }
  112. },
  113. start() {
  114. this.content.scaleX = 0;
  115. this.content.scaleY = 0;
  116. this.content.runAction(cc.scaleTo(0.35, 1, 1).easing(cc.easeBackOut()));
  117. this.secretarySprite.runAction(cc.moveBy(0.3, cc.v2(325, 0)));
  118. },
  119. /**
  120. * 重置按钮状态
  121. */
  122. _resetBtn() {
  123. this.videoBtn.active = false;
  124. this.shareBtn.active = false;
  125. this.normalBtn.active = true;
  126. },
  127. dismiss() {
  128. let finish = cc.callFunc(() => {
  129. this.node.destroy();
  130. }, this);
  131. let sequence = cc.sequence(cc.scaleTo(0.2, 0, 0).easing(cc.easeBackIn()), finish);
  132. this.content.runAction(sequence);
  133. },
  134. /**
  135. * 普通关闭,获得正常收益x1
  136. */
  137. close() {
  138. GameModule.audioMng.playClickButton();
  139. this.addIncome(this._grossIncome);
  140. this.dismiss();
  141. },
  142. /**
  143. * 增加金币收入
  144. * @param {number} value 数量
  145. */
  146. addIncome(value) {
  147. GameModule.userInfo.gold = taptapTool.add(GameModule.userInfo.gold, value);
  148. // 添加金币后立刻上报
  149. GameModule.userInfo.doReport();
  150. },
  151. /**
  152. * 看视频获取更多离线收益
  153. */
  154. watchVideo() {
  155. GameModule.audioMng.playClickButton();
  156. this.videoBtn.getComponent(cc.Button).interactable = false;
  157. GameGlobal._adVideo.showVideo('offlineIncome');
  158. },
  159. /**
  160. * 调起微信分享及后续分享逻辑
  161. */
  162. share() {
  163. GameModule.audioMng.playClickButton();
  164. if (CC_WECHATGAME || CC_QQPLAY) {
  165. this.shareBtn.getComponent(cc.Button).interactable = false;
  166. GameEvent.on(GameNotificationKey.ShowShareAction, this, (type, isOk) => {
  167. if (type == WechatShareType.OfflineIncome) {
  168. if (isOk) {
  169. this.shareActionCallback();
  170. } else {
  171. this.shareBtn.getComponent(cc.Button).interactable = true;
  172. }
  173. GameEvent.off(GameNotificationKey.ShowShareAction, this);
  174. }
  175. });
  176. WeChat.shareAction(WechatShareType.OfflineIncome, () => {
  177. }, () => {
  178. console.log('分享失败或取消');
  179. });
  180. } else {
  181. this.addIncome(taptapTool.multiple(this._grossIncome, {'n': 2, 'e': 0}));
  182. this.dismiss();
  183. }
  184. },
  185. shareActionCallback() {
  186. this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}))
  187. this.dismiss();
  188. GameEvent.off(GameNotificationKey.ShowShareAction, this);
  189. },
  190. setCoinRichText(coin) {
  191. this.coinRichText.string = `<img src='coin_small'/><outline color=#ffffff width=4><b><color=#009227> ${coin}</c></b></outline>`;
  192. },
  193. ///2倍
  194. setWatchVideoRichText(coin) {
  195. this.watchVideoRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
  196. },
  197. /// 2倍
  198. setShareVideoRichText(coin) {
  199. this.shareRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
  200. },
  201. // update (dt) {},
  202. });