]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Store chat size (#14299)
authorFlipp Syder <76629141+vulppine@users.noreply.github.com>
Mon, 6 Mar 2023 19:06:57 +0000 (11:06 -0800)
committerGitHub <noreply@github.com>
Mon, 6 Mar 2023 19:06:57 +0000 (11:06 -0800)
Content.Client/Gameplay/GameplayState.cs
Content.Client/Lobby/UI/LobbyGui.xaml.cs
Content.Client/UserInterface/Controls/RecordedSplitContainer.cs [new file with mode: 0644]
Content.Client/UserInterface/Screens/DefaultGameScreen.xaml.cs
Content.Client/UserInterface/Screens/InGameScreen.cs [new file with mode: 0644]
Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml
Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml.cs
Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Content.Client/UserInterface/Systems/Chat/Widgets/ResizableChatBox.cs
Content.Shared/CCVar/CCVars.cs

index 44914c7beeb1ee839aab27089fca2d6e48847dd2..f50c4934082ccb36888840f0e16cc646ae322ce7 100644 (file)
@@ -5,6 +5,7 @@ using Content.Client.UserInterface.Screens;
 using Content.Client.UserInterface.Systems.Actions;
 using Content.Client.UserInterface.Systems.Alerts;
 using Content.Client.UserInterface.Systems.Chat;
+using Content.Client.UserInterface.Systems.Chat.Widgets;
 using Content.Client.UserInterface.Systems.Ghost;
 using Content.Client.UserInterface.Systems.Hands;
 using Content.Client.UserInterface.Systems.Hotbar;
@@ -127,6 +128,7 @@ namespace Content.Client.Gameplay
             {
                 case ScreenType.Default:
                     _uiManager.LoadScreen<DefaultGameScreen>();
+
                     break;
                 case ScreenType.Separated:
                     _uiManager.LoadScreen<SeparatedChatGameScreen>();
index 6132b8f8bf45f4b99e6efb0f96af83c3fc5cddf2..62cbac420bc0c81b7e0835c02f1d529a79cf7c6f 100644 (file)
@@ -2,6 +2,8 @@ using Content.Client.Chat.UI;
 using Content.Client.Info;
 using Content.Client.Preferences;
 using Content.Client.Preferences.UI;
+using Content.Client.UserInterface.Screens;
+using Content.Client.UserInterface.Systems.Chat.Widgets;
 using Content.Client.UserInterface.Systems.EscapeMenu;
 using Robust.Client.AutoGenerated;
 using Robust.Client.Console;
diff --git a/Content.Client/UserInterface/Controls/RecordedSplitContainer.cs b/Content.Client/UserInterface/Controls/RecordedSplitContainer.cs
new file mode 100644 (file)
index 0000000..28021e3
--- /dev/null
@@ -0,0 +1,76 @@
+using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.Controls;
+using Robust.Shared.Input;
+
+namespace Content.Client.UserInterface.Controls;
+
+/// <summary>
+///     A split container that performs an action when the split resizing is finished.
+/// </summary>
+public sealed class RecordedSplitContainer : SplitContainer
+{
+    public Action<Vector2, Vector2>? OnSplitResizeFinish;
+
+    public double? DesiredSplitCenter;
+
+    protected override Vector2 ArrangeOverride(Vector2 finalSize)
+    {
+        if (ResizeMode == SplitResizeMode.RespectChildrenMinSize
+            && DesiredSplitCenter != null)
+        {
+            var secondMin = GetChild(1).DesiredSize;
+            double minSize = Orientation == SplitOrientation.Vertical
+                ? secondMin.Y
+                : secondMin.X;
+            double finalSizeComponent = Orientation == SplitOrientation.Vertical
+                ? finalSize.Y
+                : finalSize.X;
+
+            var firstTotalFractional = (finalSizeComponent - minSize - SplitWidth - SplitEdgeSeparation) / finalSizeComponent;
+            DesiredSplitCenter = Math.Round(DesiredSplitCenter.Value, 2, MidpointRounding.ToZero);
+
+            // total space the split center takes up must fit the available space percentage given to the first child
+            var canFirstFit = DesiredSplitCenter <= firstTotalFractional;
+
+            if (DesiredSplitCenter > 1 || DesiredSplitCenter < 0 || !canFirstFit)
+            {
+                DesiredSplitCenter = Math.Round(firstTotalFractional, 2, MidpointRounding.ToZero);
+            }
+
+            // don't need anything more than two digits of precision for this
+            var currentSplitFraction = Math.Round(SplitFraction, 2, MidpointRounding.ToZero);
+
+            // brute force it
+            if (currentSplitFraction != DesiredSplitCenter.Value)
+            {
+                SplitFraction = (float) DesiredSplitCenter.Value;
+            }
+            else
+            {
+                DesiredSplitCenter = null;
+            }
+        }
+
+        return base.ArrangeOverride(finalSize);
+    }
+
+    protected override void KeyBindUp(GUIBoundKeyEventArgs args)
+    {
+        base.KeyBindUp(args);
+
+        if (args.Function != EngineKeyFunctions.UIClick)
+        {
+            return;
+        }
+
+        if (ChildCount != 2)
+        {
+            return;
+        }
+
+        var first = GetChild(0);
+        var second = GetChild(1);
+
+        OnSplitResizeFinish?.Invoke(first.Size, second.Size);
+    }
+}
index abbaad7b7d79ac4865dbb1c7a37d95115a168dd8..28329706040d8856876764ca0e592acdd0d5e83c 100644 (file)
@@ -1,11 +1,13 @@
-using Robust.Client.AutoGenerated;
+using Content.Client.UserInterface.Systems.Chat.Widgets;
+using Robust.Client.AutoGenerated;
 using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.XAML;
 
 namespace Content.Client.UserInterface.Screens;
 
 [GenerateTypedNameReferences]
-public sealed partial class DefaultGameScreen : UIScreen
+public sealed partial class DefaultGameScreen : InGameScreen
 {
     public DefaultGameScreen()
     {
@@ -23,6 +25,14 @@ public sealed partial class DefaultGameScreen : UIScreen
         SetAnchorAndMarginPreset(Alerts, LayoutPreset.TopRight, margin: 10);
 
         Chat.OnResized += ChatOnResized;
+        Chat.OnChatResizeFinish += ChatOnResizeFinish;
+    }
+
+    private void ChatOnResizeFinish(Vector2 _)
+    {
+        var marginBottom = Chat.GetValue<float>(MarginBottomProperty);
+        var marginLeft = Chat.GetValue<float>(MarginLeftProperty);
+        OnChatResized?.Invoke(new Vector2(marginBottom, marginLeft));
     }
 
     private void ChatOnResized()
@@ -30,4 +40,14 @@ public sealed partial class DefaultGameScreen : UIScreen
         var marginBottom = Chat.GetValue<float>(MarginBottomProperty);
         SetMarginTop(Alerts, marginBottom);
     }
+
+    public override ChatBox ChatBox => Chat;
+
+    //TODO: There's probably a better way to do this... but this is also the easiest way.
+    public override void SetChatSize(Vector2 size)
+    {
+        SetMarginBottom(Chat, size.X);
+        SetMarginLeft(Chat, size.Y);
+        SetMarginTop(Alerts, Size.X);
+    }
 }
diff --git a/Content.Client/UserInterface/Screens/InGameScreen.cs b/Content.Client/UserInterface/Screens/InGameScreen.cs
new file mode 100644 (file)
index 0000000..7220bf0
--- /dev/null
@@ -0,0 +1,17 @@
+using Content.Client.UserInterface.Systems.Chat.Widgets;
+using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.Controls;
+
+namespace Content.Client.UserInterface.Screens;
+
+/// <summary>
+///     Screens that are considered to be 'in-game'.
+/// </summary>
+public abstract class InGameScreen : UIScreen
+{
+    public Action<Vector2>? OnChatResized;
+
+    public abstract ChatBox ChatBox { get; }
+
+    public abstract void SetChatSize(Vector2 size);
+}
index 6fc95012876f6b43bb1c87cf2b0a5b6fab8b8f4c..84f1eea1251a879bc3dfa03e120740914f033221 100644 (file)
     VerticalExpand="False"
     VerticalAlignment="Bottom"
     HorizontalAlignment="Center">
-    <SplitContainer Name="ScreenContainer"
-                    HorizontalExpand="True"
-                    VerticalExpand="True"
-                    SplitWidth="0">
+    <controls:RecordedSplitContainer Name="ScreenContainer" HorizontalExpand="True" VerticalExpand="True" SplitWidth="0">
         <LayoutContainer Name="ViewportContainer" HorizontalExpand="True" VerticalExpand="True">
             <controls:MainViewport Name="MainViewport"/>
             <widgets:GhostGui Name="Ghost" Access="Protected" />
             <actions:ActionsBar Name="Actions" Access="Protected" />
             <alerts:AlertsUI Name="Alerts" Access="Protected" />
         </LayoutContainer>
-        <PanelContainer HorizontalExpand="True">
+        <PanelContainer HorizontalExpand="True" MinWidth="300">
             <PanelContainer.PanelOverride>
                 <graphics:StyleBoxFlat BackgroundColor="#2B2C3B" />
             </PanelContainer.PanelOverride>
 
-            <BoxContainer Orientation="Vertical" HorizontalExpand="True" MinWidth="300" SeparationOverride="10" Margin="10">
+            <BoxContainer Orientation="Vertical" HorizontalExpand="True" SeparationOverride="10" Margin="10">
                 <menuBar:GameTopMenuBar Name="TopBar" HorizontalExpand="True" Access="Protected" />
                 <chat:ChatBox VerticalExpand="True" HorizontalExpand="True" Name="Chat" Access="Protected" />
             </BoxContainer>
         </PanelContainer>
-    </SplitContainer>
+    </controls:RecordedSplitContainer>
 </screens:SeparatedChatGameScreen>
index f15819484d968916753690ba0ad9324dc44d77a6..da7903766feafc6dcb7baabc4bcfdd671c94e7ea 100644 (file)
@@ -1,11 +1,13 @@
+using Content.Client.UserInterface.Systems.Chat.Widgets;
 using Robust.Client.AutoGenerated;
 using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.XAML;
 
 namespace Content.Client.UserInterface.Screens;
 
 [GenerateTypedNameReferences]
-public sealed partial class SeparatedChatGameScreen : UIScreen
+public sealed partial class SeparatedChatGameScreen : InGameScreen
 {
     public SeparatedChatGameScreen()
     {
@@ -20,5 +22,16 @@ public sealed partial class SeparatedChatGameScreen : UIScreen
         SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80);
         SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);
         SetAnchorAndMarginPreset(Alerts, LayoutPreset.CenterRight, margin: 10);
+
+        ScreenContainer.OnSplitResizeFinish += (first, second) =>
+            OnChatResized?.Invoke(new Vector2(ScreenContainer.SplitFraction, 0));
+    }
+
+    public override ChatBox ChatBox => GetWidget<ChatBox>()!;
+
+    public override void SetChatSize(Vector2 size)
+    {
+        ScreenContainer.DesiredSplitCenter = size.X;
+        ScreenContainer.ResizeMode = SplitContainer.SplitResizeMode.RespectChildrenMinSize;
     }
 }
