RAGECOOP-V/Client/Menus/MenusMain.cs

113 lines
3.8 KiB
C#
Raw Normal View History

using GTA;
using LemonUI;
using LemonUI.Menus;
namespace CoopClient.Menus
{
2021-12-03 20:30:00 +01:00
/// <summary>
/// Don't use it!
/// </summary>
public class MenusMain
{
2021-12-03 20:30:00 +01:00
internal ObjectPool MenuPool = new ObjectPool();
2021-12-03 20:30:00 +01:00
internal NativeMenu MainMenu = new NativeMenu("GTACOOP:R", "MAIN")
{
UseMouse = false,
Alignment = Main.MainSettings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
};
#region SUB
2021-12-03 20:30:00 +01:00
/// <summary>
/// Don't use it!
/// </summary>
public Sub.Settings SubSettings = new Sub.Settings();
#endregion
#region ITEMS
private readonly NativeItem UsernameItem = new NativeItem("Username") { AltTitle = Main.MainSettings.Username };
private readonly NativeItem ServerIpItem = new NativeItem("Server IP") { AltTitle = Main.MainSettings.LastServerAddress };
private readonly NativeItem ServerConnectItem = new NativeItem("Connect");
private readonly NativeItem AboutItem = new NativeItem("About", "~y~SOURCE~s~~n~" +
"https://github.com/GTACOOP-R~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") };
#endregion
2021-12-03 20:30:00 +01:00
/// <summary>
/// Don't use it!
/// </summary>
public MenusMain()
{
UsernameItem.Activated += UsernameActivated;
ServerIpItem.Activated += ServerIpActivated;
ServerConnectItem.Activated += (sender, item) => { Main.MainNetworking.DisConnectFromServer(Main.MainSettings.LastServerAddress); };
MainMenu.Add(UsernameItem);
MainMenu.Add(ServerIpItem);
MainMenu.Add(ServerConnectItem);
MainMenu.AddSubMenu(SubSettings.MainMenu);
MainMenu.Add(AboutItem);
MenuPool.Add(MainMenu);
MenuPool.Add(SubSettings.MainMenu);
}
2021-12-03 20:30:00 +01:00
internal void UsernameActivated(object a, System.EventArgs b)
{
string newUsername = Game.GetUserInput(WindowTitle.EnterMessage20, UsernameItem.AltTitle, 20);
if (!string.IsNullOrWhiteSpace(newUsername))
{
Main.MainSettings.Username = newUsername;
Util.SaveSettings();
UsernameItem.AltTitle = newUsername;
MenuPool.RefreshAll();
}
}
2021-12-03 20:30:00 +01:00
internal void ServerIpActivated(object a, System.EventArgs b)
{
string newServerIp = Game.GetUserInput(WindowTitle.EnterMessage60, ServerIpItem.AltTitle, 60);
if (!string.IsNullOrWhiteSpace(newServerIp) && newServerIp.Contains(":"))
{
Main.MainSettings.LastServerAddress = newServerIp;
Util.SaveSettings();
ServerIpItem.AltTitle = newServerIp;
MenuPool.RefreshAll();
}
}
2021-12-03 20:30:00 +01:00
internal void InitiateConnectionMenuSetting()
{
MainMenu.Items[0].Enabled = false;
MainMenu.Items[1].Enabled = false;
MainMenu.Items[2].Enabled = false;
}
2021-12-03 20:30:00 +01:00
internal void ConnectedMenuSetting()
{
MainMenu.Items[2].Enabled = true;
MainMenu.Items[2].Title = "Disconnect";
SubSettings.MainMenu.Items[1].Enabled = !Main.DisableTraffic && Main.NpcsAllowed;
MainMenu.Visible = false;
MenuPool.RefreshAll();
}
2021-12-03 20:30:00 +01:00
internal void DisconnectedMenuSetting()
{
MainMenu.Items[0].Enabled = true;
MainMenu.Items[1].Enabled = true;
MainMenu.Items[2].Enabled = true;
MainMenu.Items[2].Title = "Connect";
SubSettings.MainMenu.Items[1].Enabled = false;
MenuPool.RefreshAll();
}
}
}