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

63 lines
2.5 KiB
Java
Raw Normal View History

2021-10-30 16:12:39 +02:00
package io.gitlab.jfronny.inceptum.windows;
import imgui.ImGui;
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;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
//TODO allow changing name (moving), changing version, managing mods etc
public class InstanceEditWindow extends Window {
private final Path path;
private final InstanceMeta instance;
private final ImString name;
public InstanceEditWindow(Path path, InstanceMeta instance) {
super("Edit " + path.getFileName().toString());
this.path = path;
this.instance = instance;
name = new ImString(path.getFileName().toString(), NewInstanceWindow.MAX_NAME_LENGTH);
}
@Override
public void draw() {
if (ImGui.beginTabBar("InstanceEdit" + path)) {
if (ImGui.beginTabItem("General")) {
ImGui.inputTextWithHint("Name", "Name of this instance", name);
if (!Utils.VALID_FILENAME.matcher(name.get()).matches())
ImGui.text("Invalid name");
else if (!Files.exists(Inceptum.INSTANCE_DIR.resolve(name.get())) && ImGui.button("Rename")) {
try {
Path newPath = Inceptum.INSTANCE_DIR.resolve(name.get());
Files.move(path, newPath);
close();
Inceptum.open(new InstanceEditWindow(newPath, instance));
} catch (IOException e) {
e.printStackTrace();
}
}
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()));
}
}, () -> {}));
ImGui.endTabItem();
}
if (instance.isFabric() && ImGui.beginTabItem("Mods")) {
ImGui.text("Mod editing is not currently implemented");
ImGui.text("Please be patient");
ImGui.endTabItem();
}
ImGui.endTabBar();
}
}
}