Skip to content

Commit

Permalink
Merge pull request #342 from daffyyyy/main
Browse files Browse the repository at this point in the history
3.1a
  • Loading branch information
daffyyyy authored Oct 24, 2024
2 parents 3929a43 + 4a5a08a commit ea9963b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
14 changes: 7 additions & 7 deletions Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand Down Expand Up @@ -265,7 +265,7 @@ private void SetupSkinsMenu()
.Except([new KeyValuePair<string, string>("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) =>
Expand All @@ -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) =>
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,8 @@ public class WeaponPaintsConfig : BasePluginConfig

[JsonPropertyName("Additional")]
public Additional Additional { get; set; } = new();

[JsonPropertyName("MenuType")]
public string MenuType { get; set; } = "selectable";
}
}
30 changes: 27 additions & 3 deletions Utility.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0c
3.1a
1 change: 0 additions & 1 deletion WeaponAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
public override string ModuleAuthor => "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)
{
Expand Down

0 comments on commit ea9963b

Please sign in to comment.