TempCup.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. import { GameUtil } from '../GameUtil';
  7. const { ccclass, property } = _decorator;
  8. //暂存杯状态 默认 接水 倒水
  9. export enum TempCupState {
  10. Default,
  11. Pick,
  12. PourWater
  13. }
  14. @ccclass('TempCup')
  15. export class TempCup extends Component {
  16. @property({ type: Enum(CupHeight), displayName: '杯高度' })
  17. cupHeight: CupHeight = CupHeight.One
  18. @property(Node)
  19. waters: Node = null!; //水节点
  20. @property(sp.Skeleton)
  21. colorB: sp.Skeleton = null!; //水流骨骼
  22. @property(sp.Skeleton)
  23. cupSkeleton: sp.Skeleton = null!; //杯骨骼
  24. @property(Node)
  25. adNode: Node = null!;
  26. private _currentColor: WaterColors = WaterColors.Blue;
  27. private _isFull: boolean = false;
  28. get isFull(): boolean {
  29. return this._isFull;
  30. }
  31. get currentColor(): WaterColors {
  32. return this._currentColor;
  33. }
  34. get iconAd(): boolean {
  35. return this.adNode.active;
  36. }
  37. start() {
  38. this.node.on(Node.EventType.TOUCH_END, () => {
  39. this.onTouchEndAdCup();
  40. });
  41. }
  42. private onTouchEndAdCup() {
  43. if (this.iconAd) {
  44. this.adNode.active = false;
  45. console.log('关闭广告图标@@@@@');
  46. }
  47. }
  48. /**暂存杯 接水动画*/
  49. async fill(color: WaterColors) {
  50. if (this._isFull) return;
  51. const waterNode = this.waters.children[0];
  52. if (waterNode && waterNode.getComponent(sp.Skeleton)) {
  53. waterNode.active = true;
  54. this._currentColor = color;
  55. let cupColor = new Color(WaterColorHex[color]);
  56. let waterSpine = waterNode.getComponent(sp.Skeleton)!;
  57. // console.log(`暂存水的颜色:${WaterColorHex[color]}`)
  58. this.colorB.color = cupColor;
  59. waterSpine.color = cupColor;
  60. this.playAnimation(TempCupState.Pick);
  61. this._isFull = true;
  62. await GameUtil.delay(0.5);
  63. }
  64. }
  65. playAnimation(state: TempCupState) {
  66. let animaStr = state === TempCupState.Pick ? 'pick_01' :
  67. state === TempCupState.PourWater ? 'pour_01' : 'idle';
  68. const waterNode = this.waters.children[0];
  69. if (waterNode && waterNode.getComponent(sp.Skeleton)) {
  70. let waterSpine = waterNode.getComponent(sp.Skeleton)!;
  71. waterSpine.setAnimation(0, animaStr, false);
  72. this.colorB.setAnimation(0, animaStr, false);
  73. this.cupSkeleton.setAnimation(0, animaStr, false);
  74. }
  75. }
  76. /**暂存杯 倒水动画*/
  77. pour() {
  78. this.playAnimation(TempCupState.PourWater);
  79. }
  80. reset() {
  81. this._currentColor = WaterColors.White;
  82. let cupColor = new Color(WaterColorHex[this.currentColor]);
  83. let waterNode = this.waters.children[0];
  84. let waterSpine = waterNode.getComponent(sp.Skeleton)!;
  85. this.colorB.color = cupColor;
  86. waterSpine.color = cupColor;
  87. this._isFull = false;
  88. this.playAnimation(TempCupState.Default);
  89. }
  90. public getColors(): WaterColors[] {
  91. return [this.currentColor];
  92. }
  93. public isEmpty(): boolean {
  94. return this.waters.children.every(node => !node.active);
  95. }
  96. }