From 244cb7e3eb85d8387df062f484e87caa8b013ee8 Mon Sep 17 00:00:00 2001 From: T3Marius <168598779+T3Marius@users.noreply.github.com> Date: Sat, 1 Mar 2025 23:51:21 +0200 Subject: [PATCH 1/4] added: Separate functions for menus. CreateHtmlMenu and CreateScreenMenu --- VIPCore/VipCoreApi/IVipCoreApi.cs | 18 +++++++++++++----- VIPCore/VipCoreApi/IVipFeature.cs | 8 +++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/VIPCore/VipCoreApi/IVipCoreApi.cs b/VIPCore/VipCoreApi/IVipCoreApi.cs index fc4eda8f..2d22a5b1 100644 --- a/VIPCore/VipCoreApi/IVipCoreApi.cs +++ b/VIPCore/VipCoreApi/IVipCoreApi.cs @@ -1,5 +1,6 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Menu; +using CS2ScreenMenuAPI.Internal; namespace VipCoreApi; @@ -80,12 +81,12 @@ enum FeatureType /// /// void SetPlayerFeatureState(CCSPlayerController player, string feature, FeatureState newState); - + /// /// Turns off all functions /// void DisableAllFeatures(); - + /// /// /// Turns on all the functions /// @@ -228,14 +229,21 @@ enum FeatureType /// T LoadConfig(string name); + + /// + /// Returns an HTML menu. + /// + /// + /// + IMenu CreateHtmlMenu(string title); + /// - /// Returns a menu depending on the UseCenterHtmlMenu parameter from the config. + /// Returns a screen menu. /// /// /// - IMenu CreateMenu(string title); + ScreenMenu CreateScreenMenu(string title); - /// /// Returns server id /// diff --git a/VIPCore/VipCoreApi/IVipFeature.cs b/VIPCore/VipCoreApi/IVipFeature.cs index 98fa5850..d3c4bb64 100644 --- a/VIPCore/VipCoreApi/IVipFeature.cs +++ b/VIPCore/VipCoreApi/IVipFeature.cs @@ -1,5 +1,6 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Menu; +using CS2ScreenMenuAPI.Internal; using static VipCoreApi.IVipCoreApi; namespace VipCoreApi; @@ -23,7 +24,7 @@ public abstract class VipFeatureBase : IVipFeature public string ModulesConfigDirectory => Api.ModulesConfigDirectory; public string GetDatabaseConnectionString => Api.GetDatabaseConnectionString; - + protected VipFeatureBase(IVipCoreApi api) { Api = api; @@ -44,7 +45,7 @@ public virtual void OnPlayerLoaded(CCSPlayerController player, string group) public virtual void OnPlayerRemoved(CCSPlayerController player, string group) { } - + public virtual void OnSelectItem(CCSPlayerController player, FeatureState state) { } @@ -91,7 +92,8 @@ public void GiveClientTemporaryVip(CCSPlayerController player, string group, int public T LoadConfig(string name) => Api.LoadConfig(name); - public IMenu CreateMenu(string title) => Api.CreateMenu(title); + public IMenu CreatHtmlMenu(string title) => Api.CreateHtmlMenu(title); + public ScreenMenu CreateScreenMenu(string title) => Api.CreateScreenMenu(title); public void PrintToChat(CCSPlayerController player, string message) => Api.PrintToChat(player, message); From 9a849378f700e9054f3ff6c500d64287654c8fd7 Mon Sep 17 00:00:00 2001 From: T3Marius <168598779+T3Marius@users.noreply.github.com> Date: Sat, 1 Mar 2025 23:51:45 +0200 Subject: [PATCH 2/4] added: CreateScreenMenu and CreateHtmlMenu --- VIPCore/VIPCore/VipCoreApi.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/VIPCore/VIPCore/VipCoreApi.cs b/VIPCore/VIPCore/VipCoreApi.cs index c01e45b1..017f831e 100644 --- a/VIPCore/VIPCore/VipCoreApi.cs +++ b/VIPCore/VIPCore/VipCoreApi.cs @@ -5,6 +5,7 @@ using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Menu; +using CS2ScreenMenuAPI.Internal; using Microsoft.Extensions.Logging; using VipCoreApi; using static VipCoreApi.IVipCoreApi; @@ -365,7 +366,7 @@ public T LoadConfig(string name, string path) File.WriteAllText(configFilePath, JsonSerializer.Serialize(defaultConfig, new JsonSerializerOptions - { WriteIndented = true, ReadCommentHandling = JsonCommentHandling.Skip })); + { WriteIndented = true, ReadCommentHandling = JsonCommentHandling.Skip })); return defaultConfig; } @@ -383,11 +384,14 @@ public T LoadConfig(string name) return LoadConfig(name, ModulesConfigDirectory); } - public IMenu CreateMenu(string title) + public IMenu CreateHtmlMenu(string title) { - return _vipCore.CoreConfig.UseCenterHtmlMenu ? new CenterHtmlMenu(title, _vipCore) : new ChatMenu(title); + return new CenterHtmlMenu(title, _vipCore); + } + public ScreenMenu CreateScreenMenu(string title) + { + return new ScreenMenu(title, _vipCore); } - public void SetPlayerCookie(ulong steamId64, string key, T value) { if (!_playersCookie.TryGetValue(steamId64, out var cookie)) From a4d34d381a47bd531fc486c28ae6dc58800cef3b Mon Sep 17 00:00:00 2001 From: T3Marius <168598779+T3Marius@users.noreply.github.com> Date: Sat, 1 Mar 2025 23:52:09 +0200 Subject: [PATCH 3/4] added: replaced UseCenterHtmlMenu with MenuType --- VIPCore/VIPCore/Cfg.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VIPCore/VIPCore/Cfg.cs b/VIPCore/VIPCore/Cfg.cs index f20638ae..d6948ec0 100644 --- a/VIPCore/VIPCore/Cfg.cs +++ b/VIPCore/VIPCore/Cfg.cs @@ -26,7 +26,7 @@ public class CoreConfig { public int TimeMode { get; init; } = 0; public int ServerId { get; init; } = 0; - public bool UseCenterHtmlMenu { get; init; } = true; + public string MenuType { get; set; } = "screen"; [JsonPropertyName("ServerIP")] public string ServerIp { get; init; } = "0.0.0.0"; public int ServerPort { get; init; } = 27015; From 196b267bb20095f38592723157db3d2b7725af0c Mon Sep 17 00:00:00 2001 From: T3Marius <168598779+T3Marius@users.noreply.github.com> Date: Sat, 1 Mar 2025 23:52:20 +0200 Subject: [PATCH 4/4] feat: added ScreenMenu --- VIPCore/VIPCore/VIPCore.cs | 108 +++++++++++++++++++++++++-- VIPCore/VIPCore/VIPCore.csproj | 1 + VIPCore/VipCoreApi/VipCoreApi.csproj | 1 + 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/VIPCore/VIPCore/VIPCore.cs b/VIPCore/VIPCore/VIPCore.cs index 48e2d9e6..5d6e4446 100644 --- a/VIPCore/VIPCore/VIPCore.cs +++ b/VIPCore/VIPCore/VIPCore.cs @@ -8,6 +8,8 @@ using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Timers; +using CS2ScreenMenuAPI; +using CS2ScreenMenuAPI.Internal; using Microsoft.Extensions.Logging; using MySqlConnector; using VipCoreApi; @@ -59,7 +61,25 @@ public override void Load(bool hotReload) RegisterEventHandlers(); SetupTimers(); - AddCommand("css_vip", "command that opens the VIP MENU", (player, _) => CreateMenu(player)); + AddCommand("css_vip", "command that opens the VIP MENU", (player, _) => + { + switch (CoreConfig.MenuType) + { + case "html": + case "center": + CreateHtmlMenu(player); + break; + + case "screen": + case "worldtext": + CreateScreenMenu(player); + break; + + default: + Logger.LogError($"Invalid menu type: {CoreConfig.MenuType}. Please choose between: [html, center, screen]"); + break; + } + }); } private void LoadConfig() @@ -373,8 +393,86 @@ public void OnCommandReloadConfig(CCSPlayerController? controller, CommandInfo c ReplyToCommand(controller, msg); } + private void CreateScreenMenu(CCSPlayerController? player) + { + if (player == null) + return; + + if (!IsClientVip[player.Slot]) + { + PrintToChat(player, Localizer["vip.NoAcces"]); + return; + } - private void CreateMenu(CCSPlayerController? player) + if (!Users.TryGetValue(player.SteamID, out var user)) + return; + + ScreenMenu menu = VipApi.CreateScreenMenu(Localizer["menu.Title", user.group]); + + if (Config.Groups.TryGetValue(user.group, out var vipGroup)) + { + var sortedFeatures = Features + .Where(setting => setting.Value.FeatureType is not FeatureType.Hide) + .OrderBy(setting => Array.IndexOf(_sortedItems, setting.Key)) + .ThenBy(setting => setting.Key); + + foreach (var (key, feature) in sortedFeatures) + { + if (!vipGroup.Values.TryGetValue(key, out var featureValue)) continue; + if (string.IsNullOrEmpty(featureValue.ToString())) continue; + if (!user.FeatureState.TryGetValue(key, out var currentState)) continue; + + string icon = string.Empty; + if (feature.FeatureType == FeatureType.Toggle) + { + icon = currentState switch + { + FeatureState.Enabled => "[✔]", + FeatureState.Disabled => "[✘]", + FeatureState.NoAccess => "[✘]", + _ => "" + }; + } + + string optionText = Localizer[key] + (feature.FeatureType == FeatureType.Selectable ? string.Empty : $" {icon}"); + + menu.AddOption(optionText, (p, option) => + { + var state = user.FeatureState[key]; + var result = VipApi.PlayerUseFeature(player, key, state, feature.FeatureType); + + if (feature.FeatureType == FeatureType.Toggle) + { + var newState = state switch + { + FeatureState.Enabled => FeatureState.Disabled, + FeatureState.Disabled => FeatureState.Enabled, + _ => state + }; + user.FeatureState[key] = newState; + + var newIcon = newState switch + { + FeatureState.Enabled => "[✔]", + FeatureState.Disabled => "[✘]", + _ => "[✘]" + }; + + option.Text = Localizer[key] + $" {newIcon}"; + MenuAPI.GetActiveMenu(player)?.Display(); + + VipApi.PrintToChat(player, + $"{Localizer[key]}: {(newState == FeatureState.Enabled ? $"{Localizer["chat.Enabled"]}" : $"{Localizer["chat.Disabled"]}")}"); + + feature.OnSelectItem?.Invoke(p, newState); + } + }, currentState == FeatureState.NoAccess || ForcedDisabledFeatures.Contains(key)); + } + } + MenuAPI.OpenMenu(this, player, menu); + + } + private void CreateHtmlMenu(CCSPlayerController? player) { if (player == null) return; @@ -386,7 +484,7 @@ private void CreateMenu(CCSPlayerController? player) if (!Users.TryGetValue(player.SteamID, out var user)) return; - var menu = VipApi.CreateMenu(Localizer["menu.Title", user.group]); + var menu = VipApi.CreateHtmlMenu(Localizer["menu.Title", user.group]); if (Config.Groups.TryGetValue(user.group, out var vipGroup)) { var sortedFeatures = Features.Where(setting => setting.Value.FeatureType is not FeatureType.Hide) @@ -423,7 +521,7 @@ private void CreateMenu(CCSPlayerController? player) if (result == HookResult.Handled || result == HookResult.Stop) { - CreateMenu(player); + CreateHtmlMenu(player); return; } @@ -446,7 +544,7 @@ private void CreateMenu(CCSPlayerController? player) if (CoreConfig.ReOpenMenuAfterItemClick && featureType != FeatureType.Selectable) { - CreateMenu(controller); + CreateHtmlMenu(controller); } }, featureState == FeatureState.NoAccess || ForcedDisabledFeatures.Contains(key)); } diff --git a/VIPCore/VIPCore/VIPCore.csproj b/VIPCore/VIPCore/VIPCore.csproj index 65c32467..5826ccc1 100644 --- a/VIPCore/VIPCore/VIPCore.csproj +++ b/VIPCore/VIPCore/VIPCore.csproj @@ -8,6 +8,7 @@ + diff --git a/VIPCore/VipCoreApi/VipCoreApi.csproj b/VIPCore/VipCoreApi/VipCoreApi.csproj index be70016d..efdf73d9 100644 --- a/VIPCore/VipCoreApi/VipCoreApi.csproj +++ b/VIPCore/VipCoreApi/VipCoreApi.csproj @@ -8,6 +8,7 @@ +