Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArturZh committed Aug 10, 2023
2 parents 6d507ab + 13991d3 commit 5914538
Show file tree
Hide file tree
Showing 211 changed files with 4,681 additions and 1,212 deletions.
11 changes: 11 additions & 0 deletions Content.Client/Access/AccessOverriderSystem.cs
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 Content.Client/Access/UI/AccessOverriderBoundUserInterface.cs
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));
}
}
}
23 changes: 23 additions & 0 deletions Content.Client/Access/UI/AccessOverriderWindow.xaml
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>
111 changes: 111 additions & 0 deletions Content.Client/Access/UI/AccessOverriderWindow.xaml.cs
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());
}
}
}
6 changes: 6 additions & 0 deletions Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected override void Open()

_window.OnClose += Close;
_window.AtmosDeviceDataChanged += OnDeviceDataChanged;
_window.AtmosDeviceDataCopied += OnDeviceDataCopied;
_window.AtmosAlarmThresholdChanged += OnThresholdChanged;
_window.AirAlarmModeChanged += OnAirAlarmModeChanged;
_window.AutoModeChanged += OnAutoModeChanged;
Expand All @@ -47,6 +48,11 @@ private void OnDeviceDataChanged(string address, IAtmosDeviceData data)
{
SendMessage(new AirAlarmUpdateDeviceDataMessage(address, data));
}

private void OnDeviceDataCopied(IAtmosDeviceData data)
{
SendMessage(new AirAlarmCopyDeviceDataMessage(data));
}

private void OnAirAlarmModeChanged(AirAlarmMode mode)
{
Expand Down
3 changes: 3 additions & 0 deletions Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Content.Client.Atmos.Monitor.UI;
public sealed partial class AirAlarmWindow : FancyWindow
{
public event Action<string, IAtmosDeviceData>? AtmosDeviceDataChanged;
public event Action<IAtmosDeviceData>? AtmosDeviceDataCopied;
public event Action<string, AtmosMonitorThresholdType, AtmosAlarmThreshold, Gas?>? AtmosAlarmThresholdChanged;
public event Action<AirAlarmMode>? AirAlarmModeChanged;
public event Action<bool>? AutoModeChanged;
Expand Down Expand Up @@ -137,6 +138,7 @@ public void UpdateDeviceData(string addr, IAtmosDeviceData device)
{
var control= new PumpControl(pump, addr);
control.PumpDataChanged += AtmosDeviceDataChanged!.Invoke;
control.PumpDataCopied += AtmosDeviceDataCopied!.Invoke;
_pumps.Add(addr, control);
CVentContainer.AddChild(control);
}
Expand All @@ -151,6 +153,7 @@ public void UpdateDeviceData(string addr, IAtmosDeviceData device)
{
var control = new ScrubberControl(scrubber, addr);
control.ScrubberDataChanged += AtmosDeviceDataChanged!.Invoke;
control.ScrubberDataCopied += AtmosDeviceDataCopied!.Invoke;
_scrubbers.Add(addr, control);
CScrubberContainer.AddChild(control);
}
Expand Down
5 changes: 4 additions & 1 deletion Content.Client/Atmos/Monitor/UI/Widgets/PumpControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<OptionButton Name="CPressureCheck" />
</BoxContainer>
</BoxContainer>
<!-- Lower row: pressure bounds -->
<!-- Lower row: pressure bounds, copy settings -->
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
<Label Text="{Loc 'air-alarm-ui-vent-external-bound-label'}" Margin="0 0 0 1" />
Expand All @@ -30,6 +30,9 @@
<FloatSpinBox Name="CInternalBound" HorizontalExpand="True" />
</BoxContainer>
</BoxContainer>
<BoxContainer Orientation="Horizontal" Margin ="0 0 0 2">
<Button Name="CCopySettings" Text="{Loc 'air-alarm-ui-widget-copy'}" ToolTip="{Loc 'air-alarm-ui-widget-copy-tooltip'}" />
</BoxContainer>
</BoxContainer>
</CollapsibleBody>
</Collapsible>
Expand Down
7 changes: 7 additions & 0 deletions Content.Client/Atmos/Monitor/UI/Widgets/PumpControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ public sealed partial class PumpControl : BoxContainer
private string _address;

public event Action<string, IAtmosDeviceData>? PumpDataChanged;
public event Action<IAtmosDeviceData>? PumpDataCopied;

private CheckBox _enabled => CEnableDevice;
private CollapsibleHeading _addressLabel => CAddress;
private OptionButton _pumpDirection => CPumpDirection;
private OptionButton _pressureCheck => CPressureCheck;
private FloatSpinBox _externalBound => CExternalBound;
private FloatSpinBox _internalBound => CInternalBound;
private Button _copySettings => CCopySettings;

public PumpControl(GasVentPumpData data, string address)
{
Expand Down Expand Up @@ -84,6 +86,11 @@ public PumpControl(GasVentPumpData data, string address)
_data.PressureChecks = (VentPressureBound) args.Id;
PumpDataChanged?.Invoke(_address, _data);
};

_copySettings.OnPressed += _ =>
{
PumpDataCopied?.Invoke(_data);
};
}

public void ChangeData(GasVentPumpData data)
Expand Down
5 changes: 4 additions & 1 deletion Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<BoxContainer Orientation="Horizontal" Margin="0 0 0 2">
<CheckBox Name="CEnableDevice" Text="{Loc 'air-alarm-ui-widget-enable'}" />
</BoxContainer>
<!-- Upper row: toggle, direction, volume rate, widenet -->
<!-- Upper row: toggle, direction, volume rate, widenet, copy settings -->
<BoxContainer Orientation="Horizontal" Margin="0 0 0 2" HorizontalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
<Label Text="{Loc 'air-alarm-ui-scrubber-pump-direction-label'}" Margin="0 0 0 1"/>
Expand All @@ -22,6 +22,9 @@
<BoxContainer>
<CheckBox Name="CWideNet" Text="{Loc 'air-alarm-ui-scrubber-wide-net-label'}" />
</BoxContainer>
<BoxContainer Orientation="Horizontal" Margin ="0 0 0 2">
<Button Name="CCopySettings" Text="{Loc 'air-alarm-ui-widget-copy'}" ToolTip="{Loc 'air-alarm-ui-widget-copy-tooltip'}" />
</BoxContainer>
<!-- Lower row: every single gas -->
<Collapsible Orientation="Vertical" Margin="2 2 2 2">
<CollapsibleHeading Title="Gas filters" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public sealed partial class ScrubberControl : BoxContainer
private string _address;

public event Action<string, IAtmosDeviceData>? ScrubberDataChanged;
public event Action<IAtmosDeviceData>? ScrubberDataCopied;

private CheckBox _enabled => CEnableDevice;
private CollapsibleHeading _addressLabel => CAddress;
private OptionButton _pumpDirection => CPumpDirection;
private FloatSpinBox _volumeRate => CVolumeRate;
private CheckBox _wideNet => CWideNet;
private Button _copySettings => CCopySettings;

private GridContainer _gases => CGasContainer;
private Dictionary<Gas, Button> _gasControls = new();
Expand Down Expand Up @@ -75,6 +77,11 @@ public ScrubberControl(GasVentScrubberData data, string address)
_data.PumpDirection = (ScrubberPumpDirection) args.Id;
ScrubberDataChanged?.Invoke(_address, _data);
};

