]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add ItemStatus for mopping (#13745)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sat, 11 Feb 2023 01:38:45 +0000 (12:38 +1100)
committerGitHub <noreply@github.com>
Sat, 11 Feb 2023 01:38:45 +0000 (01:38 +0000)
* Add ItemStatus for mopping

Big QOL feature

* a

Content.Client/Fluids/MoppingSystem.cs [new file with mode: 0644]
Content.Client/Fluids/UI/AbsorbentItemStatus.xaml [new file with mode: 0644]
Content.Client/Fluids/UI/AbsorbentItemStatus.xaml.cs [new file with mode: 0644]
Content.Server/Fluids/EntitySystems/MoppingSystem.cs
Content.Shared/Fluids/AbsorbentComponent.cs [moved from Content.Server/Fluids/Components/AbsorbentComponent.cs with 90% similarity]
Content.Shared/Fluids/SharedMoppingSystem.cs [new file with mode: 0644]

diff --git a/Content.Client/Fluids/MoppingSystem.cs b/Content.Client/Fluids/MoppingSystem.cs
new file mode 100644 (file)
index 0000000..90f8ba4
--- /dev/null
@@ -0,0 +1,20 @@
+using Content.Client.Fluids.UI;
+using Content.Client.Items;
+using Content.Shared.Fluids;
+using Robust.Client.UserInterface;
+
+namespace Content.Client.Fluids;
+
+public sealed class MoppingSystem : SharedMoppingSystem
+{
+    public override void Initialize()
+    {
+        base.Initialize();
+        Subs.ItemStatus<AbsorbentComponent>(GetAbsorbent);
+    }
+
+    private Control GetAbsorbent(EntityUid arg)
+    {
+        return new AbsorbentItemStatus(arg, EntityManager);
+    }
+}
diff --git a/Content.Client/Fluids/UI/AbsorbentItemStatus.xaml b/Content.Client/Fluids/UI/AbsorbentItemStatus.xaml
new file mode 100644 (file)
index 0000000..d8cb4fc
--- /dev/null
@@ -0,0 +1,13 @@
+<Control xmlns="https://spacestation14.io">
+    <BoxContainer Orientation="Horizontal">
+        <ProgressBar
+            HorizontalExpand="True"
+            Name="PercentBar"
+            MinSize="20 20"
+            VerticalAlignment="Center"
+            Margin="2 8 4 2"
+            MaxValue="1.0"
+            MinValue="0.0">
+        </ProgressBar>
+    </BoxContainer>
+</Control>
diff --git a/Content.Client/Fluids/UI/AbsorbentItemStatus.xaml.cs b/Content.Client/Fluids/UI/AbsorbentItemStatus.xaml.cs
new file mode 100644 (file)
index 0000000..772be44
--- /dev/null
@@ -0,0 +1,31 @@
+using Content.Shared.Fluids;
+using Robust.Client.AutoGenerated;
+using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.XAML;
+using Robust.Shared.Timing;
+
+namespace Content.Client.Fluids.UI
+{
+    [GenerateTypedNameReferences]
+    public sealed partial class AbsorbentItemStatus : Control
+    {
+        private readonly IEntityManager _entManager;
+        private readonly EntityUid _uid;
+
+        public AbsorbentItemStatus(EntityUid uid, IEntityManager entManager)
+        {
+            RobustXamlLoader.Load(this);
+            _uid = uid;
+            _entManager = entManager;
+        }
+
+        protected override void FrameUpdate(FrameEventArgs args)
+        {
+            base.FrameUpdate(args);
+            if (!_entManager.TryGetComponent<AbsorbentComponent>(_uid, out var absorbent))
+                return;
+
+            PercentBar.Value = absorbent.Progress;
+        }
+    }
+}
index b21315aab027fdbed7922bf732497712f01bde5d..44939ad969b09bf836bd06cd95c7ab388b78b1a3 100644 (file)
@@ -1,3 +1,4 @@
+using System.Linq;
 using Content.Server.Chemistry.Components.SolutionManager;
 using Content.Server.Chemistry.EntitySystems;
 using Content.Server.DoAfter;
@@ -5,6 +6,7 @@ using Content.Server.Fluids.Components;
 using Content.Server.Popups;
 using Content.Shared.Chemistry.Components;
 using Content.Shared.FixedPoint;
+using Content.Shared.Fluids;
 using Content.Shared.Interaction;
 using Content.Shared.Tag;
 using JetBrains.Annotations;
@@ -15,7 +17,7 @@ using Robust.Shared.Map;
 namespace Content.Server.Fluids.EntitySystems;
 
 [UsedImplicitly]
-public sealed class MoppingSystem : EntitySystem
+public sealed class MoppingSystem : SharedMoppingSystem
 {
     [Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
     [Dependency] private readonly SpillableSystem _spillableSystem = default!;
@@ -30,11 +32,37 @@ public sealed class MoppingSystem : EntitySystem
     public override void Initialize()
     {
         base.Initialize();
+        SubscribeLocalEvent<AbsorbentComponent, ComponentInit>(OnAbsorbentInit);
         SubscribeLocalEvent<AbsorbentComponent, AfterInteractEvent>(OnAfterInteract);
+        SubscribeLocalEvent<AbsorbentComponent, SolutionChangedEvent>(OnAbsorbentSolutionChange);
         SubscribeLocalEvent<TransferCancelledEvent>(OnTransferCancelled);
         SubscribeLocalEvent<TransferCompleteEvent>(OnTransferComplete);
     }
 
+    private void OnAbsorbentInit(EntityUid uid, AbsorbentComponent component, ComponentInit args)
+    {
+        // TODO: I know dirty on init but no prediction moment.
+        UpdateAbsorbent(uid, component);
+    }
+
+    private void OnAbsorbentSolutionChange(EntityUid uid, AbsorbentComponent component, SolutionChangedEvent args)
+    {
+        UpdateAbsorbent(uid, component);
+    }
+
+    private void UpdateAbsorbent(EntityUid uid, AbsorbentComponent component)
+    {
+        if (!_solutionSystem.TryGetSolution(uid, AbsorbentComponent.SolutionName, out var solution))
+            return;
+
+        var oldProgress = component.Progress;
+
+        component.Progress = (float) (solution.Volume / solution.MaxVolume);
+        if (component.Progress.Equals(oldProgress))
+            return;
+        Dirty(component);
+    }
+
     private void OnAfterInteract(EntityUid uid, AbsorbentComponent component, AfterInteractEvent args)
     {
         if (!args.CanReach || args.Handled)
similarity index 90%
rename from Content.Server/Fluids/Components/AbsorbentComponent.cs
rename to Content.Shared/Fluids/AbsorbentComponent.cs
index 5e02d518e7663de1880a19db6ed81fc9f1aa0215..011e123e90c0ce1b128da7558854f987f5c8512b 100644 (file)
@@ -1,15 +1,18 @@
-using Content.Server.Fluids.EntitySystems;
 using Content.Shared.FixedPoint;
 using Robust.Shared.Audio;
+using Robust.Shared.GameStates;
 
-namespace Content.Server.Fluids.Components;
+namespace Content.Shared.Fluids;
 
 /// <summary>
 /// For entities that can clean up puddles
 /// </summary>
-[RegisterComponent, Access(typeof(MoppingSystem))]
+[RegisterComponent, NetworkedComponent]
 public sealed class AbsorbentComponent : Component
 {
+    // TODO: Predicted solutions my beloved.
+    public float Progress;
+
     public const string SolutionName = "absorbed";
 
     [DataField("pickupAmount")]
diff --git a/Content.Shared/Fluids/SharedMoppingSystem.cs b/Content.Shared/Fluids/SharedMoppingSystem.cs
new file mode 100644 (file)
index 0000000..8e6dcc8
--- /dev/null
@@ -0,0 +1,39 @@
+using Robust.Shared.GameStates;
+using Robust.Shared.Serialization;
+
+namespace Content.Shared.Fluids;
+
+public abstract class SharedMoppingSystem : EntitySystem
+{
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<AbsorbentComponent, ComponentGetState>(OnAbsorbentGetState);
+        SubscribeLocalEvent<AbsorbentComponent, ComponentHandleState>(OnAbsorbentHandleState);
+    }
+
+    private void OnAbsorbentHandleState(EntityUid uid, AbsorbentComponent component, ref ComponentHandleState args)
+    {
+        if (args.Current is not AbsorbentComponentState state)
+            return;
+
+        if (component.Progress.Equals(state.Progress))
+            return;
+
+        component.Progress = state.Progress;
+    }
+
+    private void OnAbsorbentGetState(EntityUid uid, AbsorbentComponent component, ref ComponentGetState args)
+    {
+        args.State = new AbsorbentComponentState()
+        {
+            Progress = component.Progress,
+        };
+    }
+
+    [Serializable, NetSerializable]
+    protected sealed class AbsorbentComponentState : ComponentState
+    {
+        public float Progress;
+    }
+}