SuitItem.ts 1.56 KB
import { ResUtils } from "simba-cc-resutils";
import { DummyLabel, DummyNode, DummySprite } from "../../common/CCDummyObjects";
import { GameConstData } from "../../common/gameplay/gamedata/GameConstData";
import { UIManager } from "../../common/gameplay/managers/UIManager";
import { SuitConfig } from "../model/BedRoomCatModelManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SuitItem extends cc.Component {

    @property({ type: cc.Sprite, displayName: "Icon sprite" })
    iconSprite: cc.Sprite = DummySprite;
    @property({ type: cc.Label, displayName: "Name label" })
    nameLabel: cc.Label = DummyLabel;
    @property({ type: cc.Node, displayName: "Lock root node" })
    lockRootNode: cc.Node = DummyNode;
    @property({ type: cc.Label, displayName: "Unlock condition label" })
    unlockConditionLabel: cc.Label = DummyLabel;

    private _showLockRootNode: boolean = true;
    async setData(suitConfig: SuitConfig, showLockRootNode: boolean) {
        this.iconSprite.spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + suitConfig.clothingId, cc.SpriteFrame)
        this.nameLabel.string = suitConfig.clothingName;
        this._showLockRootNode = showLockRootNode;
        if (showLockRootNode) {
            this.lockRootNode.active = true;
            this.unlockConditionLabel.string = suitConfig.unlockCondition;
        }
    }

    onBtnClick() {
        if (this._showLockRootNode) {
            UIManager.showToast("快去完成任务,领取服装吧!");
            return;
        }
    }
}