import { ui } from "../ui/layaMaxUI";
import { SC, ViewManager, ViewType } from "./ViewManager";
import { Switch } from "../Tool/Switch";
import { AudioManager } from "../Tool/AudioManager";
import { WXSDK } from "../Net/WXSDK";

export default class SetView extends ui.SetViewUI implements SC{
    private static ins:SetView;
    private SoundSwitch:Switch;
    private ShakeSwitch:Switch;
    constructor(){
        super();
    }
    public static get Instance():SetView{
        if(SetView.ins){
            return SetView.ins
        }
        else{
            return new SetView();
        }
    }
    Show(){
        this.CloseBtn.clickHandler = Laya.Handler.create(this,this.ClickClose)
        this.SoundSwitch = this.Sound.addComponent(Switch) as Switch;
         this.ShakeSwitch = this.Shake.addComponent(Switch) as Switch;
         this.SoundSwitch.ListenOn_Off(AudioManager.open,Laya.Handler.create(this,this.OpenSound,[true],false),Laya.Handler.create(this,this.OpenSound,[false],false));
         this.ShakeSwitch.ListenOn_Off(WXSDK.shake,Laya.Handler.create(this,this.OpenShake,[true],false),Laya.Handler.create(this,this.OpenShake,[false],false));
        this.height = Laya.stage.height; 
        Laya.stage.on(Laya.Event.RESIZE,this,()=>
        {
            this.height = Laya.stage.height;
        })
    }
    Close(){
        
    }
    ClickClose(){
        ViewManager.Instance.ShowView(ViewType.MainView);
    }
    //打开声音
    OpenSound(_open:boolean){
        AudioManager.open = _open;
    }
    //打开震动
    OpenShake(_open:boolean){
        WXSDK.shake = _open;
    }

} 