Skip to content

Commit

Permalink
Add a copy button to clipboard on Alert Popups.
Browse files Browse the repository at this point in the history
  • Loading branch information
Titian3 committed Aug 5, 2024
1 parent 5c0ce43 commit 896d12c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Robust.Client/UserInterface/IUserInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public partial interface IUserInterfaceManager

IDebugMonitors DebugMonitors { get; }

void Popup(string contents, string title = "Alert!");
void Popup(string contents, string title = "Alert!", string clipboardButton = "Copy");

Control? MouseGetControl(ScreenCoordinates coordinates);

Expand Down
37 changes: 34 additions & 3 deletions Robust.Client/UserInterface/UserInterfaceManager.Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,45 @@ private void RunArrange(Control control)
}
}

public void Popup(string contents, string title = "Alert!")
public void Popup(string contents, string title = "Alert!", string clipboardButton = "Copy")
{
var popup = new DefaultWindow
{
Title = title
Title = title,
};

popup.Contents.AddChild(new Label {Text = contents});
var label = new Label { Text = contents };
var copyButton = new Button
{
Text = clipboardButton,
MinSize = new Vector2(100, 30),
};

copyButton.OnPressed += _ =>
{
_clipboard.SetText(contents);
};

var grid = new GridContainer
{
Columns = 1,
VSeparationOverride = 10,
};

grid.AddChild(label);

var buttonContainer = new GridContainer
{
Columns = 2,
HSeparationOverride = 10,
};

buttonContainer.AddChild(copyButton);

grid.AddChild(buttonContainer);

popup.Contents.AddChild(grid);

popup.OpenCentered();
}

Expand Down
1 change: 1 addition & 0 deletions Robust.Client/UserInterface/UserInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ internal sealed partial class UserInterfaceManager : IUserInterfaceManagerIntern
[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;
Expand Down

0 comments on commit 896d12c

Please sign in to comment.