Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Content.Client/Chat/UI/SpeechBubble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ public enum SpeechType : byte
/// </summary>
public const float SpeechMaxWidth = 256;

/// <summary>
/// White Dream;
/// Max amount of characters in a speech bubble
/// </summary>
public int SingleBubbleCharLimit
{
get
{
var cvar = ConfigManager.GetCVar(WhiteCVars.SingleBubbleCharLimit);

if (cvar <= 0)
{
Logger.Error("Local CVar chat.bubble_character_limit is set to 0 or lower");
cvar = 1;
}

return cvar;
}
}

private readonly EntityUid _senderEntity;

private float _timeLeft = TotalTime;
Expand Down Expand Up @@ -222,6 +242,23 @@ protected FormattedMessage ExtractAndFormatSpeechSubstring(ChatMessage message,
return FormatSpeech(SharedChatSystem.GetStringInsideTag(message, tag), fontColor);
}

// WWDP EDIT START
public ChatMessage TruncateWrappedMessage(ChatMessage message, int maxLength)
{
var text = SharedChatSystem.GetStringInsideTag(message, "BubbleContent");

if (text.Length <= maxLength)
return message;

text = text[..maxLength].TrimEnd(' ', '.', ',', ';', ':', '!', '?') + "...";

var newmsg = SharedChatSystem.SetStringInsideTag(message,"BubbleContent", text);

message.WrappedMessage = newmsg;

return message;
}
// WWDP EDIT END
}

public sealed class TextSpeechBubble : SpeechBubble
Expand All @@ -238,6 +275,8 @@ protected override Control BuildBubble(ChatMessage message, string speechStyleCl
MaxWidth = SpeechMaxWidth,
};

message = TruncateWrappedMessage(message, SingleBubbleCharLimit); // WWDP edit

label.SetMessage(FormatSpeech(message.WrappedMessage, fontColor, "Bedstead")); // WWDP EDIT

var panel = new PanelContainer
Expand Down Expand Up @@ -268,6 +307,8 @@ protected override Control BuildBubble(ChatMessage message, string speechStyleCl
MaxWidth = SpeechMaxWidth
};

message = TruncateWrappedMessage(message, SingleBubbleCharLimit); // WWDP edit

label.SetMessage(FormatSpeech(SharedChatSystem.GetStringInsideTag(message, "BubbleContent"), fontColor, "Bedstead")); // WWDP EDIT // LESS USELESS ONE LINER FUNCS PLS

var unfanciedPanel = new PanelContainer
Expand Down
32 changes: 26 additions & 6 deletions Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Content.Client.UserInterface.Screens;
using Content.Client.UserInterface.Systems.Chat.Widgets;
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Shared._White.CCVar;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.Chat;
Expand Down Expand Up @@ -107,7 +108,7 @@ public sealed class ChatUIController : UIController
/// <summary>
/// The max amount of chars allowed to fit in a single speech bubble.
/// </summary>
private const int SingleBubbleCharLimit = 100;
private int SingleBubbleCharLimit => _config.GetCVar(WhiteCVars.SingleBubbleCharLimit); // WWDP moved to WhiteCvars

/// <summary>
/// Base queue delay each speech bubble has.
Expand All @@ -117,12 +118,28 @@ public sealed class ChatUIController : UIController
/// <summary>
/// Factor multiplied by speech bubble char length to add to delay.
/// </summary>
private const float BubbleDelayFactor = 0.8f / SingleBubbleCharLimit;
private const float BubbleDelayFactor = 0.8f / 100; // WWDP edit

// WWDP edit start
/// <summary>
/// The max amount of speech bubbles over a single entity at once.
/// </summary>
private const int SpeechBubbleCap = 4;
private int SpeechBubbleCap
{
get
{
var cvar = _config.GetCVar(WhiteCVars.SpeechBubbleCap);

if (cvar <= 0)
{
Logger.Error("Local CVar chat.bubble_max_count is set to 0 or lower");
cvar = 1;
}

return cvar;
}
}
// WWDP edit end

