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;
|
|
|
|
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
|
|
|
|
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 19:26:59 +02:00
|
|
|
private final InstanceManageControls imc = new InstanceManageControls();
|
|
|
|
private final ImBoolean customJava;
|
|
|
|
private final ImString customJavaPath = new ImString(128);
|
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 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);
|
|
|
|
close();
|
|
|
|
Inceptum.open(new InstanceEditWindow(newPath, instance));
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-10-30 19:26:59 +02:00
|
|
|
});
|
|
|
|
imc.snapshotsBox();
|
|
|
|
imc.versionBox(ver -> {
|
|
|
|
instance.version = ver;
|
|
|
|
save();
|
|
|
|
});
|
2021-10-30 16:12:39 +02:00
|
|
|
if (ImGui.button("Delete")) Inceptum.open(new AlertWindow("Are you sure?", "This instance will be removed forever (a long time)", () -> {
|
|
|
|
close();
|
|
|
|
try {
|
|
|
|
Utils.deleteRecursive(path);
|
|
|
|
} catch (IOException e) {
|
|
|
|
Inceptum.LOGGER.error("Could not delete the instance", e);
|
|
|
|
Inceptum.open(new AlertWindow("Could not delete", e.toString()));
|
|
|
|
}
|
|
|
|
}, () -> {}));
|
2021-10-30 19:26:59 +02:00
|
|
|
if (ImGui.checkbox("Custom Java", customJava)) {
|
|
|
|
if (customJava.get()) {
|
|
|
|
instance.java = Utils.getJvmMain(Path.of(System.getProperty("java.home"))).toAbsolutePath().toString();
|
|
|
|
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 16:12:39 +02:00
|
|
|
}
|