From d1ffab6058839deebc5c067105951f72c971ebcc Mon Sep 17 00:00:00 2001 From: sausage Date: Mon, 23 May 2022 15:01:55 +0800 Subject: [PATCH] Removed ServerList, fix Settings --- Client/Menus/RageCoopMenu.cs | 12 +- Client/Menus/Sub/Servers.cs | 135 ------------------ Client/Menus/Sub/SettingsMenu.cs | 5 +- .../Misc/{eTaskTypeIndex.cs => TaskType.cs} | 0 Client/Misc/Util.cs | 2 +- Client/RageCoop.Client.csproj | 3 +- Client/Sync/SyncParameters.cs | 2 +- 7 files changed, 9 insertions(+), 150 deletions(-) delete mode 100644 Client/Menus/Sub/Servers.cs rename Client/Misc/{eTaskTypeIndex.cs => TaskType.cs} (100%) diff --git a/Client/Menus/RageCoopMenu.cs b/Client/Menus/RageCoopMenu.cs index bd5fa88..4a2fde6 100644 --- a/Client/Menus/RageCoopMenu.cs +++ b/Client/Menus/RageCoopMenu.cs @@ -21,7 +21,6 @@ namespace RageCoop.Client.Menus }; #region SUB public Sub.SettingsMenu SubSettings = new Sub.SettingsMenu(); - public Sub.Servers ServerList = new Sub.Servers(); #endregion #region ITEMS @@ -48,7 +47,6 @@ namespace RageCoop.Client.Menus ServerIpItem.Activated += ServerIpActivated; _serverConnectItem.Activated += (sender, item) => { Main.MainNetworking.DisConnectFromServer(Main.Settings.LastServerAddress); }; - MainMenu.AddSubMenu(ServerList.MainMenu); MainMenu.Add(_usernameItem); MainMenu.Add(ServerIpItem); @@ -58,7 +56,6 @@ namespace RageCoop.Client.Menus MainMenu.AddSubMenu(DebugMenu.MainMenu); MainMenu.Add(_aboutItem); - MenuPool.Add(ServerList.MainMenu); MenuPool.Add(MainMenu); MenuPool.Add(SubSettings.MainMenu); MenuPool.Add(DebugMenu.MainMenu); @@ -94,17 +91,15 @@ namespace RageCoop.Client.Menus MainMenu.Items[0].Enabled = false; MainMenu.Items[1].Enabled = false; MainMenu.Items[2].Enabled = false; - MainMenu.Items[3].Enabled = false; } public void ConnectedMenuSetting() { - MainMenu.Items[3].Enabled = true; - MainMenu.Items[3].Title = "Disconnect"; + MainMenu.Items[2].Enabled = true; + MainMenu.Items[2].Title = "Disconnect"; SubSettings.MainMenu.Items[1].Enabled = !Main.DisableTraffic && Main.NPCsAllowed; MainMenu.Visible = false; - ServerList.MainMenu.Visible = false; } public void DisconnectedMenuSetting() @@ -112,8 +107,7 @@ namespace RageCoop.Client.Menus MainMenu.Items[0].Enabled = true; MainMenu.Items[1].Enabled = true; MainMenu.Items[2].Enabled = true; - MainMenu.Items[3].Enabled = true; - MainMenu.Items[3].Title = "Connect"; + MainMenu.Items[2].Title = "Connect"; SubSettings.MainMenu.Items[1].Enabled = false; } } diff --git a/Client/Menus/Sub/Servers.cs b/Client/Menus/Sub/Servers.cs deleted file mode 100644 index d4e6c64..0000000 --- a/Client/Menus/Sub/Servers.cs +++ /dev/null @@ -1,135 +0,0 @@ -using System; -using System.Net; -using System.Drawing; -using System.Collections.Generic; - -using Newtonsoft.Json; - -using LemonUI.Menus; - -namespace RageCoop.Client.Menus.Sub -{ - public class ServerListClass - { - [JsonProperty("address")] - public string Address { get; set; } - [JsonProperty("port")] - public string Port { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("version")] - public string Version { get; set; } - [JsonProperty("players")] - public int Players { get; set; } - [JsonProperty("maxPlayers")] - public int MaxPlayers { get; set; } - [JsonProperty("allowlist")] - public bool AllowList { get; set; } - [JsonProperty("mods")] - public bool Mods { get; set; } - [JsonProperty("npcs")] - public bool NPCs { get; set; } - [JsonProperty("country")] - public string Country { get; set; } - } - - /// - /// Don't use it! - /// - public class Servers - { - public NativeMenu MainMenu = new NativeMenu("RAGECOOP", "Servers", "Go to the server list") - { - UseMouse = false, - Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left - }; - public NativeItem ResultItem = null; - - /// - /// Don't use it! - /// - public Servers() - { - MainMenu.Banner.Color = Color.FromArgb(225, 0, 0, 0); - MainMenu.Title.Color = Color.FromArgb(255, 165, 0); - - MainMenu.Opening += (object sender, System.ComponentModel.CancelEventArgs e) => - { - MainMenu.Add(ResultItem = new NativeItem("Loading...")); - GetAllServer(); - }; - MainMenu.Closing += (object sender, System.ComponentModel.CancelEventArgs e) => - { - CleanUpList(); - }; - } - - private void CleanUpList() - { - MainMenu.Clear(); - ResultItem = null; - } - - private void GetAllServer() - { - List serverList = null; - try - { - // TLS only - ServicePointManager.Expect100Continue = true; - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12; - ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; - - WebClient client = new WebClient(); - string data = client.DownloadString(Main.Settings.MasterServer); - serverList = JsonConvert.DeserializeObject>(data); - } - catch (Exception ex) - { - ResultItem.Title = "Download failed!"; - ResultItem.Description = ex.Message; - return; - } - - if (serverList == null) - { - ResultItem.Title = "Something went wrong!"; - return; - } - if (serverList.Count == 0) - { - ResultItem.Title = "No server was found!"; - return; - } - - CleanUpList(); - - foreach (ServerListClass server in serverList) - { - string address = $"{server.Address}:{server.Port}"; - NativeItem tmpItem = new NativeItem($"[{server.Country}] {server.Name}", $"~b~{address}~s~~n~~g~Version {server.Version}.x~s~~n~Mods = {server.Mods}~n~NPCs = {server.NPCs}") { AltTitle = $"[{server.Players}/{server.MaxPlayers}][{(server.AllowList ? "~r~X~s~" : "~g~O~s~")}]" }; - tmpItem.Activated += (object sender, EventArgs e) => - { - try - { - MainMenu.Visible = false; - - Main.MainNetworking.DisConnectFromServer(address); -#if !NON_INTERACTIVE - Main.MainMenu.ServerIpItem.AltTitle = address; - - Main.MainMenu.MainMenu.Visible = true; -#endif - Main.Settings.LastServerAddress = address; - Util.SaveSettings(); - } - catch (Exception ex) - { - GTA.UI.Notification.Show($"~r~{ex.Message}"); - } - }; - MainMenu.Add(tmpItem); - } - } - } -} diff --git a/Client/Menus/Sub/SettingsMenu.cs b/Client/Menus/Sub/SettingsMenu.cs index 06ec5dc..da24022 100644 --- a/Client/Menus/Sub/SettingsMenu.cs +++ b/Client/Menus/Sub/SettingsMenu.cs @@ -53,6 +53,7 @@ namespace RageCoop.Client.Menus.Sub Game.GetUserInput(WindowTitle.EnterMessage20, Main.Settings.MenuKey.ToString(), 20)); _menuKey.AltTitle=Main.Settings.MenuKey.ToString(); + Util.SaveSettings(); } catch { } } @@ -66,6 +67,8 @@ namespace RageCoop.Client.Menus.Sub Game.GetUserInput(WindowTitle.EnterMessage20, Main.Settings.PassengerKey.ToString(), 20)); _passengerKey.AltTitle=Main.Settings.PassengerKey.ToString(); + Util.SaveSettings(); + } catch { } } @@ -80,8 +83,6 @@ namespace RageCoop.Client.Menus.Sub Main.MainMenu.MainMenu.Alignment = _flipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left; MainMenu.Alignment = _flipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left; - Main.MainMenu.ServerList.MainMenu.Alignment = _flipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left; - Main.Settings.FlipMenu = _flipMenuItem.Checked; Util.SaveSettings(); } diff --git a/Client/Misc/eTaskTypeIndex.cs b/Client/Misc/TaskType.cs similarity index 100% rename from Client/Misc/eTaskTypeIndex.cs rename to Client/Misc/TaskType.cs diff --git a/Client/Misc/Util.cs b/Client/Misc/Util.cs index e5915c8..cf0fb63 100644 --- a/Client/Misc/Util.cs +++ b/Client/Misc/Util.cs @@ -89,7 +89,7 @@ namespace RageCoop.Client { try { - string path = Directory.GetCurrentDirectory() + "\\scripts\\CoopSettings.xml"; + string path = Directory.GetCurrentDirectory() + "\\Scripts\\RageCoop\\Settings.xml"; using (FileStream stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite)) { diff --git a/Client/RageCoop.Client.csproj b/Client/RageCoop.Client.csproj index 44693ae..0aeac7a 100644 --- a/Client/RageCoop.Client.csproj +++ b/Client/RageCoop.Client.csproj @@ -124,7 +124,7 @@ - + @@ -138,7 +138,6 @@ - diff --git a/Client/Sync/SyncParameters.cs b/Client/Sync/SyncParameters.cs index 9fe9146..1a1b036 100644 --- a/Client/Sync/SyncParameters.cs +++ b/Client/Sync/SyncParameters.cs @@ -8,6 +8,6 @@ namespace RageCoop.Client { internal class SyncParameters { - public static float PositioinPrediction = 0.06f; + public static float PositioinPrediction = 0.03f; } }