GuideToWx.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /** 引导到微信 */
  2. import JsbSystem from "../../../mk/system/JsbSystem";
  3. import { DataEventId } from "../../data/GameData";
  4. import { GuideState } from "../../data/module/GuideToWxData";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class GuideToWx extends cc.Component {
  8. @property(cc.Sprite)
  9. sp_money: cc.Sprite = null;
  10. @property(cc.Sprite)
  11. sp_getMoney: cc.Sprite = null;
  12. @property(cc.Sprite)
  13. sp_fill: cc.Sprite = null;
  14. @property(cc.Node)
  15. node_target: cc.Node = null;
  16. @property(cc.Node)
  17. hand: cc.Node = null;
  18. @property(cc.VideoPlayer)
  19. videoPlayer: cc.VideoPlayer = null;
  20. @property(cc.Node)
  21. nodeStateArr: cc.Node[] = [];
  22. /** 进度条进度 */
  23. private fillPer = 0;
  24. /** 根据金额获取index */
  25. private moneyIndex = 0;
  26. private checkCloseGuide = false;
  27. private lastTimeSpan = -1;
  28. async start() {
  29. this.node_target.opacity = 0;
  30. this.hand.active = false;
  31. this.moneyIndex = this.getIndexByMoney();
  32. let path = 'module/guideToWx/texture/money_' + this.moneyIndex;
  33. this.sp_money.spriteFrame = await mk.loader.load(path, cc.SpriteFrame);
  34. let response = await mk.http.sendData('getAddServiceState', {});
  35. mk.console.logSingle('GuideToWx getAddServiceState ', response);
  36. if (response.errcode != 0) {
  37. return
  38. }
  39. console.log("state >> ", response.data.state)
  40. switch (response.data.state) {
  41. case 0:
  42. let state = mk.storage.getStorage('GuideState');
  43. if (!state) {
  44. state = '0';
  45. }
  46. gData.guideToWxData.guideState = parseInt(state);
  47. break;
  48. case 1:
  49. gData.guideToWxData.guideState = GuideState.canGetMoney;
  50. break;
  51. case 2:
  52. gData.guideToWxData.guideState = GuideState.gotMoney;
  53. break;
  54. }
  55. await mk.time.WaitForSeconds(0.3);
  56. this.setState();
  57. this.videoPlayer.node.on("completed", this.onCompleted, this);
  58. if (!mk.guide.isGuiding()) {
  59. this.playVideo();
  60. }
  61. else {
  62. this.checkCloseGuide = true;
  63. }
  64. }
  65. playVideo() {
  66. this.videoPlayer.node.active = true;
  67. mk.audio.setPauseMusic();
  68. this.videoPlayer.play();
  69. }
  70. update() {
  71. if (this.checkCloseGuide) {
  72. if (!mk.guide.isGuiding()) {
  73. this.checkCloseGuide = false;
  74. this.playVideo();
  75. }
  76. }
  77. if (this.lastTimeSpan != -1) {
  78. let pass = Date.now() - this.lastTimeSpan;
  79. mk.console.logSingle('GuideToWx pass ', pass);
  80. if (pass >= 10000) {
  81. gData.guideToWxData.guideState = 3;
  82. mk.storage.setStorage('GuideState', gData.guideToWxData.guideState);
  83. this.setState();
  84. }
  85. this.lastTimeSpan = -1;
  86. }
  87. }
  88. async setState() {
  89. this.nodeStateArr.forEach(element => {
  90. element.active = true;
  91. });
  92. this.node_target.opacity = 0;
  93. this.node_target.active = true;
  94. let nodeState: cc.Node = null;
  95. let path = '';
  96. switch (gData.guideToWxData.guideState) {
  97. case GuideState.none:
  98. this.fillPer = 0;
  99. path = 'module/guideToWx/texture/addService';
  100. nodeState = this.nodeStateArr[0];
  101. break;
  102. case GuideState.sendApply:
  103. this.fillPer = 0.33;
  104. path = 'module/guideToWx/texture/addService';
  105. nodeState = this.nodeStateArr[1];
  106. break;
  107. case GuideState.waitForPass:
  108. this.fillPer = 0.66;
  109. path = 'module/guideToWx/texture/addService';
  110. nodeState = this.nodeStateArr[2];
  111. break;
  112. case GuideState.canGetMoney:
  113. this.fillPer = 1;
  114. path = 'module/guideToWx/texture/get_' + this.moneyIndex;
  115. nodeState = this.nodeStateArr[3];
  116. break;
  117. case GuideState.gotMoney:
  118. this.fillPer = 1;
  119. path = 'module/guideToWx/texture/getSuccess';
  120. this.node_target.active = false;
  121. break;
  122. }
  123. this.sp_getMoney.spriteFrame = await mk.loader.load(path, cc.SpriteFrame);
  124. cc.tween(this.sp_fill)
  125. .to(0.5, { fillRange: this.fillPer })
  126. .start();
  127. if (nodeState) {
  128. this.node_target.x = nodeState.x;
  129. cc.tween(nodeState).delay(0.5)
  130. .to(0.25, { scale: 1.2 })
  131. .to(0.25, { scale: 1 })
  132. .call(() => {
  133. nodeState.active = false;
  134. this.hand.active = true;
  135. })
  136. .start();
  137. }
  138. cc.tween(this.node_target)
  139. .delay(1.5)
  140. .to(0.5, { opacity: 255 })
  141. .start();
  142. }
  143. getIndexByMoney() {
  144. let index = 0;
  145. switch (parseFloat(gData.guideToWxData.money)) {
  146. case 0.3:
  147. index = 0;
  148. break;
  149. case 0.5:
  150. index = 1;
  151. break;
  152. case 0.8:
  153. index = 2;
  154. break;
  155. case 1:
  156. index = 3;
  157. break;
  158. }
  159. return index;
  160. }
  161. async clickService() {
  162. mk.audio.playEffect('button');
  163. if (gData.guideToWxData.guideState == GuideState.none || gData.guideToWxData.guideState == GuideState.sendApply
  164. || gData.guideToWxData.guideState == GuideState.waitForPass) {
  165. this.lastTimeSpan = Date.now();
  166. mk.console.logSingle('GuideToWx lastTimeSpan ', this.lastTimeSpan);
  167. JsbSystem.WXLaunchMiniProgram(gData.guideToWxData.ghId);
  168. }
  169. else if (gData.guideToWxData.guideState == GuideState.canGetMoney) {
  170. let response = await mk.http.sendData('customerServiceCash', {});
  171. mk.console.logSingle('GuideToWx customerServiceCash ', response);
  172. if (response.errcode != 0) {
  173. if (response.data.count) {
  174. gData.tipPanelData.openCashFailTip(response.data.count);
  175. }
  176. else {
  177. mk.tip.pop('提现排队中,多看视频优先提现');
  178. }
  179. return;
  180. }
  181. mk.data.sendDataEvent(DataEventId.guideToWx, `领取${gData.guideToWxData.money}元`);
  182. gData.receiptNotice.receip_rmb = parseFloat(gData.guideToWxData.money);
  183. mk.ui.openPanel('module/receiptNotice/receiptNotice');
  184. gData.guideToWxData.guideState = GuideState.gotMoney;
  185. this.setState();
  186. }
  187. else if (gData.guideToWxData.guideState == GuideState.gotMoney) {
  188. mk.tip.pop('您已经领取成功!');
  189. }
  190. }
  191. clickClose() {
  192. mk.audio.playEffect('button');
  193. mk.ui.closePanel(this.node.name);
  194. }
  195. onDisable() {
  196. mk.audio.setResumeMusic();
  197. this.videoPlayer.node.off("completed", this.onCompleted, this);
  198. }
  199. onCompleted() {
  200. this.videoPlayer.play();
  201. }
  202. }