package io.gitlab.jfronny.glaunch.windows; import imgui.ImGui; import imgui.type.ImString; import io.gitlab.jfronny.glaunch.GLaunch; import io.gitlab.jfronny.glaunch.Window; import io.gitlab.jfronny.glaunch.install.SetupStepInfo; import io.gitlab.jfronny.glaunch.install.Step; import io.gitlab.jfronny.glaunch.install.Steps; import io.gitlab.jfronny.glaunch.model.VersionsList; import io.gitlab.jfronny.glaunch.model.VersionsListInfo; import io.gitlab.jfronny.glaunch.util.mojang.McApi; import java.io.IOException; public class NewInstanceWindow extends Window { VersionsList manifest = McApi.getVersions(); VersionsListInfo selected = null; LoaderType loaderType = null; State state = State.Version; String name = ""; public NewInstanceWindow() { super("New Instance"); } @Override public void preFirstDraw() { ImGui.setNextWindowSize(200, 800); } @Override public void draw() { if (ImGui.button("Cancel")) close(); switch (state) { case Version -> { ImGui.text("Select a version"); GLaunch.CONFIG.snapshots = ImGui.checkbox("Show snapshots", GLaunch.CONFIG.snapshots); if (ImGui.checkbox("Ae", true)) { //TODO fix GLaunch.LOGGER.info("Ao"); } for (VersionsListInfo version : manifest.versions) { if (!version.type.equals("release") && !GLaunch.CONFIG.snapshots) continue; if (ImGui.button(version.id)) { selected = version; state = State.Loader; break; } } } case Loader -> { ImGui.text("Select a mod loader"); //TODO implement fabric support for (LoaderType value : LoaderType.values()) { if (ImGui.button(value.name())) { state = State.Name; } } } case Name -> { ImString is = new ImString(name); ImGui.text("Select a name"); ImGui.inputText("", is); name = is.get(); if (ImGui.button("OK")) state = State.Installing; } case Installing -> { ImGui.text("Installing..."); try { SetupStepInfo stepInfo = new SetupStepInfo(McApi.getVersionInfo(selected), loaderType, name); for (Step step : Steps.STEPS) { step.execute(stepInfo); } } catch (IOException e) { GLaunch.LOGGER.error("Could not initialize instance", e); GLaunch.open(new AlertWindow("Could not initialize instance, look at the log for details")); close(); } } } } enum State { Version, Loader, Name, Installing } public enum LoaderType { None, Fabric } }