import SkinScene from "../views/SkinScene";
import SceneCtrl from "../ctrls/SceneCtrl";
import StartScene from "./StartScene";
import ProgressBar from "../components/ProgressBar";
import { Decorator } from "../Decorator/Decorator";
import SoundMgr from "../Mgr/SoundMgr";
import MainScene from "./MainScene";

@Decorator.OnUpdate
export default class extends SkinScene {
    get skinKey() { return "LoadScene" }
    get groupName() { return "load_scene" }
    private progress: ProgressBar = null;
    public labelProgress: eui.Label;

    onSkinComplete() {
        super.onSkinComplete();
        let progress = new ProgressBar();
        this.addChild(progress);
        progress.horizontalCenter = 3;
        progress.verticalCenter = 68;
        this.progress = progress;
        this.loadRes();
    }

    async loadRes() {
        this.progress.value = 0;
        this.updateAntPos();
        this.labelProgress.text = "0%"

        await RES.loadGroup("main_res");
        this.progress.value = 0.2;
        this.updateAntPos();
        this.labelProgress.text = "20%"

        await RES.loadGroup("start_scene");
        this.progress.value = 0.4;
        this.updateAntPos();
        this.labelProgress.text = "40%"

        await RES.loadGroup("main_scene");
        this.progress.value = 0.6;
        this.updateAntPos();
        this.labelProgress.text = "60%"

        await RES.loadGroup("sound");
        this.progress.value = 0.8;
        this.updateAntPos();
        this.labelProgress.text = "80%"

        await RES.loadGroup("animation");
        this.progress.value = 1;
        this.updateAntPos();
        this.labelProgress.text = "100%"

        setTimeout(async () => {
            SceneCtrl.instance.change(StartScene);
        }, 500);
    }

    private updateAntPos() {
        // this.ant.x = this.ant.parent.globalToLocal(this.progress.parent.localToGlobal(this.progress.fill.x).x).x;
    }
}