_copySettings.OnPressed += _ =>
{
ScrubberDataCopied?.Invoke(_data);
};

foreach (var value in Enum.GetValues<Gas>())
{
Expand Down
11 changes: 8 additions & 3 deletions Content.Client/Humanoid/HumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ private void ApplyMarking(EntityUid uid,

for (var j = 0; j < markingPrototype.Sprites.Count; j++)
{
if (markingPrototype.Sprites[j] is not SpriteSpecifier.Rsi rsi)
var markingSprite = markingPrototype.Sprites[j];

if (markingSprite is not SpriteSpecifier.Rsi rsi)
{
continue;
}
Expand All @@ -314,7 +316,7 @@ private void ApplyMarking(EntityUid uid,

if (!sprite.LayerMapTryGet(layerId, out _))
{
var layer = sprite.AddLayer(markingPrototype.Sprites[j], targetLayer + j + 1);
var layer = sprite.AddLayer(markingSprite, targetLayer + j + 1);
sprite.LayerMapSet(layerId, layer);
sprite.LayerSetSprite(layerId, rsi);
}
Expand All @@ -326,7 +328,10 @@ private void ApplyMarking(EntityUid uid,
continue;
}

if (colors != null)
// Okay so if the marking prototype is modified but we load old marking data this may no longer be valid
// and we need to check the index is correct.
// So if that happens just default to white?
if (colors != null && j < colors.Count)
{
sprite.LayerSetColor(layerId, colors[j]);
}
Expand Down
Loading

0 comments on commit 5914538

Please sign in to comment.