TempCup.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { _decorator, Component, Enum, Node } from 'cc';
  2. import { CupHeight, WaterColors } from '../TakeGobletGlobalInstance';
  3. import { Water } from './Water';
  4. import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
  5. import { GameEvent } from '../Enum/GameEvent';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('TempCup')
  8. export class TempCup extends Component {
  9. @property({ type: Enum(CupHeight), displayName: '杯高度' })
  10. cupHeight: CupHeight = CupHeight.One
  11. @property(Node)
  12. waters: Node = null!; //水节点
  13. @property(Node)
  14. adNode: Node = null!;
  15. private _currentColor: WaterColors = WaterColors.Blue;
  16. private _isFull: boolean = false;
  17. get isFull(): boolean {
  18. return this._isFull;
  19. }
  20. get currentColor(): WaterColors {
  21. return this._currentColor;
  22. }
  23. get iconAd(): boolean {
  24. return this.adNode.active;
  25. }
  26. start() {
  27. this.node.on(Node.EventType.TOUCH_END, () => {
  28. this.onTouchEndAdCup();
  29. });
  30. }
  31. private onTouchEndAdCup() {
  32. if (this.iconAd) {
  33. this.adNode.active = false;
  34. console.log('关闭广告图标@@@@@');
  35. }
  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. }