
import { IWindow } from "./Component/IWindow";
import { SwitchButton, SwitchButtonState } from "./Component/SwitchButton";
import { WindowManager, WindowType } from "./WindowManager";
import { ui } from "../ui/layaMaxUI";
import PlaySoundManager from "../Scripts/Game/PlaySoundManager";
import WxApi from "../WXSDK/wxsdk";
import { PlayerAccount, AccountUser } from "../Scripts/Network/PlayerAccount";
import ADPlayer from "../WXSDK/ADPlayer";


export class SettingWindow extends ui.Window.SettingWindowUI implements IWindow
{
    private static instance:SettingWindow;
    constructor()
    {
        super();
        SettingWindow.instance = this;
    }

    public static get Instance()
    {
        return SettingWindow.instance;
    }

    soundswitctbutton:SwitchButton;
    shakeswitchbutton:SwitchButton;

    OnOpen(_data = null)
    {
        this.userid.text = "用户ID:" + PlayerAccount.CurrentAccount.CurAccountData.GetUser(AccountUser.user_id);

        this.closeBtn.clickHandler = Laya.Handler.create(this,this.OnCLickClose);

        this.soundswitctbutton = this.soundPan.addComponent(SwitchButton) as SwitchButton;
        this.shakeswitchbutton = this.shakePan.addComponent(SwitchButton) as SwitchButton;

        this.soundswitctbutton.Init(PlaySoundManager.CanPlaySound,Laya.Handler.create(this,this.OnOpenSound,[true],false),Laya.Handler.create(this,this.OnOpenSound,[false],false));
        this.shakeswitchbutton.Init(WxApi.CanShake,Laya.Handler.create(this,this.OnOpenShake,[true],false),Laya.Handler.create(this,this.OnOpenShake,[false],false));
        ADPlayer.showBannerAd();
        this.height = Laya.stage.height;
    }

    OnOpenSound(_open:boolean)
    {
        PlaySoundManager.CanPlaySound = _open;
    }

    OnOpenShake(_open:boolean)
    {
        WxApi.CanShake = _open;
    }

    OnCLickClose()
    {
        WindowManager.Instance.ShowWindow(WindowType.HomeWindow);
    }

    OnHide()
    {

    }
}