]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
make cargo balance ui updating its own component (#28295)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Sat, 13 Jul 2024 06:11:14 +0000 (06:11 +0000)
committerGitHub <noreply@github.com>
Sat, 13 Jul 2024 06:11:14 +0000 (16:11 +1000)
* add BankClientComponent and event

* query BankClient instead of hardcoded CargoOrderConsole for updating

* add BankClient to all ordering consoles

* :trollface:

* add Balance field to BankClient

* forgor

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
* m

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Content.Server/Cargo/Systems/CargoSystem.Orders.cs
Content.Server/Cargo/Systems/CargoSystem.cs
Content.Shared/Cargo/Components/BankClientComponent.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml
Resources/Prototypes/Entities/Objects/Misc/paper.yml
Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml

index a288d7b07d4ab63fa982cfa7dd4b08c7b2e3afa2..dd408755e672b4afdfec591e6b3c0e9557cd4206 100644 (file)
@@ -40,6 +40,7 @@ namespace Content.Server.Cargo.Systems
             SubscribeLocalEvent<CargoOrderConsoleComponent, BoundUIOpenedEvent>(OnOrderUIOpened);
             SubscribeLocalEvent<CargoOrderConsoleComponent, ComponentInit>(OnInit);
             SubscribeLocalEvent<CargoOrderConsoleComponent, InteractUsingEvent>(OnInteractUsing);
+            SubscribeLocalEvent<CargoOrderConsoleComponent, BankBalanceUpdatedEvent>(OnOrderBalanceUpdated);
             Reset();
         }
 
@@ -315,6 +316,15 @@ namespace Content.Server.Cargo.Systems
 
         #endregion
 
+
+        private void OnOrderBalanceUpdated(Entity<CargoOrderConsoleComponent> ent, ref BankBalanceUpdatedEvent args)
+        {
+            if (!_uiSystem.IsUiOpen(ent.Owner, CargoConsoleUiKey.Orders))
+                return;
+
+            UpdateOrderState(ent, args.Station);
+        }
+
         private void UpdateOrderState(EntityUid consoleUid, EntityUid? station)
         {
             if (station == null ||
index a93a7bdcc225b723fa07c5c148a54ce5b8777ff9..1b33404e355574a42fc9c3dec70ea7c6ae2c55a4 100644 (file)
@@ -81,18 +81,18 @@ public sealed partial class CargoSystem : SharedCargoSystem
     public void UpdateBankAccount(EntityUid uid, StationBankAccountComponent component, int balanceAdded)
     {
         component.Balance += balanceAdded;
-        var query = EntityQueryEnumerator<CargoOrderConsoleComponent>();
+        var query = EntityQueryEnumerator<BankClientComponent, TransformComponent>();
 
-        while (query.MoveNext(out var oUid, out var _))
+        var ev = new BankBalanceUpdatedEvent(uid, component.Balance);
+        while (query.MoveNext(out var client, out var comp, out var xform))
         {
-            if (!_uiSystem.IsUiOpen(oUid, CargoConsoleUiKey.Orders))
-                continue;
-
-            var station = _station.GetOwningStation(oUid);
+            var station = _station.GetOwningStation(client, xform);
             if (station != uid)
                 continue;
 
-            UpdateOrderState(oUid, station);
+            comp.Balance = component.Balance;
+            Dirty(client, comp);
+            RaiseLocalEvent(client, ref ev);
         }
     }
 }
diff --git a/Content.Shared/Cargo/Components/BankClientComponent.cs b/Content.Shared/Cargo/Components/BankClientComponent.cs
new file mode 100644 (file)
index 0000000..4fd7085
--- /dev/null
@@ -0,0 +1,26 @@
+using Content.Shared.Cargo;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Cargo.Components;
+
+/// <summary>
+/// Makes an entity a client of the station's bank account.
+/// When its balance changes it will have <see cref="BankBalanceUpdatedEvent"/> raised on it.
+/// Other systems can then use this for logic or to update ui states.
+/// </summary>
+[RegisterComponent, NetworkedComponent, Access(typeof(SharedCargoSystem))]
+[AutoGenerateComponentState]
+public sealed partial class BankClientComponent : Component
+{
+    /// <summary>
+    /// The balance updated for the last station this entity was a part of.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public int Balance;
+}
+
+/// <summary>
+/// Raised on an entity with <see cref="BankClientComponent"/> when the bank's balance is updated.
+/// </summary>
+[ByRefEvent]
+public record struct BankBalanceUpdatedEvent(EntityUid Station, int Balance);
index a0eb01e03b3021ecb4cfdfc601f4b53a29253b52..0c814e08f7140589ce30b82702dad5afbe2c0bc1 100644 (file)
@@ -69,6 +69,7 @@
   - type: RadarConsole
     followEntity: true
   - type: CargoOrderConsole
+  - type: BankClient
   - type: CrewMonitoringConsole
   - type: GeneralStationRecordConsole
     canDeleteEntries: true
index 1c8d8754884f3302cab34e3dc288f4c16c75a15f..5dbafa6416aec97989c4a58d690279ce4a701745 100644 (file)
           tags:
           - Write
   - type: CargoOrderConsole
+  - type: BankClient
   - type: ActivatableUI
     verbText: qm-clipboard-computer-verb-text
     key: enum.CargoConsoleUiKey.Orders
index 3f9a9bc222e8402cf556dd2f511f6a5b0c1afb79..4baf9bb5dc67eb3a9c9088d8db923e9c0439f9a2 100644 (file)
     - map: ["computerLayerKeys"]
       state: tech_key
   - type: CargoOrderConsole
+  - type: BankClient
   - type: ActiveRadio
     channels:
     - Supply