2022-09-04 21:21:24 +02:00
|
|
|
package io.gitlab.jfronny.inceptum.imgui.window.edit;
|
2022-01-23 18:53:16 +01:00
|
|
|
|
|
|
|
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;
|
2022-01-23 18:53:16 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-01-24 19:21:23 +01:00
|
|
|
public InstanceEditWindow(Path path, InstanceMeta instance) throws IOException {
|
2022-01-23 18:53:16 +01:00
|
|
|
super(path.getFileName().toString() + " - Edit");
|
2022-01-24 19:21:23 +01:00
|
|
|
this.name = path.getFileName().toString();
|
2022-01-23 18:53:16 +01:00
|
|
|
this.path = path;
|
|
|
|
this.instance = instance;
|
2022-01-24 19:21:23 +01:00
|
|
|
this.mds = ModsDirScanner.get(path.resolve("mods"), instance);
|
|
|
|
this.mds.start();
|
2022-01-23 18:53:16 +01:00
|
|
|
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);
|
2022-01-23 18:53:16 +01:00
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
}
|