diff --git a/Content.Client/DoAfter/DoAfterSystem.cs b/Content.Client/DoAfter/DoAfterSystem.cs index 761747b8e9..8c2d8344d3 100644 --- a/Content.Client/DoAfter/DoAfterSystem.cs +++ b/Content.Client/DoAfter/DoAfterSystem.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Content.Shared.DoAfter; using Content.Shared.Hands.Components; using Robust.Client.Graphics; @@ -51,4 +52,58 @@ public sealed class DoAfterSystem : SharedDoAfterSystem var handsQuery = GetEntityQuery(); Update(playerEntity.Value, active, comp, time, xformQuery, handsQuery); } + + /// + /// Try to find an active do-after being executed by the local player. + /// + /// The entity the do after must be targeting () + /// The found do-after. + /// The event to be raised on the found do-after when it completes. + /// The progress of the found do-after, from 0 to 1. + /// The type of event that must be raised by the found do-after. + /// True if a do-after was found. + public bool TryFindActiveDoAfter( + EntityUid entity, + [NotNullWhen(true)] out Shared.DoAfter.DoAfter? doAfter, + [NotNullWhen(true)] out T? @event, + out float progress) + where T : DoAfterEvent + { + var playerEntity = _player.LocalPlayer?.ControlledEntity; + + doAfter = null; + @event = null; + progress = default; + + if (!TryComp(playerEntity, out ActiveDoAfterComponent? active)) + return false; + + if (_metadata.EntityPaused(playerEntity.Value)) + return false; + + var comp = Comp(playerEntity.Value); + + var time = GameTiming.CurTime; + + foreach (var candidate in comp.DoAfters.Values) + { + if (candidate.Cancelled) + continue; + + if (candidate.Args.Target != entity) + continue; + + if (candidate.Args.Event is not T candidateEvent) + continue; + + @event = candidateEvent; + doAfter = candidate; + var elapsed = time - doAfter.StartTime; + progress = (float) Math.Min(1, elapsed.TotalSeconds / doAfter.Args.Delay.TotalSeconds); + + return true; + } + + return false; + } } diff --git a/Content.Client/Power/Generator/GeneratorWindow.xaml b/Content.Client/Power/Generator/GeneratorWindow.xaml index 86da3835e2..bae63a09ed 100644 --- a/Content.Client/Power/Generator/GeneratorWindow.xaml +++ b/Content.Client/Power/Generator/GeneratorWindow.xaml @@ -1,22 +1,39 @@  + MinSize="450 235" + SetSize="450 235" + Resizable="False" + Title="{Loc 'portable-generator-ui-title'}"> - + +