From 711350f50ca908b0435b7cfe93f60227053fb49a Mon Sep 17 00:00:00 2001 From: Juzlus Date: Wed, 19 Nov 2025 02:52:44 +0100 Subject: [PATCH] chat message config --- .../src/jRandomSkills.cs | 1 - jRandomSkills - SRC Files/src/lang/en.json | 3 +- .../src/player/PlayerEvents.cs | 4 +- jRandomSkills - SRC Files/src/utils/Config.cs | 25 ++++ .../src/utils/MeansureString.cs | 138 ++++++++++++++++++ .../src/utils/SkillUtils.cs | 19 ++- 6 files changed, 178 insertions(+), 12 deletions(-) create mode 100644 jRandomSkills - SRC Files/src/utils/MeansureString.cs diff --git a/jRandomSkills - SRC Files/src/jRandomSkills.cs b/jRandomSkills - SRC Files/src/jRandomSkills.cs index 6c51d01..99636b7 100644 --- a/jRandomSkills - SRC Files/src/jRandomSkills.cs +++ b/jRandomSkills - SRC Files/src/jRandomSkills.cs @@ -23,7 +23,6 @@ namespace src public CCSGameRules? GameRules { get; set; } private ConcurrentBag ManifestResources { get; set; } = [ "models/actors/ghost_speaker.vmdl" ]; public IWasdMenuManager? MenuManager; - public const string Tag = "jRandomSkills"; public override string ModuleName => "[CS2] [ jRandomSkills ]"; public override string ModuleAuthor => "D3X, Juzlus"; diff --git a/jRandomSkills - SRC Files/src/lang/en.json b/jRandomSkills - SRC Files/src/lang/en.json index 3cb440f..38b95e3 100644 --- a/jRandomSkills - SRC Files/src/lang/en.json +++ b/jRandomSkills - SRC Files/src/lang/en.json @@ -454,8 +454,7 @@ "bombsite_b": "Bombsite B", "teammate_skills": "Your teammates' skills", - "summary_start": "Summary of the last round", - "summary_end": "=======================================", + "summary": "Summary of the last round", "menu_controlls_scroll": "W/S - Scroll", "menu_controlls_padding": " | ", diff --git a/jRandomSkills - SRC Files/src/player/PlayerEvents.cs b/jRandomSkills - SRC Files/src/player/PlayerEvents.cs index 517ce04..be5f5e5 100644 --- a/jRandomSkills - SRC Files/src/player/PlayerEvents.cs +++ b/jRandomSkills - SRC Files/src/player/PlayerEvents.cs @@ -434,11 +434,11 @@ namespace src.player if (Config.LoadedConfig.SummaryAfterTheRound && !string.IsNullOrEmpty(skillsText)) { - SkillUtils.PrintToChat(player, string.Empty, title: player.GetTranslation("summary_start"), border: "t"); + SkillUtils.PrintToChat(player, string.Empty, title: player.GetTranslation("summary"), border: "t"); foreach (string text in skillsText.Split("\n")) if (!string.IsNullOrEmpty(text)) SkillUtils.PrintToChat(player, text, title: player.GetTranslation("teammate_skills"), border: ""); - SkillUtils.PrintToChat(player, string.Empty, title: player.GetTranslation("summary_start"), border: "b"); + SkillUtils.PrintToChat(player, string.Empty, border: "b"); } }); } diff --git a/jRandomSkills - SRC Files/src/utils/Config.cs b/jRandomSkills - SRC Files/src/utils/Config.cs index 7324dd0..105dbda 100644 --- a/jRandomSkills - SRC Files/src/utils/Config.cs +++ b/jRandomSkills - SRC Files/src/utils/Config.cs @@ -87,6 +87,7 @@ namespace src.utils public bool DisableSkillsOnRoundEnd { get; set; } public LanguageSystem LanguageSystem { get; set; } public HtmlHudCustomisation HtmlHudCustomisation { get; set; } + public ChatMessage ChatMessage { get; set; } public NormalCommands NormalCommands { get; set; } public VotingCommands VotingCommands { get; set; } @@ -143,6 +144,18 @@ namespace src.utils WSADMenuControllsLineColor3 = "green", }; + ChatMessage = new ChatMessage + { + MaxWidth = 1280, + LineSymbol = '―', + LineColor = "\x04", + LineShow = true, + InfoPlayerNameColor = "\x02", + InfoSkillColor = "\x06", + InfoMessageShow = true, + TagFormat = "\x02◢◆◤ {TAG} ◥◆◣", + }; + NormalCommands = new NormalCommands { SetSkillCommand = new NormalCommand("ustawskill, ustaw_skill, setskill, set_skill, definirhabilidade, configurarhabilidade, 设置技能, 配置技能", "@jRandmosSkills/admin"), @@ -168,6 +181,18 @@ namespace src.utils } } + public class ChatMessage + { + public required float MaxWidth { get; set; } + public required char LineSymbol { get; set; } + public required string LineColor { get; set; } + public required bool LineShow { get; set; } + public required string InfoPlayerNameColor { get; set; } + public required string InfoSkillColor { get; set; } + public required bool InfoMessageShow { get; set; } + public required string TagFormat { get; set; } + } + public class HtmlHudCustomisation { public required string HeaderLineColor { get; set; } diff --git a/jRandomSkills - SRC Files/src/utils/MeansureString.cs b/jRandomSkills - SRC Files/src/utils/MeansureString.cs new file mode 100644 index 0000000..0b96c15 --- /dev/null +++ b/jRandomSkills - SRC Files/src/utils/MeansureString.cs @@ -0,0 +1,138 @@ +using CounterStrikeSharp.API; +using System.Text.RegularExpressions; + +namespace src.player; + +public static class MeansureString +{ + static readonly float DefaultCharWidth = 22.25f; + static readonly Dictionary CharWidth = new() + { + ['0'] = 22.25f, + ['1'] = 22.25f, + ['2'] = 22.25f, + ['3'] = 22.25f, + ['4'] = 22.25f, + ['5'] = 22.25f, + ['6'] = 22.25f, + ['7'] = 22.25f, + ['8'] = 22.25f, + ['9'] = 22.25f, + ['a'] = 22.25f, + ['b'] = 22.25f, + ['c'] = 20.00f, + ['d'] = 22.25f, + ['e'] = 22.25f, + ['f'] = 11.11f, + ['g'] = 22.25f, + ['h'] = 22.25f, + ['i'] = 8.89f, + ['j'] = 8.89f, + ['k'] = 20.00f, + ['l'] = 8.89f, + ['m'] = 33.33f, + ['n'] = 22.25f, + ['o'] = 22.25f, + ['p'] = 22.25f, + ['q'] = 22.25f, + ['r'] = 13.33f, + ['s'] = 20.00f, + ['t'] = 11.11f, + ['u'] = 22.25f, + ['v'] = 20.00f, + ['w'] = 28.89f, + ['x'] = 20.00f, + ['y'] = 20.00f, + ['z'] = 20.00f, + ['A'] = 26.69f, + ['B'] = 26.69f, + ['C'] = 28.89f, + ['D'] = 28.89f, + ['E'] = 26.69f, + ['F'] = 24.44f, + ['G'] = 31.11f, + ['H'] = 28.89f, + ['I'] = 11.11f, + ['J'] = 20.00f, + ['K'] = 26.69f, + ['L'] = 22.25f, + ['M'] = 33.33f, + ['N'] = 28.89f, + ['O'] = 31.11f, + ['P'] = 26.69f, + ['Q'] = 31.11f, + ['R'] = 28.89f, + ['S'] = 26.69f, + ['T'] = 24.44f, + ['U'] = 28.89f, + ['V'] = 26.69f, + ['W'] = 37.75f, + ['X'] = 26.69f, + ['Y'] = 26.69f, + ['Z'] = 24.44f, + ['\''] = 7.64f, + ['!'] = 11.11f, + ['@'] = 40.61f, + ['#'] = 22.25f, + ['$'] = 22.25f, + ['%'] = 35.56f, + ['^'] = 18.77f, + ['&'] = 26.69f, + ['*'] = 15.56f, + ['('] = 13.33f, + [')'] = 13.33f, + ['_'] = 22.25f, + ['-'] = 13.33f, + ['+'] = 23.36f, + ['='] = 23.36f, + [','] = 11.11f, + ['.'] = 11.11f, + [';'] = 11.11f, + [':'] = 11.11f, + ['<'] = 23.36f, + ['>'] = 23.36f, + ['/'] = 11.11f, + ['?'] = 22.25f, + ['\\'] = 11.11f, + ['|'] = 10.39f, + ['`'] = 13.33f, + ['~'] = 23.36f, + ['"'] = 14.20f, + [' '] = 11.11f, + ['―'] = 40.00f, + ['◢'] = 30.00f, + ['◆'] = 30.00f, + ['◤'] = 30.00f, + }; + + private static float GetWidth(string s) + { + float w = 0; + foreach (char c in s) + w += CharWidth.TryGetValue(c, out var cw) ? cw : DefaultCharWidth; + return w; + } + + private static string StripColors(string s) + { + if (string.IsNullOrWhiteSpace(s)) return s; + return Regex.Replace(s, @"[\x01-\x10]", string.Empty); + } + + public static string GetTextDashed(string content, float targetWidth, char symbol, string color) + { + string cleanContent = StripColors(content); + float contentWidth = GetWidth(cleanContent); + float dashWidth = CharWidth.TryGetValue(symbol, out var cw) ? cw : DefaultCharWidth; + + float remaining = targetWidth - contentWidth; + + if (remaining <= 0) return content; + int totalDashes = (int)Math.Floor(remaining / dashWidth); + + int left = totalDashes / 2; + int right = totalDashes - left; + + return color + new string(symbol, left) + content + color + new string(symbol, right); + } +} \ No newline at end of file diff --git a/jRandomSkills - SRC Files/src/utils/SkillUtils.cs b/jRandomSkills - SRC Files/src/utils/SkillUtils.cs index 0e980b9..da32e36 100644 --- a/jRandomSkills - SRC Files/src/utils/SkillUtils.cs +++ b/jRandomSkills - SRC Files/src/utils/SkillUtils.cs @@ -20,14 +20,19 @@ namespace src.utils private static readonly MemoryFunctionWithReturn HEGrenadeProjectile_CreateFunc = new(GameData.GetSignature("HEGrenadeProjectile_CreateFunc")); private static readonly MemoryFunctionVoid TerminateRoundFunc = new(GameData.GetSignature("CCSGameRules_TerminateRound")); - public static void PrintToChat(CCSPlayerController player, string msg, string border = "tb", string title = jRandomSkills.Tag) + public static void PrintToChat(CCSPlayerController player, string msg, string border = "tb", string? title = null) { - if (border.Contains('t')) - player.PrintToChat($" {ChatColors.Green}―――――――――――{ChatColors.DarkRed}◢◆◤ {title} ◥◆◣{ChatColors.Green}―――――――――――"); - if (!string.IsNullOrEmpty(msg)) - player.PrintToChat($" {ChatColors.Green} {msg}"); - if (border.Contains('b')) - player.PrintToChat($" {ChatColors.Green}―――――――――――――――{new string('―', title.Length)}―――――――――――――――"); + var config = Config.LoadedConfig.ChatMessage; + float maxWidth = config.MaxWidth; + char symbol = config.LineSymbol; + if (string.IsNullOrEmpty(title)) title = player.GetTranslation("jRandomSkills"); + + if (border.Contains('t') && config.LineShow) + player.PrintToChat($" {MeansureString.GetTextDashed($"{(config.TagFormat.Contains("{TAG}") ? config.TagFormat.Replace("{TAG}", title) : $"\u0002◢◆◤ {title} ◥◆◣")}", maxWidth, symbol, config.LineColor)}"); + if (!string.IsNullOrEmpty(msg) && config.InfoMessageShow) + player.PrintToChat($" {config.InfoSkillColor} {msg.Replace("\x02", config.InfoPlayerNameColor).Replace("\x06", config.InfoSkillColor)}"); + if (border.Contains('b') && config.LineShow) + player.PrintToChat($" {MeansureString.GetTextDashed("", maxWidth, symbol, config.LineColor)}"); } public static bool IsFreezeTime()