
cc.Class({
    extends: cc.Component,

    properties: {
        cityPic: cc.Sprite,
        incomeSpeedLabel: cc.Label,
        indexLabel: cc.Label,
        stateSprite: cc.Sprite,
        incomeLayout: cc.Node,
    },

    // onLoad () {},


    init(info, incomeSpeed) {
        this.info = info;

        this.indexLabel.string = info.id;
        this.indexLabel.node.active = true;

        if (info.selected) {
            this.statePath = 'selected';
            this.picPath = info.unlockPicId;
        } else if (info.unlock) {
            this.statePath = 'unlocked';
            this.picPath = info.unlockPicId;
        } else {
            this.statePath = 'lock';
            this.picPath = info.picId;
            this.indexLabel.node.active = false;
        }

        cc.loader.loadRes('./map/' + this.picPath, cc.SpriteFrame, (err, spriteFrame) => {
            this.cityPic.spriteFrame = spriteFrame;
        });

        cc.loader.loadRes('./map/' + this.statePath, cc.SpriteFrame, (err, spriteFrame) => {
            this.stateSprite.spriteFrame = spriteFrame;
        });

        if (incomeSpeed > 0) {
            this.incomeLayout.active = true;
            this.incomeSpeedLabel.string = `${incomeSpeed}/天`;
        } else {
            this.incomeLayout.active = false;
        }

    },

    start() {

    },

    fakeLock() {
        cc.loader.loadRes('./map/' + this.info.picId, cc.SpriteFrame, (err, spriteFrame) => {
            this.cityPic.spriteFrame = spriteFrame;
        });

        cc.loader.loadRes('./map/' + 'lock', cc.SpriteFrame, (err, spriteFrame) => {
            this.stateSprite.spriteFrame = spriteFrame;
        });
    },

    fakeUnLock() {
        cc.loader.loadRes('./map/' + this.info.unlockPicId, cc.SpriteFrame, (err, spriteFrame) => {
            this.cityPic.spriteFrame = spriteFrame;
        });

        cc.loader.loadRes('./map/' + 'unlock', cc.SpriteFrame, (err, spriteFrame) => {
            this.stateSprite.spriteFrame = spriteFrame;
        });
    },



    showFinishAnimation(cb) {
        this.cityPic.node.setScale(0);

        let end = cc.callFunc(() => {
            cb && cb();
        }, this);
        let scale = cc.sequence(cc.scaleTo(0.3, 1, 1).easing(cc.easeBackOut()), end);
        this.cityPic.node.runAction(scale);
    },

    // update (dt) {},
});
