2021-10-29 22:50:42 +02:00
|
|
|
package io.gitlab.jfronny.inceptum.windows;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
|
|
|
import imgui.ImGui;
|
2021-10-28 21:31:51 +02:00
|
|
|
import imgui.flag.ImGuiWindowFlags;
|
|
|
|
import imgui.type.ImBoolean;
|
2021-10-29 22:50:42 +02:00
|
|
|
import imgui.type.ImInt;
|
|
|
|
import io.gitlab.jfronny.inceptum.Inceptum;
|
2021-10-30 22:05:24 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.InceptumGui;
|
2021-10-30 16:12:39 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.install.Steps;
|
2021-10-29 22:50:42 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.util.MapAppender;
|
|
|
|
import io.gitlab.jfronny.inceptum.util.Utils;
|
2021-10-30 14:22:07 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.util.api.account.AccountManager;
|
|
|
|
import io.gitlab.jfronny.inceptum.util.api.account.AuthInfo;
|
|
|
|
import io.gitlab.jfronny.inceptum.util.api.account.MicrosoftAccount;
|
2021-10-30 16:12:39 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.windows.control.InstanceView;
|
2021-10-28 23:27:47 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.util.List;
|
2021-11-04 11:49:40 +01:00
|
|
|
import java.util.function.Predicate;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
|
|
|
public class MainWindow extends Window {
|
2021-10-29 22:50:42 +02:00
|
|
|
private final ImBoolean darkTheme = new ImBoolean(Inceptum.CONFIG.darkTheme);
|
2021-10-28 21:31:51 +02:00
|
|
|
private final ImBoolean debugTools = new ImBoolean(false);
|
2021-10-29 22:50:42 +02:00
|
|
|
private final ImInt accountIndex = new ImInt(0);
|
2021-10-27 22:00:08 +02:00
|
|
|
public MainWindow() {
|
2021-10-29 22:50:42 +02:00
|
|
|
super("Inceptum");
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
|
2021-10-28 21:31:51 +02:00
|
|
|
@Override
|
|
|
|
public int getFlags() {
|
|
|
|
return ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.AlwaysAutoResize;
|
|
|
|
}
|
|
|
|
|
2021-10-27 22:00:08 +02:00
|
|
|
@Override
|
|
|
|
public void draw() {
|
2021-10-28 21:31:51 +02:00
|
|
|
ImGui.beginMenuBar();
|
|
|
|
if (ImGui.beginMenu("File")) {
|
2021-10-30 22:05:24 +02:00
|
|
|
if (ImGui.menuItem("New Instance")) InceptumGui.open(new NewInstanceWindow());
|
2021-10-30 16:12:39 +02:00
|
|
|
if (ImGui.menuItem("Re-download resources")) {
|
|
|
|
try {
|
2021-10-30 19:26:59 +02:00
|
|
|
Utils.clearDirectory(Inceptum.ASSETS_DIR);
|
|
|
|
Utils.clearDirectory(Inceptum.LIBRARIES_DIR);
|
2021-11-11 20:11:20 +01:00
|
|
|
Utils.clearDirectory(Inceptum.NATIVES_DIR, path -> !path.endsWith("forceload"));
|
2021-10-30 19:26:59 +02:00
|
|
|
Utils.clearDirectory(Inceptum.CACHE_DIR);
|
2021-10-30 22:05:24 +02:00
|
|
|
Steps.reDownload();
|
2021-10-30 16:12:39 +02:00
|
|
|
} catch (IOException e) {
|
2021-10-30 22:05:24 +02:00
|
|
|
Inceptum.showError("Could not execute refresh task", e);
|
2021-10-30 16:12:39 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-30 22:05:24 +02:00
|
|
|
if (ImGui.menuItem("Exit Inceptum")) InceptumGui.exit();
|
2021-10-29 22:50:42 +02:00
|
|
|
ImGui.endMenu();
|
|
|
|
}
|
|
|
|
if (ImGui.beginMenu("Account")) {
|
2021-10-30 22:05:24 +02:00
|
|
|
if (ImGui.menuItem("New")) InceptumGui.open(new MicrosoftLoginWindow());
|
2021-10-29 22:50:42 +02:00
|
|
|
AuthInfo selected = AccountManager.getSelectedAccount();
|
|
|
|
List<MicrosoftAccount> accounts = AccountManager.getAccounts();
|
|
|
|
for (int i = 0, accountsSize = accounts.size(); i < accountsSize; i++) {
|
|
|
|
MicrosoftAccount account = accounts.get(i);
|
|
|
|
if (selected.equals(account)) accountIndex.set(i);
|
|
|
|
if (ImGui.radioButton(account.minecraftUsername, accountIndex, i)) {
|
|
|
|
AccountManager.switchAccount(account);
|
|
|
|
}
|
|
|
|
ImGui.sameLine();
|
|
|
|
if (ImGui.button("X")) AccountManager.removeAccount(account);
|
|
|
|
}
|
2021-10-28 21:31:51 +02:00
|
|
|
ImGui.endMenu();
|
|
|
|
}
|
|
|
|
if (ImGui.beginMenu("Settings")) {
|
|
|
|
if (ImGui.checkbox("Dark Theme", darkTheme)) {
|
2021-10-29 22:50:42 +02:00
|
|
|
Inceptum.CONFIG.darkTheme = darkTheme.get();
|
|
|
|
Inceptum.saveConfig();
|
2021-10-30 22:05:24 +02:00
|
|
|
InceptumGui.applyTheme();
|
2021-10-28 21:31:51 +02:00
|
|
|
}
|
|
|
|
ImGui.endMenu();
|
|
|
|
}
|
|
|
|
if (ImGui.beginMenu("Help")) {
|
2021-10-30 22:05:24 +02:00
|
|
|
if (ImGui.menuItem("About")) InceptumGui.open(new AboutWindow());
|
|
|
|
if (ImGui.menuItem("Log")) InceptumGui.open(new LogWindow(MapAppender.LOG));
|
2021-10-28 21:31:51 +02:00
|
|
|
ImGui.checkbox("Debug Tools", debugTools);
|
|
|
|
ImGui.endMenu();
|
|
|
|
}
|
|
|
|
ImGui.endMenuBar();
|
|
|
|
|
|
|
|
if (debugTools.get()) {
|
|
|
|
ImGui.showDemoWindow();
|
|
|
|
}
|
|
|
|
|
2021-10-30 14:22:07 +02:00
|
|
|
List<Path> paths;
|
|
|
|
try {
|
2021-10-30 19:26:59 +02:00
|
|
|
if (!Files.exists(Inceptum.INSTANCE_DIR)) Files.createDirectories(Inceptum.INSTANCE_DIR);
|
2021-11-04 11:49:40 +01:00
|
|
|
paths = Utils.ls(Inceptum.INSTANCE_DIR, (Predicate<Path>) Files::isDirectory);
|
2021-10-30 14:22:07 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
Inceptum.LOGGER.error("Could not list instances");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (paths.isEmpty()) {
|
2021-10-28 23:27:47 +02:00
|
|
|
ImGui.text("You have not yet created an instance");
|
|
|
|
ImGui.text("Use File->New Instance to do so");
|
|
|
|
}
|
2021-10-30 16:12:39 +02:00
|
|
|
else InstanceView.draw(paths);
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
}
|