From 573604a9d9d79ae36f7928be3345388b5e8f3306 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:14:10 +0200 Subject: [PATCH] 3.1a - Possibility to change menu type by config `MenuType:` - selectable (each player can change menu type by command css_menus) - dynamic (center + keys) - center (center + chat) - chat - console --- Commands.cs | 14 +++++++------- Config.cs | 3 +++ Utility.cs | 30 +++++++++++++++++++++++++++--- VERSION | 2 +- WeaponAction.cs | 1 - WeaponPaints.cs | 2 +- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Commands.cs b/Commands.cs index 2420de64..e8b94f4e 100644 --- a/Commands.cs +++ b/Commands.cs @@ -181,7 +181,7 @@ private void SetupKnifeMenu() .Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet")) .ToDictionary(pair => pair.Key, pair => pair.Value); - var giveItemMenu = MenuApi?.NewMenu(Localizer["wp_knife_menu_title"]); + var giveItemMenu = Utility.CreateMenu(Localizer["wp_knife_menu_title"]); var handleGive = (CCSPlayerController player, ChatMenuOption option) => { @@ -265,7 +265,7 @@ private void SetupSkinsMenu() .Except([new KeyValuePair("weapon_knife", "Default Knife")]) .ToDictionary(kvp => kvp.Value, kvp => kvp.Key); - var weaponSelectionMenu = MenuApi?.NewMenu(Localizer["wp_skin_menu_weapon_title"]); + var weaponSelectionMenu = Utility.CreateMenu(Localizer["wp_skin_menu_weapon_title"]); // Function to handle skin selection for a specific weapon var handleWeaponSelection = (CCSPlayerController? player, ChatMenuOption option) => @@ -280,7 +280,7 @@ private void SetupSkinsMenu() weaponName?.ToString() == selectedWeaponClassname )?.ToList(); - var skinSubMenu = MenuApi?.NewMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]); + var skinSubMenu = Utility.CreateMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]); // Function to handle skin selection for the chosen weapon var handleSkinSelection = (CCSPlayerController p, ChatMenuOption opt) => @@ -416,7 +416,7 @@ private void SetupSkinsMenu() private void SetupGlovesMenu() { - var glovesSelectionMenu = MenuApi?.NewMenu(Localizer["wp_glove_menu_title"]); + var glovesSelectionMenu = Utility.CreateMenu(Localizer["wp_glove_menu_title"]); if (glovesSelectionMenu == null) return; glovesSelectionMenu.PostSelectAction = PostSelectAction.Close; @@ -625,7 +625,7 @@ private void SetupAgentsMenu() if (!CommandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) || DateTime.UtcNow >= (CommandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow)) { - var agentsSelectionMenu = MenuApi?.NewMenu(Localizer["wp_agent_menu_title"]); + var agentsSelectionMenu = Utility.CreateMenu(Localizer["wp_agent_menu_title"]); if (agentsSelectionMenu == null) return; agentsSelectionMenu.PostSelectAction = PostSelectAction.Close; @@ -665,7 +665,7 @@ private void SetupAgentsMenu() private void SetupMusicMenu() { - var musicSelectionMenu = MenuApi?.NewMenu(Localizer["wp_music_menu_title"]); + var musicSelectionMenu = Utility.CreateMenu(Localizer["wp_music_menu_title"]); if (musicSelectionMenu == null) return; musicSelectionMenu.PostSelectAction = PostSelectAction.Close; @@ -800,7 +800,7 @@ private void SetupMusicMenu() private void SetupPinsMenu() { - var pinsSelectionMenu = MenuApi?.NewMenu(Localizer["wp_pins_menu_title"]); + var pinsSelectionMenu = Utility.CreateMenu(Localizer["wp_pins_menu_title"]); if (pinsSelectionMenu == null) return; pinsSelectionMenu.PostSelectAction = PostSelectAction.Close; diff --git a/Config.cs b/Config.cs index 9b0041e1..a23198eb 100644 --- a/Config.cs +++ b/Config.cs @@ -99,5 +99,8 @@ public class WeaponPaintsConfig : BasePluginConfig [JsonPropertyName("Additional")] public Additional Additional { get; set; } = new(); + + [JsonPropertyName("MenuType")] + public string MenuType { get; set; } = "selectable"; } } \ No newline at end of file diff --git a/Utility.cs b/Utility.cs index 57a8fba1..d80e8b21 100644 --- a/Utility.cs +++ b/Utility.cs @@ -1,6 +1,8 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Translations; +using CounterStrikeSharp.API.Modules.Menu; using Dapper; +using MenuManager; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -188,10 +190,32 @@ internal static void Log(string message) Console.WriteLine("[WeaponPaints] " + message); Console.ResetColor(); } - - internal static string ReplaceTags(string message) + + internal static IMenu? CreateMenu(string title) { - return message.ReplaceColorTags(); + var menuType = WeaponPaints.Instance.Config.MenuType.ToLower(); + + var menu = menuType switch + { + _ when menuType.Equals("selectable", StringComparison.CurrentCultureIgnoreCase) => + WeaponPaints.MenuApi?.NewMenu(title), + + _ when menuType.Equals("dynamic", StringComparison.CurrentCultureIgnoreCase) => + WeaponPaints.MenuApi?.NewMenuForcetype(title, MenuType.ButtonMenu), + + _ when menuType.Equals("center", StringComparison.CurrentCultureIgnoreCase) => + WeaponPaints.MenuApi?.NewMenuForcetype(title, MenuType.CenterMenu), + + _ when menuType.Equals("chat", StringComparison.CurrentCultureIgnoreCase) => + WeaponPaints.MenuApi?.NewMenuForcetype(title, MenuType.ChatMenu), + + _ when menuType.Equals("console", StringComparison.CurrentCultureIgnoreCase) => + WeaponPaints.MenuApi?.NewMenuForcetype(title, MenuType.ConsoleMenu), + + _ => WeaponPaints.MenuApi?.NewMenu(title) + }; + + return menu; } internal static async Task CheckVersion(string version, ILogger logger) diff --git a/VERSION b/VERSION index 79f604f4..75fc8132 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0c \ No newline at end of file +3.1a \ No newline at end of file diff --git a/WeaponAction.cs b/WeaponAction.cs index c8a7b641..aa3bf5fe 100644 --- a/WeaponAction.cs +++ b/WeaponAction.cs @@ -542,7 +542,6 @@ private void GiveOnItemPickup(CCSPlayerController player) var weapon = handle.Value; if (weapon == null || !weapon.IsValid) continue; - if (myWeapons.Count == 1) { var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.USP)); diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 45a178fc..350ed997 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -17,7 +17,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig "Nereziel & daffyy"; public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based"; public override string ModuleName => "WeaponPaints"; - public override string ModuleVersion => "3.0c"; + public override string ModuleVersion => "3.1a"; public override void Load(bool hotReload) {