RAGECOOP-V/Client/Menus/RageCoopMenu.cs

116 lines
3.8 KiB
C#
Raw Normal View History

using GTA;
2022-04-06 02:18:24 +02:00
using System.Drawing;
using LemonUI;
using LemonUI.Menus;
2022-05-22 15:55:26 +08:00
namespace RageCoop.Client.Menus
{
2021-12-03 20:30:00 +01:00
/// <summary>
/// Don't use it!
/// </summary>
public class RageCoopMenu
{
2022-05-22 15:55:26 +08:00
public ObjectPool MenuPool = new ObjectPool();
2022-05-22 15:55:26 +08:00
public NativeMenu MainMenu = new NativeMenu("RAGECOOP", "MAIN")
{
UseMouse = false,
2022-05-22 15:55:26 +08:00
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
};
#region SUB
public SettingsMenu SubSettings = new SettingsMenu();
#endregion
#region ITEMS
2022-05-22 15:55:26 +08:00
private readonly NativeItem _usernameItem = new NativeItem("Username") { AltTitle = Main.Settings.Username };
public readonly NativeItem ServerIpItem = new NativeItem("Server IP") { AltTitle = Main.Settings.LastServerAddress };
private readonly NativeItem _serverConnectItem = new NativeItem("Connect");
private readonly NativeItem _aboutItem = new NativeItem("About", "~y~SOURCE~s~~n~" +
2022-04-06 02:18:24 +02:00
"https://github.com/RAGECOOP~n~" +
"~y~VERSION~s~~n~" +
2021-09-28 16:51:16 +02:00
Main.CurrentVersion.Replace("_", ".")) { LeftBadge = new LemonUI.Elements.ScaledTexture("commonmenu", "shop_new_star") };
2022-05-22 15:55:26 +08:00
#endregion
2021-12-03 20:30:00 +01:00
/// <summary>
/// Don't use it!
/// </summary>
public RageCoopMenu()
{
2022-04-06 02:18:24 +02:00
MainMenu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
MainMenu.Title.Color = Color.FromArgb(255, 165, 0);
_usernameItem.Activated += UsernameActivated;
ServerIpItem.Activated += ServerIpActivated;
_serverConnectItem.Activated += (sender, item) => { Networking.DisConnectFromServer(Main.Settings.LastServerAddress); };
MainMenu.Add(_usernameItem);
MainMenu.Add(ServerIpItem);
MainMenu.Add(_serverConnectItem);
MainMenu.AddSubMenu(SubSettings.Menu);
MainMenu.AddSubMenu(DevToolMenu.Menu);
MainMenu.AddSubMenu(DebugMenu.Menu);
MenuPool.Add(MainMenu);
MenuPool.Add(SubSettings.Menu);
MenuPool.Add(DevToolMenu.Menu);
MenuPool.Add(DebugMenu.Menu);
MenuPool.Add(DebugMenu.DiagnosticMenu);
MainMenu.Add(_aboutItem);
}
2022-05-22 15:55:26 +08:00
public void UsernameActivated(object a, System.EventArgs b)
{
string newUsername = Game.GetUserInput(WindowTitle.EnterMessage20, _usernameItem.AltTitle, 20);
if (!string.IsNullOrWhiteSpace(newUsername))
{
2022-05-22 15:55:26 +08:00
Main.Settings.Username = newUsername;
Util.SaveSettings();
_usernameItem.AltTitle = newUsername;
}
}
2022-05-22 15:55:26 +08:00
public void ServerIpActivated(object a, System.EventArgs b)
{
string newServerIp = Game.GetUserInput(WindowTitle.EnterMessage60, ServerIpItem.AltTitle, 60);
if (!string.IsNullOrWhiteSpace(newServerIp) && newServerIp.Contains(":"))
{
2022-05-22 15:55:26 +08:00
Main.Settings.LastServerAddress = newServerIp;
Util.SaveSettings();
ServerIpItem.AltTitle = newServerIp;
}
}
2022-05-22 15:55:26 +08:00
public void InitiateConnectionMenuSetting()
{
_usernameItem.Enabled = false;
ServerIpItem.Enabled = false;
_serverConnectItem.Enabled = false;
}
2022-05-22 15:55:26 +08:00
public void ConnectedMenuSetting()
{
_serverConnectItem.Enabled = true;
_serverConnectItem.Title = "Disconnect";
MainMenu.Visible = false;
}
2022-05-22 15:55:26 +08:00
public void DisconnectedMenuSetting()
{
_usernameItem.Enabled = true;
ServerIpItem.Enabled = true;
_serverConnectItem.Enabled = true;
_serverConnectItem.Title = "Connect";
}
}
}