Inceptum/launcher-imgui/src/main/java/io/gitlab/jfronny/inceptum/imgui/window/edit/InstanceEditWindow.java

83 lines
2.6 KiB
Java
Raw Normal View History

2022-09-04 21:21:24 +02:00
package io.gitlab.jfronny.inceptum.imgui.window.edit;
import imgui.ImGui;
2022-09-04 21:21:24 +02:00
import io.gitlab.jfronny.commons.io.JFiles;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.imgui.control.Tab;
import io.gitlab.jfronny.inceptum.imgui.window.GuiUtil;
import io.gitlab.jfronny.inceptum.imgui.window.Window;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.launcher.util.InstanceLock;
import io.gitlab.jfronny.inceptum.launcher.system.mds.ModsDirScanner;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
public class InstanceEditWindow extends Window {
protected final Path path;
protected final String name;
protected final InstanceMeta instance;
protected final ModsDirScanner mds;
private final List<Tab> tabs;
protected boolean reDownload = false;
protected boolean lastTabWasMods = false;
public InstanceEditWindow(Path path, InstanceMeta instance) throws IOException {
super(path.getFileName().toString() + " - Edit");
this.name = path.getFileName().toString();
this.path = path;
this.instance = instance;
this.mds = ModsDirScanner.get(path.resolve("mods"), instance);
this.mds.start();
this.tabs = List.of(
new GeneralTab(this),
new ArgumentsTab(this),
new ModsTab(this),
new ExportTab(this)
);
}
@Override
public void draw() {
if (InstanceLock.isSetupLocked(path)) {
ImGui.text("This instance is still being set up.");
return;
}
try {
if (InstanceLock.isRunningLocked(path)) {
ImGui.text("This instance is running. Edits in this state will result in breakage.");
}
} catch (IOException e) {
ImGui.text("Could not read lock state on this instance");
Utils.LOGGER.error("Could not read lock state", e);
}
lastTabWasMods = false;
if (ImGui.beginTabBar("InstanceEdit" + path)) {
for (Tab tab : tabs) tab.render();
ImGui.endTabBar();
}
}
protected void save() {
try {
2022-09-04 21:21:24 +02:00
JFiles.writeObject(path.resolve("instance.json"), instance);
} catch (IOException e) {
Utils.LOGGER.error("Could not write instance config", e);
}
}
@Override
public void close() {
super.close();
if (reDownload) {
GuiUtil.reload(path);
}
}
@Override
public int getFlags() {
return lastTabWasMods ? 0 : super.getFlags();
}
}