diff --git a/LittleWarGameClient/font/LcdSolid-VPzB.ttf b/LittleWarGameClient/Assets/LcdSolid-VPzB.ttf similarity index 100% rename from LittleWarGameClient/font/LcdSolid-VPzB.ttf rename to LittleWarGameClient/Assets/LcdSolid-VPzB.ttf diff --git a/LittleWarGameClient/font/info.txt b/LittleWarGameClient/Assets/info.txt similarity index 100% rename from LittleWarGameClient/font/info.txt rename to LittleWarGameClient/Assets/info.txt diff --git a/LittleWarGameClient/logo.ico b/LittleWarGameClient/Assets/logo.ico similarity index 100% rename from LittleWarGameClient/logo.ico rename to LittleWarGameClient/Assets/logo.ico diff --git a/LittleWarGameClient/soldier.png b/LittleWarGameClient/Assets/soldier.png similarity index 100% rename from LittleWarGameClient/soldier.png rename to LittleWarGameClient/Assets/soldier.png diff --git a/LittleWarGameClient/wolfRunning.gif b/LittleWarGameClient/Assets/wolfRunning.gif similarity index 100% rename from LittleWarGameClient/wolfRunning.gif rename to LittleWarGameClient/Assets/wolfRunning.gif diff --git a/LittleWarGameClient/GameForm.Designer.cs b/LittleWarGameClient/GameForm.Designer.cs index 697c54a..54c06a6 100644 --- a/LittleWarGameClient/GameForm.Designer.cs +++ b/LittleWarGameClient/GameForm.Designer.cs @@ -112,6 +112,7 @@ private void InitializeComponent() webBrowser.Name = "webBrowser"; webBrowser.Size = new Size(1264, 681); webBrowser.TabIndex = 3; + webBrowser.LoadError += webView_LoadError; webBrowser.LoadingStateChanged += webView_LoadingStateChanged; // // GameForm diff --git a/LittleWarGameClient/GameForm.cs b/LittleWarGameClient/GameForm.cs index d09aa0f..ae2225f 100644 --- a/LittleWarGameClient/GameForm.cs +++ b/LittleWarGameClient/GameForm.cs @@ -1,19 +1,8 @@ -using System.Runtime.CompilerServices; -using System.Text.Json; -using System.Text.Json.Serialization; -using System.Windows.Forms; -using System.IO; -using System.Reflection.Metadata; -using System.Reflection; -using System.Data; -using System.Diagnostics; -using NAudio.CoreAudioApi; -using nud2dlib.Windows.Forms; -using nud2dlib; using CefSharp; -using CefSharp.Handler; using CefSharp.WinForms; -using CefSharp.DevTools.Debugger; +using LittleWarGameClient.Handlers; +using LittleWarGameClient.Helpers; +using LittleWarGameClient.Interceptors; namespace LittleWarGameClient { @@ -31,12 +20,14 @@ internal static GameForm Instance } internal const string baseUrl = @"https://littlewargame.com/play"; - private readonly Settings settings; + private readonly SettingsHandler settings; private readonly KeyboardHandler kbHandler; private readonly VersionHandler vHandler; - private readonly AudioManager audioMngr; + private readonly AudioHandler audioMngr; private FormWindowState PreviousWindowState; + internal int requestCallCounter = 0; + private int requestCallWhereLoadingFinished = -1; private bool wasSmallWindow = false; private bool gameHasLoaded = false; private bool mouseLocked; @@ -45,9 +36,9 @@ internal GameForm() { PreInitWeb(); InitializeComponent(); - loadingText.Font = new Font(FontManager.lwgFont, 48F, FontStyle.Regular, GraphicsUnit.Point); - settings = new Settings(); - audioMngr = new AudioManager(Text); + loadingText.Font = new Font(FontHandler.lwgFont, 48F, FontStyle.Regular, GraphicsUnit.Point); + settings = new SettingsHandler(); + audioMngr = new AudioHandler(Text); kbHandler = new KeyboardHandler(settings); vHandler = new VersionHandler(settings); InitScreen(); @@ -195,26 +186,6 @@ private void GameForm_Load(object sender, EventArgs e) Activate(); } - private void webView_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e) - { - if (e.IsLoading) - { - InvokeUI(() => - { - loadingPanel.Visible = true; - loadingTimer.Enabled = true; - gameHasLoaded = false; - }); - } - else // has loaded - { - var addonJS = System.IO.File.ReadAllText("js/addons.js"); - webBrowser.ExecuteScriptAsync(addonJS); - ElementMessage.CallJSFunc(webBrowser, "init.function", $"\"{vHandler.CurrentVersion}\", {settings.GetMouseLock().ToString().ToLower()}, {settings.GetVolume()}"); - kbHandler.InitHotkeyNames((ChromiumWebBrowser)sender, settings); - } - } - internal void InvokeUI(Action a) { if (formInstance != null && formInstance.InvokeRequired) @@ -289,7 +260,6 @@ internal void AddonsLoadedPostLogic() ForceResizeGameWindows(); loadingPanel.Visible = false; loadingTimer.Enabled = false; - loadingText.Text = "Reconnecting"; } internal void ChangeVolume(float value) @@ -303,5 +273,46 @@ internal async void VolumeChangePostLogic(float value) settings.SetVolume(value); await settings.SaveAsync(); } + + private void webView_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e) + { + if (e.IsLoading) + { + InvokeUI(() => + { + loaderImage.Visible = true; + loadingPanel.Visible = true; + loadingText.Text = "Loading"; + loadingText.Enabled = true; + loadingTimer.Enabled = true; + gameHasLoaded = false; + }); + } + else // has loaded + { + if (requestCallWhereLoadingFinished < requestCallCounter) + { + requestCallWhereLoadingFinished = requestCallCounter; + var addonJS = System.IO.File.ReadAllText("js/addons.js"); + webBrowser.ExecuteScriptAsync(addonJS); + ElementMessage.CallJSFunc(webBrowser, "init.function", $"\"{vHandler.CurrentVersion}\", {settings.GetMouseLock().ToString().ToLower()}, {settings.GetVolume()}"); + kbHandler.InitHotkeyNames((ChromiumWebBrowser)sender, settings); + } + } + } + + private void webView_LoadError(object sender, LoadErrorEventArgs e) + { + InvokeUI(() => + { + loaderImage.Visible = false; + loadingText.Text = "ERROR"; + loadingText.Enabled = false; + loadingText.Visible = true; + loadingTimer.Enabled = false; + gameHasLoaded = false; + }); + OverlayForm.Instance.AddOverlayMessage("loadError", new Notification("Error: Website could not be loaded")); + } } } diff --git a/LittleWarGameClient/GameForm.resx b/LittleWarGameClient/GameForm.resx index 4d514b2..fc888dc 100644 --- a/LittleWarGameClient/GameForm.resx +++ b/LittleWarGameClient/GameForm.resx @@ -1,7 +1,7 @@