TempCup.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { _decorator, color, Color, Component, Enum, Node, sp } from 'cc';
  2. import { CupHeight, WaterColorHex, 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(sp.Skeleton)
  14. colorB: sp.Skeleton = null!; //水流骨骼
  15. @property(sp.Skeleton)
  16. cupSkeleton: sp.Skeleton = null!; //杯骨骼
  17. @property(Node)
  18. adNode: Node = null!;
  19. private _currentColor: WaterColors = WaterColors.Blue;
  20. private _isFull: boolean = false;
  21. get isFull(): boolean {
  22. return this._isFull;
  23. }
  24. get currentColor(): WaterColors {
  25. return this._currentColor;
  26. }
  27. get iconAd(): boolean {
  28. return this.adNode.active;
  29. }
  30. start() {
  31. this.node.on(Node.EventType.TOUCH_END, () => {
  32. this.onTouchEndAdCup();
  33. });
  34. }
  35. private onTouchEndAdCup() {
  36. if (this.iconAd) {
  37. this.adNode.active = false;
  38. console.log('关闭广告图标@@@@@');
  39. }
  40. }
  41. fill(color: WaterColors) {
  42. if (this._isFull) return;
  43. const waterNode = this.waters.children[0];
  44. if (waterNode && waterNode.getComponent(sp.Skeleton)) {
  45. waterNode.active = true;
  46. this._currentColor = color;
  47. let cupColor = new Color(WaterColorHex[color]);
  48. let waterSpine = waterNode.getComponent(sp.Skeleton)!;
  49. console.log(`暂存水的颜色:${WaterColorHex[color]}`)
  50. this.colorB.color = cupColor;
  51. waterSpine.color = cupColor;
  52. waterSpine.setAnimation(0, 'pick_01', false);
  53. this.colorB.setAnimation(0, 'pick_01', false);
  54. this.cupSkeleton.setAnimation(0, 'pick_01', false);
  55. this._isFull = true;
  56. }
  57. }
  58. pour() {
  59. }
  60. reset() {
  61. this.waters.children[0].active = false;
  62. this._isFull = false;
  63. console.log('暂存杯已重置');
  64. }
  65. public getColors(): WaterColors[] {
  66. return [this.currentColor];
  67. }
  68. public isEmpty(): boolean {
  69. return this.waters.children.every(node => !node.active);
  70. }
  71. }