private LayoutContainer _speechBubbleRoot = default!;

Expand Down Expand Up @@ -460,9 +477,12 @@ private void CreateSpeechBubble(EntityUid entity, SpeechBubbleData speechData)

if (existing.Count > SpeechBubbleCap)
{
// Get the oldest to start fading fast.
var last = existing[0];
last.FadeNow();
// WWDP edit start
// Get all of the older ones
var lastBubbles = existing[..^SpeechBubbleCap];
foreach (var last in lastBubbles)
last.FadeNow();
// WWDP edit end
}
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/_White/TTS/TTSSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class TTSSystem : EntitySystem
[Dependency] private readonly SharedTransformSystem _xforms = default!;
[Dependency] private readonly LanguageSystem _language = default!;

private const int MaxMessageChars = 100 * 2; // same as SingleBubbleCharLimit * 2
private int MaxMessageChars => _cfg.GetCVar(WhiteCVars.SingleBubbleCharLimit) * 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Поиск файла TTSSystem.cs и WhiteCVars.cs
find . -type f -name "TTSSystem.cs" -o -name "WhiteCVars.cs" | head -20

Repository: WWhiteDreamProject/wwdpublic

Length of output: 197


🏁 Script executed:

#!/bin/bash
# Поиск файлов, содержащих SingleBubbleCharLimit
rg "SingleBubbleCharLimit" -l --type=cs

Repository: WWhiteDreamProject/wwdpublic

Length of output: 258


🏁 Script executed:

#!/bin/bash
# Проверка содержимого файла TTSSystem.cs около строки 27
rg -B 10 -A 10 "MaxMessageChars" Content.Server/_White/TTS/TTSSystem.cs

Repository: WWhiteDreamProject/wwdpublic

Length of output: 1587


🏁 Script executed:

#!/bin/bash
# Найти определение SingleBubbleCharLimit в WhiteCVars
rg -B 2 -A 2 "SingleBubbleCharLimit" Content.Shared/_White/CCVar/WhiteCVars.cs

Repository: WWhiteDreamProject/wwdpublic

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Найти определение TTSEnabled для сравнения флагов
rg -B 2 -A 2 "TTSEnabled" Content.Shared/_White/CCVar/WhiteCVars.cs

Repository: WWhiteDreamProject/wwdpublic

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Проверить все CVAR определения в файле WhiteCVars для понимания паттерна
cat Content.Shared/_White/CCVar/WhiteCVars.cs | head -100

Repository: WWhiteDreamProject/wwdpublic

Length of output: 631


🏁 Script executed:

#!/bin/bash
# Найти все файлы WhiteCVars.*
find . -type f -name "WhiteCVars*.cs" | xargs ls -la

Repository: WWhiteDreamProject/wwdpublic

Length of output: 1477


🏁 Script executed:

#!/bin/bash
# Прочитать WhiteCVars.Chat.cs
cat Content.Shared/_White/CCVar/WhiteCVars.Chat.cs

Repository: WWhiteDreamProject/wwdpublic

Length of output: 908


🏁 Script executed:

#!/bin/bash
# Прочитать WhiteCVars.TTS.cs
cat Content.Shared/_White/CCVar/WhiteCVars.TTS.cs

Repository: WWhiteDreamProject/wwdpublic

Length of output: 1799


🏁 Script executed:

#!/bin/bash
# Поиск других примеров, где серверный код читает CLIENT CVAR
rg -B 3 -A 3 "GetCVar.*CVar\.CLIENT" --type=cs | head -50

Repository: WWhiteDreamProject/wwdpublic

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Проверить доступ к GetCVar в серверном контексте для CLIENT-only CVAR
rg "IConfigurationManager.*GetCVar" --type=cs -A 2 | head -50

Repository: WWhiteDreamProject/wwdpublic

Length of output: 800


