package io.gitlab.jfronny.inceptum.windows; import imgui.ImGui; import imgui.type.ImBoolean; import imgui.type.ImString; import io.gitlab.jfronny.inceptum.Inceptum; import io.gitlab.jfronny.inceptum.InceptumGui; import io.gitlab.jfronny.inceptum.install.Steps; import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta; import io.gitlab.jfronny.inceptum.util.JvmUtils; import io.gitlab.jfronny.inceptum.util.Utils; import io.gitlab.jfronny.inceptum.windows.control.InstanceManageControls; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; public class InstanceEditWindow extends Window { private final Path path; private final InstanceMeta instance; private final InstanceManageControls imc; private final ImBoolean customJava; private final ImString customJavaPath = new ImString(128); private boolean reDownload = false; public InstanceEditWindow(Path path, InstanceMeta instance) { super("Edit " + path.getFileName().toString()); this.path = path; this.instance = instance; customJava = new ImBoolean(instance.java != null); imc = new InstanceManageControls(instance.getLoaderVersion()); } @Override public void draw() { if (ImGui.beginTabBar("InstanceEdit" + path)) { if (ImGui.beginTabItem("General")) { imc.nameBox("Rename", name -> { try { Path newPath = Inceptum.INSTANCE_DIR.resolve(name); Files.move(path, newPath); InceptumGui.open(new InstanceEditWindow(newPath, instance)); close(); } catch (IOException e) { e.printStackTrace(); } }); imc.snapshotsBox(); imc.versionBox(ver -> { reDownload = true; instance.version = ver; save(); }); if (ImGui.button("Delete")) Inceptum.showOkCancel("This instance will be removed forever (a long time)", "Are you sure?", () -> { try { Utils.deleteRecursive(path); } catch (IOException e) { Inceptum.showError("Could not delete the instance", e); } close(); }, () -> {}); if (ImGui.checkbox("Custom Java", customJava)) { if (customJava.get()) { instance.java = JvmUtils.getJvm(); customJavaPath.set(instance.java); } else { instance.java = null; } save(); } if (customJava.get() && ImGui.inputText("Path", customJavaPath)) { instance.java = customJavaPath.get();; save(); } ImGui.text("Did you know that every instance in Inceptum is a git repository?"); ImGui.endTabItem(); } if (instance.isFabric() && ImGui.beginTabItem("Mods")) { //TODO implement ImGui.text("Mod editing is not currently implemented"); ImGui.text("Please be patient"); ImGui.endTabItem(); } ImGui.endTabBar(); } } private void save() { try { Utils.writeObject(path.resolve("instance.json"), instance); } catch (IOException e) { Inceptum.LOGGER.error("Could not write instance config", e); } } @Override public void close() { super.close(); if (reDownload) { try { Steps.reDownload(path); } catch (IOException e) { Inceptum.showError("Could not re-download data", e); } } } }