AttendancePanel.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * 代码描述
  3. */
  4. import { Audio } from "../../common/src/Audio";
  5. import { GameDataCenter } from "../../common/src/GameDataCenter";
  6. import { Utils } from "../../common/src/Utils";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export class AttendancePanel extends cc.Component {
  10. @property({ type: cc.Node, tooltip: '面板' })
  11. panel: cc.Node = null;
  12. private day: number = 0;
  13. private ui: string[] = ['special1', 'coin', 'special4', 'special3', 'coin', 'special2', 'coin'];
  14. private num: number[] = [1, 100, 1, 1, 300, 1];
  15. onEnable() {
  16. this.panel.getChildByName('closeButton').on('click', this.onClose, this);
  17. this.panel.getChildByName('button').getChildByName('doubleGet').on('click', this.onDoubleGet, this);
  18. this.panel.getChildByName('button').getChildByName('get').on('click', this.onGet, this);
  19. this.day = (GameDataCenter.signIn) % 7;
  20. Utils.openPanel(this.node.getChildByName('panel'));
  21. Utils.btnTween(this.panel.getChildByName('button').getChildByName('doubleGet'))
  22. let node = this.panel.getChildByName('days');
  23. if (this.day == 7) {
  24. for (let i = 0; i < this.day; i++) {
  25. node.children[i].getChildByName('mask').active = false;
  26. }
  27. }
  28. else {
  29. for (let i = 0; i < this.day; i++) {
  30. node.children[i].getChildByName('mask').active = true;
  31. }
  32. }
  33. let today = node.children[this.day];
  34. Utils.btnTween(today);
  35. today.getComponent(cc.Sprite).enabled = false;
  36. today.getChildByName('bottom').getComponent(cc.Sprite).enabled = false;
  37. today.getChildByName('bottom').getChildByName('label').color = cc.color('#FFFFFF' as any);
  38. today.getChildByName('bottom').getChildByName('label').x -= 20;
  39. today.getChildByName('bottom').getChildByName('videoIcon').active = true;
  40. today.getChildByName('di').active = true;
  41. today.on('click', this.onDoubleGet, this);
  42. }
  43. /**关闭 */
  44. private onClose(): void {
  45. Audio.playSoundByPath('attendance:res/snd/click');
  46. this.node.destroy();
  47. }
  48. /**领取 */
  49. private onGet(): void {
  50. Audio.playSoundByPath('attendance:res/snd/click');
  51. GameDataCenter.isSignIn = true;
  52. GameDataCenter.signIn++;
  53. if (this.day == 6) {
  54. for (let i = 1; i <= 4; i++) {
  55. cc.systemEvent.emit('updateUI', `special${i}`, 2);
  56. }
  57. }
  58. else {
  59. cc.systemEvent.emit('updateUI', this.ui[this.day], this.num[this.day]);
  60. }
  61. this.node.destroy();
  62. }
  63. /**双倍领取 */
  64. private onDoubleGet(): void {
  65. Audio.playSoundByPath('attendance:res/snd/click');
  66. GameDataCenter.isSignIn = true;
  67. GameDataCenter.signIn++;
  68. if (this.day == 6) {
  69. for (let i = 1; i <= 4; i++) {
  70. cc.systemEvent.emit('updateUI', `special${i}`, 4);
  71. }
  72. }
  73. else {
  74. cc.systemEvent.emit('updateUI', this.ui[this.day], this.num[this.day] * 2);
  75. }
  76. this.node.destroy();
  77. }
  78. }