Skip to content

Commit

Permalink
Simplify canUseMenu check for when staff only mode is or isn't enabled.
Browse files Browse the repository at this point in the history
This should improve performance for players that aren't allowed to use anything from vMenu.
  • Loading branch information
TomGrobbe committed Dec 4, 2021
1 parent ee72f45 commit fcbe679
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
2 changes: 1 addition & 1 deletion SharedClasses/PermissionsManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
100 changes: 53 additions & 47 deletions vMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,62 +391,68 @@ private static void PostPermissionsSetup()
break;
}

if ((IsAllowed(Permission.Staff) && GetSettingsBool(Setting.vmenu_menu_staff_only)) || GetSettingsBool(Setting.vmenu_menu_staff_only) == false)
bool canUseMenu()
{
if (GetSettingsInt(Setting.vmenu_menu_toggle_key) != -1)
{
MenuToggleKey = (Control)GetSettingsInt(Setting.vmenu_menu_toggle_key);
//MenuToggleKey = GetSettingsInt(Setting.vmenu_menu_toggle_key);
}
if (GetSettingsInt(Setting.vmenu_noclip_toggle_key) != -1)
{
NoClipKey = GetSettingsInt(Setting.vmenu_noclip_toggle_key);
}
if (GetSettingsBool(Setting.vmenu_menu_staff_only) == false) return true;
else if (IsAllowed(Permission.Staff)) return true;
return false;
}

// Create the main menu.
Menu = new Menu(Game.Player.Name, "Main Menu");
PlayerSubmenu = new Menu(Game.Player.Name, "Player Related Options");
VehicleSubmenu = new Menu(Game.Player.Name, "Vehicle Related Options");
WorldSubmenu = new Menu(Game.Player.Name, "World Options");
if (!canUseMenu())
{
MenuController.MainMenu = null;
MenuController.DisableMenuButtons = true;
MenuController.DontOpenAnyMenu = true;
MenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle key
return;
}

// Add the main menu to the menu pool.
MenuController.AddMenu(Menu);
MenuController.MainMenu = Menu;
if (GetSettingsInt(Setting.vmenu_menu_toggle_key) != -1)
{
MenuToggleKey = (Control)GetSettingsInt(Setting.vmenu_menu_toggle_key);
//MenuToggleKey = GetSettingsInt(Setting.vmenu_menu_toggle_key);
}
if (GetSettingsInt(Setting.vmenu_noclip_toggle_key) != -1)
{
NoClipKey = GetSettingsInt(Setting.vmenu_noclip_toggle_key);
}

MenuController.AddSubmenu(Menu, PlayerSubmenu);
MenuController.AddSubmenu(Menu, VehicleSubmenu);
MenuController.AddSubmenu(Menu, WorldSubmenu);
// Create the main menu.
Menu = new Menu(Game.Player.Name, "Main Menu");
PlayerSubmenu = new Menu(Game.Player.Name, "Player Related Options");
VehicleSubmenu = new Menu(Game.Player.Name, "Vehicle Related Options");
WorldSubmenu = new Menu(Game.Player.Name, "World Options");

// Create all (sub)menus.
CreateSubmenus();
// Add the main menu to the menu pool.
MenuController.AddMenu(Menu);
MenuController.MainMenu = Menu;

if (!GetSettingsBool(Setting.vmenu_disable_player_stats_setup))
{
// Manage Stamina
if (PlayerOptionsMenu != null && PlayerOptionsMenu.PlayerStamina && IsAllowed(Permission.POUnlimitedStamina))
StatSetInt((uint)GetHashKey("MP0_STAMINA"), 100, true);
else
StatSetInt((uint)GetHashKey("MP0_STAMINA"), 0, true);

// Manage other stats, in order of appearance in the pause menu (stats) page.
StatSetInt((uint)GetHashKey("MP0_SHOOTING_ABILITY"), 100, true); // Shooting
StatSetInt((uint)GetHashKey("MP0_STRENGTH"), 100, true); // Strength
StatSetInt((uint)GetHashKey("MP0_STEALTH_ABILITY"), 100, true); // Stealth
StatSetInt((uint)GetHashKey("MP0_FLYING_ABILITY"), 100, true); // Flying
StatSetInt((uint)GetHashKey("MP0_WHEELIE_ABILITY"), 100, true); // Driving
StatSetInt((uint)GetHashKey("MP0_LUNG_CAPACITY"), 100, true); // Lung Capacity
StatSetFloat((uint)GetHashKey("MP0_PLAYER_MENTAL_STATE"), 0f, true); // Mental State
}
MenuController.AddSubmenu(Menu, PlayerSubmenu);
MenuController.AddSubmenu(Menu, VehicleSubmenu);
MenuController.AddSubmenu(Menu, WorldSubmenu);

TriggerEvent("vMenu:SetupTickFunctions");
}
else
// Create all (sub)menus.
CreateSubmenus();

if (!GetSettingsBool(Setting.vmenu_disable_player_stats_setup))
{
MenuController.MainMenu = null;
MenuController.DisableMenuButtons = true;
MenuController.DontOpenAnyMenu = true;
MenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle key
// Manage Stamina
if (PlayerOptionsMenu != null && PlayerOptionsMenu.PlayerStamina && IsAllowed(Permission.POUnlimitedStamina))
StatSetInt((uint)GetHashKey("MP0_STAMINA"), 100, true);
else
StatSetInt((uint)GetHashKey("MP0_STAMINA"), 0, true);

// Manage other stats, in order of appearance in the pause menu (stats) page.
StatSetInt((uint)GetHashKey("MP0_SHOOTING_ABILITY"), 100, true); // Shooting
StatSetInt((uint)GetHashKey("MP0_STRENGTH"), 100, true); // Strength
StatSetInt((uint)GetHashKey("MP0_STEALTH_ABILITY"), 100, true); // Stealth
StatSetInt((uint)GetHashKey("MP0_FLYING_ABILITY"), 100, true); // Flying
StatSetInt((uint)GetHashKey("MP0_WHEELIE_ABILITY"), 100, true); // Driving
StatSetInt((uint)GetHashKey("MP0_LUNG_CAPACITY"), 100, true); // Lung Capacity
StatSetFloat((uint)GetHashKey("MP0_PLAYER_MENTAL_STATE"), 0f, true); // Mental State
}

TriggerEvent("vMenu:SetupTickFunctions");
}

/// <summary>
Expand Down

0 comments on commit fcbe679

Please sign in to comment.