Skip to content

Commit

Permalink
Merge pull request #2008 from space-syndicate/upstream-sync
Browse files Browse the repository at this point in the history
Upstream sync
  • Loading branch information
Morb0 authored Apr 2, 2024
2 parents 9a15446 + 0c35762 commit 7f599b9
Show file tree
Hide file tree
Showing 954 changed files with 13,810 additions and 5,900 deletions.
4 changes: 4 additions & 0 deletions Content.Client/Access/UI/AccessLevelControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<GridContainer xmlns="https://spacestation14.io"
Columns="5"
HorizontalAlignment="Center">
</GridContainer>
52 changes: 52 additions & 0 deletions Content.Client/Access/UI/AccessLevelControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Linq;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Content.Shared.Access;
using Content.Shared.Access.Systems;

namespace Content.Client.Access.UI;

[GenerateTypedNameReferences]
public sealed partial class AccessLevelControl : GridContainer
{
public readonly Dictionary<ProtoId<AccessLevelPrototype>, Button> ButtonsList = new();

public AccessLevelControl()
{
RobustXamlLoader.Load(this);
}

public void Populate(List<ProtoId<AccessLevelPrototype>> accessLevels, IPrototypeManager prototypeManager)
{
foreach (var access in accessLevels)
{
if (!prototypeManager.TryIndex(access, out var accessLevel))
{
Logger.Error($"Unable to find accesslevel for {access}");
continue;
}

var newButton = new Button
{
Text = accessLevel.GetAccessLevelName(),
ToggleMode = true,
};
AddChild(newButton);
ButtonsList.Add(accessLevel.ID, newButton);
}
}

public void UpdateState(
List<ProtoId<AccessLevelPrototype>> pressedList,
List<ProtoId<AccessLevelPrototype>>? enabledList = null)
{
foreach (var (accessName, button) in ButtonsList)
{
button.Pressed = pressedList.Contains(accessName);
button.Disabled = !(enabledList?.Contains(accessName) ?? true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override void UpdateState(BoundUserInterfaceState state)
_window?.UpdateState(castState);
}

public void SubmitData(List<string> newAccessList)
public void SubmitData(List<ProtoId<AccessLevelPrototype>> newAccessList)
{
SendMessage(new WriteToTargetAccessReaderIdMessage(newAccessList));
}
Expand Down
17 changes: 4 additions & 13 deletions Content.Client/Access/UI/AccessOverriderWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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();

Expand All @@ -25,21 +24,21 @@ public AccessOverriderWindow(AccessOverriderBoundUserInterface owner, IPrototype
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_logMill = _logManager.GetSawmill(SharedAccessOverriderSystem.Sawmill);
var logMill = _logManager.GetSawmill(SharedAccessOverriderSystem.Sawmill);

_owner = owner;

foreach (var access in accessLevels)
{
if (!prototypeManager.TryIndex(access, out var accessLevel))
{
_logMill.Error($"Unable to find accesslevel for {access}");
logMill.Error($"Unable to find accesslevel for {access}");
continue;
}

var newButton = new Button
{
Text = GetAccessLevelName(accessLevel),
Text = accessLevel.GetAccessLevelName(),
ToggleMode = true,
};

Expand All @@ -49,14 +48,6 @@ public AccessOverriderWindow(AccessOverriderBoundUserInterface owner, IPrototype
}
}

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;
Expand Down Expand Up @@ -105,7 +96,7 @@ 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());
_accessButtons.Where(x => x.Value.Pressed).Select(x => new ProtoId<AccessLevelPrototype>(x.Key)).ToList());
}
}
}
4 changes: 2 additions & 2 deletions Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.Access;
using Content.Shared.Access.Components;
using Content.Shared.Access;
using Content.Shared.Access.Systems;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.CrewManifest;
Expand Down Expand Up @@ -28,7 +29,6 @@ protected override void Open()
if (EntMan.TryGetComponent<IdCardConsoleComponent>(Owner, out var idCard))
{
accessLevels = idCard.AccessLevels;
accessLevels.Sort();
}
else
{
Expand Down Expand Up @@ -65,7 +65,7 @@ protected override void UpdateState(BoundUserInterfaceState state)
_window?.UpdateState(castState);
}

