Card.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { _decorator, Animation, Component, Label, Node, ProgressBar, Sprite } from 'cc';
  2. import { resMgr } from '../../Frames/ResourcesMgr';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('Card')
  5. export class Card extends Component {
  6. private _lock: Node = null;
  7. private _label: Node = null;
  8. private _sprite: Node = null;
  9. private _shadow: Node = null;
  10. private _oreCount: Node = null;
  11. private _consume: Node = null;
  12. consumeCount: number = null;
  13. //是否可以点击
  14. clickable: boolean = true;
  15. //是否禁用
  16. disabled: boolean = false;
  17. private _shadow001: Node = null;
  18. protected onLoad(): void {
  19. this._lock = this.node.getChildByName("Lock");
  20. this._label = this.node.getChildByName("Label");
  21. this._sprite = this.node.getChildByName("Sprite");
  22. this._shadow = this.node.getChildByName("Shadow");
  23. this._consume = this.node.getChildByName("Count");
  24. this._shadow001 = this.node.getChildByName("Shadow-001");
  25. this._oreCount = this.node.parent.parent.getChildByPath("OreSpeed/_oreSpeed");
  26. }
  27. start() {
  28. //这个Card可以使用的条件:clickable === true; disabled === false
  29. this.consumeCount = Number(this._consume.getComponent(Label).string);
  30. }
  31. protected update(dt: number): void {
  32. const strOreCount: string = this._oreCount.getComponent(Label).string;
  33. if (this.consumeCount) {
  34. if (Number(strOreCount) <= this.consumeCount) {
  35. //开启阴影
  36. this._shadow.active = true;
  37. //不可点击
  38. this.clickable = false;
  39. } else {
  40. //阴影关闭
  41. this._shadow.active = false;
  42. //可以点击
  43. this.clickable = true;
  44. }
  45. }
  46. }
  47. //冷却当中
  48. aniPlay() {
  49. this._shadow001.active = true;
  50. this._shadow001.getComponent(Animation).play();
  51. }
  52. aniStart() {
  53. //如何没被禁用,则动画开始播放的时候,开始禁用
  54. if (!this.disabled) {
  55. this.disabled = true;
  56. }
  57. }
  58. aniEnd() {
  59. //如何被禁用,则动画结束播放的时候,不禁用
  60. if (this.disabled) {
  61. this.disabled = false;
  62. }
  63. this._shadow001.active = false;
  64. }
  65. setLock(b: boolean) {
  66. this._lock.active = b;
  67. }
  68. setlabel(b: boolean) {
  69. this._label.active = b;
  70. }
  71. setSprite(name: string) {
  72. this._sprite.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(name);
  73. }
  74. }