package io.gitlab.jfronny.inceptum.frontend.gui.window; import imgui.ImGui; import imgui.type.ImString; import io.gitlab.jfronny.inceptum.Inceptum; import io.gitlab.jfronny.inceptum.frontend.cli.commands.GitCommand; import io.gitlab.jfronny.inceptum.frontend.gui.control.InstanceManageControls; import io.gitlab.jfronny.inceptum.util.Utils; import io.gitlab.jfronny.inceptum.util.install.SetupStepInfo; import io.gitlab.jfronny.inceptum.util.install.Steps; import org.eclipse.jgit.api.errors.GitAPIException; import java.io.IOException; import java.net.URISyntaxException; public class NewInstanceWindow extends Window { private final InstanceManageControls imc = new InstanceManageControls(null); private final ImString inceptumRepo = new ImString(GuiUtil.INPUT_FIELD_LENGTH); private final ImString inceptumName = new ImString(GuiUtil.INPUT_FIELD_LENGTH); private String inceptumNamePrev = ""; public NewInstanceWindow() { super("New Instance"); } @Override public void draw() { if (ImGui.beginTabBar("NewInstanceBar")) { if (ImGui.beginTabItem("New")) { imc.snapshotsBox(); imc.versionBox(ver -> {}); imc.nameBox("OK", name -> { try { GuiUtil.createInstance(new SetupStepInfo(imc.getVersionInfo(), imc.getLoaderInfo(), name, Steps.createProcessState())); } catch (IOException e) { Utils.LOGGER.error("Could not initialize instance creation", e); } close(); }); ImGui.endTabItem(); } if (ImGui.beginTabItem("Clone")) { if (ImGui.inputTextWithHint("URL", "Repo to download", inceptumRepo) && (inceptumName.isEmpty() || inceptumName.get().isEmpty() || inceptumName.get().equals(inceptumNamePrev))) { try { inceptumName.set(GitCommand.CloneCommand.getName(inceptumRepo.get())); inceptumNamePrev = inceptumName.get(); } catch (URISyntaxException ignored) { } } ImGui.inputTextWithHint("Name", "Name of the new instance", inceptumName); if (ImGui.button("OK")) { close(); try { GitCommand.CloneCommand.clone(inceptumRepo.get(), inceptumName.get()); } catch (GitAPIException | IOException e) { Inceptum.showError("Could not clone instance", e); } } ImGui.endTabItem(); } if (ImGui.beginTabItem("Import")) { ImGui.text("Importing CurseForge or Modrinth packs is not yet implemented"); //TODO generic importer based on zip contents and file name ("mrpack") ImGui.endTabItem(); } ImGui.endTabBar(); } } }