]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Paper save button, back to ctrl+enter save. (#25870)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Wed, 6 Mar 2024 01:35:26 +0000 (02:35 +0100)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2024 01:35:26 +0000 (12:35 +1100)
* Revert "Change keybindings for paper (#25853)"

This reverts commit 4b56996fcdbf88581d31d4c8aeb184f0c4c23309.

* Add a save button to the paper editing UI instead.

Content.Client/Paper/UI/PaperBoundUserInterface.cs
Content.Client/Paper/UI/PaperWindow.xaml
Content.Client/Paper/UI/PaperWindow.xaml.cs
Resources/Locale/en-US/paper/paper-component.ftl
Resources/keybinds.yml

index 6b12cfe3a712f724cae218e4356ea84cf49d516d..4b0ac868f01704ff157bda37af7d0c0aa66510a2 100644 (file)
@@ -1,6 +1,5 @@
 using JetBrains.Annotations;
 using Robust.Client.UserInterface.Controls;
-using Robust.Shared.Input;
 using Robust.Shared.Utility;
 using static Content.Shared.Paper.SharedPaperComponent;
 
@@ -22,15 +21,7 @@ public sealed class PaperBoundUserInterface : BoundUserInterface
 
         _window = new PaperWindow();
         _window.OnClose += Close;
-        _window.Input.OnKeyBindDown += args => // Solution while TextEdit don't have events
-        {
-            if (args.Function == EngineKeyFunctions.MultilineTextSubmit)
-            {
-                var text = Rope.Collapse(_window.Input.TextRope);
-                Input_OnTextEntered(text);
-                args.Handle();
-            }
-        };
+        _window.OnSaved += Input_OnTextEntered;
 
         if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals))
         {
index 279dd72b272cea87cc1b0f7c7ef3ac0dd8ee6868..2344afd5ef708b9a2cd506296267c1e3cedea944 100644 (file)
@@ -25,5 +25,9 @@
                 </PanelContainer>
             </ScrollContainer>
         </PanelContainer>
+        <!-- Bottom buttons for editing -->
+        <BoxContainer Name="EditButtons" Orientation="Horizontal" HorizontalAlignment="Right" Margin="6">
+            <Button Name="SaveButton" />
+        </BoxContainer>
     </BoxContainer>
 </paper:PaperWindow>
index c3192a495d61eff36e5a3e8404235a3b62ddb411..7a5fd652643d7b669d6d0049d2ca37794f168cfb 100644 (file)
@@ -2,18 +2,22 @@ using System.Numerics;
 using Content.Shared.Paper;
 using Robust.Client.AutoGenerated;
 using Robust.Client.Graphics;
+using Robust.Client.Input;
 using Robust.Client.ResourceManagement;
 using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.XAML;
 using Robust.Shared.Utility;
 using Robust.Client.UserInterface.RichText;
+using Robust.Shared.Input;
 
 namespace Content.Client.Paper.UI
 {
     [GenerateTypedNameReferences]
     public sealed partial class PaperWindow : BaseWindow
     {
+        [Dependency] private readonly IInputManager _inputManager = default!;
+
         private static Color DefaultTextColor = new(25, 25, 25);
 
         // <summary>
@@ -41,8 +45,11 @@ namespace Content.Client.Paper.UI
             typeof(ItalicTag)
         };
 
+        public event Action<string>? OnSaved;
+
         public PaperWindow()
         {
+            IoCManager.InjectDependencies(this);
             RobustXamlLoader.Load(this);
 
             // We can't configure the RichTextLabel contents from xaml, so do it here:
@@ -50,6 +57,23 @@ namespace Content.Client.Paper.UI
 
             // Hook up the close button:
             CloseButton.OnPressed += _ => Close();
+
+            Input.OnKeyBindDown += args => // Solution while TextEdit don't have events
+            {
+                if (args.Function == EngineKeyFunctions.MultilineTextSubmit)
+                {
+                    RunOnSaved();
+                    args.Handle();
+                }
+            };
+
+            SaveButton.OnPressed += _ =>
+            {
+                RunOnSaved();
+            };
+
+            SaveButton.Text = Loc.GetString("paper-ui-save-button",
+                ("keybind", _inputManager.GetKeyFunctionButtonString(EngineKeyFunctions.MultilineTextSubmit)));
         }
 
         /// <summary>
@@ -196,6 +220,7 @@ namespace Content.Client.Paper.UI
             bool isEditing = state.Mode == SharedPaperComponent.PaperAction.Write;
             bool wasEditing = InputContainer.Visible;
             InputContainer.Visible = isEditing;
+            EditButtons.Visible = isEditing;
 
             var msg = new FormattedMessage();
             msg.AddMarkupPermissive(state.Text);
@@ -266,5 +291,10 @@ namespace Content.Client.Paper.UI
             }
             return mode & _allowedResizeModes;
         }
+
+        private void RunOnSaved()
+        {
+            OnSaved?.Invoke(Rope.Collapse(Input.TextRope));
+        }
     }
 }
index d10201b4cf95492ff00a8b0466f1802da07f34eb..a62616631f4abd5ba9c31468b429dfbb1dcdf1b1 100644 (file)
@@ -10,3 +10,5 @@ paper-component-examine-detail-stamped-by = {CAPITALIZE(THE($paper))} {CONJUGATE
 
 paper-component-action-stamp-paper-other = {CAPITALIZE(THE($user))} stamps {THE($target)} with {THE($stamp)}.
 paper-component-action-stamp-paper-self = You stamp {THE($target)} with {THE($stamp)}.
+
+paper-ui-save-button = Save ({$keybind})
index 756a09927a52742029364c57d3136caa2dc51e08..b8cfc40c1c482d82d14faf68e65de32991d8967b 100644 (file)
@@ -371,12 +371,10 @@ binds:
 - function: TextNewline
   type: State
   key: Return
-  mod1: Shift
   canRepeat: true
 - function: TextNewline
   type: State
   key: NumpadEnter
-  mod1: Shift
   canRepeat: true
 - function: TextSubmit
   type: State
@@ -387,9 +385,11 @@ binds:
 - function: MultilineTextSubmit
   type: State
   key: Return
+  mod1: Control
 - function: MultilineTextSubmit
   type: State
   key: NumpadEnter
+  mod1: Control
 - function: TextSelectAll
   type: State
   key: A