mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Add a copy to clipboard button on alert popups. (#5336)
* Add a copy button to clipboard on Alert Popups. * ButtonFlag and better formatting. * Localization and style cleanup
This commit is contained in:
2
Resources/Locale/en-US/userinterface.ftl
Normal file
2
Resources/Locale/en-US/userinterface.ftl
Normal file
@@ -0,0 +1,2 @@
|
||||
popup-copy-button = Copy
|
||||
popup-title = Alert!
|
||||
@@ -64,7 +64,7 @@ namespace Robust.Client.UserInterface
|
||||
|
||||
IDebugMonitors DebugMonitors { get; }
|
||||
|
||||
void Popup(string contents, string title = "Alert!");
|
||||
void Popup(string contents, string? title = null, bool clipboardButton = true);
|
||||
|
||||
Control? MouseGetControl(ScreenCoordinates coordinates);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Numerics;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Profiling;
|
||||
@@ -53,14 +54,47 @@ internal sealed partial class UserInterfaceManager
|
||||
}
|
||||
}
|
||||
|
||||
public void Popup(string contents, string title = "Alert!")
|
||||
public void Popup(string contents, string? title = null, bool clipboardButton = true)
|
||||
{
|
||||
var popup = new DefaultWindow
|
||||
{
|
||||
Title = title
|
||||
Title = string.IsNullOrEmpty(title) ? Loc.GetString("popup-title") : title,
|
||||
};
|
||||
|
||||
popup.Contents.AddChild(new Label {Text = contents});
|
||||
var label = new Label { Text = contents };
|
||||
|
||||
var vBox = new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
};
|
||||
|
||||
vBox.AddChild(label);
|
||||
|
||||
if (clipboardButton)
|
||||
{
|
||||
var copyButton = new Button
|
||||
{
|
||||
Text = Loc.GetString("popup-copy-button"),
|
||||
HorizontalExpand = true,
|
||||
};
|
||||
|
||||
copyButton.OnPressed += _ =>
|
||||
{
|
||||
_clipboard.SetText(contents);
|
||||
};
|
||||
|
||||
var hBox = new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
HorizontalAlignment = Control.HAlignment.Right,
|
||||
};
|
||||
|
||||
hBox.AddChild(copyButton);
|
||||
vBox.AddChild(hBox);
|
||||
}
|
||||
|
||||
popup.Contents.AddChild(vBox);
|
||||
|
||||
popup.OpenCentered();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace Robust.Client.UserInterface
|
||||
[Dependency] private readonly IEntitySystemManager _systemManager = default!;
|
||||
[Dependency] private readonly ILogManager _logManager = default!;
|
||||
[Dependency] private readonly IRuntimeLog _runtime = default!;
|
||||
[Dependency] private readonly IClipboardManager _clipboard = null!;
|
||||
|
||||
private IAudioSource? _clickSource;
|
||||
private IAudioSource? _hoverSource;
|
||||
|
||||
Reference in New Issue
Block a user