package io.gitlab.jfronny.inceptum.windows; import imgui.ImGui; import imgui.flag.ImGuiWindowFlags; import imgui.type.ImBoolean; import imgui.type.ImInt; import io.gitlab.jfronny.inceptum.Inceptum; import io.gitlab.jfronny.inceptum.InceptumGui; import io.gitlab.jfronny.inceptum.install.Steps; import io.gitlab.jfronny.inceptum.util.MapAppender; import io.gitlab.jfronny.inceptum.util.Utils; 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; import io.gitlab.jfronny.inceptum.windows.control.InstanceView; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.function.Predicate; public class MainWindow extends Window { private final ImBoolean darkTheme = new ImBoolean(Inceptum.CONFIG.darkTheme); private final ImBoolean debugTools = new ImBoolean(false); private final ImInt accountIndex = new ImInt(0); public MainWindow() { super("Inceptum"); } @Override public int getFlags() { return ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.AlwaysAutoResize; } @Override public void draw() { ImGui.beginMenuBar(); if (ImGui.beginMenu("File")) { if (ImGui.menuItem("New Instance")) InceptumGui.open(new NewInstanceWindow()); if (ImGui.menuItem("Re-download resources")) { try { Utils.clearDirectory(Inceptum.ASSETS_DIR); Utils.clearDirectory(Inceptum.LIBRARIES_DIR, path -> !path.startsWith(Inceptum.LIBRARIES_DIR.resolve("io/gitlab/jfronny"))); Utils.clearDirectory(Inceptum.NATIVES_DIR, path -> !path.endsWith("forceload")); Utils.clearDirectory(Inceptum.CACHE_DIR); Steps.reDownload(); } catch (IOException e) { Inceptum.showError("Could not execute refresh task", e); } } if (ImGui.menuItem("Exit Inceptum")) InceptumGui.exit(); ImGui.endMenu(); } if (ImGui.beginMenu("Account")) { if (ImGui.menuItem("New")) InceptumGui.open(new MicrosoftLoginWindow()); AuthInfo selected = AccountManager.getSelectedAccount(); List 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); } ImGui.endMenu(); } if (ImGui.beginMenu("Settings")) { if (ImGui.checkbox("Dark Theme", darkTheme)) { Inceptum.CONFIG.darkTheme = darkTheme.get(); Inceptum.saveConfig(); InceptumGui.applyTheme(); } ImGui.endMenu(); } if (ImGui.beginMenu("Help")) { if (ImGui.menuItem("About")) InceptumGui.open(new AboutWindow()); if (ImGui.menuItem("Log")) InceptumGui.open(new LogWindow(MapAppender.LOG)); ImGui.checkbox("Debug Tools", debugTools); ImGui.endMenu(); } ImGui.endMenuBar(); if (debugTools.get()) { ImGui.showDemoWindow(); } List paths; try { if (!Files.exists(Inceptum.INSTANCE_DIR)) Files.createDirectories(Inceptum.INSTANCE_DIR); paths = Utils.ls(Inceptum.INSTANCE_DIR, (Predicate) Files::isDirectory); } catch (IOException e) { Inceptum.LOGGER.error("Could not list instances"); return; } if (paths.isEmpty()) { ImGui.text("You have not yet created an instance"); ImGui.text("Use File->New Instance to do so"); } else InstanceView.draw(paths); } }