TempCup.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { _decorator, Component, Enum, Node } from 'cc';
  2. import { CupHeight, WaterColors } from '../TakeGobletGlobalInstance';
  3. import { Water } from './Water';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('TempCup')
  6. export class TempCup extends Component {
  7. @property({ type: Enum(CupHeight), displayName: '杯高度' })
  8. cupHeight: CupHeight = CupHeight.One
  9. @property(Node)
  10. waters: Node = null!; //水节点
  11. @property(Node)
  12. adNode: Node = null!;
  13. private _currentColor: WaterColors = WaterColors.Blue;
  14. private _isFull: boolean = false;
  15. get isFull(): boolean {
  16. return this._isFull;
  17. }
  18. get currentColor(): WaterColors {
  19. return this._currentColor;
  20. }
  21. get iconAd(): boolean {
  22. return this.adNode.active;
  23. }
  24. start() {
  25. this.node.on(Node.EventType.TOUCH_END, () => {
  26. this.onTouchEndAdCup();
  27. });
  28. }
  29. private onTouchEndAdCup() {
  30. if (this.iconAd) {
  31. this.adNode.active = false;
  32. console.log('关闭广告图标@@@@@');
  33. }
  34. }
  35. update(deltaTime: number) {
  36. }
  37. fill(color: WaterColors) {
  38. if (this._isFull) return;
  39. const waterNode = this.waters.children[0];
  40. if (waterNode) {
  41. const water = waterNode.getComponent(Water)!;
  42. water.color = color;
  43. waterNode.active = true;
  44. this._currentColor = color;
  45. this._isFull = true;
  46. }
  47. }
  48. reset() {
  49. this.waters.children[0].active = false;
  50. this._isFull = false;
  51. console.log('暂存杯已重置');
  52. }
  53. public getColors(): WaterColors[] {
  54. return this.waters.children
  55. .filter(node => node.active)
  56. .map(node => node.getComponent(Water)!.color);
  57. }
  58. public getActiveWaters(): Water[] {
  59. return this.waters.children
  60. .filter(node => node.active)
  61. .map(node => node.getComponent(Water)!);
  62. }
  63. public isEmpty(): boolean {
  64. return this.waters.children.every(node => !node.active);
  65. }
  66. }