Sign.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import JsbSystem from "../../../mk/system/JsbSystem";
  2. import TableView from "../../component/TableView";
  3. import { AdFun } from "../../data/AdData";
  4. import { DataEventId, GameProp, RewardType, VideoAdType } from "../../data/GameData";
  5. /**
  6. * 签到界面
  7. * - 每天第一次上线默认弹出一次【除首日】。待处理
  8. * - 全部签完后,不可再签到。此处需要判断上次签到天数。
  9. * - 滑动列表需要滚动到对应签到条目的高度,待处理。
  10. * @author 薛鸿潇
  11. */
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class Sign extends cc.Component {
  15. @property({ type: cc.ScrollView, displayName: '滚动视图' })
  16. private scroll_view: cc.ScrollView = null!;
  17. @property({ type: cc.Animation, displayName: '按钮_动画' })
  18. private anim_btn: cc.Animation = null!;
  19. private tableview: TableView = null;
  20. onLoad() {
  21. }
  22. start() {
  23. mk.ad.showNative(4);
  24. // gData.sign.sign_can = gData.gameData.getProp(GameProp.sign_can);
  25. gData.sign.initListData();
  26. gData.sign.init_data = true;
  27. this.initScollView();
  28. }
  29. /**
  30. * 初始化滚动视图
  31. */
  32. private initScollView() {
  33. let list_data = gData.sign.list_data;
  34. this.scroll_view.node.emit('srollview-init', list_data)
  35. this.tableview = this.scroll_view.node.getComponent('TableView')
  36. let index = gData.sign.getItemIndexByCanSign();
  37. this.scheduleOnce(() => {
  38. this.tableview.contentMoveByIndex(index)
  39. }, 0.1)
  40. }
  41. update(dt) {
  42. if (gData.sign.init_data) {
  43. this.initBtnStyle();
  44. return;
  45. }
  46. if (gData.sign.adData) {
  47. // 展示奖励
  48. this.getReward();
  49. }
  50. }
  51. lateUpdate() {
  52. gData.sign.adData = null;
  53. }
  54. /**
  55. * 点击领取按钮
  56. */
  57. private clickReceiveReward() {
  58. mk.audio.playEffect("button");
  59. if (gData.gameData.gameData.isSignInToday == 1) return;
  60. if (!gData.sign.haveSignDay()) return;
  61. const index = gData.gameData.gameData.signInDay;
  62. if (gData.sign.c_sign[index].rewardType === RewardType.rmb) {
  63. if (!gData.loginData.isAuth) {
  64. JsbSystem.WxAuth();
  65. return;
  66. }
  67. }
  68. mk.ad.videoAdType = VideoAdType.Sign;
  69. // 看广告
  70. mk.ad.watchAd((success: boolean) => {
  71. mk.console.log("watchAD:" + success);
  72. if (success) {
  73. gData.adData.watchVideo(AdFun.sign);
  74. //FC:埋点
  75. if (gData.sign.c_sign[index].rewardType === RewardType.rmb) {
  76. mk.data.sendDataEvent(DataEventId.signWithDrawal, "签到提现成功");
  77. }
  78. mk.ad.destroyNativeAd();
  79. }
  80. });
  81. }
  82. /**
  83. * 拿奖励
  84. */
  85. private async getReward() {
  86. // 完成展示
  87. await gData.sign.signComplete();
  88. const index_old = gData.sign.getItemIndexByCanSign();
  89. // 指定条目数据刷新
  90. this.tableview.resetItemData(index_old, gData.sign.list_data[index_old]);
  91. }
  92. /**
  93. * 初始化按钮样式
  94. */
  95. private initBtnStyle() {
  96. if (gData.gameData.gameData.isSignInToday == 0 && gData.sign.haveSignDay()) {
  97. this.anim_btn.play();
  98. // this.anim_btn.getComponent(SetGray).setGray(false);
  99. this.anim_btn.getComponent(mk.component.setGray).setGray(false)
  100. } else {
  101. this.anim_btn.stop();
  102. this.anim_btn.node.scale = 1;
  103. // this.anim_btn.getComponent('SetGray').setGray(true);
  104. this.anim_btn.getComponent(mk.component.setGray).setGray(true)
  105. }
  106. gData.sign.init_data = false;
  107. }
  108. onClickClose() {
  109. mk.ad.destroyNativeAd();
  110. mk.ad.checkShowInterByChance();
  111. }
  112. onDisable() {
  113. let showGuide = false;
  114. if (gData.sign.success) {
  115. gData.sign.success = false;
  116. gData.safeDepositBoxData.creatPacketAnim(2);
  117. gData.cashNormal.checkGuideBank();
  118. }
  119. if (!showGuide) {
  120. const isAutoOpenPanel = gData.gameData.getProp(GameProp.isAutoOpenPanel);
  121. if (isAutoOpenPanel === 1) {
  122. gData.guideToWxData.checkPop();
  123. gData.gameData.setProp(GameProp.isAutoOpenPanel, 2);
  124. }
  125. }
  126. }
  127. }