Make ID console fancier.
This commit is contained in:
@@ -1,132 +1,185 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Shared.Access;
|
using Content.Shared.Access;
|
||||||
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Utility;
|
|
||||||
using static Content.Shared.GameObjects.Components.Access.SharedIdCardConsoleComponent;
|
using static Content.Shared.GameObjects.Components.Access.SharedIdCardConsoleComponent;
|
||||||
|
|
||||||
namespace Content.Client.GameObjects.Components.Access
|
namespace Content.Client.GameObjects.Components.Access
|
||||||
{
|
{
|
||||||
public class IdCardConsoleWindow : SS14Window
|
public class IdCardConsoleWindow : SS14Window
|
||||||
{
|
{
|
||||||
|
private readonly Button _privilegedIdButton;
|
||||||
|
private readonly Button _targetIdButton;
|
||||||
|
|
||||||
|
private readonly Label _privilegedIdLabel;
|
||||||
|
private readonly Label _targetIdLabel;
|
||||||
|
|
||||||
private readonly Label _fullNameLabel;
|
private readonly Label _fullNameLabel;
|
||||||
private readonly LineEdit _fullNameLineEdit;
|
private readonly LineEdit _fullNameLineEdit;
|
||||||
private readonly Label _jobTitleLabel;
|
private readonly Label _jobTitleLabel;
|
||||||
private readonly LineEdit _jobTitleLineEdit;
|
private readonly LineEdit _jobTitleLineEdit;
|
||||||
|
|
||||||
|
private readonly Button _fullNameSaveButton;
|
||||||
|
private readonly Button _jobTitleSaveButton;
|
||||||
|
|
||||||
private readonly IdCardConsoleBoundUserInterface _owner;
|
private readonly IdCardConsoleBoundUserInterface _owner;
|
||||||
private readonly Button _privilegedIdButton;
|
|
||||||
private readonly Button _targetIdButton;
|
|
||||||
private readonly Button _submitButton;
|
|
||||||
private readonly ILocalizationManager _localizationManager;
|
|
||||||
|
|
||||||
private Dictionary<string, Button> _accessButtons = new Dictionary<string, Button>();
|
private readonly ILocalizationManager _loc;
|
||||||
|
|
||||||
public IdCardConsoleWindow(IdCardConsoleBoundUserInterface owner, ILocalizationManager localizationManager)
|
private readonly Dictionary<string, Button> _accessButtons = new Dictionary<string, Button>();
|
||||||
|
|
||||||
|
private string _lastFullName;
|
||||||
|
private string _lastJobTitle;
|
||||||
|
|
||||||
|
protected override Vector2? CustomSize => (650, 270);
|
||||||
|
|
||||||
|
public IdCardConsoleWindow(IdCardConsoleBoundUserInterface owner, ILocalizationManager loc)
|
||||||
{
|
{
|
||||||
_localizationManager = localizationManager;
|
_loc = loc;
|
||||||
_owner = owner;
|
_owner = owner;
|
||||||
var vBox = new VBoxContainer();
|
var vBox = new VBoxContainer();
|
||||||
|
|
||||||
|
vBox.AddChild(new GridContainer
|
||||||
{
|
{
|
||||||
var hBox = new HBoxContainer();
|
Columns = 3,
|
||||||
vBox.AddChild(hBox);
|
Children =
|
||||||
|
{
|
||||||
|
new Label {Text = loc.GetString("Privileged ID:")},
|
||||||
|
(_privilegedIdButton = new Button()),
|
||||||
|
(_privilegedIdLabel = new Label()),
|
||||||
|
|
||||||
_privilegedIdButton = new Button();
|
new Label {Text = loc.GetString("Target ID:")},
|
||||||
_privilegedIdButton.OnPressed += _ => _owner.ButtonPressed(UiButton.PrivilegedId);
|
(_targetIdButton = new Button()),
|
||||||
hBox.AddChild(_privilegedIdButton);
|
(_targetIdLabel = new Label())
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
_targetIdButton = new Button();
|
_privilegedIdButton.OnPressed += _ => _owner.ButtonPressed(UiButton.PrivilegedId);
|
||||||
_targetIdButton.OnPressed += _ => _owner.ButtonPressed(UiButton.TargetId);
|
_targetIdButton.OnPressed += _ => _owner.ButtonPressed(UiButton.TargetId);
|
||||||
hBox.AddChild(_targetIdButton);
|
|
||||||
}
|
// Separator
|
||||||
|
vBox.AddChild(new Control {CustomMinimumSize = (0, 8)});
|
||||||
|
|
||||||
|
// Name and job title line edits.
|
||||||
|
vBox.AddChild(new GridContainer
|
||||||
|
{
|
||||||
|
Columns = 3,
|
||||||
|
HSeparationOverride = 4,
|
||||||
|
Children =
|
||||||
|
{
|
||||||
|
// Name
|
||||||
|
(_fullNameLabel = new Label
|
||||||
|
{
|
||||||
|
Text = loc.GetString("Full name:")
|
||||||
|
}),
|
||||||
|
(_fullNameLineEdit = new LineEdit
|
||||||
|
{
|
||||||
|
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||||
|
}),
|
||||||
|
(_fullNameSaveButton = new Button
|
||||||
|
{
|
||||||
|
Text = loc.GetString("Save"),
|
||||||
|
Disabled = true
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Title
|
||||||
|
(_jobTitleLabel = new Label
|
||||||
|
{
|
||||||
|
Text = loc.GetString("Job title:")
|
||||||
|
}),
|
||||||
|
(_jobTitleLineEdit = new LineEdit
|
||||||
|
{
|
||||||
|
SizeFlagsHorizontal = SizeFlags.FillExpand
|
||||||
|
}),
|
||||||
|
(_jobTitleSaveButton = new Button
|
||||||
|
{
|
||||||
|
Text = loc.GetString("Save"),
|
||||||
|
Disabled = true
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
_fullNameLineEdit.OnTextEntered += _ => SubmitData();
|
||||||
|
_fullNameLineEdit.OnTextChanged += _ =>
|
||||||
|
{
|
||||||
|
_fullNameSaveButton.Disabled = _fullNameSaveButton.Text == _lastFullName;
|
||||||
|
};
|
||||||
|
_fullNameSaveButton.OnPressed += _ => SubmitData();
|
||||||
|
|
||||||
|
_jobTitleLineEdit.OnTextEntered += _ => SubmitData();
|
||||||
|
_jobTitleLineEdit.OnTextChanged += _ =>
|
||||||
|
{
|
||||||
|
_jobTitleSaveButton.Disabled = _jobTitleLineEdit.Text == _lastJobTitle;
|
||||||
|
};
|
||||||
|
_jobTitleSaveButton.OnPressed += _ => SubmitData();
|
||||||
|
|
||||||
|
// Separator
|
||||||
|
vBox.AddChild(new Control {CustomMinimumSize = (0, 8)});
|
||||||
|
|
||||||
{
|
{
|
||||||
var hBox = new HBoxContainer();
|
var grid = new GridContainer
|
||||||
vBox.AddChild(hBox);
|
|
||||||
hBox.AddChild(_fullNameLabel = new Label()
|
|
||||||
{
|
{
|
||||||
Text = localizationManager.GetString("Full name:")
|
Columns = 4,
|
||||||
});
|
SizeFlagsHorizontal = SizeFlags.ShrinkCenter
|
||||||
|
|
||||||
_fullNameLineEdit = new LineEdit()
|
|
||||||
{
|
|
||||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
|
||||||
};
|
};
|
||||||
hBox.AddChild(_fullNameLineEdit);
|
vBox.AddChild(grid);
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
var hBox = new HBoxContainer();
|
|
||||||
vBox.AddChild(hBox);
|
|
||||||
hBox.AddChild(_jobTitleLabel = new Label()
|
|
||||||
{
|
|
||||||
Text = localizationManager.GetString("Job title:")
|
|
||||||
});
|
|
||||||
|
|
||||||
_jobTitleLineEdit = new LineEdit()
|
|
||||||
{
|
|
||||||
SizeFlagsHorizontal = SizeFlags.FillExpand
|
|
||||||
};
|
|
||||||
hBox.AddChild(_jobTitleLineEdit);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
var hBox = new HBoxContainer();
|
|
||||||
vBox.AddChild(hBox);
|
|
||||||
|
|
||||||
foreach (var accessName in SharedAccess.AllAccess)
|
foreach (var accessName in SharedAccess.AllAccess)
|
||||||
{
|
{
|
||||||
var newButton = new Button()
|
var newButton = new Button
|
||||||
{
|
{
|
||||||
Text = accessName,
|
Text = accessName,
|
||||||
ToggleMode = true,
|
ToggleMode = true,
|
||||||
};
|
};
|
||||||
hBox.AddChild(newButton);
|
grid.AddChild(newButton);
|
||||||
_accessButtons.Add(accessName, newButton);
|
_accessButtons.Add(accessName, newButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
var hBox = new HBoxContainer();
|
|
||||||
vBox.AddChild(hBox);
|
|
||||||
|
|
||||||
_submitButton = new Button()
|
|
||||||
{
|
|
||||||
Text = localizationManager.GetString("Submit")
|
|
||||||
};
|
|
||||||
_submitButton.OnPressed += _ => owner.SubmitData(
|
|
||||||
_fullNameLineEdit.Text,
|
|
||||||
_jobTitleLineEdit.Text,
|
|
||||||
// Iterate over the buttons dictionary, filter by `Pressed`, only get key from the key/value pair
|
|
||||||
_accessButtons.Where(x => x.Value.Pressed).Select(x => x.Key).ToList());
|
|
||||||
hBox.AddChild(_submitButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
Contents.AddChild(vBox);
|
Contents.AddChild(vBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateState(IdCardConsoleBoundUserInterfaceState state)
|
public void UpdateState(IdCardConsoleBoundUserInterfaceState state)
|
||||||
{
|
{
|
||||||
_privilegedIdButton.Text = state.IsPrivilegedIdPresent
|
_privilegedIdButton.Text = state.IsPrivilegedIdPresent
|
||||||
? _localizationManager.GetString("Remove privileged ID card")
|
? _loc.GetString("Eject")
|
||||||
: _localizationManager.GetString("Insert privileged ID card");
|
: _loc.GetString("Insert");
|
||||||
|
|
||||||
|
_privilegedIdLabel.Text = state.PrivilegedIdName;
|
||||||
|
|
||||||
_targetIdButton.Text = state.IsTargetIdPresent
|
_targetIdButton.Text = state.IsTargetIdPresent
|
||||||
? _localizationManager.GetString("Remove target ID card")
|
? _loc.GetString("Eject")
|
||||||
: _localizationManager.GetString("Insert target ID card");
|
: _loc.GetString("Insert");
|
||||||
|
|
||||||
var interfaceEnabled = state.IsPrivilegedIdPresent && state.IsPrivilegedIdAuthorized && state.IsTargetIdPresent;
|
_targetIdLabel.Text = state.TargetIdName;
|
||||||
|
|
||||||
|
var interfaceEnabled =
|
||||||
|
state.IsPrivilegedIdPresent && state.IsPrivilegedIdAuthorized && state.IsTargetIdPresent;
|
||||||
|
|
||||||
|
var fullNameDirty = _lastFullName != null && _fullNameLineEdit.Text != state.TargetIdFullName;
|
||||||
|
var jobTitleDirty = _lastJobTitle != null && _jobTitleLineEdit.Text != state.TargetIdJobTitle;
|
||||||
|
|
||||||
_fullNameLabel.Modulate = interfaceEnabled ? Color.White : Color.Gray;
|
_fullNameLabel.Modulate = interfaceEnabled ? Color.White : Color.Gray;
|
||||||
_fullNameLineEdit.Editable = interfaceEnabled;
|
_fullNameLineEdit.Editable = interfaceEnabled;
|
||||||
_fullNameLineEdit.Text = state.TargetIdFullName;
|
if (!fullNameDirty)
|
||||||
|
{
|
||||||
|
_fullNameLineEdit.Text = state.TargetIdFullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
_fullNameSaveButton.Disabled = !interfaceEnabled || !fullNameDirty;
|
||||||
|
|
||||||
_jobTitleLabel.Modulate = interfaceEnabled ? Color.White : Color.Gray;
|
_jobTitleLabel.Modulate = interfaceEnabled ? Color.White : Color.Gray;
|
||||||
_jobTitleLineEdit.Editable = interfaceEnabled;
|
_jobTitleLineEdit.Editable = interfaceEnabled;
|
||||||
_jobTitleLineEdit.Text = state.TargetIdJobTitle;
|
if (!jobTitleDirty)
|
||||||
|
{
|
||||||
|
_jobTitleLineEdit.Text = state.TargetIdJobTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
_jobTitleSaveButton.Disabled = !interfaceEnabled || !jobTitleDirty;
|
||||||
|
|
||||||
foreach (var (accessName, button) in _accessButtons)
|
foreach (var (accessName, button) in _accessButtons)
|
||||||
{
|
{
|
||||||
@@ -137,7 +190,17 @@ namespace Content.Client.GameObjects.Components.Access
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_submitButton.Disabled = !interfaceEnabled;
|
_lastFullName = state.TargetIdFullName;
|
||||||
|
_lastJobTitle = state.TargetIdJobTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SubmitData()
|
||||||
|
{
|
||||||
|
_owner.SubmitData(
|
||||||
|
_fullNameLineEdit.Text,
|
||||||
|
_jobTitleLineEdit.Text,
|
||||||
|
// Iterate over the buttons dictionary, filter by `Pressed`, only get key from the key/value pair
|
||||||
|
_accessButtons.Where(x => x.Value.Pressed).Select(x => x.Key).ToList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ namespace Content.Server.GameObjects.Components.Access
|
|||||||
TryWriteToTargetId(msg.FullName, msg.JobTitle, msg.AccessList);
|
TryWriteToTargetId(msg.FullName, msg.JobTitle, msg.AccessList);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateUserInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -162,7 +164,9 @@ namespace Content.Server.GameObjects.Components.Access
|
|||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null);
|
null,
|
||||||
|
_privilegedIdContainer.ContainedEntity?.Name ?? "",
|
||||||
|
_targetIdContainer.ContainedEntity?.Name ?? "");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -174,7 +178,9 @@ namespace Content.Server.GameObjects.Components.Access
|
|||||||
true,
|
true,
|
||||||
targetIdComponent.FullName,
|
targetIdComponent.FullName,
|
||||||
targetIdComponent.JobTitle,
|
targetIdComponent.JobTitle,
|
||||||
targetAccessComponent.Tags);
|
targetAccessComponent.Tags,
|
||||||
|
_privilegedIdContainer.ContainedEntity?.Name ?? "",
|
||||||
|
_targetIdContainer.ContainedEntity?.Name ?? "");
|
||||||
}
|
}
|
||||||
_userInterface.SetState(newState);
|
_userInterface.SetState(newState);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,11 @@ namespace Content.Shared.GameObjects.Components.Access
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public class IdCardConsoleBoundUserInterfaceState : BoundUserInterfaceState
|
public class IdCardConsoleBoundUserInterfaceState : BoundUserInterfaceState
|
||||||
{
|
{
|
||||||
|
public readonly string PrivilegedIdName;
|
||||||
public readonly bool IsPrivilegedIdPresent;
|
public readonly bool IsPrivilegedIdPresent;
|
||||||
public readonly bool IsPrivilegedIdAuthorized;
|
public readonly bool IsPrivilegedIdAuthorized;
|
||||||
public readonly bool IsTargetIdPresent;
|
public readonly bool IsTargetIdPresent;
|
||||||
|
public readonly string TargetIdName;
|
||||||
public readonly string TargetIdFullName;
|
public readonly string TargetIdFullName;
|
||||||
public readonly string TargetIdJobTitle;
|
public readonly string TargetIdJobTitle;
|
||||||
public readonly List<string> TargetIdAccessList;
|
public readonly List<string> TargetIdAccessList;
|
||||||
@@ -57,7 +59,7 @@ namespace Content.Shared.GameObjects.Components.Access
|
|||||||
bool isTargetIdPresent,
|
bool isTargetIdPresent,
|
||||||
string targetIdFullName,
|
string targetIdFullName,
|
||||||
string targetIdJobTitle,
|
string targetIdJobTitle,
|
||||||
List<string> targetIdAccessList)
|
List<string> targetIdAccessList, string privilegedIdName, string targetIdName)
|
||||||
{
|
{
|
||||||
IsPrivilegedIdPresent = isPrivilegedIdPresent;
|
IsPrivilegedIdPresent = isPrivilegedIdPresent;
|
||||||
IsPrivilegedIdAuthorized = isPrivilegedIdAuthorized;
|
IsPrivilegedIdAuthorized = isPrivilegedIdAuthorized;
|
||||||
@@ -65,6 +67,8 @@ namespace Content.Shared.GameObjects.Components.Access
|
|||||||
TargetIdFullName = targetIdFullName;
|
TargetIdFullName = targetIdFullName;
|
||||||
TargetIdJobTitle = targetIdJobTitle;
|
TargetIdJobTitle = targetIdJobTitle;
|
||||||
TargetIdAccessList = targetIdAccessList;
|
TargetIdAccessList = targetIdAccessList;
|
||||||
|
PrivilegedIdName = privilegedIdName;
|
||||||
|
TargetIdName = targetIdName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user