
const { ccclass, property } = cc._decorator;

@ccclass
export default class GetUI extends cc.Component {

    @property(cc.Node)
    public node_rectBg: cc.Node = null;
    @property(cc.Sprite)
    public spr_icon: cc.Sprite = null;
    @property(cc.Label)
    public label_name: cc.Label = null;
    @property(cc.Node)
    public node_getBtn: cc.Node = null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {
        this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height);
        this.node_getBtn.on(cc.Node.EventType.TOUCH_END, this.onClickGetBtn, this);
    }

    // update (dt) {}

    /**初始化
     * @param url 
     * @param name 
     * @param num  数量
     * @param multipleNum 倍数
     */
    init(url: string, name: string, num: number, multipleNum: number = 1) {

        mk.loader.load(url,cc.SpriteFrame).then((spriteFrame)=>{
           this.spr_icon.spriteFrame = spriteFrame;
        })

        if (multipleNum == 1) {
            this.label_name.string = ` ${name} x${num}`;
        }
        else {
            // this.label_name.string = ` ${name} ${num} * ${multipleNum}`;
            this.label_name.string = ` ${name} x${multipleNum}`;
        }

        // x${num}
    }

    onClickGetBtn() {
        
        //AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
        mk.audio.playEffect("button");

        // this.node.active = false;
        mk.ui.closePanel("GetUI")
    }
}
