Sign.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. gData.sign.init_data = false;
  39. this.initBtnStyle();
  40. return;
  41. }
  42. if (gData.sign.adData) {
  43. // 展示奖励
  44. this.getReward();
  45. gData.sign.adData = null;
  46. }
  47. }
  48. /**
  49. * 点击领取按钮
  50. */
  51. private clickReceiveReward() {
  52. if (!gData.sign.sign_can) return;
  53. if (!gData.sign.haveSignDay()) return;
  54. // 看广告
  55. gData.adData.watchVideo(AdFun.sign);
  56. }
  57. /**
  58. * 拿奖励
  59. */
  60. private getReward() {
  61. let index_old = gData.sign.getItemIndexByCanSign();
  62. // 完成展示
  63. gData.sign.signComplete();
  64. // 指定条目数据刷新
  65. this.tableview.resetItemData(index_old, gData.sign.list_data[index_old]);
  66. // 打开奖励界面
  67. // to do
  68. }
  69. /**
  70. * 初始化按钮样式
  71. */
  72. private initBtnStyle() {
  73. if (gData.sign.sign_can && gData.sign.haveSignDay()) {
  74. this.anim_btn.play();
  75. this.anim_btn.getComponent('SetGray').setGray(false);
  76. } else {
  77. this.anim_btn.stop();
  78. this.anim_btn.node.scale = 1;
  79. this.anim_btn.getComponent('SetGray').setGray(true);
  80. }
  81. }
  82. }