Added chat window transparency slider to options (#24990)

* Adds a new slider to the misc tab in options that lets the player set chat window transparency

* Tweaked variable names

* Fixed order to match UI

* Renamed set chat window transparency function

* Changed and refactored to opacity instead of transparency

* Remove unnecessary int to float conversions

Slider used to be 0-100 while the CCVar was 0.0-1.0f. This is confusing and was only used for rounding to 2 decimal points.

* Round the value to two decimal points

* Remove rounding for now

* Rename

* Unhardcode chat color by moving to stylesheet

* Fix indent

* Make opacity slider only change opacity

---------

Co-authored-by: Your Name <you@example.com>
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
This commit is contained in:
Sk1tch
2024-04-01 13:48:02 -07:00
committed by GitHub
parent a05f95269f
commit bc31c193c2
8 changed files with 90 additions and 25 deletions

View File

@@ -9,6 +9,7 @@ using Content.Client.Chat.UI;
using Content.Client.Examine;
using Content.Client.Gameplay;
using Content.Client.Ghost;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Screens;
using Content.Client.UserInterface.Systems.Chat.Widgets;
using Content.Client.UserInterface.Systems.Gameplay;
@@ -54,7 +55,6 @@ public sealed class ChatUIController : UIController
[Dependency] private readonly IStateManager _state = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IReplayRecordingManager _replayRecording = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[UISystemDependency] private readonly ExamineSystem? _examine = default;
[UISystemDependency] private readonly GhostSystem? _ghost = default;
@@ -179,8 +179,8 @@ public sealed class ChatUIController : UIController
_net.RegisterNetMessage<MsgChatMessage>(OnChatMessage);
_net.RegisterNetMessage<MsgDeleteChatMessagesBy>(OnDeleteChatMessagesBy);
SubscribeNetworkEvent<DamageForceSayEvent>(OnDamageForceSay);
_cfg.OnValueChanged(CCVars.ChatEnableColorName, (value) => { _chatNameColorsEnabled = value; });
_chatNameColorsEnabled = _cfg.GetCVar(CCVars.ChatEnableColorName);
_config.OnValueChanged(CCVars.ChatEnableColorName, (value) => { _chatNameColorsEnabled = value; });
_chatNameColorsEnabled = _config.GetCVar(CCVars.ChatEnableColorName);
_speechBubbleRoot = new LayoutContainer();
@@ -232,6 +232,9 @@ public sealed class ChatUIController : UIController
{
_chatNameColors[i] = nameColors[i].ToHex();
}
_config.OnValueChanged(CCVars.ChatWindowOpacity, OnChatWindowOpacityChanged);
}
public void OnScreenLoad()
@@ -240,6 +243,8 @@ public sealed class ChatUIController : UIController
var viewportContainer = UIManager.ActiveScreen!.FindControl<LayoutContainer>("ViewportContainer");
SetSpeechBubbleRoot(viewportContainer);
SetChatWindowOpacity(_config.GetCVar(CCVars.ChatWindowOpacity));
}
public void OnScreenUnload()
@@ -247,6 +252,34 @@ public sealed class ChatUIController : UIController
SetMainChat(false);
}
private void OnChatWindowOpacityChanged(float opacity)
{
SetChatWindowOpacity(opacity);
}
private void SetChatWindowOpacity(float opacity)
{
var chatBox = UIManager.ActiveScreen?.GetWidget<ChatBox>() ?? UIManager.ActiveScreen?.GetWidget<ResizableChatBox>();
var panel = chatBox?.ChatWindowPanel;
if (panel is null)
return;
Color color;
if (panel.PanelOverride is StyleBoxFlat styleBoxFlat)
color = styleBoxFlat.BackgroundColor;
else if (panel.TryGetStyleProperty<StyleBox>(PanelContainer.StylePropertyPanel, out var style)
&& style is StyleBoxFlat propStyleBoxFlat)
color = propStyleBoxFlat.BackgroundColor;
else
color = StyleNano.ChatBackgroundColor;
panel.PanelOverride = new StyleBoxFlat
{
BackgroundColor = color.WithAlpha(opacity)
};
}
public void SetMainChat(bool setting)
{
if (UIManager.ActiveScreen == null)
@@ -770,7 +803,7 @@ public sealed class ChatUIController : UIController
ProcessChatMessage(msg);
if ((msg.Channel & ChatChannel.AdminRelated) == 0 ||
_cfg.GetCVar(CCVars.ReplayRecordAdminChat))
_config.GetCVar(CCVars.ReplayRecordAdminChat))
{
_replayRecording.RecordClientMessage(msg);
}
@@ -830,7 +863,7 @@ public sealed class ChatUIController : UIController
break;
case ChatChannel.LOOC:
if (_cfg.GetCVar(CCVars.LoocAboveHeadShow))
if (_config.GetCVar(CCVars.LoocAboveHeadShow))
AddSpeechBubble(msg, SpeechBubble.SpeechType.Looc);
break;
}