Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

реверт чатстака на время фиксов #947

Merged
merged 2 commits into from
Dec 27, 2024
Merged
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
40 changes: 9 additions & 31 deletions Content.Client/Chat/UI/SpeechBubble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,6 @@ public enum SpeechType : byte
Looc
}

protected RichTextLabel? ContentLabel;

public void UpdateText(ChatMessage message, int repeat)
{
if (ContentLabel == null)
return;

if (this is TextSpeechBubble)
{
var updatedMessage = $"{message.WrappedMessage} x{repeat}";
ContentLabel.SetMessage(FormatSpeech(updatedMessage));
}
else if (this is FancyTextSpeechBubble)
{
var bubbleContent = SharedChatSystem.GetStringInsideTag(message, "BubbleContent");
var updatedMessage = $"{bubbleContent} x{repeat}";
ContentLabel.SetMessage(FormatSpeech(updatedMessage));
}

_timeLeft = TotalTime;
}

/// <summary>
/// The total time a speech bubble stays on screen.
/// </summary>
Expand Down Expand Up @@ -228,17 +206,17 @@ public TextSpeechBubble(ChatMessage message, EntityUid senderEntity, string spee

protected override Control BuildBubble(ChatMessage message, string speechStyleClass, Color? fontColor = null)
{
ContentLabel = new RichTextLabel
var label = new RichTextLabel
{
MaxWidth = SpeechMaxWidth,
};

ContentLabel.SetMessage(FormatSpeech(message.WrappedMessage, fontColor));
label.SetMessage(FormatSpeech(message.WrappedMessage, fontColor));

var panel = new PanelContainer
{
StyleClasses = { "speechBox", speechStyleClass },
Children = { ContentLabel },
Children = { label },
ModulateSelfOverride = Color.White.WithAlpha(0.75f)
};

Expand All @@ -258,17 +236,17 @@ protected override Control BuildBubble(ChatMessage message, string speechStyleCl
{
if (!ConfigManager.GetCVar(CCVars.ChatEnableFancyBubbles))
{
ContentLabel = new RichTextLabel
var label = new RichTextLabel
{
MaxWidth = SpeechMaxWidth
};

ContentLabel.SetMessage(ExtractAndFormatSpeechSubstring(message, "BubbleContent", fontColor));
label.SetMessage(ExtractAndFormatSpeechSubstring(message, "BubbleContent", fontColor));

var unfanciedPanel = new PanelContainer
{
StyleClasses = { "speechBox", speechStyleClass },
Children = { ContentLabel },
Children = { label },
ModulateSelfOverride = Color.White.WithAlpha(0.75f)
};
return unfanciedPanel;
Expand All @@ -279,7 +257,7 @@ protected override Control BuildBubble(ChatMessage message, string speechStyleCl
Margin = new Thickness(1, 1, 1, 1)
};

ContentLabel = new RichTextLabel
var bubbleContent = new RichTextLabel
{
MaxWidth = SpeechMaxWidth,
Margin = new Thickness(2, 6, 2, 2),
Expand All @@ -288,13 +266,13 @@ protected override Control BuildBubble(ChatMessage message, string speechStyleCl

//We'll be honest. *Yes* this is hacky. Doing this in a cleaner way would require a bottom-up refactor of how saycode handles sending chat messages. -Myr
bubbleHeader.SetMessage(ExtractAndFormatSpeechSubstring(message, "BubbleHeader", fontColor));
ContentLabel.SetMessage(ExtractAndFormatSpeechSubstring(message, "BubbleContent", fontColor));
bubbleContent.SetMessage(ExtractAndFormatSpeechSubstring(message, "BubbleContent", fontColor));

//As for below: Some day this could probably be converted to xaml. But that is not today. -Myr
var mainPanel = new PanelContainer
{
StyleClasses = { "speechBox", speechStyleClass },
Children = { ContentLabel },
Children = { bubbleContent },
ModulateSelfOverride = Color.White.WithAlpha(0.75f),
HorizontalAlignment = HAlignment.Center,
VerticalAlignment = VAlignment.Bottom,
Expand Down
58 changes: 3 additions & 55 deletions Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@

namespace Content.Client.UserInterface.Systems.Chat;

public class SpeechBubbleStack
{
public required SpeechBubble Bubble { get; set; }
public required string Message { get; set; }
public int RepeatCount { get; set; } = 1;
public SpeechBubble.SpeechType Type { get; set; }
}

public sealed class ChatUIController : UIController
{
[Dependency] private readonly IClientAdminManager _admin = default!;
Expand Down Expand Up @@ -180,10 +172,6 @@ private readonly Dictionary<EntityUid, SpeechBubbleQueueData> _queuedSpeechBubbl
public ChatSelectChannel SelectableChannels { get; private set; }
private ChatSelectChannel PreferredChannel { get; set; } = ChatSelectChannel.OOC;

public ChatMessage? LastMessage = null;

private readonly Dictionary<EntityUid, SpeechBubbleStack> _lastBubbles = new();

public event Action<ChatSelectChannel>? CanSendChannelsChanged;
public event Action<ChatChannel>? FilterableChannelsChanged;
public event Action<ChatSelectChannel>? SelectableChannelsChanged;
Expand Down Expand Up @@ -466,19 +454,9 @@ private void AddSpeechBubble(ChatMessage msg, SpeechBubble.SpeechType speechType

private void CreateSpeechBubble(EntityUid entity, SpeechBubbleData speechData)
{
var message = speechData.Message;
var type = speechData.Type;
var bubble =
SpeechBubble.CreateSpeechBubble(speechData.Type, speechData.Message, entity);

if (_lastBubbles.TryGetValue(entity, out var stack) &&
stack.Message == message.WrappedMessage &&
stack.Type == type)
{
stack.RepeatCount++;
stack.Bubble.UpdateText(message, stack.RepeatCount);
return;
}

var bubble = SpeechBubble.CreateSpeechBubble(type, message, entity);
bubble.OnDied += SpeechBubbleDied;

if (_activeSpeechBubbles.TryGetValue(entity, out var existing))
Expand All @@ -498,13 +476,6 @@ private void CreateSpeechBubble(EntityUid entity, SpeechBubbleData speechData)
existing.Add(bubble);
_speechBubbleRoot.AddChild(bubble);

_lastBubbles[entity] = new SpeechBubbleStack
{
Bubble = bubble,
Message = message.WrappedMessage,
Type = type
};

if (existing.Count > SpeechBubbleCap)
{
// Get the oldest to start fading fast.
Expand Down Expand Up @@ -540,9 +511,6 @@ public void RemoveSpeechBubble(EntityUid entityUid, SpeechBubble bubble)
var list = _activeSpeechBubbles[entityUid];
list.Remove(bubble);

if (_lastBubbles.TryGetValue(entityUid, out var stack) && stack.Bubble == bubble)
_lastBubbles.Remove(entityUid);

if (list.Count == 0)
{
_activeSpeechBubbles.Remove(entityUid);
Expand Down Expand Up @@ -912,22 +880,6 @@ public void ProcessChatMessage(ChatMessage msg, bool speechBubble = true)
}
}

if (LastMessage != null && msg.Message == LastMessage.Message)
{
LastMessage.repeat++;
LastMessage.WrappedMessage = msg.WrappedMessage + $" x{LastMessage.repeat}";

foreach (var chat in _chats)
{
chat.UpdateMessage(chat.GetHistoryLength() - 1, LastMessage);
}

TryBuble(msg, speechBubble);
return;
}

LastMessage = msg;

// Log all incoming chat to repopulate when filter is un-toggled
if (!msg.HideChat)
{
Expand All @@ -946,11 +898,7 @@ public void ProcessChatMessage(ChatMessage msg, bool speechBubble = true)
}
}

TryBuble(msg, speechBubble);
}

private void TryBuble(ChatMessage msg, bool speechBubble)
{
// Local messages that have an entity attached get a speech bubble.
if (!speechBubble || msg.SenderEntity == default)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
xmlns="https://spacestation14.io"
xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Chat.Widgets"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Systems.Chat.Controls"
xmlns:controls1="clr-namespace:Content.Client._Sunrise.UI.Controls"
MouseFilter="Stop"
HorizontalExpand="True"
VerticalExpand="True"
MinSize="465 225">
<PanelContainer Name="ChatWindowPanel" Access="Public" HorizontalExpand="True" VerticalExpand="True"
StyleClasses="StyleNano.StyleClassChatPanel">
<BoxContainer Orientation="Vertical" SeparationOverride="4" HorizontalExpand="True" VerticalExpand="True">
<controls1:SunriseOutputPanel Name="Contents" HorizontalExpand="True" VerticalExpand="True" Margin="8 8 8 4" />
<OutputPanel Name="Contents" HorizontalExpand="True" VerticalExpand="True" Margin="8 8 8 4" />
<controls:ChatInputBox HorizontalExpand="True" Name="ChatInput" Access="Public" Margin="2"/>
</BoxContainer>
</PanelContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,6 @@ private void OnChannelFilter(ChatChannel channel, bool active)
}
}

public int GetHistoryLength()
{
return _controller.History.Count;
}

public void UpdateMessage(int index, ChatMessage message)
{
var updatedTuple = (_controller.History[index].Item1, message);
_controller.History.Pop();
_controller.History.Add(updatedTuple);

var color = message.MessageColorOverride != null
? message.MessageColorOverride.Value
: message.Channel.TextColor();

var formatted = new FormattedMessage(3);

formatted.AddMarkup(message.WrappedMessage);
formatted.PushColor(color);

Contents.UpdateLastMessage(formatted);
}

public void AddLine(string message, Color color)
{
var formatted = new FormattedMessage(3);
Expand Down
Loading
Loading