Store chat size (#14299)

This commit is contained in:
Flipp Syder
2023-03-06 11:06:57 -08:00
committed by GitHub
parent 11d4dec18f
commit ec3a519a46
10 changed files with 224 additions and 19 deletions

View File

@@ -7,6 +7,8 @@ using Content.Client.Chat.UI;
using Content.Client.Examine;
using Content.Client.Gameplay;
using Content.Client.Ghost;
using Content.Client.Lobby.UI;
using Content.Client.UserInterface.Screens;
using Content.Client.UserInterface.Systems.Chat.Widgets;
using Content.Shared.Administration;
using Content.Shared.CCVar;
@@ -184,18 +186,85 @@ public sealed class ChatUIController : UIController
public void SetMainChat(bool setting)
{
// This isn't very nice to look at.
var widget = UIManager.ActiveScreen?.GetWidget<ChatBox>();
if (widget == null)
if (UIManager.ActiveScreen == null)
{
widget = UIManager.ActiveScreen?.GetWidget<ResizableChatBox>();
if (widget == null)
{
return;
}
return;
}
widget.Main = setting;
ChatBox chatBox;
string? chatSizeRaw;
switch (UIManager.ActiveScreen)
{
case DefaultGameScreen defaultScreen:
chatBox = defaultScreen.ChatBox;
chatSizeRaw = _config.GetCVar(CCVars.DefaultScreenChatSize);
SetChatSizing(chatSizeRaw, defaultScreen, setting);
break;
case SeparatedChatGameScreen separatedScreen:
chatBox = separatedScreen.ChatBox;
chatSizeRaw = _config.GetCVar(CCVars.SeparatedScreenChatSize);
SetChatSizing(chatSizeRaw, separatedScreen, setting);
break;
default:
// this could be better?
var maybeChat = UIManager.ActiveScreen.GetWidget<ChatBox>();
chatBox = maybeChat ?? throw new Exception("Cannot get chat box in screen!");
break;
}
chatBox.Main = setting;
}
private void SetChatSizing(string sizing, InGameScreen screen, bool setting)
{
if (!setting)
{
screen.OnChatResized -= StoreChatSize;
return;
}
screen.OnChatResized += StoreChatSize;
if (string.IsNullOrEmpty(sizing))
{
return;
}
var split = sizing.Split(",");
var chatSize = new Vector2(
float.Parse(split[0]),
float.Parse(split[1]));
screen.SetChatSize(chatSize);
}
private void StoreChatSize(Vector2 size)
{
if (UIManager.ActiveScreen == null)
{
throw new Exception("Cannot get active screen!");
}
var stringSize = $"{size.X},{size.Y}";
switch (UIManager.ActiveScreen)
{
case DefaultGameScreen _:
_config.SetCVar(CCVars.DefaultScreenChatSize, stringSize);
break;
case SeparatedChatGameScreen _:
_config.SetCVar(CCVars.SeparatedScreenChatSize, stringSize);
break;
default:
// do nothing
return;
}
_config.SaveToFile();
}
private void FocusChat()