Removed ServerList, fix Settings

This commit is contained in:
sausage
2022-05-23 15:01:55 +08:00
parent 1d5b83bf56
commit d1ffab6058
7 changed files with 9 additions and 150 deletions

View File

@ -21,7 +21,6 @@ namespace RageCoop.Client.Menus
}; };
#region SUB #region SUB
public Sub.SettingsMenu SubSettings = new Sub.SettingsMenu(); public Sub.SettingsMenu SubSettings = new Sub.SettingsMenu();
public Sub.Servers ServerList = new Sub.Servers();
#endregion #endregion
#region ITEMS #region ITEMS
@ -48,7 +47,6 @@ namespace RageCoop.Client.Menus
ServerIpItem.Activated += ServerIpActivated; ServerIpItem.Activated += ServerIpActivated;
_serverConnectItem.Activated += (sender, item) => { Main.MainNetworking.DisConnectFromServer(Main.Settings.LastServerAddress); }; _serverConnectItem.Activated += (sender, item) => { Main.MainNetworking.DisConnectFromServer(Main.Settings.LastServerAddress); };
MainMenu.AddSubMenu(ServerList.MainMenu);
MainMenu.Add(_usernameItem); MainMenu.Add(_usernameItem);
MainMenu.Add(ServerIpItem); MainMenu.Add(ServerIpItem);
@ -58,7 +56,6 @@ namespace RageCoop.Client.Menus
MainMenu.AddSubMenu(DebugMenu.MainMenu); MainMenu.AddSubMenu(DebugMenu.MainMenu);
MainMenu.Add(_aboutItem); MainMenu.Add(_aboutItem);
MenuPool.Add(ServerList.MainMenu);
MenuPool.Add(MainMenu); MenuPool.Add(MainMenu);
MenuPool.Add(SubSettings.MainMenu); MenuPool.Add(SubSettings.MainMenu);
MenuPool.Add(DebugMenu.MainMenu); MenuPool.Add(DebugMenu.MainMenu);
@ -94,17 +91,15 @@ namespace RageCoop.Client.Menus
MainMenu.Items[0].Enabled = false; MainMenu.Items[0].Enabled = false;
MainMenu.Items[1].Enabled = false; MainMenu.Items[1].Enabled = false;
MainMenu.Items[2].Enabled = false; MainMenu.Items[2].Enabled = false;
MainMenu.Items[3].Enabled = false;
} }
public void ConnectedMenuSetting() public void ConnectedMenuSetting()
{ {
MainMenu.Items[3].Enabled = true; MainMenu.Items[2].Enabled = true;
MainMenu.Items[3].Title = "Disconnect"; MainMenu.Items[2].Title = "Disconnect";
SubSettings.MainMenu.Items[1].Enabled = !Main.DisableTraffic && Main.NPCsAllowed; SubSettings.MainMenu.Items[1].Enabled = !Main.DisableTraffic && Main.NPCsAllowed;
MainMenu.Visible = false; MainMenu.Visible = false;
ServerList.MainMenu.Visible = false;
} }
public void DisconnectedMenuSetting() public void DisconnectedMenuSetting()
@ -112,8 +107,7 @@ namespace RageCoop.Client.Menus
MainMenu.Items[0].Enabled = true; MainMenu.Items[0].Enabled = true;
MainMenu.Items[1].Enabled = true; MainMenu.Items[1].Enabled = true;
MainMenu.Items[2].Enabled = true; MainMenu.Items[2].Enabled = true;
MainMenu.Items[3].Enabled = true; MainMenu.Items[2].Title = "Connect";
MainMenu.Items[3].Title = "Connect";
SubSettings.MainMenu.Items[1].Enabled = false; SubSettings.MainMenu.Items[1].Enabled = false;
} }
} }

View File

@ -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; }
}
/// <summary>
/// Don't use it!
/// </summary>
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;
/// <summary>
/// Don't use it!
/// </summary>
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<ServerListClass> 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<List<ServerListClass>>(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);
}
}
}
}

View File

@ -53,6 +53,7 @@ namespace RageCoop.Client.Menus.Sub
Game.GetUserInput(WindowTitle.EnterMessage20, Game.GetUserInput(WindowTitle.EnterMessage20,
Main.Settings.MenuKey.ToString(), 20)); Main.Settings.MenuKey.ToString(), 20));
_menuKey.AltTitle=Main.Settings.MenuKey.ToString(); _menuKey.AltTitle=Main.Settings.MenuKey.ToString();
Util.SaveSettings();
} }
catch { } catch { }
} }
@ -66,6 +67,8 @@ namespace RageCoop.Client.Menus.Sub
Game.GetUserInput(WindowTitle.EnterMessage20, Game.GetUserInput(WindowTitle.EnterMessage20,
Main.Settings.PassengerKey.ToString(), 20)); Main.Settings.PassengerKey.ToString(), 20));
_passengerKey.AltTitle=Main.Settings.PassengerKey.ToString(); _passengerKey.AltTitle=Main.Settings.PassengerKey.ToString();
Util.SaveSettings();
} }
catch { } catch { }
} }
@ -80,8 +83,6 @@ namespace RageCoop.Client.Menus.Sub
Main.MainMenu.MainMenu.Alignment = _flipMenuItem.Checked ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left; 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; 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; Main.Settings.FlipMenu = _flipMenuItem.Checked;
Util.SaveSettings(); Util.SaveSettings();
} }

View File

@ -89,7 +89,7 @@ namespace RageCoop.Client
{ {
try 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)) using (FileStream stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite))
{ {

View File

@ -124,7 +124,7 @@
<Compile Include="COOPAPI.cs" /> <Compile Include="COOPAPI.cs" />
<Compile Include="Debug.cs" /> <Compile Include="Debug.cs" />
<Compile Include="Networking\DownloadManager.cs" /> <Compile Include="Networking\DownloadManager.cs" />
<Compile Include="Misc\eTaskTypeIndex.cs" /> <Compile Include="Misc\TaskType.cs" />
<Compile Include="Menus\Sub\DebugMenu.cs" /> <Compile Include="Menus\Sub\DebugMenu.cs" />
<Compile Include="Networking\Receive.cs" /> <Compile Include="Networking\Receive.cs" />
<Compile Include="Networking\Send.cs" /> <Compile Include="Networking\Send.cs" />
@ -138,7 +138,6 @@
<Compile Include="Main.cs" /> <Compile Include="Main.cs" />
<Compile Include="Networking\MapLoader.cs" /> <Compile Include="Networking\MapLoader.cs" />
<Compile Include="Menus\RageCoopMenu.cs" /> <Compile Include="Menus\RageCoopMenu.cs" />
<Compile Include="Menus\Sub\Servers.cs" />
<Compile Include="Menus\Sub\SettingsMenu.cs" /> <Compile Include="Menus\Sub\SettingsMenu.cs" />
<Compile Include="Networking\Networking.cs" /> <Compile Include="Networking\Networking.cs" />
<Compile Include="PlayerList.cs" /> <Compile Include="PlayerList.cs" />

View File

@ -8,6 +8,6 @@ namespace RageCoop.Client
{ {
internal class SyncParameters internal class SyncParameters
{ {
public static float PositioinPrediction = 0.06f; public static float PositioinPrediction = 0.03f;
} }
} }