diff --git a/fluXis/FluXisGame.cs b/fluXis/FluXisGame.cs index 054ba641..7ae190d4 100644 --- a/fluXis/FluXisGame.cs +++ b/fluXis/FluXisGame.cs @@ -8,6 +8,8 @@ using fluXis.Database.Maps; using fluXis.Graphics.Background; using fluXis.Graphics.Sprites.Icons; +using fluXis.Graphics.UserInterface.Buttons; +using fluXis.Graphics.UserInterface.Buttons.Presets; using fluXis.Graphics.UserInterface.Panel; using fluXis.Graphics.UserInterface.Panel.Presets; using fluXis.Graphics.UserInterface.Panel.Types; @@ -82,6 +84,7 @@ public partial class FluXisGame : FluXisGameBase, IKeyBindingHandler overlayContainer; private Dashboard dashboard; + private LoginOverlay loginOverlay; private UserProfileOverlay userProfileOverlay; private MapSetOverlay mapSetOverlay; private Toolbar toolbar; @@ -145,8 +148,7 @@ private void load() loadComponent(new MusicPlayer(), overlayContainer.Add, true); loadComponent(new SettingsMenu(), overlayContainer.Add, true); - var login = new LoginOverlay(); - loadComponent(login, buffer.Add, true); + loadComponent(loginOverlay = new LoginOverlay(), buffer.Add, true); loadComponent(new RegisterOverlay(), buffer.Add, true); loadComponent(new MultifactorOverlay(), buffer.Add, true); @@ -163,11 +165,7 @@ private void load() loadComponent(MenuScreen = new MenuScreen()); - LoadQueue.Push(new LoadTask("Downloading server config...", c => APIClient.PullServerConfig(c, _ => - { - panelContainer.Content = new SingleButtonPanel(FontAwesome6.Solid.TriangleExclamation, "Failed to download server config!", - "Online functionality will be unavailable until you restart the game.", "Okay", () => c?.Invoke()); - }), false)); + LoadQueue.Push(new LoadTask("Downloading server config...", downloadServerConfig, false)); LoadQueue.Push(new LoadTask("Loading splashes...", c => Task.Run(() => { @@ -176,40 +174,7 @@ private void load() c(); }), false)); - LoadQueue.Push(new LoadTask("Logging in...", c => - { - if (!APIClient.CanUseOnline) - { - c(); - return; - } - - if (APIClient.HasCredentials) - _ = tryRelog(); - else - showLogin(); - - return; - - async Task tryRelog() - { - var error = await APIClient.ReLogin(); - if (error != null) showLogin(); - else cont(); - } - - void showLogin() => Schedule(() => login.Show(cont, () => - { - APIClient.DisableOnline(); - c(); - })); - - void cont() - { - APIClient.TryConnecting(); - c(); - } - }, false)); + LoadQueue.Push(new LoadTask("Logging in...", tryLogin, false)); LoadQueue.Push(new LoadTask("Checking for bundled maps...", MapStore.DownloadBundledMaps, false)); LoadQueue.Push(new LoadTask("Loading collections...", Collections.Fetch, false)); @@ -251,6 +216,59 @@ private void loadNext() LoadQueue.PerformNext(loadNext); } + private void downloadServerConfig(Action c) + { + APIClient.PullServerConfig(c, _ => + { + panelContainer.Content = new ButtonPanel + { + Icon = FontAwesome6.Solid.TriangleExclamation, + Text = "Failed to download server config!", + SubText = "Online functionality will be unavailable.", + Buttons = new[] + { + new PrimaryButtonData("Retry", () => downloadServerConfig(c)), + new ButtonData { Text = "Play offline", Action = () => c?.Invoke() } + } + }; + }); + } + + private void tryLogin(Action c) + { + if (!APIClient.CanUseOnline) + { + c(); + return; + } + + if (APIClient.HasCredentials) + _ = tryRelog(); + else + showLogin(); + + return; + + async Task tryRelog() + { + var error = await APIClient.ReLogin(); + if (error != null) showLogin(); + else cont(); + } + + void showLogin() => Schedule(() => loginOverlay.Show(cont, () => + { + APIClient.DisableOnline(); + c(); + })); + + void cont() + { + APIClient.TryConnecting(); + c(); + } + } + public void WaitForReady(Action action) { if (screenStack?.CurrentScreen is null or LoadingScreen or IntroAnimation)