Skip to content

Commit

Permalink
add quit game, quit session, disconnect buttons to new submenu in mis…
Browse files Browse the repository at this point in the history
…c settings.
  • Loading branch information
TomGrobbe committed May 10, 2018
1 parent 88e55e2 commit 31bbe7a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
21 changes: 21 additions & 0 deletions vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@ public void DriveWander()
}
#endregion

#region Quit session & Quit game
/// <summary>
/// Quit the current network session, but leaves you connected to the server so addons/resources are still streamed.
/// </summary>
private void QuitSession()
{
NetworkSessionEnd(true, true);
}

/// <summary>
/// Quit the game after 5 seconds.
/// </summary>
private async void QuitGame()
{
Notify.Info("The game will exit in 5 seconds.", true, true);
Debug.WriteLine("Game will be terminated in 5 seconds, because the player used the Quit Game option in vMenu.");
await Delay(5000);
ForceSocialClubUpdate(); // bye bye
}
#endregion

#region Teleport to player (or teleport into the player's vehicle)
/// <summary>
/// Teleport to the specified player id. (Optionally teleport into their vehicle).
Expand Down
39 changes: 39 additions & 0 deletions vMenu/menus/MiscSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,44 @@ private void CreateMenu()
UIMenuCheckboxItem lockCamX = new UIMenuCheckboxItem("Lock Camera Horizontal Rotation", false, "Locks your camera horizontal rotation. Could be useful in helicopters I guess.");
UIMenuCheckboxItem lockCamY = new UIMenuCheckboxItem("Lock Camera Vertical Rotation", false, "Locks your camera vertical rotation. Could be useful in helicopters I guess.");

UIMenu connectionSubmenu = new UIMenu(GetPlayerName(PlayerId()), "Connection Options", true)
{
ScaleWithSafezone = false,
MouseControlsEnabled = false,
MouseEdgeEnabled = false,
ControlDisablingEnabled = false
};
UIMenuItem connectionSubmenuBtn = new UIMenuItem("Connection Options", "Server connection/game quit options.");
UIMenuItem quitSession = new UIMenuItem("Quit Session", "Leaves you connected to the server, but quits the network session. " +
"Use this if you need to have addons streamed but want to use the rockstar editor.");
UIMenuItem quitGame = new UIMenuItem("Quit Game", "Exits the game after 5 seconds.");
UIMenuItem disconnectFromServer = new UIMenuItem("Disconnect From Server", "Disconnects you from the server and returns you to the serverlist. " +
"~r~This feature is not recommended, quit the game instead for a better experience.");
connectionSubmenu.AddItem(quitSession);
connectionSubmenu.AddItem(quitGame);
connectionSubmenu.AddItem(disconnectFromServer);

MainMenu.Mp.Add(connectionSubmenu);
connectionSubmenu.RefreshIndex();
connectionSubmenu.UpdateScaleform();
menu.BindMenuToItem(connectionSubmenu, connectionSubmenuBtn);

connectionSubmenu.OnItemSelect += (sender, item, index) =>
{
if (item == quitGame)
{
cf.QuitGame();
}
else if (item == quitSession)
{
cf.QuitSession();
}
else if (item == disconnectFromServer)
{
BaseScript.TriggerServerEvent("vMenu:DisconnectSelf");
}
};

// Add menu items to the menu.
if (cf.IsAllowed(Permission.MSTeleportToWp))
{
Expand All @@ -71,6 +109,7 @@ private void CreateMenu()
// Always allowed
menu.AddItem(speedKmh);
menu.AddItem(speedMph);
menu.AddItem(connectionSubmenuBtn);

if (cf.IsAllowed(Permission.MSShowCoordinates))
{
Expand Down
10 changes: 10 additions & 0 deletions vMenuServer/MainServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ public MainServer()
EventHandlers.Add("vMenu:UpdateServerWeather", new Action<string, bool, bool>(UpdateWeather));
EventHandlers.Add("vMenu:UpdateServerWeatherCloudsType", new Action<bool>(UpdateWeatherCloudsType));
EventHandlers.Add("vMenu:UpdateServerTime", new Action<int, int, bool>(UpdateTime));
EventHandlers.Add("vMenu:DisconnectSelf", new Action<Player>(DisconnectSource));

string addons = LoadResourceFile(GetCurrentResourceName(), "addons.json") ?? LoadResourceFile(GetCurrentResourceName(), "config/addons.json") ?? "{}";
var json = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(addons);
Expand Down Expand Up @@ -382,6 +383,15 @@ public MainServer()
Tick += TimeLoop;
}
}

/// <summary>
/// Disconnect the source player because they used the disconnect menu button.
/// </summary>
/// <param name="src"></param>
private void DisconnectSource([FromSource] Player src)
{
src.Drop("You disconnected yourself.");
}
#endregion

#region Manage weather and time changes.
Expand Down

0 comments on commit 31bbe7a

Please sign in to comment.