Sign.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import TableView from "../../component/TableView";
  2. import { AdFun } from "../../data/AdData";
  3. /**
  4. * 签到界面
  5. * - 每天第一次上线默认弹出一次【除首日】。待处理
  6. * - 全部签完后,不可再签到。此处需要判断上次签到天数。
  7. * - 滑动列表需要滚动到对应签到条目的高度,待处理。
  8. * @author 薛鸿潇
  9. */
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class Sign extends cc.Component {
  13. @property({ type: cc.ScrollView, displayName: '滚动视图' })
  14. private scroll_view: cc.ScrollView = null!;
  15. @property({ type: cc.Animation, displayName: '按钮_动画' })
  16. private anim_btn: cc.Animation = null!;
  17. private tableview: TableView = null;
  18. onLoad() {
  19. }
  20. start() {
  21. // gData.sign.sign_can = gData.gameData.getProp(GameProp.sign_can);
  22. gData.sign.initListData();
  23. gData.sign.init_data = true;
  24. this.initScollView();
  25. }
  26. /**
  27. * 初始化滚动视图
  28. */
  29. private initScollView() {
  30. let list_data = gData.sign.list_data;
  31. this.scroll_view.node.emit('srollview-init', list_data)
  32. this.tableview = this.scroll_view.node.getComponent('TableView')
  33. let index = gData.sign.getItemIndexByCanSign();
  34. this.tableview.contentMoveByIndex(index)
  35. }
  36. update(dt) {
  37. if (gData.sign.init_data) {
  38. this.initBtnStyle();
  39. return;
  40. }
  41. if (gData.sign.adData) {
  42. // 展示奖励
  43. this.getReward();
  44. }
  45. }
  46. lateUpdate() {
  47. gData.sign.init_data = false;
  48. gData.sign.adData = null;
  49. }
  50. /**
  51. * 点击领取按钮
  52. */
  53. private clickReceiveReward() {
  54. mk.audio.playEffect("button");
  55. if (gData.gameData.gameData.isSignInToday == 1) return;
  56. if (!gData.sign.haveSignDay()) return;
  57. // 看广告
  58. mk.ad.watchAd((success: boolean) => {
  59. mk.console.log("watchAD:" + success);
  60. if (success) {
  61. gData.adData.watchVideo(AdFun.sign);
  62. }
  63. });
  64. }
  65. /**
  66. * 拿奖励
  67. */
  68. private getReward() {
  69. const index_old = gData.sign.getItemIndexByCanSign();
  70. // 完成展示
  71. gData.sign.signComplete();
  72. // 指定条目数据刷新
  73. this.tableview.resetItemData(index_old, gData.sign.list_data[index_old]);
  74. // 打开奖励界面
  75. // to do
  76. }
  77. /**
  78. * 初始化按钮样式
  79. */
  80. private initBtnStyle() {
  81. if (gData.gameData.gameData.isSignInToday == 0 && gData.sign.haveSignDay()) {
  82. this.anim_btn.play();
  83. this.anim_btn.getComponent('SetGray').setGray(false);
  84. } else {
  85. this.anim_btn.stop();
  86. this.anim_btn.node.scale = 1;
  87. this.anim_btn.getComponent('SetGray').setGray(true);
  88. }
  89. }
  90. }