Files
RAGECOOP-V/Client/Scripts/Menus/CoopMenu.cs

196 lines
6.4 KiB
C#
Raw Normal View History

2022-10-23 19:02:39 +08:00
using System;
using System.Drawing;
using GTA;
2022-09-06 21:46:35 +08:00
using GTA.Native;
2022-10-23 19:02:39 +08:00
using GTA.UI;
using LemonUI;
2022-10-23 19:02:39 +08:00
using LemonUI.Elements;
using LemonUI.Menus;
2022-06-19 15:04:38 +08:00
using LemonUI.Scaleform;
2022-05-22 15:55:26 +08:00
namespace RageCoop.Client.Menus
{
2021-12-03 20:30:00 +01:00
/// <summary>
2022-10-23 19:02:39 +08:00
/// Don't use it!
2021-12-03 20:30:00 +01:00
/// </summary>
internal static class CoopMenu
{
public static ObjectPool MenuPool = new ObjectPool();
2022-10-23 19:02:39 +08:00
public static NativeMenu Menu = new NativeMenu("RAGECOOP", "MAIN")
{
UseMouse = false,
2023-02-13 20:44:50 +08:00
Alignment = Settings.FlipMenu ? Alignment.Right : Alignment.Left
};
2022-10-23 19:02:39 +08:00
public static PopUp PopUp = new PopUp
2022-06-19 15:04:38 +08:00
{
2022-09-06 21:46:35 +08:00
Title = "",
Prompt = "",
2022-06-19 15:04:38 +08:00
Subtitle = "",
2022-09-06 21:46:35 +08:00
Error = "",
2022-06-19 15:04:38 +08:00
ShowBackground = true,
2022-10-23 19:02:39 +08:00
Visible = false
2022-06-19 15:04:38 +08:00
};
2021-12-03 20:30:00 +01:00
/// <summary>
2022-10-23 19:02:39 +08:00
/// Don't use it!
2021-12-03 20:30:00 +01:00
/// </summary>
static CoopMenu()
{
Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
Menu.Title.Color = Color.FromArgb(255, 165, 0);
2022-04-06 02:18:24 +02:00
_usernameItem.Activated += UsernameActivated;
2022-09-06 21:46:35 +08:00
_passwordItem.Activated += _passwordActivated;
ServerIpItem.Activated += ServerIpActivated;
2022-10-23 19:02:39 +08:00
_serverConnectItem.Activated += (sender, item) =>
{
2023-02-13 20:44:50 +08:00
Networking.ToggleConnection(Settings.LastServerAddress);
2022-10-23 19:02:39 +08:00
};
2022-05-31 23:12:32 -08:00
Menu.AddSubMenu(ServersMenu.Menu);
Menu.Add(_usernameItem);
Menu.Add(_passwordItem);
Menu.Add(ServerIpItem);
Menu.Add(_serverConnectItem);
Menu.AddSubMenu(SettingsMenu.Menu);
Menu.AddSubMenu(DevToolMenu.Menu);
Menu.AddSubMenu(DebugMenu.Menu);
MenuPool.Add(Menu);
MenuPool.Add(SettingsMenu.Menu);
MenuPool.Add(DevToolMenu.Menu);
MenuPool.Add(DebugMenu.Menu);
MenuPool.Add(DebugMenu.DiagnosticMenu);
2023-03-18 15:58:31 +08:00
MenuPool.Add(DebugMenu.TuneMenu);
2022-05-31 23:12:32 -08:00
MenuPool.Add(ServersMenu.Menu);
2022-06-19 15:04:38 +08:00
MenuPool.Add(PopUp);
Menu.Add(_aboutItem);
}
2022-10-23 19:02:39 +08:00
public static NativeMenu LastMenu { get; set; } = Menu;
2022-07-20 17:50:01 +08:00
public static bool ShowPopUp(string prompt, string title, string subtitle, string error, bool showbackground)
2022-06-19 15:04:38 +08:00
{
2022-09-06 21:46:35 +08:00
PopUp.Prompt = prompt;
PopUp.Title = title;
PopUp.Subtitle = subtitle;
PopUp.Error = error;
PopUp.ShowBackground = showbackground;
PopUp.Visible = true;
2022-08-18 17:45:08 +08:00
Script.Yield();
2022-06-19 15:04:38 +08:00
while (true)
{
Game.DisableAllControlsThisFrame();
MenuPool.Process();
2022-08-25 00:58:21 +08:00
var scaleform = new Scaleform("instructional_buttons");
scaleform.CallFunction("CLEAR_ALL");
scaleform.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
scaleform.CallFunction("CREATE_CONTAINER");
2022-10-23 19:02:39 +08:00
scaleform.CallFunction("SET_DATA_SLOT", 0,
Call<string>((Hash)0x0499D7B09FC9B407, 2, (int)Control.FrontendAccept, 0), "Continue");
2022-10-23 19:02:39 +08:00
scaleform.CallFunction("SET_DATA_SLOT", 1,
Call<string>((Hash)0x0499D7B09FC9B407, 2, (int)Control.FrontendCancel, 0), "Cancel");
2022-08-25 00:58:21 +08:00
scaleform.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
scaleform.Render2D();
2022-06-19 15:04:38 +08:00
if (Game.IsControlJustPressed(Control.FrontendAccept))
{
2022-09-06 21:46:35 +08:00
PopUp.Visible = false;
2022-06-19 15:04:38 +08:00
return true;
}
2022-10-23 19:02:39 +08:00
if (Game.IsControlJustPressed(Control.FrontendCancel))
2022-06-19 15:04:38 +08:00
{
PopUp.Visible = false;
return false;
}
2022-10-23 19:02:39 +08:00
2022-09-06 21:46:35 +08:00
Script.Yield();
2022-08-24 19:26:40 +08:00
Game.DisableAllControlsThisFrame();
2022-06-19 15:04:38 +08:00
}
}
2022-10-23 19:02:39 +08:00
public static void UsernameActivated(object a, EventArgs b)
{
2022-10-23 19:02:39 +08:00
var newUsername = Game.GetUserInput(WindowTitle.EnterMessage20, _usernameItem.AltTitle, 20);
if (!string.IsNullOrWhiteSpace(newUsername))
{
2023-02-13 20:44:50 +08:00
Settings.Username = newUsername;
Util.SaveSettings();
_usernameItem.AltTitle = newUsername;
}
}
2022-10-23 19:02:39 +08:00
private static void _passwordActivated(object sender, EventArgs e)
{
2022-10-23 19:02:39 +08:00
var newPass = Game.GetUserInput(WindowTitle.EnterMessage20, "", 20);
2023-02-13 20:44:50 +08:00
Settings.Password = newPass;
2022-08-18 17:45:08 +08:00
Util.SaveSettings();
_passwordItem.AltTitle = new string('*', newPass.Length);
}
2022-10-23 19:02:39 +08:00
public static void ServerIpActivated(object a, EventArgs b)
{
2022-10-23 19:02:39 +08:00
var newServerIp = Game.GetUserInput(WindowTitle.EnterMessage60, ServerIpItem.AltTitle, 60);
if (!string.IsNullOrWhiteSpace(newServerIp) && newServerIp.Contains(":"))
{
2023-02-13 20:44:50 +08:00
Settings.LastServerAddress = newServerIp;
Util.SaveSettings();
ServerIpItem.AltTitle = newServerIp;
}
}
public static void InitiateConnectionMenuSetting()
{
_usernameItem.Enabled = false;
ServerIpItem.Enabled = false;
_serverConnectItem.Enabled = false;
}
public static void ConnectedMenuSetting()
{
_serverConnectItem.Enabled = true;
_serverConnectItem.Title = "Disconnect";
Menu.Visible = false;
}
public static void DisconnectedMenuSetting()
{
_usernameItem.Enabled = true;
ServerIpItem.Enabled = true;
_serverConnectItem.Enabled = true;
_serverConnectItem.Title = "Connect";
}
2022-10-23 19:02:39 +08:00
#region ITEMS
private static readonly NativeItem _usernameItem = new NativeItem("Username")
2023-03-18 15:58:31 +08:00
{ AltTitle = Settings.Username };
2022-10-23 19:02:39 +08:00
private static readonly NativeItem _passwordItem = new NativeItem("Password")
2023-03-18 15:58:31 +08:00
{ AltTitle = new string('*', Settings.Password.Length) };
2022-10-23 19:02:39 +08:00
public static readonly NativeItem ServerIpItem = new NativeItem("Server IP")
2023-03-18 15:58:31 +08:00
{ AltTitle = Settings.LastServerAddress };
2022-10-23 19:02:39 +08:00
internal static readonly NativeItem _serverConnectItem = new NativeItem("Connect");
private static readonly NativeItem _aboutItem = new NativeItem("About", "~y~SOURCE~s~~n~" +
"https://github.com/RAGECOOP~n~" +
"~y~VERSION~s~~n~" +
2023-02-13 20:44:50 +08:00
Main.ModVersion)
2023-03-18 15:58:31 +08:00
{ LeftBadge = new ScaledTexture("commonmenu", "shop_new_star") };
2022-10-23 19:02:39 +08:00
#endregion
}
2022-10-23 19:02:39 +08:00
}