import { ui } from "../ui/layaMaxUI";
import { SC } from "./ViewManager";
import { AccountManager } from "../Net/AccountManager";
import { StageControl } from "../Game/StageControl";
import { GameManager } from "../Game/GameManager";
import { SDKZS } from "../Net/SDKZS";
import { WXSDK } from "../Net/WXSDK";
export default class InGameView extends ui.InGameViewUI implements SC{
    private static ins:InGameView;
    public goaltext:Laya.Text;
    constructor(){
        super();
        InGameView.ins = this;
    }
    public static get Instance():InGameView{
        if(InGameView.ins){
            return InGameView.ins
        }
        else{
            return new InGameView();
        }
    }
    Show(){
        WXSDK.AldEvent("进入游戏内界面");
        let stage = Number(AccountManager.Instance.curplayerData.GainAccount("stage"));
        if(stage == 1){
            this.Guide1.visible = true;
            this.ani1.play(0,true);
            this.Guide2.visible = false;
            this.Guide3.visible = false;
            this.Guide4.visible = false;
        }
        else if(stage == 2){
            this.Guide1.visible = false;
            this.Guide2.visible = false;
            this.Guide3.visible = false;
            this.Guide4.visible = false;
        }
        else{
            this.Guide1.visible = false;
            this.Guide2.visible = false;
            this.Guide3.visible = false;
            this.Guide4.visible = false;
        }
        this.GoldNum.text = AccountManager.Instance.curplayerData.GainAccount("money");
        this.goaltext = this.GoalProgress.getChildByName("goal") as Laya.Text;
        // this.goaltext.text = GameManager.Instance.KillNum.toString();
        this.SetData();
        this.InitUI();
        this.height = Laya.stage.height;
        Laya.stage.on(Laya.Event.RESIZE,this,()=>
        {
            this.height = Laya.stage.height;
        })
    }
    Close(){

    }
    InitUI(){
        this.goaltext.text = GameManager.Instance.KillNum.toString();
        this.GoalProgress.value = GameManager.Instance.KillNum/StageControl.Instance.curstage.Goal;
    }

    private SetData() {
        SDKZS.SetHuTuiList(this.BottomList, 2, "");
        this.GunGun();
    }
    GunGun() {
        var maxBtm;
        try {
            this.BottomList.scrollBar.value = 0;
            maxBtm = this.BottomList.scrollBar.max;
        } catch (error) {
            console.error(error);
            return;
        }
        var tempBtm = 1;
        Laya.timer.frameLoop(1, this, () => {
            this.BottomList.scrollBar.value += tempBtm;
            if (this.BottomList.scrollBar.value >= maxBtm || this.BottomList.scrollBar.value <= 0) {
                tempBtm = -tempBtm;
            }
        });
    }
    
}