2022-09-04 21:21:24 +02:00
|
|
|
package io.gitlab.jfronny.inceptum.imgui.control;
|
2021-10-30 16:12:39 +02:00
|
|
|
|
|
|
|
import imgui.ImGui;
|
|
|
|
import imgui.flag.ImGuiTableFlags;
|
2022-09-04 21:21:24 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.common.Utils;
|
|
|
|
import io.gitlab.jfronny.inceptum.imgui.GuiMain;
|
|
|
|
import io.gitlab.jfronny.inceptum.imgui.window.edit.InstanceEditWindow;
|
2022-10-27 20:54:55 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.system.instance.InstanceList;
|
2022-11-04 17:02:24 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.system.launch.InstanceLauncher;
|
2022-10-27 20:54:55 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.system.setup.Steps;
|
2021-10-30 16:12:39 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
|
|
|
public class InstanceView {
|
2022-09-26 19:09:02 +02:00
|
|
|
public static void draw() throws IOException {
|
2022-11-18 21:58:40 +01:00
|
|
|
if (InstanceList.isEmpty) {
|
2022-09-26 19:09:02 +02:00
|
|
|
ImGui.text("You have not yet created an instance");
|
|
|
|
ImGui.text("Use File->New Instance to do so");
|
2022-11-04 17:02:24 +01:00
|
|
|
return;
|
2022-09-26 19:09:02 +02:00
|
|
|
}
|
2021-10-30 16:12:39 +02:00
|
|
|
if (ImGui.beginTable("Instances", 2, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders)) {
|
2022-11-04 17:02:24 +01:00
|
|
|
for (Instance instance : InstanceList.ordered()) {
|
2022-11-18 21:58:40 +01:00
|
|
|
if (instance.isSetupLocked) {
|
2021-10-30 16:12:39 +02:00
|
|
|
ImGui.tableNextColumn();
|
|
|
|
ImGui.text("Setting up");
|
|
|
|
ImGui.tableNextColumn();
|
|
|
|
ImGui.text("This instance is currently being set up");
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-10 21:20:01 +01:00
|
|
|
if (!Files.exists(instance.path.resolve(InstanceList.INSTANCE_CONFIG_NAME))) {
|
|
|
|
Utils.LOGGER.error("Invalid instance (doesn't contain " + InstanceList.INSTANCE_CONFIG_NAME + "): " + instance);
|
2021-10-30 16:12:39 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ImGui.tableNextColumn();
|
2022-11-18 21:58:40 +01:00
|
|
|
boolean runDisabled = instance.isRunningLocked;
|
2022-01-04 13:00:15 +01:00
|
|
|
if (runDisabled) ImGui.beginDisabled();
|
2022-10-19 21:26:06 +02:00
|
|
|
if (ImGui.button(instance.toString())) {
|
2021-11-25 17:55:50 +01:00
|
|
|
try {
|
2022-10-19 21:26:06 +02:00
|
|
|
Steps.reDownload(instance, Steps.createProcessState());
|
2021-11-25 17:55:50 +01:00
|
|
|
} catch (IOException e) {
|
2022-01-27 17:57:13 +01:00
|
|
|
Utils.LOGGER.error("Could not redownload instance, trying to start anyways", e);
|
2021-11-25 17:55:50 +01:00
|
|
|
}
|
2022-10-19 21:26:06 +02:00
|
|
|
InstanceLauncher.launchClient(instance);
|
2021-11-24 19:53:06 +01:00
|
|
|
}
|
2022-01-04 13:00:15 +01:00
|
|
|
if (runDisabled) ImGui.endDisabled();
|
2021-10-30 16:12:39 +02:00
|
|
|
ImGui.tableNextColumn();
|
2022-11-18 21:58:40 +01:00
|
|
|
if (ImGui.button("Edit##" + instance.id)) {
|
2022-01-24 19:21:23 +01:00
|
|
|
try {
|
2022-10-19 21:26:06 +02:00
|
|
|
GuiMain.open(new InstanceEditWindow(instance));
|
2022-01-24 19:21:23 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
Utils.LOGGER.error("Could not open instance edit window", e);
|
|
|
|
}
|
|
|
|
}
|
2021-10-30 16:12:39 +02:00
|
|
|
}
|
|
|
|
ImGui.endTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|