index 33f1de054707fc4360592dba642cf66b99cda274..f493c3e6f574f908ba1b79dd1f007325937a4984 100644 (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;
+        }
+
+        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;
-            }
         }
 
-        widget.Main = setting;
+        _config.SaveToFile();
     }
 
     private void FocusChat()
index 004b054806a7277009219b36a7be3b0b229e47a1..492ebcc9da90453251f45c3fe7a15076835be0db 100644 (file)
@@ -31,6 +31,8 @@ public sealed class ResizableChatBox : ChatBox
 
         private byte _clampIn;
 
+        public Action<Vector2>? OnChatResizeFinish;
+
         protected override void EnteredTree()
         {
             base.EnteredTree();
@@ -73,6 +75,8 @@ public sealed class ResizableChatBox : ChatBox
 
                 // If this is done in MouseDown, Godot won't fire MouseUp as you need focus to receive MouseUps.
                 UserInterfaceManager.KeyboardFocused?.ReleaseKeyboardFocus();
+
+                OnChatResizeFinish?.Invoke(Size);
             }
 
             base.KeyBindUp(args);
index 9bcaccc48d606f6f35fbb2ed70f3862ace46bb6c..50d223f50ca60a909c6454c7e357ceeef8148628 100644 (file)
@@ -1199,6 +1199,11 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<string> UILayout =
             CVarDef.Create("ui.layout", "Default", CVar.CLIENTONLY | CVar.ARCHIVE);
 
+        public static readonly CVarDef<string> DefaultScreenChatSize =
+            CVarDef.Create("ui.default_chat_size", "", CVar.CLIENTONLY | CVar.ARCHIVE);
+
+        public static readonly CVarDef<string> SeparatedScreenChatSize =
+            CVarDef.Create("ui.separated_chat_size", "0.6,0", CVar.CLIENTONLY | CVar.ARCHIVE);
 
 
         /*