Split windows from main class
This commit is contained in:
parent
e3b3e50bd2
commit
62dd7da114
|
@ -2,32 +2,17 @@ package io.gitlab.jfronny.inceptum.gtk;
|
|||
|
||||
import ch.bailu.gtk.GTK;
|
||||
import ch.bailu.gtk.gio.ApplicationFlags;
|
||||
import ch.bailu.gtk.gio.Menu;
|
||||
import ch.bailu.gtk.gtk.*;
|
||||
import ch.bailu.gtk.gtk.Application;
|
||||
import ch.bailu.gtk.type.Str;
|
||||
import ch.bailu.gtk.type.Strs;
|
||||
import io.gitlab.jfronny.inceptum.common.*;
|
||||
import io.gitlab.jfronny.inceptum.gtk.menu.MenuBuilder;
|
||||
import io.gitlab.jfronny.inceptum.gtk.util.I18n;
|
||||
import io.gitlab.jfronny.inceptum.gtk.window.MainWindow;
|
||||
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv;
|
||||
import io.gitlab.jfronny.inceptum.launcher.api.account.*;
|
||||
import io.gitlab.jfronny.inceptum.launcher.util.InstanceList;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.install.Steps;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.launch.InstanceLauncher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
|
||||
public class GtkMain {
|
||||
public static final Str ID = new Str("io.gitlab.jfronny.inceptum");
|
||||
public static final Str TITLE = new Str("Inceptum");
|
||||
public static final int WIDTH = 720 / 2;
|
||||
public static final int HEIGHT = 1440 / 2;
|
||||
private static MenuBuilder launchMenu;
|
||||
private static MenuBuilder accountsMenu;
|
||||
private static Button listButton;
|
||||
private static Button gridButton;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
LauncherEnv.initialize(GtkEnvBackend.INSTANCE);
|
||||
|
@ -46,72 +31,8 @@ public class GtkMain {
|
|||
public static int showGui(String[] args) throws IOException {
|
||||
var app = new Application(ID, ApplicationFlags.FLAGS_NONE);
|
||||
app.onActivate(() -> {
|
||||
var menu = new MenuBuilder(app);
|
||||
var file = menu.submenu("file");
|
||||
file.button("new", GtkMain::showNewInstanceDialog);
|
||||
file.button("redownload", () -> {
|
||||
//TODO
|
||||
});
|
||||
file.button("exit", app::quit);
|
||||
launchMenu = menu.submenu("launch");
|
||||
generateLaunchMenu();
|
||||
accountsMenu = menu.submenu("account");
|
||||
generateAccountsMenu();
|
||||
var help = menu.submenu("help");
|
||||
help.button("about", GtkMain::showAboutDialog);
|
||||
help.button("log", () -> {
|
||||
//TODO
|
||||
});
|
||||
|
||||
var header = new HeaderBar();
|
||||
var newButton = new Button();
|
||||
newButton.setIconName(new Str("list-add-symbolic"));
|
||||
newButton.onClicked(GtkMain::showNewInstanceDialog);
|
||||
|
||||
var accountsButton = new MenuButton();
|
||||
accountsButton.setIconName(new Str("avatar-default-symbolic"));
|
||||
accountsButton.setPopover(accountsMenu.asPopover());
|
||||
|
||||
listButton = new Button();
|
||||
listButton.setIconName(new Str("view-list-symbolic"));
|
||||
listButton.onClicked(() -> {
|
||||
InceptumConfig.listView = true;
|
||||
InceptumConfig.saveConfig();
|
||||
generateWindowBody();
|
||||
});
|
||||
|
||||
gridButton = new Button();
|
||||
gridButton.setIconName(new Str("view-grid-symbolic"));
|
||||
gridButton.onClicked(() -> {
|
||||
InceptumConfig.listView = false;
|
||||
InceptumConfig.saveConfig();
|
||||
generateWindowBody();
|
||||
});
|
||||
|
||||
var uiMenu = new MenuBuilder(app, new Menu(), "hamburger");
|
||||
uiMenu.button("support", () -> Utils.openWebBrowser(new URI("https://gitlab.com/jfmods/inceptum/-/issues")));
|
||||
uiMenu.button("preferences", () -> {}); //TODO preferences UI inspired by boxes
|
||||
uiMenu.button("about", GtkMain::showAboutDialog);
|
||||
var menuButton = new MenuButton();
|
||||
menuButton.setIconName(new Str("open-menu-symbolic"));
|
||||
menuButton.setPopover(uiMenu.asPopover());
|
||||
|
||||
header.packStart(newButton);
|
||||
|
||||
header.packEnd(menuButton);
|
||||
header.packEnd(gridButton);
|
||||
header.packEnd(listButton);
|
||||
header.packEnd(accountsButton);
|
||||
|
||||
var window = new ApplicationWindow(app);
|
||||
window.setDefaultSize(WIDTH, HEIGHT);
|
||||
window.setTitle(TITLE);
|
||||
window.setTitlebar(header);
|
||||
window.setShowMenubar(GTK.FALSE);
|
||||
window.setChild(new TextView());
|
||||
|
||||
generateWindowBody();
|
||||
|
||||
GtkMenubar.create(app);
|
||||
var window = new MainWindow(app);
|
||||
window.show();
|
||||
GtkEnvBackend.INSTANCE.dialogParent = window;
|
||||
window.onCloseRequest(() -> {
|
||||
|
@ -121,70 +42,4 @@ public class GtkMain {
|
|||
});
|
||||
return app.run(args.length, new Strs(args));
|
||||
}
|
||||
|
||||
private static void generateWindowBody() {
|
||||
if (listButton != null) listButton.setVisible(GTK.is(!InceptumConfig.listView));
|
||||
if (gridButton != null) gridButton.setVisible(GTK.is(InceptumConfig.listView));
|
||||
//TODO create list/grid view
|
||||
}
|
||||
|
||||
private static void showAboutDialog() {
|
||||
AboutDialog dialog = new AboutDialog();
|
||||
dialog.setProgramName(new Str("Inceptum"));
|
||||
dialog.setCopyright(new Str("Copyright (C) 2021 JFronny"));
|
||||
dialog.setVersion(new Str(BuildMetadata.VERSION.toString()));
|
||||
dialog.setLicenseType(License.MIT_X11);
|
||||
dialog.setLicense(I18n.str("about.license"));
|
||||
dialog.setWebsiteLabel(I18n.str("about.contact"));
|
||||
dialog.setWebsite(new Str("https://jfronny.gitlab.io/contact.html"));
|
||||
if (!BuildMetadata.IS_PUBLIC) {
|
||||
dialog.setComments(I18n.str("about.unsupported-build"));
|
||||
}
|
||||
int vm = Runtime.version().feature();
|
||||
dialog.setSystemInformation(I18n.str(BuildMetadata.VM_VERSION == vm ? "about.jvm" : "about.jvm.unsupported", vm));
|
||||
//TODO setLogo
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private static void showNewInstanceDialog() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
private static void generateLaunchMenu() {
|
||||
Objects.requireNonNull(launchMenu);
|
||||
launchMenu.clear();
|
||||
try {
|
||||
InstanceList.forEachLaunchable(entry -> {
|
||||
Utils.LOGGER.info("Entry " + entry.toString());
|
||||
launchMenu.literalButton(entry.id(), entry.toString(), () -> {
|
||||
try {
|
||||
Steps.reDownload(entry.path(), Steps.createProcessState());
|
||||
} catch (IOException e) {
|
||||
Utils.LOGGER.error("Could not redownload instance, trying to start anyways", e);
|
||||
}
|
||||
InstanceLauncher.launchClient(entry.path(), entry.meta());
|
||||
//TODO figure out why this crashes
|
||||
});
|
||||
});
|
||||
} catch (IOException e) {
|
||||
Utils.LOGGER.error("Could not generate launch menu", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateAccountsMenu() {
|
||||
Objects.requireNonNull(accountsMenu);
|
||||
accountsMenu.clear();
|
||||
accountsMenu.button("new", () -> {
|
||||
//TODO
|
||||
});
|
||||
accountsMenu.button("manage", () -> {
|
||||
//TODO UI to add/remove accounts
|
||||
});
|
||||
List<MicrosoftAccount> accounts = new ArrayList<>(AccountManager.getAccounts());
|
||||
accounts.add(null);
|
||||
accountsMenu.literalRadio("account", accounts.get(AccountManager.getSelectedIndex()), accounts, (i, acc) -> {
|
||||
if (acc == null) return I18n.get("account.none");
|
||||
return acc.minecraftUsername;
|
||||
}, AccountManager::switchAccount);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package io.gitlab.jfronny.inceptum.gtk;
|
||||
|
||||
import ch.bailu.gtk.gtk.Application;
|
||||
import io.gitlab.jfronny.inceptum.common.R;
|
||||
import io.gitlab.jfronny.inceptum.common.Utils;
|
||||
import io.gitlab.jfronny.inceptum.gtk.menu.MenuBuilder;
|
||||
import io.gitlab.jfronny.inceptum.gtk.util.I18n;
|
||||
import io.gitlab.jfronny.inceptum.gtk.window.AboutWindow;
|
||||
import io.gitlab.jfronny.inceptum.gtk.window.NewInstanceWindow;
|
||||
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv;
|
||||
import io.gitlab.jfronny.inceptum.launcher.api.account.AccountManager;
|
||||
import io.gitlab.jfronny.inceptum.launcher.api.account.MicrosoftAccount;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.install.Steps;
|
||||
import io.gitlab.jfronny.inceptum.launcher.system.launch.InstanceLauncher;
|
||||
import io.gitlab.jfronny.inceptum.launcher.util.InstanceList;
|
||||
import io.gitlab.jfronny.inceptum.launcher.util.InstanceLock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class GtkMenubar {
|
||||
public static MenuBuilder accountsMenu;
|
||||
public static MenuBuilder launchMenu;
|
||||
|
||||
public static void create(Application app) {
|
||||
var menu = new MenuBuilder(app);
|
||||
var file = menu.submenu("file");
|
||||
file.button("new", NewInstanceWindow::createAndShow);
|
||||
file.button("redownload", () -> {
|
||||
//TODO
|
||||
});
|
||||
file.button("exit", app::quit);
|
||||
launchMenu = menu.submenu("launch");
|
||||
generateLaunchMenu();
|
||||
accountsMenu = menu.submenu("account");
|
||||
generateAccountsMenu();
|
||||
var help = menu.submenu("help");
|
||||
help.button("about", AboutWindow::createAndShow);
|
||||
help.button("log", () -> {
|
||||
//TODO
|
||||
});
|
||||
}
|
||||
|
||||
public static void generateLaunchMenu() {
|
||||
Objects.requireNonNull(launchMenu);
|
||||
launchMenu.clear();
|
||||
try {
|
||||
InstanceList.forEach(entry -> {
|
||||
launchMenu.literalButton(entry.id(), entry.toString(), () -> {
|
||||
Runnable launch = () -> {
|
||||
try {
|
||||
Steps.reDownload(entry.path(), Steps.createProcessState());
|
||||
} catch (IOException e) {
|
||||
Utils.LOGGER.error("Could not redownload instance, trying to start anyways", e);
|
||||
}
|
||||
InstanceLauncher.launchClient(entry.path(), entry.meta());
|
||||
};
|
||||
if (InstanceLock.isSetupLocked(entry.path())) {
|
||||
LauncherEnv.showError(I18n.get("launch.locked.setup"), I18n.get("launch.locked"));
|
||||
return;
|
||||
}
|
||||
if (InstanceLock.isRunningLocked(entry.path())) {
|
||||
LauncherEnv.showOkCancel(I18n.get("launch.locked.running"), I18n.get("launch.locked"), () -> {
|
||||
new Thread(launch).start(); //TODO loom
|
||||
}, R::nop);
|
||||
}
|
||||
new Thread(launch).start();
|
||||
});
|
||||
});
|
||||
} catch (IOException e) {
|
||||
Utils.LOGGER.error("Could not generate launch menu", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateAccountsMenu() {
|
||||
Objects.requireNonNull(accountsMenu);
|
||||
accountsMenu.clear();
|
||||
accountsMenu.button("new", () -> {
|
||||
//TODO
|
||||
});
|
||||
accountsMenu.button("manage", () -> {
|
||||
//TODO UI to add/remove accounts
|
||||
});
|
||||
List<MicrosoftAccount> accounts = new ArrayList<>(AccountManager.getAccounts());
|
||||
accounts.add(null);
|
||||
accountsMenu.literalRadio("account", accounts.get(AccountManager.getSelectedIndex()), accounts, (i, acc) -> {
|
||||
if (acc == null) return I18n.get("account.none");
|
||||
return acc.minecraftUsername;
|
||||
}, AccountManager::switchAccount);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ public class TestStart {
|
|||
|
||||
var window = new ApplicationWindow(app);
|
||||
window.setDefaultSize(200, 50);
|
||||
window.setTitle(GtkMain.TITLE);
|
||||
window.setTitle(new Str("Inceptum"));
|
||||
window.setChild(button);
|
||||
window.show();
|
||||
GtkEnvBackend.INSTANCE.dialogParent = window;
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package io.gitlab.jfronny.inceptum.gtk.window;
|
||||
|
||||
import ch.bailu.gtk.gtk.AboutDialog;
|
||||
import ch.bailu.gtk.gtk.License;
|
||||
import ch.bailu.gtk.type.Str;
|
||||
import io.gitlab.jfronny.inceptum.common.BuildMetadata;
|
||||
import io.gitlab.jfronny.inceptum.gtk.util.I18n;
|
||||
|
||||
public class AboutWindow extends AboutDialog {
|
||||
public AboutWindow() {
|
||||
setProgramName(new Str("Inceptum"));
|
||||
setCopyright(new Str("Copyright (C) 2021 JFronny"));
|
||||
setVersion(new Str(BuildMetadata.VERSION.toString()));
|
||||
setLicenseType(License.MIT_X11);
|
||||
setLicense(I18n.str("about.license"));
|
||||
setWebsiteLabel(I18n.str("about.contact"));
|
||||
setWebsite(new Str("https://jfronny.gitlab.io/contact.html"));
|
||||
if (!BuildMetadata.IS_PUBLIC) {
|
||||
setComments(I18n.str("about.unsupported-build"));
|
||||
}
|
||||
int vm = Runtime.version().feature();
|
||||
setSystemInformation(I18n.str(BuildMetadata.VM_VERSION == vm ? "about.jvm" : "about.jvm.unsupported", vm));
|
||||
//TODO setLogo
|
||||
}
|
||||
|
||||
public static void createAndShow() {
|
||||
new AboutWindow().show();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package io.gitlab.jfronny.inceptum.gtk.window;
|
||||
|
||||
import ch.bailu.gtk.GTK;
|
||||
import ch.bailu.gtk.gio.Menu;
|
||||
import ch.bailu.gtk.gtk.*;
|
||||
import ch.bailu.gtk.type.Str;
|
||||
import io.gitlab.jfronny.inceptum.common.InceptumConfig;
|
||||
import io.gitlab.jfronny.inceptum.common.Utils;
|
||||
import io.gitlab.jfronny.inceptum.gtk.GtkMenubar;
|
||||
import io.gitlab.jfronny.inceptum.gtk.menu.MenuBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class MainWindow extends ApplicationWindow {
|
||||
private final Button listButton;
|
||||
private final Button gridButton;
|
||||
|
||||
public MainWindow(Application app) {
|
||||
super(app);
|
||||
|
||||
var header = new HeaderBar();
|
||||
var newButton = new Button();
|
||||
newButton.setIconName(new Str("list-add-symbolic"));
|
||||
newButton.onClicked(NewInstanceWindow::createAndShow);
|
||||
|
||||
var accountsButton = new MenuButton();
|
||||
accountsButton.setIconName(new Str("avatar-default-symbolic"));
|
||||
accountsButton.setPopover(GtkMenubar.accountsMenu.asPopover());
|
||||
|
||||
listButton = new Button();
|
||||
listButton.setIconName(new Str("view-list-symbolic"));
|
||||
listButton.onClicked(() -> {
|
||||
InceptumConfig.listView = true;
|
||||
InceptumConfig.saveConfig();
|
||||
generateWindowBody();
|
||||
});
|
||||
|
||||
gridButton = new Button();
|
||||
gridButton.setIconName(new Str("view-grid-symbolic"));
|
||||
gridButton.onClicked(() -> {
|
||||
InceptumConfig.listView = false;
|
||||
InceptumConfig.saveConfig();
|
||||
generateWindowBody();
|
||||
});
|
||||
|
||||
var uiMenu = new MenuBuilder(app, new Menu(), "hamburger");
|
||||
uiMenu.button("support", () -> Utils.openWebBrowser(new URI("https://gitlab.com/jfmods/inceptum/-/issues")));
|
||||
uiMenu.button("preferences", () -> {}); //TODO preferences UI inspired by boxes
|
||||
uiMenu.button("about", AboutWindow::createAndShow);
|
||||
var menuButton = new MenuButton();
|
||||
menuButton.setIconName(new Str("open-menu-symbolic"));
|
||||
menuButton.setPopover(uiMenu.asPopover());
|
||||
|
||||
header.packStart(newButton);
|
||||
|
||||
header.packEnd(menuButton);
|
||||
header.packEnd(gridButton);
|
||||
header.packEnd(listButton);
|
||||
header.packEnd(accountsButton);
|
||||
|
||||
setDefaultSize(360, 720);
|
||||
setTitle(new Str("Inceptum"));
|
||||
setTitlebar(header);
|
||||
setShowMenubar(GTK.FALSE);
|
||||
setChild(new TextView());
|
||||
|
||||
generateWindowBody();
|
||||
}
|
||||
|
||||
private void generateWindowBody() {
|
||||
if (listButton != null) listButton.setVisible(GTK.is(!InceptumConfig.listView));
|
||||
if (gridButton != null) gridButton.setVisible(GTK.is(InceptumConfig.listView));
|
||||
//TODO create list/grid view
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package io.gitlab.jfronny.inceptum.gtk.window;
|
||||
|
||||
public class NewInstanceWindow {
|
||||
public static void createAndShow() {
|
||||
//TODO
|
||||
}
|
||||
}
|
|
@ -21,3 +21,9 @@ cancel=Cancel
|
|||
menu.hamburger.support=Support
|
||||
menu.hamburger.preferences=Preferences
|
||||
menu.hamburger.about=About
|
||||
launch.locked=Can't launch right now
|
||||
launch.locked.setup=This instance is currently setting up.\
|
||||
Please wait until that is finished before playing.
|
||||
launch.locked.running=This instance is currently running.\
|
||||
Click OK to start a second instance of the game.\
|
||||
Please be aware that doing so is unsupported and WILL cause issues!
|
||||
|
|
|
@ -20,3 +20,10 @@ cancel=Abbrechen
|
|||
menu.hamburger.support=Unterstützung
|
||||
menu.hamburger.preferences=Einstellungen
|
||||
menu.hamburger.about=Über
|
||||
launch.locked=Instanz kann momentan nicht gestartet werden
|
||||
launch.locked.setup=Diese Instanz wird noch eingerichtet.\
|
||||
Bitte warte, bis dieser Prozess abgeschlossen ist,\
|
||||
bevor du sie startest.
|
||||
launch.locked.running=Diese Instanz läuft bereits.\
|
||||
Bestätigen sie den Start mit OK, um sie ein zweites mal zu starten.\
|
||||
Bitte seien sie sich bewusst, dass dies zu Problemen führen wird und NICHT UNTERSÜTZT ist.
|
||||
|
|
Loading…
Reference in New Issue