Card.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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可以使用的条件:disabled === false; clickable === true
  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.disabled = true;
  51. this._shadow001.getComponent(Animation).play();
  52. this._shadow001.getComponent(Animation).on(Animation.EventType.FINISHED,()=>{
  53. this.disabled = false;
  54. this._shadow001.active = false;
  55. })
  56. }
  57. aniStart() {
  58. //如何没被禁用,则动画开始播放的时候,开始禁用
  59. this.disabled = true;
  60. }
  61. aniEnd() {
  62. //如何被禁用,则动画结束播放的时候,不禁用
  63. this.disabled = false;
  64. this._shadow001.active = false;
  65. }
  66. setLock(b: boolean) {
  67. this._lock.active = b;
  68. }
  69. setlabel(b: boolean) {
  70. this._label.active = b;
  71. }
  72. setSprite(name: string) {
  73. this._sprite.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(name);
  74. }
  75. }