🏁 Script executed:

#!/bin/bash
# Проверить как GetCVar работает с CLIENT-only CVARs
# Найти примеры использования GetCVar с CLIENT флагом на сервере
rg "GetCVar.*SingleBubbleCharLimit|GetCVar.*ColoredBubbleChat|GetCVar.*ChatFancyFont" --type=cs -B 2 -A 2

Repository: WWhiteDreamProject/wwdpublic

Length of output: 1861


🏁 Script executed:

#!/bin/bash
# Проверить документацию или комментарии про множитель * 2
rg -B 5 -A 5 "MaxMessageChars|SingleBubbleCharLimit.*\*.*2" Content.Server/_White/TTS/TTSSystem.cs

Repository: WWhiteDreamProject/wwdpublic

Length of output: 988


🏁 Script executed:

#!/bin/bash
# Проверить, есть ли другие примеры в TTSSystem.cs, где используется MaxMessageChars
cat -n Content.Server/_White/TTS/TTSSystem.cs | grep -i "maxmessagechars\|singlebubble"

Repository: WWhiteDreamProject/wwdpublic

Length of output: 238


Исправьте доступность CVAR на сервере.

SingleBubbleCharLimit определён с флагами CVar.CLIENT | CVar.ARCHIVE (без CVar.SERVER или CVar.REPLICATED). Серверный код читает эту переменную через GetCVar(), но для CLIENT-only CVAR будет возвращаться только значение по умолчанию (43), независимо от конфигурации клиента. Это несогласовано с TTSEnabled, которая правильно использует флаг CVar.SERVER | CVar.REPLICATED.

Чтобы исправить:

  1. Добавьте флаг CVar.REPLICATED в определение SingleBubbleCharLimit в WhiteCVars.Chat.cs, либо переместите в WhiteCVars.TTS.cs с флагом CVar.SERVER | CVar.REPLICATED.
  2. Добавьте комментарий, объясняющий множитель * 2 в строке 27 — почему сервер использует двойное значение лимита по сравнению с клиентом.
  3. Рассмотрите кэширование MaxMessageChars через OnValueChanged (как для _isEnabled) вместо вычисления свойства на каждый вызов.

private bool _isEnabled;

public override void Initialize()
Expand Down
16 changes: 16 additions & 0 deletions Content.Shared/Chat/SharedChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,22 @@ public static string GetStringInsideTag(ChatMessage message, string tag)
return rawmsg.Substring(tagStart, tagEnd - tagStart);
}

// WWDP edit start
// Returns a message with a string inside tag removed and replaced
public static string SetStringInsideTag(ChatMessage message, string tag, string strInsert)
{
var rawmsg = message.WrappedMessage;
var tagStart = rawmsg.IndexOf($"[{tag}]");
var tagEnd = rawmsg.IndexOf($"[/{tag}]");
if (tagStart < 0 || tagEnd < 0)
return rawmsg;
tagStart += tag.Length + 2;
rawmsg = rawmsg.Remove(tagStart, tagEnd - tagStart);
rawmsg = rawmsg.Insert(tagStart, $"{strInsert}");
return rawmsg;
}
// WWDP edit end

// WD EDIT START - Moved from ClatUIController
/// <summary>
/// Returns the chat name color for a mob
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/_White/CCVar/WhiteCVars.Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ public sealed partial class WhiteCVars

public static readonly CVarDef<bool> ColoredBubbleChat =
CVarDef.Create("chat.colored_bubble", true, CVar.CLIENTONLY | CVar.ARCHIVE);

public static readonly CVarDef<int> SingleBubbleCharLimit =
CVarDef.Create("chat.bubble_character_limit", 43, CVar.CLIENT | CVar.ARCHIVE);

public static readonly CVarDef<int> SpeechBubbleCap =
CVarDef.Create("chat.bubble_max_count", 1, CVar.CLIENT | CVar.ARCHIVE);
}
Loading