mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using Content.Shared.DeviceLinking.Components;
|
|
using Content.Shared.UserInterface;
|
|
|
|
namespace Content.Shared.DeviceLinking.Systems;
|
|
|
|
public abstract partial class SharedRandomGateSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedUserInterfaceSystem _ui = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<RandomGateComponent, AfterActivatableUIOpenEvent>(OnAfterActivatableUIOpen);
|
|
SubscribeLocalEvent<RandomGateComponent, RandomGateProbabilityChangedMessage>(OnProbabilityChanged);
|
|
}
|
|
|
|
private void OnAfterActivatableUIOpen(Entity<RandomGateComponent> ent, ref AfterActivatableUIOpenEvent args)
|
|
{
|
|
UpdateUI(ent);
|
|
}
|
|
|
|
private void OnProbabilityChanged(Entity<RandomGateComponent> ent, ref RandomGateProbabilityChangedMessage args)
|
|
{
|
|
ent.Comp.SuccessProbability = Math.Clamp(args.Probability, 0f, 100f) / 100f;
|
|
Dirty(ent);
|
|
UpdateUI(ent);
|
|
}
|
|
|
|
private void UpdateUI(Entity<RandomGateComponent> ent)
|
|
{
|
|
if (!_ui.HasUi(ent.Owner, RandomGateUiKey.Key))
|
|
return;
|
|
|
|
_ui.SetUiState(ent.Owner, RandomGateUiKey.Key, new RandomGateBoundUserInterfaceState(ent.Comp.SuccessProbability));
|
|
}
|
|
}
|