Sign.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import JsbSystem from "../../../mk/system/JsbSystem";
  2. import TableView from "../../component/TableView";
  3. import { AdFun } from "../../data/AdData";
  4. import { RewardType } 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. // 看广告
  67. mk.ad.watchAd((success: boolean) => {
  68. mk.console.log("watchAD:" + success);
  69. if (success) {
  70. gData.adData.watchVideo(AdFun.sign);
  71. mk.ad.destroyNativeAd();
  72. }
  73. });
  74. }
  75. /**
  76. * 拿奖励
  77. */
  78. private getReward() {
  79. const index_old = gData.sign.getItemIndexByCanSign();
  80. // 完成展示
  81. gData.sign.signComplete();
  82. // 指定条目数据刷新
  83. this.tableview.resetItemData(index_old, gData.sign.list_data[index_old]);
  84. // 打开奖励界面
  85. // to do
  86. }
  87. /**
  88. * 初始化按钮样式
  89. */
  90. private initBtnStyle() {
  91. if (gData.gameData.gameData.isSignInToday == 0 && gData.sign.haveSignDay()) {
  92. this.anim_btn.play();
  93. this.anim_btn.getComponent('SetGray').setGray(false);
  94. } else {
  95. this.anim_btn.stop();
  96. this.anim_btn.node.scale = 1;
  97. this.anim_btn.getComponent('SetGray').setGray(true);
  98. }
  99. gData.sign.init_data = false;
  100. }
  101. onClickClose() {
  102. mk.ad.destroyNativeAd();
  103. mk.ad.checkShowInterByChance();
  104. }
  105. }