import { Widget, _decorator, Node, Label } from 'cc';
import { UIBase } from '../scriptBase/UIBase';
import { Switcher } from '../uiExtend/Switcher';
import { Setting } from '../Setting';
import { AudioMgr } from '../manager/AudioMgr';
import { UI } from '../enum/UI';
import { Bundle } from '../enum/Bundle';
const { ccclass, property, requireComponent } = _decorator;

@ccclass('UI/UISetting')
@requireComponent(Widget)
export class UISetting extends UIBase {

    private swBgm: Switcher = null
    private swSfx: Switcher = null

    protected onLoad(): void {
        this.swBgm = this.findComp('SwBgm', Switcher)
        this.swSfx = this.findComp('SwSfx', Switcher)
    }

    public onOpen(data?: any): void {
        this.swBgm.IsOn = Setting.BgmEnabled
        this.swSfx.IsOn = Setting.SfxEnabled
    }

    public onClose(data?: any): void {

    }

    protected onBtnCloseClick(): void {
        this.close()
    }

    protected onSwBgmClick(): void {
        Setting.BgmEnabled = !Setting.BgmEnabled
        if (Setting.BgmEnabled) {
            AudioMgr.playBgm()
        } else {
            AudioMgr.stopBgm()
        }
    }

    protected onSwSfxClick(): void {
        Setting.SfxEnabled = !Setting.SfxEnabled
    }

}


