Inceptum/src/main/java/io/gitlab/jfronny/inceptum/windows/InstanceEditWindow.java

108 lines
3.9 KiB
Java
Raw Normal View History

2021-10-30 16:12:39 +02:00
package io.gitlab.jfronny.inceptum.windows;
import imgui.ImGui;
2021-10-30 19:26:59 +02:00
import imgui.type.ImBoolean;
2021-10-30 16:12:39 +02:00
import imgui.type.ImString;
import io.gitlab.jfronny.inceptum.Inceptum;
2021-10-30 22:05:24 +02:00
import io.gitlab.jfronny.inceptum.InceptumGui;
import io.gitlab.jfronny.inceptum.install.Steps;
2021-10-30 16:12:39 +02:00
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.util.JvmUtils;
2021-10-30 16:12:39 +02:00
import io.gitlab.jfronny.inceptum.util.Utils;
2021-10-30 19:26:59 +02:00
import io.gitlab.jfronny.inceptum.windows.control.InstanceManageControls;
2021-10-30 16:12:39 +02:00
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;
2021-10-30 22:05:24 +02:00
private final InstanceManageControls imc;
2021-10-30 19:26:59 +02:00
private final ImBoolean customJava;
private final ImString customJavaPath = new ImString(128);
2021-10-30 22:05:24 +02:00
private boolean reDownload = false;
2021-10-30 16:12:39 +02:00
public InstanceEditWindow(Path path, InstanceMeta instance) {
super("Edit " + path.getFileName().toString());
this.path = path;
this.instance = instance;
2021-10-30 19:26:59 +02:00
customJava = new ImBoolean(instance.java != null);
2021-10-30 22:05:24 +02:00
imc = new InstanceManageControls(instance.getLoaderVersion());
2021-10-30 16:12:39 +02:00
}
@Override
public void draw() {
if (ImGui.beginTabBar("InstanceEdit" + path)) {
if (ImGui.beginTabItem("General")) {
2021-10-30 19:26:59 +02:00
imc.nameBox("Rename", name -> {
2021-10-30 16:12:39 +02:00
try {
2021-10-30 19:26:59 +02:00
Path newPath = Inceptum.INSTANCE_DIR.resolve(name);
2021-10-30 16:12:39 +02:00
Files.move(path, newPath);
2021-10-30 22:05:24 +02:00
InceptumGui.open(new InstanceEditWindow(newPath, instance));
2021-10-30 16:12:39 +02:00
close();
} catch (IOException e) {
e.printStackTrace();
}
2021-10-30 19:26:59 +02:00
});
imc.snapshotsBox();
imc.versionBox(ver -> {
2021-10-30 22:05:24 +02:00
reDownload = true;
2021-10-30 19:26:59 +02:00
instance.version = ver;
save();
});
2021-10-30 22:05:24 +02:00
if (ImGui.button("Delete")) Inceptum.showOkCancel("This instance will be removed forever (a long time)", "Are you sure?", () -> {
2021-10-30 16:12:39 +02:00
try {
Utils.deleteRecursive(path);
} catch (IOException e) {
2021-10-30 22:05:24 +02:00
Inceptum.showError("Could not delete the instance", e);
2021-10-30 16:12:39 +02:00
}
2021-10-30 22:05:24 +02:00
close();
}, () -> {});
2021-10-30 19:26:59 +02:00
if (ImGui.checkbox("Custom Java", customJava)) {
if (customJava.get()) {
instance.java = JvmUtils.getJvm();
2021-10-30 19:26:59 +02:00
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?");
2021-10-30 16:12:39 +02:00
ImGui.endTabItem();
}
if (instance.isFabric() && ImGui.beginTabItem("Mods")) {
2021-10-30 19:26:59 +02:00
//TODO implement
2021-10-30 16:12:39 +02:00
ImGui.text("Mod editing is not currently implemented");
ImGui.text("Please be patient");
ImGui.endTabItem();
}
ImGui.endTabBar();
}
}
2021-10-30 19:26:59 +02:00
private void save() {
try {
Utils.writeObject(path.resolve("instance.json"), instance);
} catch (IOException e) {
Inceptum.LOGGER.error("Could not write instance config", e);
}
}
2021-10-30 22:05:24 +02:00
@Override
public void close() {
super.close();
if (reDownload) {
try {
Steps.reDownload(path);
} catch (IOException e) {
Inceptum.showError("Could not re-download data", e);
}
}
}
2021-10-30 16:12:39 +02:00
}