forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/space-wizards/space-stati…
- Loading branch information
Showing
211 changed files
with
4,681 additions
and
1,212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Content.Shared.Access.Systems; | ||
using JetBrains.Annotations; | ||
|
||
namespace Content.Client.Access | ||
{ | ||
[UsedImplicitly] | ||
public sealed class AccessOverriderSystem : SharedAccessOverriderSystem | ||
{ | ||
|
||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
Content.Client/Access/UI/AccessOverriderBoundUserInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Content.Shared.Access.Components; | ||
using Content.Shared.Access.Systems; | ||
using Content.Shared.Containers.ItemSlots; | ||
using Robust.Client.GameObjects; | ||
using Robust.Shared.Prototypes; | ||
using static Content.Shared.Access.Components.AccessOverriderComponent; | ||
|
||
namespace Content.Client.Access.UI | ||
{ | ||
public sealed class AccessOverriderBoundUserInterface : BoundUserInterface | ||
{ | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
private readonly SharedAccessOverriderSystem _accessOverriderSystem = default!; | ||
|
||
private AccessOverriderWindow? _window; | ||
|
||
public AccessOverriderBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) | ||
{ | ||
_accessOverriderSystem = EntMan.System<SharedAccessOverriderSystem>(); | ||
} | ||
|
||
protected override void Open() | ||
{ | ||
base.Open(); | ||
|
||
List<string> accessLevels; | ||
|
||
if (EntMan.TryGetComponent<AccessOverriderComponent>(Owner, out var accessOverrider)) | ||
{ | ||
accessLevels = accessOverrider.AccessLevels; | ||
accessLevels.Sort(); | ||
} | ||
|
||
else | ||
{ | ||
accessLevels = new List<string>(); | ||
_accessOverriderSystem.Log.Error($"No AccessOverrider component found for {EntMan.ToPrettyString(Owner)}!"); | ||
} | ||
|
||
_window = new AccessOverriderWindow(this, _prototypeManager, accessLevels) | ||
{ | ||
Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName | ||
}; | ||
|
||
_window.PrivilegedIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(PrivilegedIdCardSlotId)); | ||
|
||
_window.OnClose += Close; | ||
_window.OpenCentered(); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
if (!disposing) | ||
return; | ||
|
||
_window?.Dispose(); | ||
} | ||
|
||
protected override void UpdateState(BoundUserInterfaceState state) | ||
{ | ||
base.UpdateState(state); | ||
var castState = (AccessOverriderBoundUserInterfaceState) state; | ||
_window?.UpdateState(castState); | ||
} | ||
|
||
public void SubmitData(List<string> newAccessList) | ||
{ | ||
SendMessage(new WriteToTargetAccessReaderIdMessage(newAccessList)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<DefaultWindow xmlns="https://spacestation14.io" | ||
MinSize="650 290"> | ||
<BoxContainer Orientation="Vertical"> | ||
<GridContainer Columns="2"> | ||
<GridContainer Columns="3" HorizontalExpand="True"> | ||
<Label Text="{Loc 'access-overrider-window-privileged-id'}" /> | ||
<Button Name="PrivilegedIdButton" Access="Public"/> | ||
<Label Name="PrivilegedIdLabel" /> | ||
</GridContainer> | ||
</GridContainer> | ||
<Label Name="TargetNameLabel" /> | ||
<Control MinSize="0 8"/> | ||
<GridContainer Name="AccessLevelGrid" Columns="5" HorizontalAlignment="Center"> | ||
|
||
<!-- Access level buttons are added here by the C# code --> | ||
|
||
</GridContainer> | ||
<Control MinSize="0 8"/> | ||
<Label Name="MissingPrivilegesLabel" /> | ||
<Control MinSize="0 4"/> | ||
<Label Name="MissingPrivilegesText" /> | ||
</BoxContainer> | ||
</DefaultWindow> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System.Linq; | ||
using Content.Shared.Access; | ||
using Content.Shared.Access.Systems; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.CustomControls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Prototypes; | ||
using static Content.Shared.Access.Components.AccessOverriderComponent; | ||
|
||
namespace Content.Client.Access.UI | ||
{ | ||
[GenerateTypedNameReferences] | ||
public sealed partial class AccessOverriderWindow : DefaultWindow | ||
{ | ||
[Dependency] private readonly ILogManager _logManager = default!; | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
|
||
private readonly ISawmill _logMill = default!; | ||
private readonly AccessOverriderBoundUserInterface _owner; | ||
private readonly Dictionary<string, Button> _accessButtons = new(); | ||
|
||
public AccessOverriderWindow(AccessOverriderBoundUserInterface owner, IPrototypeManager prototypeManager, | ||
List<string> accessLevels) | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
_logMill = _logManager.GetSawmill(SharedAccessOverriderSystem.Sawmill); | ||
|
||
_owner = owner; | ||
|
||
foreach (var access in accessLevels) | ||
{ | ||
if (!prototypeManager.TryIndex<AccessLevelPrototype>(access, out var accessLevel)) | ||
{ | ||
_logMill.Error($"Unable to find accesslevel for {access}"); | ||
continue; | ||
} | ||
|
||
var newButton = new Button | ||
{ | ||
Text = GetAccessLevelName(accessLevel), | ||
ToggleMode = true, | ||
}; | ||
|
||
AccessLevelGrid.AddChild(newButton); | ||
_accessButtons.Add(accessLevel.ID, newButton); | ||
newButton.OnPressed += _ => SubmitData(); | ||
} | ||
} | ||
|
||
private static string GetAccessLevelName(AccessLevelPrototype prototype) | ||
{ | ||
if (prototype.Name is { } name) | ||
return Loc.GetString(name); | ||
|
||
return prototype.ID; | ||
} | ||
|
||
public void UpdateState(AccessOverriderBoundUserInterfaceState state) | ||
{ | ||
PrivilegedIdLabel.Text = state.PrivilegedIdName; | ||
PrivilegedIdButton.Text = state.IsPrivilegedIdPresent | ||
? Loc.GetString("access-overrider-window-eject-button") | ||
: Loc.GetString("access-overrider-window-insert-button"); | ||
|
||
TargetNameLabel.Text = state.TargetLabel; | ||
TargetNameLabel.FontColorOverride = state.TargetLabelColor; | ||
|
||
MissingPrivilegesLabel.Text = ""; | ||
MissingPrivilegesLabel.FontColorOverride = Color.Yellow; | ||
|
||
MissingPrivilegesText.Text = ""; | ||
MissingPrivilegesText.FontColorOverride = Color.Yellow; | ||
|
||
if (state.MissingPrivilegesList != null && state.MissingPrivilegesList.Any()) | ||
{ | ||
List<string> missingPrivileges = new List<string>(); | ||
|
||
foreach (string tag in state.MissingPrivilegesList) | ||
{ | ||
string privilege = Loc.GetString(_prototypeManager.Index<AccessLevelPrototype>(tag)?.Name ?? "generic-unknown"); | ||
missingPrivileges.Add(privilege); | ||
} | ||
|
||
MissingPrivilegesLabel.Text = Loc.GetString("access-overrider-window-missing-privileges"); | ||
MissingPrivilegesText.Text = string.Join(", ", missingPrivileges); | ||
} | ||
|
||
var interfaceEnabled = state.IsPrivilegedIdPresent && state.IsPrivilegedIdAuthorized; | ||
|
||
foreach (var (accessName, button) in _accessButtons) | ||
{ | ||
button.Disabled = !interfaceEnabled; | ||
if (interfaceEnabled) | ||
{ | ||
button.Pressed = state.TargetAccessReaderIdAccessList?.Contains(accessName) ?? false; | ||
button.Disabled = (!state.AllowedModifyAccessList?.Contains(accessName)) ?? true; | ||
} | ||
} | ||
} | ||
|
||
private void SubmitData() | ||
{ | ||
_owner.SubmitData( | ||
|
||
// 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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.