]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Multiline edit everywhere (#15216)
authorMorb <14136326+Morb0@users.noreply.github.com>
Fri, 14 Apr 2023 19:57:47 +0000 (12:57 -0700)
committerGitHub <noreply@github.com>
Fri, 14 Apr 2023 19:57:47 +0000 (12:57 -0700)
12 files changed:
Content.Client/Administration/UI/AdminAnnounceWindow.xaml
Content.Client/Administration/UI/AdminAnnounceWindow.xaml.cs
Content.Client/Administration/UI/AdminMenuWindowEui.cs
Content.Client/Communications/UI/CommunicationsConsoleBoundUserInterface.cs
Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml
Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml.cs
Content.Client/Paper/UI/PaperBoundUserInterface.cs
Content.Client/Paper/UI/PaperWindow.xaml
Content.Server/Communications/CommunicationsConsoleSystem.cs
Resources/Locale/en-US/administration/ui/admin-announce-window.ftl
Resources/Locale/en-US/communications/communications-console-component.ftl
Resources/keybinds.yml

index f789bdba5d0bb02b826b5e9594b9056364a4f87e..f7f004dcb230e71a83fc17dcb9a791f3ec5f7265 100644 (file)
@@ -8,7 +8,7 @@
             <Control HorizontalExpand="True" SizeFlagsStretchRatio="1" />
             <OptionButton Name="AnnounceMethod" Access="Public" HorizontalExpand="True" SizeFlagsStretchRatio="2"/>
         </BoxContainer>
-        <LineEdit Name="Announcement" Access="Public" PlaceHolder="{Loc admin-announce-announcement-placeholder}"/>
+        <TextEdit Name="Announcement" Access="Public" VerticalExpand="True" MinHeight="100" />
 
         <GridContainer Rows="1">
             <CheckBox Name="KeepWindowOpen" Access="Public" Text="{Loc 'admin-announce-keep-open'}" />
index 4fcf8f7ed386fbe60f57ffa2d637c41610b254ca..5156b7f3c1fe0c76d21ac7114cf9b9301c82b0cf 100644 (file)
@@ -1,8 +1,10 @@
 using Content.Shared.Administration;
 using Robust.Client.AutoGenerated;
+using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.XAML;
+using Robust.Shared.Utility;
 
 namespace Content.Client.Administration.UI
 {
@@ -16,18 +18,18 @@ namespace Content.Client.Administration.UI
             RobustXamlLoader.Load(this);
             IoCManager.InjectDependencies(this);
 
+            Announcement.Placeholder = new Rope.Leaf(_localization.GetString("admin-announce-announcement-placeholder"));
             AnnounceMethod.AddItem(_localization.GetString("admin-announce-type-station"));
             AnnounceMethod.SetItemMetadata(0, AdminAnnounceType.Station);
             AnnounceMethod.AddItem(_localization.GetString("admin-announce-type-server"));
             AnnounceMethod.SetItemMetadata(1, AdminAnnounceType.Server);
             AnnounceMethod.OnItemSelected += AnnounceMethodOnOnItemSelected;
-            Announcement.OnTextChanged += AnnouncementOnOnTextChanged;
+            Announcement.OnKeyBindUp += AnnouncementOnOnTextChanged;
         }
 
-
-        private void AnnouncementOnOnTextChanged(LineEdit.LineEditEventArgs args)
+        private void AnnouncementOnOnTextChanged(GUIBoundKeyEventArgs args)
         {
-            AnnounceButton.Disabled = args.Text.TrimStart() == "";
+            AnnounceButton.Disabled = Rope.Collapse(Announcement.TextRope).TrimStart() == "";
         }
 
         private void AnnounceMethodOnOnItemSelected(OptionButton.ItemSelectedEventArgs args)
index 2de0664b1726f8f8dd5765edd328a049f9a5c841..7b9691ff94474a356f6f4636c54b4c0403a8268d 100644 (file)
@@ -1,6 +1,7 @@
 using Content.Client.Eui;
 using Content.Shared.Administration;
 using Robust.Client.UserInterface.Controls;
+using Robust.Shared.Utility;
 
 namespace Content.Client.Administration.UI
 {
@@ -19,7 +20,7 @@ namespace Content.Client.Administration.UI
         {
             SendMessage(new AdminAnnounceEuiMsg.DoAnnounce
             {
-                Announcement = _window.Announcement.Text,
+                Announcement = Rope.Collapse(_window.Announcement.TextRope),
                 Announcer =  _window.Announcer.Text,
                 AnnounceType =  (AdminAnnounceType) (_window.AnnounceMethod.SelectedMetadata ?? AdminAnnounceType.Station),
                 CloseAfter = !_window.KeepWindowOpen.Pressed,
index 2a0da896f1684294bfc5ea447ae284c8bc2b5c6a..7428594be82d9a827cf8a5a76657ecbb97882492 100644 (file)
@@ -1,10 +1,6 @@
-using System;
-using Content.Shared.Communications;
+using Content.Shared.Communications;
 using Robust.Client.GameObjects;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
 using Robust.Shared.Timing;
-using Robust.Shared.ViewVariables;
 
 namespace Content.Client.Communications.UI
 {
@@ -59,8 +55,22 @@ namespace Content.Client.Communications.UI
 
         public void AnnounceButtonPressed(string message)
         {
-            var msg = message.Length <= 256 ? message.Trim() : $"{message.Trim().Substring(0, 256)}...";
-            SendMessage(new CommunicationsConsoleAnnounceMessage(msg));
+            var msg = (message.Length <= 256 ? message.Trim() : $"{message.Trim().Substring(0, 256)}...").ToCharArray();
+
+            // No more than 2 newlines, other replaced to spaces
+            var newlines = 0;
+            for (var i = 0; i < msg.Length; i++)
+            {
+                if (msg[i] != '\n')
+                    continue;
+
+                if (newlines >= 2)
+                    msg[i] = ' ';
+
+                newlines++;
+            }
+
+            SendMessage(new CommunicationsConsoleAnnounceMessage(new string(msg)));
         }
 
         public void CallShuttle()
index 1f5ec1d0b586650a87a7fd323aa3b544641755f5..86c0b4e2d5337b74027343e5fc1761af62b299cd 100644 (file)
@@ -1,9 +1,9 @@
 <controls:FancyWindow xmlns="https://spacestation14.io"
     xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
     Title="{Loc 'comms-console-menu-title'}"
-    MinSize="350 225">
+    MinSize="400 225">
     <BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" Margin="5">
-        <LineEdit Name="MessageInput" PlaceHolder="{Loc 'comms-console-menu-announcement-placeholder'}" HorizontalExpand="True" Margin="0 0 0 5" />
+        <TextEdit Name="MessageInput" HorizontalExpand="True" VerticalExpand="True" Margin="0 0 0 5" MinHeight="100" />
         <Button Name="AnnounceButton" Text="{Loc 'comms-console-menu-announcement-button'}" StyleClasses="OpenLeft" Access="Public" />
 
         <OptionButton Name="AlertLevelButton" StyleClasses="OpenRight" Access="Public" />
index 48bd0c014c73281655d0ce013531bf59d31dce93..8ab444f9bafcb62667a42ad8bc710e6ebb22d1b9 100644 (file)
@@ -1,14 +1,8 @@
 using Content.Client.UserInterface.Controls;
 using System.Threading;
 using Robust.Client.AutoGenerated;
-using Robust.Client.UserInterface;
-using Robust.Client.UserInterface.Controls;
-using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.XAML;
-using Robust.Shared.IoC;
-using Robust.Shared.Localization;
-using Robust.Shared.Maths;
-using static Robust.Client.UserInterface.Controls.BoxContainer;
+using Robust.Shared.Utility;
 using Timer = Robust.Shared.Timing.Timer;
 
 namespace Content.Client.Communications.UI
@@ -26,7 +20,10 @@ namespace Content.Client.Communications.UI
 
             Owner = owner;
 
-            AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(MessageInput.Text.Trim());
+            var loc = IoCManager.Resolve<ILocalizationManager>();
+            MessageInput.Placeholder = new Rope.Leaf(loc.GetString("comms-console-menu-announcement-placeholder"));
+
+            AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(Rope.Collapse(MessageInput.TextRope).Trim());
             AnnounceButton.Disabled = !owner.CanAnnounce;
 
             AlertLevelButton.OnItemSelected += args =>
index 1088aee02b5420cf9bc9b4117e2013f3be3ab464..8c0338f805b51d4d351b5b183f923c71f2343e3f 100644 (file)
@@ -1,8 +1,8 @@
 using JetBrains.Annotations;
 using Robust.Client.GameObjects;
 using Robust.Client.UserInterface.Controls;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
+using Robust.Shared.Input;
+using Robust.Shared.Utility;
 using static Content.Shared.Paper.SharedPaperComponent;
 
 namespace Content.Client.Paper.UI
@@ -23,7 +23,15 @@ namespace Content.Client.Paper.UI
 
             _window = new PaperWindow();
             _window.OnClose += Close;
-            _window.Input.OnTextEntered += Input_OnTextEntered;
+            _window.Input.OnKeyBindDown += args => // Solution while TextEdit don't have events
+            {
+                if (args.Function == EngineKeyFunctions.TextSubmit)
+                {
+                    var text = Rope.Collapse(_window.Input.TextRope);
+                    Input_OnTextEntered(text);
+                    args.Handle();
+                }
+            };
 
             if (entityMgr.TryGetComponent<PaperVisualsComponent>(Owner.Owner, out var visuals))
             {
@@ -39,15 +47,16 @@ namespace Content.Client.Paper.UI
             _window?.Populate((PaperBoundUserInterfaceState) state);
         }
 
-        private void Input_OnTextEntered(LineEdit.LineEditEventArgs obj)
+        private void Input_OnTextEntered(string text)
         {
-            if (!string.IsNullOrEmpty(obj.Text))
+            if (!string.IsNullOrEmpty(text))
             {
-                SendMessage(new PaperInputTextMessage(obj.Text));
+                SendMessage(new PaperInputTextMessage(text));
 
                 if (_window != null)
                 {
-                    _window.Input.Text = string.Empty;
+                    _window.Input.TextRope = Rope.Leaf.Empty;
+                    _window.Input.CursorPosition = new TextEdit.CursorPos(0, TextEdit.LineBreakBias.Top);
                 }
             }
         }
index c2f4a197e2136bbb4ca7a7459bd79dba7a739e16..9b4a03f086b1fe4b9e0e97db5cf6a96976c07387 100644 (file)
         <PanelContainer Name="PaperBackground" StyleClasses="PaperDefaultBorder" VerticalExpand="True" HorizontalExpand="True">
             <ScrollContainer Name="ScrollingContents" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalExpand="True" VerticalExpand="True" HScrollEnabled="False">
                 <PanelContainer Name="PaperContent" VerticalExpand="True" HorizontalExpand="True" MaxWidth="600">
-                    <BoxContainer Orientation="Vertical" VerticalAlignment="Top">
+                    <BoxContainer Orientation="Vertical" VerticalAlignment="Stretch">
                         <TextureButton Name="HeaderImage" HorizontalAlignment="Center" VerticalAlignment="Top" MouseFilter="Ignore"/>
                         <Control Name="TextAlignmentPadding" VerticalAlignment="Top" />
                         <RichTextLabel Name="BlankPaperIndicator" StyleClasses="LabelSecondaryColor"
                             VerticalAlignment="Top" HorizontalAlignment="Center"/>
                         <RichTextLabel StyleClasses="PaperWrittenText" Name="WrittenTextLabel" VerticalAlignment="Top"/>
-                            <PanelContainer Name="InputContainer" StyleClasses="TransparentBorderedWindowPanel"
-                            VerticalAlignment="Top" HorizontalExpand="True">
-                            <LineEdit Name="Input" StyleClasses="PaperLineEdit" Access="Public" />
+                        <PanelContainer Name="InputContainer" StyleClasses="TransparentBorderedWindowPanel" MinHeight="100"
+                                        VerticalAlignment="Stretch" VerticalExpand="True" HorizontalExpand="True">
+                            <TextEdit Name="Input" StyleClasses="PaperLineEdit" Access="Public" />
                         </PanelContainer>
                     </BoxContainer>
                     <BoxContainer Name="StampDisplay" Orientation="Vertical" VerticalAlignment="Bottom" Margin="6"/>
index 3a1df97e18197754ba904a4d0992b1a154071e8a..45d291ec5d3232c34e49921163d80fae3992c066 100644 (file)
@@ -39,6 +39,7 @@ namespace Content.Server.Communications
         [Dependency] private readonly IAdminLogManager _adminLogger = default!;
 
         private const int MaxMessageLength = 256;
+        private const int MaxMessageNewlines = 2;
         private const float UIUpdateInterval = 5.0f;
 
         public override void Initialize()
@@ -223,7 +224,21 @@ namespace Content.Server.Communications
         private void OnAnnounceMessage(EntityUid uid, CommunicationsConsoleComponent comp,
             CommunicationsConsoleAnnounceMessage message)
         {
-            var msg = message.Message.Length <= MaxMessageLength ? message.Message.Trim() : $"{message.Message.Trim().Substring(0, MaxMessageLength)}...";
+            var msgChars = (message.Message.Length <= MaxMessageLength ? message.Message.Trim() : $"{message.Message.Trim().Substring(0, MaxMessageLength)}...").ToCharArray();
+
+            var newlines = 0;
+            for (var i = 0; i < msgChars.Length; i++)
+            {
+                if (msgChars[i] != '\n')
+                    continue;
+
+                if (newlines >= MaxMessageNewlines)
+                    msgChars[i] = ' ';
+
+                newlines++;
+            }
+
+            var msg = new string(msgChars);
             var author = Loc.GetString("comms-console-announcement-unknown-sender");
             if (message.Session.AttachedEntity is {Valid: true} mob)
             {
index 88dcb9e37f99b22e7a7e92325d789682a7414c7b..1db8cfad25f9ab6c34578338276e50b0e587beb7 100644 (file)
@@ -1,5 +1,5 @@
 admin-announce-title = Make Announcement
-admin-announce-announcement-placeholder = Announcement text
+admin-announce-announcement-placeholder = Announcement text...
 admin-announce-announcer-placeholder = Announcer
 admin-announce-announcer-default = Central Command
 admin-announce-button = Announce
index 1ff0a9a89195257551f1ee46d740d6f8c4e47834..a2fe03963d501f8ebdfd662f76f680cd6b0de813 100644 (file)
@@ -1,6 +1,6 @@
 # User interface
 comms-console-menu-title = Communications Console
-comms-console-menu-announcement-placeholder = Announcement
+comms-console-menu-announcement-placeholder = Announcement text...
 comms-console-menu-announcement-button = Announce
 comms-console-menu-call-shuttle = Call emergency shuttle
 comms-console-menu-recall-shuttle = Recall emergency shuttle
index 8a70d2b10097f8b187d19838b93a97e2b99eb653..7a03fdb88d8beba9ba06407f3f12ad1e25d0c794 100644 (file)
@@ -331,10 +331,12 @@ binds:
   type: State
   key: Return
   canRepeat: true
+  mod1: Shift
 - function: TextNewline
   type: State
   key: NumpadEnter
   canRepeat: true
+  mod1: Shift
 - function: TextSubmit
   type: State
   key: Return