Card.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. private _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. if(this._shadow001.active){
  30. this._shadow001.active = false;
  31. }
  32. this._consumeCount = Number(this._consume.getComponent(Label).string);
  33. }
  34. protected update(dt: number): void {
  35. const strOreCount: string = this._oreCount.getComponent(Label).string;
  36. if (this._consumeCount) {
  37. if (Number(strOreCount) <= this._consumeCount) {
  38. //开启阴影
  39. this._shadow.active = true;
  40. //不可点击
  41. this.clickable = false;
  42. } else {
  43. //阴影关闭
  44. this._shadow.active = false;
  45. //可以点击
  46. this.clickable = true;
  47. }
  48. }
  49. }
  50. //冷却当中
  51. aniPlay(){
  52. this._shadow001.active = true;
  53. this._shadow001.getComponent(Animation).play();
  54. }
  55. aniStart(){
  56. //如何没被禁用,则动画开始播放的时候,开始禁用
  57. if(!this.disabled){
  58. this.disabled = true;
  59. }
  60. }
  61. aniEnd(){
  62. //如何被禁用,则动画结束播放的时候,不禁用
  63. if(this.disabled){
  64. this.disabled = false;
  65. }
  66. this._shadow001.active = false;
  67. }
  68. setLock(b: boolean) {
  69. this._lock.active = b;
  70. }
  71. setlabel(b: boolean) {
  72. this._label.active = b;
  73. }
  74. setSprite(name: string) {
  75. this._sprite.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(name);
  76. }
  77. }