From 2b7ac7c41767d00a346df1c3c75a88e0c3772ea7 Mon Sep 17 00:00:00 2001 From: Ivan Martell Date: Thu, 29 Aug 2024 14:09:58 +0900 Subject: [PATCH] Organized the project better --- .../{font => Assets}/LcdSolid-VPzB.ttf | Bin LittleWarGameClient/{font => Assets}/info.txt | 0 LittleWarGameClient/{ => Assets}/logo.ico | Bin LittleWarGameClient/{ => Assets}/soldier.png | Bin .../{ => Assets}/wolfRunning.gif | Bin LittleWarGameClient/GameForm.Designer.cs | 1 + LittleWarGameClient/GameForm.cs | 91 ++++++++++-------- LittleWarGameClient/GameForm.resx | 4 +- .../AudioHandler.cs} | 8 +- .../FontHandler.cs} | 4 +- .../{ => Handlers}/KeyboardHandler.cs | 20 ++-- .../SettingsHandler.cs} | 7 +- .../{ => Handlers}/VersionHandler.cs | 16 +-- .../{Extensions.cs => Helpers/PanelHelper.cs} | 4 +- .../{ => Helpers}/SettingsHelper.cs | 2 +- .../WebInteropHelper.cs} | 2 +- .../ContextMenuInterceptor.cs | 7 +- .../{ => Interceptors}/DownloadInterceptor.cs | 9 +- .../{ => Interceptors}/RequestInterceptor.cs | 13 +-- .../LittleWarGameClient.csproj | 4 +- LittleWarGameClient/OverlayForm.cs | 11 ++- .../Properties/Resources.Designer.cs | 10 +- LittleWarGameClient/Properties/Resources.resx | 6 +- .../Resources/LcdSolid-VPzB.ttf | Bin 0 -> 34900 bytes LittleWarGameClient/Resources/soldier.png | Bin 0 -> 12318 bytes LittleWarGameClient/Resources/wolfRunning.gif | Bin 0 -> 47660 bytes LittleWarGameClient/SplashScreen.cs | 3 +- LittleWarGameClient/js/lwg-5.0.0.js | 2 +- 28 files changed, 117 insertions(+), 107 deletions(-) rename LittleWarGameClient/{font => Assets}/LcdSolid-VPzB.ttf (100%) rename LittleWarGameClient/{font => Assets}/info.txt (100%) rename LittleWarGameClient/{ => Assets}/logo.ico (100%) rename LittleWarGameClient/{ => Assets}/soldier.png (100%) rename LittleWarGameClient/{ => Assets}/wolfRunning.gif (100%) rename LittleWarGameClient/{AudioManager.cs => Handlers/AudioHandler.cs} (96%) rename LittleWarGameClient/{FontManager.cs => Handlers/FontHandler.cs} (92%) rename LittleWarGameClient/{ => Handlers}/KeyboardHandler.cs (87%) rename LittleWarGameClient/{Settings.cs => Handlers/SettingsHandler.cs} (98%) rename LittleWarGameClient/{ => Handlers}/VersionHandler.cs (92%) rename LittleWarGameClient/{Extensions.cs => Helpers/PanelHelper.cs} (86%) rename LittleWarGameClient/{ => Helpers}/SettingsHelper.cs (99%) rename LittleWarGameClient/{WebMessage.cs => Helpers/WebInteropHelper.cs} (98%) rename LittleWarGameClient/{ => Interceptors}/ContextMenuInterceptor.cs (69%) rename LittleWarGameClient/{ => Interceptors}/DownloadInterceptor.cs (87%) rename LittleWarGameClient/{ => Interceptors}/RequestInterceptor.cs (72%) create mode 100644 LittleWarGameClient/Resources/LcdSolid-VPzB.ttf create mode 100644 LittleWarGameClient/Resources/soldier.png create mode 100644 LittleWarGameClient/Resources/wolfRunning.gif 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 @@