Sign.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import JsbSystem from "../../../mk/system/JsbSystem";
  2. import TableView from "../../component/TableView";
  3. import { AdFun } from "../../data/AdData";
  4. import { DataEventId, 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.tableview.contentMoveByIndex(index)
  38. }
  39. update(dt) {
  40. if (gData.sign.init_data) {
  41. this.initBtnStyle();
  42. return;
  43. }
  44. if (gData.sign.adData) {
  45. // 展示奖励
  46. this.getReward();
  47. }
  48. }
  49. lateUpdate() {
  50. gData.sign.adData = null;
  51. }
  52. /**
  53. * 点击领取按钮
  54. */
  55. private clickReceiveReward() {
  56. mk.audio.playEffect("button");
  57. if (gData.gameData.gameData.isSignInToday == 1) return;
  58. if (!gData.sign.haveSignDay()) return;
  59. const index_old = gData.sign.getItemIndexByCanSign();
  60. if (gData.sign.c_sign[index_old].rewardType === RewardType.rmb) {
  61. if (!gData.loginData.isAuth) {
  62. JsbSystem.WxAuth();
  63. return;
  64. }
  65. }
  66. mk.ad.videoAdType = VideoAdType.Sign;
  67. // 看广告
  68. mk.ad.watchAd((success: boolean) => {
  69. mk.console.log("watchAD:" + success);
  70. if (success) {
  71. gData.adData.watchVideo(AdFun.sign);
  72. //FC:埋点
  73. if (gData.sign.c_sign[index_old].rewardType === RewardType.rmb) {
  74. mk.data.sendDataEvent(DataEventId.signWithDrawal, "签到提现成功");
  75. }
  76. mk.ad.destroyNativeAd();
  77. }
  78. });
  79. }
  80. /**
  81. * 拿奖励
  82. */
  83. private getReward() {
  84. const index_old = gData.sign.getItemIndexByCanSign();
  85. // 完成展示
  86. gData.sign.signComplete();
  87. // 指定条目数据刷新
  88. this.tableview.resetItemData(index_old, gData.sign.list_data[index_old]);
  89. // 打开奖励界面
  90. // to do
  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. }