Inceptum/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/NewInstanceWindow.java

68 lines
3.0 KiB
Java
Raw Normal View History

2022-09-04 21:21:24 +02:00
package io.gitlab.jfronny.inceptum.imgui.window;
2021-10-27 22:00:08 +02:00
2022-01-18 19:22:26 +01:00
import imgui.ImGui;
import io.gitlab.jfronny.commons.ref.R;
2022-09-04 21:21:24 +02:00
import io.gitlab.jfronny.inceptum.common.Utils;
2022-09-19 21:26:23 +02:00
import io.gitlab.jfronny.inceptum.imgui.GuiMain;
2022-09-04 21:21:24 +02:00
import io.gitlab.jfronny.inceptum.imgui.control.InstanceManageControls;
2022-09-19 21:26:23 +02:00
import io.gitlab.jfronny.inceptum.imgui.window.dialog.ProcessStateWatcherWindow;
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv;
import io.gitlab.jfronny.inceptum.launcher.system.importer.Importers;
2022-10-27 20:54:55 +02:00
import io.gitlab.jfronny.inceptum.launcher.system.setup.SetupStepInfo;
import io.gitlab.jfronny.inceptum.launcher.system.setup.Steps;
2022-09-19 21:26:23 +02:00
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState;
2021-10-27 22:00:08 +02:00
import java.io.IOException;
2022-09-19 21:26:23 +02:00
import java.nio.file.Path;
import java.util.List;
2021-10-27 22:00:08 +02:00
public class NewInstanceWindow extends Window {
private final InstanceManageControls imc = new InstanceManageControls(null);
2022-09-04 21:21:24 +02:00
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();
2022-09-04 21:21:24 +02:00
imc.versionBox(R::nop);
2022-01-18 19:22:26 +01:00
imc.nameBox("OK", name -> {
try {
GuiUtil.createInstance(new SetupStepInfo(imc.getVersionInfo(),
imc.loaderInfo,
2022-01-18 19:22:26 +01:00
name,
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-27 17:05:32 +01:00
if (ImGui.beginTabItem("Import")) {
ImGui.text("You can also just add an instance directory and it'll be loaded automatically");
ImGui.text("Using git to manage it is recommended if you do so");
ImGui.spacing();
2022-09-19 21:26:23 +02:00
ImGui.text("Below, you can import a CurseForge, Modrinth or MultiMC pack");
if (ImGui.button("Import")) {
List<Path> packs = GuiMain.openFileDialog("Import Pack", null, new String[]{"*.zip", "*.mrpack"}, "Modpack", true);
2022-09-19 21:26:23 +02:00
if (!packs.isEmpty()) {
ProcessState state = new ProcessState(Importers.MAX_STEPS * packs.size(), "Initializing");
GuiMain.open(new ProcessStateWatcherWindow("Importing", "Could not import packs", state, cToken -> {
for (Path pack : packs) {
Path imported = Importers.importPack(pack, state);
LauncherEnv.showInfo(pack.fileName + " has been successfully imported as " + imported.fileName, "Imported pack");
2022-09-19 21:26:23 +02:00
}
}, null));
}
}
2022-01-18 19:22:26 +01:00
ImGui.endTabItem();
}
ImGui.endTabBar();
}
2021-10-27 22:00:08 +02:00
}
}