Fix disposal units in general (#1552)
* Makes disposal units able to be entered when unpowered * Make the unit's light turn off when unpowered * Remove event handlers on component removal * Make the disposal unit's lever engage when queueing an auto engage * Autoengaging the lever on insert was a mistake * Make the engage button active when engaged * Make the engage button toggleable * Fix nullable error
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,15 +343,27 @@ 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
|
||||
{
|
||||
appearance.SetData(Visuals.VisualState, VisualState.Anchored);
|
||||
|
||||
if (ContainedEntities.Count > 0)
|
||||
{
|
||||
@@ -355,7 +375,6 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
? 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<AnchorableComponent>();
|
||||
var collidable = Owner.EnsureComponent<CollidableComponent>();
|
||||
|
||||
var collidable = Owner.EnsureComponent<CollidableComponent>();
|
||||
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<IGameTiming>();
|
||||
if (Engaged ||
|
||||
!msg.Entity.HasComponent<HandsComponent>() ||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user