OfflineGrossIncome.js 6.7 KB

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