123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import { _decorator, Animation, Component, Label, Node, ProgressBar, Sprite } from 'cc';
- import { resMgr } from '../../Frames/ResourcesMgr';
- const { ccclass, property } = _decorator;
- @ccclass('Card')
- export class Card extends Component {
- private _lock: Node = null;
- private _label: Node = null;
- private _sprite: Node = null;
- private _shadow: Node = null;
- private _oreCount: Node = null;
- private _consume: Node = null;
- consumeCount: number = null;
- //是否可以点击
- clickable: boolean = true;
- //是否禁用
- disabled: boolean = false;
- private _shadow001: Node = null;
- protected onLoad(): void {
- this._lock = this.node.getChildByName("Lock");
- this._label = this.node.getChildByName("Label");
- this._sprite = this.node.getChildByName("Sprite");
- this._shadow = this.node.getChildByName("Shadow");
- this._consume = this.node.getChildByName("Count");
- this._shadow001 = this.node.getChildByName("Shadow-001");
- this._oreCount = this.node.parent.parent.getChildByPath("OreSpeed/_oreSpeed");
- }
- start() {
- //这个Card可以使用的条件:disabled === false; clickable === true
- this.consumeCount = Number(this._consume.getComponent(Label).string);
- }
- protected update(dt: number): void {
- const strOreCount: string = this._oreCount.getComponent(Label).string;
- if (this.consumeCount) {
- if (Number(strOreCount) <= this.consumeCount) {
- //开启阴影
- this._shadow.active = true;
- //不可点击
- this.clickable = false;
- } else {
- //阴影关闭
- this._shadow.active = false;
- //可以点击
- this.clickable = true;
- }
- }
- }
- //冷却当中
- aniPlay() {
- this._shadow001.active = true;
- this.disabled = true;
- this._shadow001.getComponent(Animation).play();
- this._shadow001.getComponent(Animation).on(Animation.EventType.FINISHED,()=>{
- this.disabled = false;
- this._shadow001.active = false;
- })
- }
- aniStart() {
- //如何没被禁用,则动画开始播放的时候,开始禁用
- this.disabled = true;
- }
- aniEnd() {
- //如何被禁用,则动画结束播放的时候,不禁用
- this.disabled = false;
- this._shadow001.active = false;
- }
- setLock(b: boolean) {
- this._lock.active = b;
- }
- setlabel(b: boolean) {
- this._label.active = b;
- }
- setSprite(name: string) {
- this._sprite.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(name);
- }
- }
|