package io.gitlab.jfronny.inceptum.frontend.gui.control; import imgui.ImGui; import imgui.flag.ImGuiTableFlags; import io.gitlab.jfronny.inceptum.InceptumGui; import io.gitlab.jfronny.inceptum.util.install.Steps; import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta; import io.gitlab.jfronny.inceptum.util.InstanceLock; import io.gitlab.jfronny.inceptum.util.Utils; import io.gitlab.jfronny.inceptum.frontend.gui.window.edit.InstanceEditWindow; import io.gitlab.jfronny.inceptum.util.InstanceLauncher; 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 paths) { if (ImGui.beginTable("Instances", 2, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Borders)) { for (Path path : paths) { if (InstanceLock.isSetupLocked(path)) { 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); continue; } InstanceMeta instance; try { instance = Utils.loadObject(path.resolve("instance.json"), InstanceMeta.class); //TODO investigate the perf impact of this } catch (IOException e) { Utils.LOGGER.error("Could not load instance.json", e); continue; } ImGui.tableNextColumn(); boolean runDisabled = false; try { if (InstanceLock.isRunningLocked(path)) runDisabled = true; } catch (IOException e) { continue; } if (runDisabled) ImGui.beginDisabled(); if (ImGui.button(path.getFileName().toString())) { try { Steps.reDownload(path, Steps.createProcessState()); } catch (IOException e) { e.printStackTrace(); } InstanceLauncher.launchClient(path, instance); } if (runDisabled) ImGui.endDisabled(); ImGui.tableNextColumn(); if (ImGui.button("Edit##" + path)) InceptumGui.open(new InstanceEditWindow(path, instance)); } ImGui.endTable(); } } }