diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalUnitWindow.cs b/Content.Client/GameObjects/Components/Disposal/DisposalUnitWindow.cs index e5e36af038..2aa013469d 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalUnitWindow.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalUnitWindow.cs @@ -65,7 +65,11 @@ namespace Content.Client.GameObjects.Components.Disposal Children = { new Label {Text = Loc.GetString("Handle:")}, - (Engage = new Button {Text = Loc.GetString("Engage")}) + (Engage = new Button + { + Text = Loc.GetString("Engage"), + ToggleMode = true + }) } }, new Control {CustomMinimumSize = (0, 10)}, @@ -135,6 +139,7 @@ namespace Content.Client.GameObjects.Components.Disposal _unitState.Text = state.UnitState; UpdatePressureBar(state.Pressure); Power.Pressed = state.Powered; + Engage.Pressed = state.Engaged; } } } diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs index 7e82224a34..31f1c56c7d 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs @@ -38,6 +38,7 @@ namespace Content.Server.GameObjects.Components.Disposal { #pragma warning disable 649 [Dependency] private readonly IServerNotifyManager _notifyManager = default!; + [Dependency] private readonly IGameTiming _gameTiming = default!; #pragma warning restore 649 public override string Name => "DisposalUnit"; @@ -116,7 +117,7 @@ namespace Content.Server.GameObjects.Components.Disposal public bool CanInsert(IEntity entity) { - if (!Powered || !Anchored) + if (!Anchored) { return false; } @@ -191,11 +192,20 @@ namespace Content.Server.GameObjects.Components.Disposal return _pressure >= 1 && Powered && Anchored; } + private void ToggleEngage() + { + Engaged ^= true; + + if (Engaged) + { + TryFlush(); + } + } + public bool TryFlush() { if (!CanFlush()) { - Engaged = true; return false; } @@ -252,7 +262,8 @@ namespace Content.Server.GameObjects.Components.Disposal private DisposalUnitBoundUserInterfaceState GetInterfaceState() { - return new DisposalUnitBoundUserInterfaceState(Owner.Name, Loc.GetString($"{State}"), _pressure, Powered); + var state = Loc.GetString($"{State}"); + return new DisposalUnitBoundUserInterfaceState(Owner.Name, state, _pressure, Powered, Engaged); } private void UpdateInterface() @@ -300,7 +311,7 @@ namespace Content.Server.GameObjects.Components.Disposal TryEjectContents(); break; case UiButton.Engage: - TryFlush(); + ToggleEngage(); break; case UiButton.Power: TogglePower(); @@ -324,9 +335,6 @@ namespace Content.Server.GameObjects.Components.Disposal return; } - appearance.SetData(Visuals.Handle, Engaged - ? HandleState.Engaged - : HandleState.Normal); if (!Anchored) { @@ -335,26 +343,37 @@ namespace Content.Server.GameObjects.Components.Disposal appearance.SetData(Visuals.Light, LightState.Off); return; } + else + { + appearance.SetData(Visuals.VisualState, VisualState.Anchored); + } + + appearance.SetData(Visuals.Handle, Engaged + ? HandleState.Engaged + : HandleState.Normal); + + if (!Powered) + { + appearance.SetData(Visuals.Light, LightState.Off); + return; + } if (flush) { appearance.SetData(Visuals.VisualState, VisualState.Flushing); appearance.SetData(Visuals.Light, LightState.Off); + return; } - else + + if (ContainedEntities.Count > 0) { - appearance.SetData(Visuals.VisualState, VisualState.Anchored); - - if (ContainedEntities.Count > 0) - { - appearance.SetData(Visuals.Light, LightState.Full); - return; - } - - appearance.SetData(Visuals.Light, _pressure < 1 - ? LightState.Charging - : LightState.Ready); + appearance.SetData(Visuals.Light, LightState.Full); + return; } + + appearance.SetData(Visuals.Light, _pressure < 1 + ? LightState.Charging + : LightState.Ready); } public void Update(float frameTime) @@ -383,6 +402,11 @@ namespace Content.Server.GameObjects.Components.Disposal UpdateInterface(); } + private void PowerStateChanged(object? sender, PowerStateEventArgs args) + { + UpdateVisualState(); + } + public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); @@ -423,14 +447,30 @@ namespace Content.Server.GameObjects.Components.Disposal base.Startup(); Owner.EnsureComponent(); - var collidable = Owner.EnsureComponent(); + var collidable = Owner.EnsureComponent(); collidable.AnchoredChanged += UpdateVisualState; + + if (Owner.TryGetComponent(out PowerReceiverComponent receiver)) + { + receiver.OnPowerStateChanged += PowerStateChanged; + } + UpdateVisualState(); } public override void OnRemove() { + if (Owner.TryGetComponent(out ICollidableComponent collidable)) + { + collidable.AnchoredChanged -= UpdateVisualState; + } + + if (Owner.TryGetComponent(out PowerReceiverComponent receiver)) + { + receiver.OnPowerStateChanged -= PowerStateChanged; + } + foreach (var entity in _container.ContainedEntities.ToArray()) { _container.ForceRemove(entity); @@ -453,15 +493,14 @@ namespace Content.Server.GameObjects.Components.Disposal switch (message) { case RelayMovementEntityMessage msg: - var timing = IoCManager.Resolve(); if (Engaged || !msg.Entity.HasComponent() || - timing.CurTime < _lastExitAttempt + ExitAttemptDelay) + _gameTiming.CurTime < _lastExitAttempt + ExitAttemptDelay) { break; } - _lastExitAttempt = timing.CurTime; + _lastExitAttempt = _gameTiming.CurTime; Remove(msg.Entity); break; } @@ -556,6 +595,7 @@ namespace Content.Server.GameObjects.Components.Disposal protected override void Activate(IEntity user, DisposalUnitComponent component) { + component.Engaged = true; component.TryFlush(); } } diff --git a/Content.Shared/GameObjects/Components/Disposal/SharedDisposalUnitComponent.cs b/Content.Shared/GameObjects/Components/Disposal/SharedDisposalUnitComponent.cs index 3914979123..12cae99e46 100644 --- a/Content.Shared/GameObjects/Components/Disposal/SharedDisposalUnitComponent.cs +++ b/Content.Shared/GameObjects/Components/Disposal/SharedDisposalUnitComponent.cs @@ -63,13 +63,16 @@ namespace Content.Shared.GameObjects.Components.Disposal public readonly string UnitState; public readonly float Pressure; public readonly bool Powered; + public readonly bool Engaged; - public DisposalUnitBoundUserInterfaceState(string unitName, string unitState, float pressure, bool powered) + public DisposalUnitBoundUserInterfaceState(string unitName, string unitState, float pressure, bool powered, + bool engaged) { UnitName = unitName; UnitState = unitState; Pressure = pressure; Powered = powered; + Engaged = engaged; } }