Inceptum/src/main/java/io/gitlab/jfronny/inceptum/frontend/gui/control/InstanceView.java

65 lines
2.7 KiB
Java
Raw Normal View History

package io.gitlab.jfronny.inceptum.frontend.gui.control;
2021-10-30 16:12:39 +02:00
import imgui.ImGui;
import imgui.flag.ImGuiTableFlags;
2021-10-30 22:05:24 +02:00
import io.gitlab.jfronny.inceptum.InceptumGui;
import io.gitlab.jfronny.inceptum.util.install.Steps;
2021-10-30 16:12:39 +02:00
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.util.InstanceLock;
2021-10-30 16:12:39 +02:00
import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.frontend.gui.window.edit.InstanceEditWindow;
import io.gitlab.jfronny.inceptum.util.InstanceLauncher;
2021-10-30 16:12:39 +02:00
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class InstanceView {
public static void draw(List<Path> paths) {
if (ImGui.beginTable("Instances", 2, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders)) {
for (Path path : paths) {
if (InstanceLock.isSetupLocked(path)) {
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;
}
if (!Files.exists(path.resolve("instance.json"))) {
Utils.LOGGER.error("Invalid instance (doesn't contain instance.json): " + path);
2021-10-30 16:12:39 +02:00
continue;
}
InstanceMeta instance;
try {
2022-01-24 15:04:03 +01:00
instance = Utils.loadObject(path.resolve("instance.json"), InstanceMeta.class); //TODO investigate the perf impact of this
2021-10-30 16:12:39 +02:00
} catch (IOException e) {
Utils.LOGGER.error("Could not load instance.json", e);
2021-10-30 16:12:39 +02:00
continue;
}
ImGui.tableNextColumn();
boolean runDisabled = false;
2022-01-04 12:51:51 +01:00
try {
if (InstanceLock.isRunningLocked(path))
runDisabled = true;
2022-01-04 12:51:51 +01:00
} catch (IOException e) {
continue;
2021-10-30 16:12:39 +02:00
}
if (runDisabled) ImGui.beginDisabled();
2021-11-24 19:53:06 +01:00
if (ImGui.button(path.getFileName().toString())) {
try {
Steps.reDownload(path, Steps.createProcessState());
} catch (IOException e) {
e.printStackTrace();
}
InstanceLauncher.launchClient(path, instance);
2021-11-24 19:53:06 +01:00
}
if (runDisabled) ImGui.endDisabled();
2021-10-30 16:12:39 +02:00
ImGui.tableNextColumn();
2021-10-30 22:05:24 +02:00
if (ImGui.button("Edit##" + path)) InceptumGui.open(new InstanceEditWindow(path, instance));
2021-10-30 16:12:39 +02:00
}
ImGui.endTable();
}
}
}