mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-14 19:29:53 +01:00
* Added random gate * minor edit * cleaning up my shit after trying to do something faster * new lines * some changes * joke * UI * Long Division * Dont use ctrl + x in 3 am * I hope these are the final touches * One thing, I don't know why * noname commit * no way, 1kk of code lines edit * sudo rm -rf ... and something there... * update * sometimes its sad
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using Content.Shared.DeviceLinking.Components;
|
|
using Content.Shared.UserInterface;
|
|
|
|
namespace Content.Shared.DeviceLinking.Systems;
|
|
|
|
public abstract class SharedRandomGateSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly 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));
|
|
}
|
|
}
|