RAGECOOP-V/Client/Menus/MenusMain.cs
Makinolo 7b467aec18 Creates interface to communicate with other mods and menus optional
The interface static class will be used from 3rd party mods to
initiate, close and configure the connection. The project can be
compiled with the NON_INTERACTIVE copiler flag to remove the menus
and leave only the interface as a controller.
This is an initial implementation, future additions will support
more operations.
2021-09-26 21:31:40 -06:00

101 lines
3.5 KiB
C#

using GTA;
using LemonUI;
using LemonUI.Menus;
namespace CoopClient.Menus
{
public class MenusMain
{
public ObjectPool MenuPool = new ObjectPool();
public NativeMenu MainMenu = new NativeMenu("GTACOOP:R", Main.CurrentModVersion.Replace("_", "."))
{
UseMouse = false,
Alignment = Main.MainSettings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
};
#region ===== SUB =====
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", "~g~GTACOOP~s~:~b~R ~s~by EntenKoeniq") { LeftBadge = new LemonUI.Elements.ScaledTexture("commonmenu", "shop_new_star") };
#endregion // !ITEMS
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);
}
public 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();
}
}
public 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();
}
}
public void InitiateConnectionMenuSetting()
{
MainMenu.Items[0].Enabled = false;
MainMenu.Items[1].Enabled = false;
MainMenu.Items[2].Enabled = false;
}
public 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();
}
public 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();
}
}
}