public void SubmitData(string newFullName, string newJobTitle, List<string> newAccessList, string newJobPrototype)
public void SubmitData(string newFullName, string newJobTitle, List<ProtoId<AccessLevelPrototype>> newAccessList, string newJobPrototype)
{
if (newFullName.Length > MaxFullNameLength)
newFullName = newFullName[..MaxFullNameLength];
Expand Down
6 changes: 1 addition & 5 deletions Content.Client/Access/UI/IdCardConsoleWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
<Label Text="{Loc 'id-card-console-window-job-selection-label'}" />
<OptionButton Name="JobPresetOptionButton" />
</GridContainer>
<GridContainer Name="AccessLevelGrid" Columns="5" HorizontalAlignment="Center">

<!-- Access level buttons are added here by the C# code -->

</GridContainer>
<Control Name="AccessLevelControlContainer" />
</BoxContainer>
</DefaultWindow>
51 changes: 14 additions & 37 deletions Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed partial class IdCardConsoleWindow : DefaultWindow

private readonly IdCardConsoleBoundUserInterface _owner;

private readonly Dictionary<string, Button> _accessButtons = new();
private AccessLevelControl _accessButtons = new();
private readonly List<string> _jobPrototypeIds = new();

private string? _lastFullName;
Expand Down Expand Up @@ -66,36 +66,18 @@ public IdCardConsoleWindow(IdCardConsoleBoundUserInterface owner, IPrototypeMana

JobPresetOptionButton.OnItemSelected += SelectJobPreset;

foreach (var access in accessLevels)
{
if (!prototypeManager.TryIndex<AccessLevelPrototype>(access, out var accessLevel))
{
_logMill.Error($"Unable to find accesslevel for {access}");
continue;
}
_accessButtons.Populate(accessLevels, prototypeManager);
AccessLevelControlContainer.AddChild(_accessButtons);

var newButton = new Button
{
Text = GetAccessLevelName(accessLevel),
ToggleMode = true,
};
AccessLevelGrid.AddChild(newButton);
_accessButtons.Add(accessLevel.ID, newButton);
newButton.OnPressed += _ => SubmitData();
foreach (var (id, button) in _accessButtons.ButtonsList)
{
button.OnPressed += _ => SubmitData();
}
}

private static string GetAccessLevelName(AccessLevelPrototype prototype)
{
if (prototype.Name is { } name)
return Loc.GetString(name);

return prototype.ID;
}

private void ClearAllAccess()
{
foreach (var button in _accessButtons.Values)
foreach (var button in _accessButtons.ButtonsList.Values)
{
if (button.Pressed)
{
Expand All @@ -119,7 +101,7 @@ private void SelectJobPreset(OptionButton.ItemSelectedEventArgs args)
// this is a sussy way to do this
foreach (var access in job.Access)
{
if (_accessButtons.TryGetValue(access, out var button) && !button.Disabled)
if (_accessButtons.ButtonsList.TryGetValue(access, out var button) && !button.Disabled)
{
button.Pressed = true;
}
Expand All @@ -134,7 +116,7 @@ private void SelectJobPreset(OptionButton.ItemSelectedEventArgs args)

foreach (var access in groupPrototype.Tags)
{
if (_accessButtons.TryGetValue(access, out var button) && !button.Disabled)
if (_accessButtons.ButtonsList.TryGetValue(access, out var button) && !button.Disabled)
{
button.Pressed = true;
}
Expand Down Expand Up @@ -184,15 +166,10 @@ public void UpdateState(IdCardConsoleBoundUserInterfaceState state)

JobPresetOptionButton.Disabled = !interfaceEnabled;

foreach (var (accessName, button) in _accessButtons)
{
button.Disabled = !interfaceEnabled;
if (interfaceEnabled)
{
button.Pressed = state.TargetIdAccessList?.Contains(accessName) ?? false;
button.Disabled = (!state.AllowedModifyAccessList?.Contains(accessName)) ?? true;
}
}
_accessButtons.UpdateState(state.TargetIdAccessList?.ToList() ??
new List<ProtoId<AccessLevelPrototype>>(),
state.AllowedModifyAccessList?.ToList() ??
new List<ProtoId<AccessLevelPrototype>>());

var jobIndex = _jobPrototypeIds.IndexOf(state.TargetIdJobPrototype);
if (jobIndex >= 0)
Expand All @@ -215,7 +192,7 @@ private void 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(),
_accessButtons.ButtonsList.Where(x => x.Value.Pressed).Select(x => x.Key).ToList(),
jobProtoDirty ? _jobPrototypeIds[JobPresetOptionButton.SelectedId] : string.Empty);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Content.Client/Anomaly/Ui/AnomalyScannerMenu.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<controls:FancyWindow
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'anomaly-scanner-ui-title'}"
MinSize="350 260"
SetSize="350 260">
MinSize="350 400"
SetSize="350 400">
<BoxContainer Orientation="Vertical" VerticalExpand="True" Margin="10 0 10 10">
<RichTextLabel Name="TextDisplay"></RichTextLabel>
</BoxContainer>
Expand Down
16 changes: 0 additions & 16 deletions Content.Client/Chemistry/Components/HyposprayComponent.cs

This file was deleted.

15 changes: 15 additions & 0 deletions Content.Client/Chemistry/EntitySystems/HypospraySystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Content.Client.Chemistry.UI;
using Content.Client.Items;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;

namespace Content.Client.Chemistry.EntitySystems;

public sealed class HypospraySystem : SharedHypospraySystem
{
public override void Initialize()
{
base.Initialize();
Subs.ItemStatus<HyposprayComponent>(ent => new HyposprayStatusControl(ent, _solutionContainers));
}
}
13 changes: 0 additions & 13 deletions Content.Client/Chemistry/EntitySystems/InjectorSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Content.Client.Chemistry.Components;
using Content.Client.Chemistry.UI;
using Content.Client.Items;
using Content.Shared.Chemistry.Components;
Expand All @@ -13,17 +12,5 @@ public override void Initialize()
{
base.Initialize();
Subs.ItemStatus<InjectorComponent>(ent => new InjectorStatusControl(ent, SolutionContainers));
SubscribeLocalEvent<HyposprayComponent, ComponentHandleState>(OnHandleHyposprayState);
Subs.ItemStatus<HyposprayComponent>(ent => new HyposprayStatusControl(ent));
}

private void OnHandleHyposprayState(EntityUid uid, HyposprayComponent component, ref ComponentHandleState args)
{
if (args.Current is not HyposprayComponentState cState)
return;

component.CurrentVolume = cState.CurVolume;
component.TotalVolume = cState.MaxVolume;
component.UiUpdateNeeded = true;
}
}
Loading

0 comments on commit 7f599b9

Please sign in to comment.