Agent ID Cards (#7041)
This commit is contained in:
64
Content.Client/Access/UI/AgentIDCardBoundUserInterface.cs
Normal file
64
Content.Client/Access/UI/AgentIDCardBoundUserInterface.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Content.Shared.Access.Systems;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Access.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a <see cref="AgentIDCardWindow"/> and updates it when new server messages are received.
|
||||
/// </summary>
|
||||
public sealed class AgentIDCardBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private AgentIDCardWindow? _window;
|
||||
|
||||
public AgentIDCardBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new AgentIDCardWindow();
|
||||
if (State != null)
|
||||
UpdateState(State);
|
||||
|
||||
_window.OpenCentered();
|
||||
|
||||
_window.OnClose += Close;
|
||||
_window.OnNameEntered += OnNameChanged;
|
||||
_window.OnJobEntered += OnJobChanged;
|
||||
}
|
||||
|
||||
private void OnNameChanged(string newName)
|
||||
{
|
||||
SendMessage(new AgentIDCardNameChangedMessage(newName));
|
||||
}
|
||||
|
||||
private void OnJobChanged(string newJob)
|
||||
{
|
||||
SendMessage(new AgentIDCardJobChangedMessage(newJob));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the UI state based on server-sent info
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
if (_window == null || state is not AgentIDCardBoundUserInterfaceState cast)
|
||||
return;
|
||||
|
||||
_window.SetCurrentName(cast.CurrentName);
|
||||
_window.SetCurrentJob(cast.CurrentJob);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing) return;
|
||||
_window?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
10
Content.Client/Access/UI/AgentIDCardWindow.xaml
Normal file
10
Content.Client/Access/UI/AgentIDCardWindow.xaml
Normal file
@@ -0,0 +1,10 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="{Loc agent-id-menu-title}">
|
||||
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
|
||||
<Label Name="CurrentName" Text="{Loc 'agent-id-card-current-name'}" />
|
||||
<LineEdit Name="NameLineEdit" />
|
||||
<Label Name="CurrentJob" Text="{Loc 'agent-id-card-current-job'}" />
|
||||
<LineEdit Name="JobLineEdit" />
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
32
Content.Client/Access/UI/AgentIDCardWindow.xaml.cs
Normal file
32
Content.Client/Access/UI/AgentIDCardWindow.xaml.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Access.UI
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class AgentIDCardWindow : DefaultWindow
|
||||
{
|
||||
public event Action<string>? OnNameEntered;
|
||||
|
||||
public event Action<string>? OnJobEntered;
|
||||
|
||||
public AgentIDCardWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
NameLineEdit.OnTextEntered += e => OnNameEntered?.Invoke(e.Text);
|
||||
JobLineEdit.OnTextEntered += e => OnJobEntered?.Invoke(e.Text);
|
||||
}
|
||||
|
||||
public void SetCurrentName(string name)
|
||||
{
|
||||
NameLineEdit.Text = name;
|
||||
}
|
||||
|
||||
public void SetCurrentJob(string job)
|
||||
{
|
||||
JobLineEdit.Text = job;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@ namespace Content.Client.Entry
|
||||
"DiseaseSwab",
|
||||
"FloorTile",
|
||||
"RandomInsulation",
|
||||
"AgentIDCard",
|
||||
"Electrified",
|
||||
"Electrocution",
|
||||
"Paper",
|
||||
|
||||
Reference in New Issue
Block a user