From 2eb2ded7f3f50aa24cfbb7ced63db3a0e829a3f9 Mon Sep 17 00:00:00 2001
From: Morb <14136326+Morb0@users.noreply.github.com>
Date: Fri, 14 Apr 2023 12:57:47 -0700
Subject: [PATCH] Multiline edit everywhere (#15216)
---
.../UI/AdminAnnounceWindow.xaml | 2 +-
.../UI/AdminAnnounceWindow.xaml.cs | 10 ++++----
.../Administration/UI/AdminMenuWindowEui.cs | 3 ++-
...CommunicationsConsoleBoundUserInterface.cs | 24 +++++++++++++------
.../UI/CommunicationsConsoleMenu.xaml | 4 ++--
.../UI/CommunicationsConsoleMenu.xaml.cs | 13 ++++------
.../Paper/UI/PaperBoundUserInterface.cs | 23 ++++++++++++------
Content.Client/Paper/UI/PaperWindow.xaml | 8 +++----
.../CommunicationsConsoleSystem.cs | 17 ++++++++++++-
.../ui/admin-announce-window.ftl | 2 +-
.../communications-console-component.ftl | 2 +-
Resources/keybinds.yml | 2 ++
12 files changed, 73 insertions(+), 37 deletions(-)
diff --git a/Content.Client/Administration/UI/AdminAnnounceWindow.xaml b/Content.Client/Administration/UI/AdminAnnounceWindow.xaml
index f789bdba5d..f7f004dcb2 100644
--- a/Content.Client/Administration/UI/AdminAnnounceWindow.xaml
+++ b/Content.Client/Administration/UI/AdminAnnounceWindow.xaml
@@ -8,7 +8,7 @@
-
+
diff --git a/Content.Client/Administration/UI/AdminAnnounceWindow.xaml.cs b/Content.Client/Administration/UI/AdminAnnounceWindow.xaml.cs
index 4fcf8f7ed3..5156b7f3c1 100644
--- a/Content.Client/Administration/UI/AdminAnnounceWindow.xaml.cs
+++ b/Content.Client/Administration/UI/AdminAnnounceWindow.xaml.cs
@@ -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)
diff --git a/Content.Client/Administration/UI/AdminMenuWindowEui.cs b/Content.Client/Administration/UI/AdminMenuWindowEui.cs
index 2de0664b17..7b9691ff94 100644
--- a/Content.Client/Administration/UI/AdminMenuWindowEui.cs
+++ b/Content.Client/Administration/UI/AdminMenuWindowEui.cs
@@ -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,
diff --git a/Content.Client/Communications/UI/CommunicationsConsoleBoundUserInterface.cs b/Content.Client/Communications/UI/CommunicationsConsoleBoundUserInterface.cs
index 2a0da896f1..7428594be8 100644
--- a/Content.Client/Communications/UI/CommunicationsConsoleBoundUserInterface.cs
+++ b/Content.Client/Communications/UI/CommunicationsConsoleBoundUserInterface.cs
@@ -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()
diff --git a/Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml b/Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml
index 1f5ec1d0b5..86c0b4e2d5 100644
--- a/Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml
+++ b/Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml
@@ -1,9 +1,9 @@
+ MinSize="400 225">
-
+
diff --git a/Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml.cs b/Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml.cs
index 48bd0c014c..8ab444f9ba 100644
--- a/Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml.cs
+++ b/Content.Client/Communications/UI/CommunicationsConsoleMenu.xaml.cs
@@ -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();
+ 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 =>
diff --git a/Content.Client/Paper/UI/PaperBoundUserInterface.cs b/Content.Client/Paper/UI/PaperBoundUserInterface.cs
index 1088aee02b..8c0338f805 100644
--- a/Content.Client/Paper/UI/PaperBoundUserInterface.cs
+++ b/Content.Client/Paper/UI/PaperBoundUserInterface.cs
@@ -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(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);
}
}
}
diff --git a/Content.Client/Paper/UI/PaperWindow.xaml b/Content.Client/Paper/UI/PaperWindow.xaml
index c2f4a197e2..9b4a03f086 100644
--- a/Content.Client/Paper/UI/PaperWindow.xaml
+++ b/Content.Client/Paper/UI/PaperWindow.xaml
@@ -10,15 +10,15 @@
-
+
-
-
+
+
diff --git a/Content.Server/Communications/CommunicationsConsoleSystem.cs b/Content.Server/Communications/CommunicationsConsoleSystem.cs
index 3a1df97e18..45d291ec5d 100644
--- a/Content.Server/Communications/CommunicationsConsoleSystem.cs
+++ b/Content.Server/Communications/CommunicationsConsoleSystem.cs
@@ -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)
{
diff --git a/Resources/Locale/en-US/administration/ui/admin-announce-window.ftl b/Resources/Locale/en-US/administration/ui/admin-announce-window.ftl
index 88dcb9e37f..1db8cfad25 100644
--- a/Resources/Locale/en-US/administration/ui/admin-announce-window.ftl
+++ b/Resources/Locale/en-US/administration/ui/admin-announce-window.ftl
@@ -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
diff --git a/Resources/Locale/en-US/communications/communications-console-component.ftl b/Resources/Locale/en-US/communications/communications-console-component.ftl
index 1ff0a9a891..a2fe03963d 100644
--- a/Resources/Locale/en-US/communications/communications-console-component.ftl
+++ b/Resources/Locale/en-US/communications/communications-console-component.ftl
@@ -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
diff --git a/Resources/keybinds.yml b/Resources/keybinds.yml
index 8a70d2b100..7a03fdb88d 100644
--- a/Resources/keybinds.yml
+++ b/Resources/keybinds.yml
@@ -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