2022-01-18 18:43:39 +01:00
|
|
|
package io.gitlab.jfronny.inceptum.frontend.gui;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
2022-01-18 19:22:26 +01:00
|
|
|
import imgui.ImGui;
|
|
|
|
import imgui.type.ImString;
|
|
|
|
import io.gitlab.jfronny.inceptum.Inceptum;
|
|
|
|
import io.gitlab.jfronny.inceptum.frontend.cli.commands.GitCommand;
|
2022-01-18 18:43:39 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.frontend.gui.control.InstanceManageControls;
|
2022-01-19 19:14:13 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.Utils;
|
|
|
|
import io.gitlab.jfronny.inceptum.util.install.SetupStepInfo;
|
|
|
|
import io.gitlab.jfronny.inceptum.util.install.Steps;
|
2022-01-18 19:22:26 +01:00
|
|
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2022-01-18 19:22:26 +01:00
|
|
|
import java.net.URISyntaxException;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
|
|
|
public class NewInstanceWindow extends Window {
|
2022-01-18 19:22:26 +01:00
|
|
|
private final InstanceManageControls imc = new InstanceManageControls(null);
|
2022-01-20 18:13:37 +01:00
|
|
|
private final ImString inceptumRepo = new ImString(GuiUtil.INPUT_FIELD_LENGTH);
|
|
|
|
private final ImString inceptumName = new ImString(GuiUtil.INPUT_FIELD_LENGTH);
|
2022-01-19 19:14:13 +01:00
|
|
|
private String inceptumNamePrev = "";
|
2021-10-27 22:00:08 +02:00
|
|
|
public NewInstanceWindow() {
|
|
|
|
super("New Instance");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void draw() {
|
2022-01-18 19:22:26 +01:00
|
|
|
if (ImGui.beginTabBar("NewInstanceBar")) {
|
|
|
|
if (ImGui.beginTabItem("New")) {
|
|
|
|
imc.snapshotsBox();
|
|
|
|
imc.versionBox(ver -> {});
|
|
|
|
imc.nameBox("OK", name -> {
|
|
|
|
try {
|
2022-01-19 19:14:13 +01:00
|
|
|
GuiUtil.createInstance(new SetupStepInfo(imc.getVersionInfo(),
|
2022-01-18 19:22:26 +01:00
|
|
|
imc.getLoaderInfo(),
|
|
|
|
name,
|
2022-01-19 19:14:13 +01:00
|
|
|
Steps.createProcessState()));
|
2022-01-18 19:22:26 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
Utils.LOGGER.error("Could not initialize instance creation", e);
|
|
|
|
}
|
|
|
|
close();
|
|
|
|
});
|
|
|
|
ImGui.endTabItem();
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
2022-01-18 19:22:26 +01:00
|
|
|
if (ImGui.beginTabItem("Inceptum")) {
|
2022-01-19 19:14:13 +01:00
|
|
|
if (ImGui.inputTextWithHint("URL", "Repo to download", inceptumRepo)
|
|
|
|
&& (inceptumName.isEmpty() || inceptumName.get().isEmpty() || inceptumName.get().equals(inceptumNamePrev))) {
|
2022-01-18 19:22:26 +01:00
|
|
|
try {
|
|
|
|
inceptumName.set(GitCommand.CloneCommand.getName(inceptumRepo.get()));
|
2022-01-19 19:14:13 +01:00
|
|
|
inceptumNamePrev = inceptumName.get();
|
2022-01-18 19:22:26 +01:00
|
|
|
} 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("CurseForge")) {
|
|
|
|
ImGui.text("Importing CurseForge packs is not yet implemented");
|
|
|
|
ImGui.endTabItem();
|
|
|
|
}
|
|
|
|
if (ImGui.beginTabItem("Modrinth")) {
|
|
|
|
ImGui.text("Importing Modrinth packs is not yet implemented");
|
|
|
|
ImGui.endTabItem();
|
|
|
|
}
|
|
|
|
ImGui.endTabBar();
|
|
|
|
}
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
}
|