Paper save button, back to ctrl+enter save. (#25870)

* Revert "Change keybindings for paper (#25853)"

This reverts commit 4b56996fcd.

* Add a save button to the paper editing UI instead.
This commit is contained in:
Pieter-Jan Briers
2024-03-06 02:35:26 +01:00
committed by GitHub
parent b5066dc4c6
commit d385c1bb23
5 changed files with 39 additions and 12 deletions

View File

@@ -1,6 +1,5 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using static Content.Shared.Paper.SharedPaperComponent; using static Content.Shared.Paper.SharedPaperComponent;
@@ -22,15 +21,7 @@ public sealed class PaperBoundUserInterface : BoundUserInterface
_window = new PaperWindow(); _window = new PaperWindow();
_window.OnClose += Close; _window.OnClose += Close;
_window.Input.OnKeyBindDown += args => // Solution while TextEdit don't have events _window.OnSaved += Input_OnTextEntered;
{
if (args.Function == EngineKeyFunctions.MultilineTextSubmit)
{
var text = Rope.Collapse(_window.Input.TextRope);
Input_OnTextEntered(text);
args.Handle();
}
};
if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals)) if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals))
{ {

View File

@@ -25,5 +25,9 @@
</PanelContainer> </PanelContainer>
</ScrollContainer> </ScrollContainer>
</PanelContainer> </PanelContainer>
<!-- Bottom buttons for editing -->
<BoxContainer Name="EditButtons" Orientation="Horizontal" HorizontalAlignment="Right" Margin="6">
<Button Name="SaveButton" />
</BoxContainer>
</BoxContainer> </BoxContainer>
</paper:PaperWindow> </paper:PaperWindow>

View File

@@ -2,18 +2,22 @@ using System.Numerics;
using Content.Shared.Paper; using Content.Shared.Paper;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Client.UserInterface.RichText; using Robust.Client.UserInterface.RichText;
using Robust.Shared.Input;
namespace Content.Client.Paper.UI namespace Content.Client.Paper.UI
{ {
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class PaperWindow : BaseWindow public sealed partial class PaperWindow : BaseWindow
{ {
[Dependency] private readonly IInputManager _inputManager = default!;
private static Color DefaultTextColor = new(25, 25, 25); private static Color DefaultTextColor = new(25, 25, 25);
// <summary> // <summary>
@@ -41,8 +45,11 @@ namespace Content.Client.Paper.UI
typeof(ItalicTag) typeof(ItalicTag)
}; };
public event Action<string>? OnSaved;
public PaperWindow() public PaperWindow()
{ {
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
// We can't configure the RichTextLabel contents from xaml, so do it here: // 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: // Hook up the close button:
CloseButton.OnPressed += _ => Close(); 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> /// <summary>
@@ -196,6 +220,7 @@ namespace Content.Client.Paper.UI
bool isEditing = state.Mode == SharedPaperComponent.PaperAction.Write; bool isEditing = state.Mode == SharedPaperComponent.PaperAction.Write;
bool wasEditing = InputContainer.Visible; bool wasEditing = InputContainer.Visible;
InputContainer.Visible = isEditing; InputContainer.Visible = isEditing;
EditButtons.Visible = isEditing;
var msg = new FormattedMessage(); var msg = new FormattedMessage();
msg.AddMarkupPermissive(state.Text); msg.AddMarkupPermissive(state.Text);
@@ -266,5 +291,10 @@ namespace Content.Client.Paper.UI
} }
return mode & _allowedResizeModes; return mode & _allowedResizeModes;
} }
private void RunOnSaved()
{
OnSaved?.Invoke(Rope.Collapse(Input.TextRope));
}
} }
} }

View 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-other = {CAPITALIZE(THE($user))} stamps {THE($target)} with {THE($stamp)}.
paper-component-action-stamp-paper-self = You stamp {THE($target)} with {THE($stamp)}. paper-component-action-stamp-paper-self = You stamp {THE($target)} with {THE($stamp)}.
paper-ui-save-button = Save ({$keybind})

View File

@@ -371,12 +371,10 @@ binds:
- function: TextNewline - function: TextNewline
type: State type: State
key: Return key: Return
mod1: Shift
canRepeat: true canRepeat: true
- function: TextNewline - function: TextNewline
type: State type: State
key: NumpadEnter key: NumpadEnter
mod1: Shift
canRepeat: true canRepeat: true
- function: TextSubmit - function: TextSubmit
type: State type: State
@@ -387,9 +385,11 @@ binds:
- function: MultilineTextSubmit - function: MultilineTextSubmit
type: State type: State
key: Return key: Return
mod1: Control
- function: MultilineTextSubmit - function: MultilineTextSubmit
type: State type: State
key: NumpadEnter key: NumpadEnter
mod1: Control
- function: TextSelectAll - function: TextSelectAll
type: State type: State
key: A key: A