SignPanel.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { _decorator, Button, Component, Node } from 'cc';
  2. import { BasePanel } from './BasePanel';
  3. import { Sign_Reward } from './Sign_Reward';
  4. import ch_sign from '../../ch/sign/sign';
  5. import { MyGame } from '../Game/MyGame';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('SignPanel')
  8. export class SignPanel extends BasePanel {
  9. @property(Button)
  10. private Sign_Btn: Button;
  11. @property(Button)
  12. private Double_Get_Btn: Button;
  13. @property({ type: [Sign_Reward] })
  14. sigin_rewards: Sign_Reward[] = [];
  15. start() {
  16. this.Sign_Btn = this.node.getChildByName("Sign_Btn").getComponent(Button);
  17. this.Double_Get_Btn = this.node.getChildByName("Double_Get_Btn").getComponent(Button);
  18. this.show_info();
  19. this.Sign_Btn.node.on(Button.EventType.CLICK, this.onSigin, this);
  20. this.Double_Get_Btn.node.on(Button.EventType.CLICK, this.onDoubleSigin, this);
  21. }
  22. update(deltaTime: number) {
  23. }
  24. private async show_info() {
  25. await ch_sign.getInstance().getSignData();
  26. const rewards = this.sigin_rewards;
  27. for (let i = 0; i < rewards.length; i++) {
  28. rewards[i].show(i + 1);
  29. }
  30. }
  31. private async onSigin() {
  32. let day = await ch_sign.getInstance().signIn();
  33. if (day == 0) {
  34. console.log("签到失败");
  35. } else {
  36. //签到成功获取奖励
  37. console.log("签到成功");
  38. this.sigin_rewards[day-1].show(day);
  39. MyGame.getInstance().setSignData(ch_sign.getInstance().getSignData());
  40. MyGame.getInstance().saveData();
  41. }
  42. }
  43. //
  44. private async onDoubleSigin() {
  45. if (ch_sign.getInstance().checkReSigin() == 0) {
  46. console.log("无需补签");
  47. return;
  48. }
  49. //可以补签
  50. }
  51. onEnter() {
  52. super.onEnter();
  53. this.show_info();
  54. }
  55. onClose() {
  56. super.onClose(null);
  57. }
  58. }