make cargo balance ui updating its own component (#28295)

* 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>
This commit is contained in:
deltanedas
2024-07-13 06:11:14 +00:00
committed by GitHub
parent 044d84142c
commit 87f7ea8aa9
6 changed files with 46 additions and 7 deletions

View File

@@ -40,6 +40,7 @@ namespace Content.Server.Cargo.Systems
SubscribeLocalEvent<CargoOrderConsoleComponent, BoundUIOpenedEvent>(OnOrderUIOpened); SubscribeLocalEvent<CargoOrderConsoleComponent, BoundUIOpenedEvent>(OnOrderUIOpened);
SubscribeLocalEvent<CargoOrderConsoleComponent, ComponentInit>(OnInit); SubscribeLocalEvent<CargoOrderConsoleComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<CargoOrderConsoleComponent, InteractUsingEvent>(OnInteractUsing); SubscribeLocalEvent<CargoOrderConsoleComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<CargoOrderConsoleComponent, BankBalanceUpdatedEvent>(OnOrderBalanceUpdated);
Reset(); Reset();
} }
@@ -315,6 +316,15 @@ namespace Content.Server.Cargo.Systems
#endregion #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) private void UpdateOrderState(EntityUid consoleUid, EntityUid? station)
{ {
if (station == null || if (station == null ||

View File

@@ -81,18 +81,18 @@ public sealed partial class CargoSystem : SharedCargoSystem
public void UpdateBankAccount(EntityUid uid, StationBankAccountComponent component, int balanceAdded) public void UpdateBankAccount(EntityUid uid, StationBankAccountComponent component, int balanceAdded)
{ {
component.Balance += 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)) var station = _station.GetOwningStation(client, xform);
continue;
var station = _station.GetOwningStation(oUid);
if (station != uid) if (station != uid)
continue; continue;
UpdateOrderState(oUid, station); comp.Balance = component.Balance;
Dirty(client, comp);
RaiseLocalEvent(client, ref ev);
} }
} }
} }

View File

@@ -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);

View File

@@ -69,6 +69,7 @@
- type: RadarConsole - type: RadarConsole
followEntity: true followEntity: true
- type: CargoOrderConsole - type: CargoOrderConsole
- type: BankClient
- type: CrewMonitoringConsole - type: CrewMonitoringConsole
- type: GeneralStationRecordConsole - type: GeneralStationRecordConsole
canDeleteEntries: true canDeleteEntries: true

View File

@@ -548,6 +548,7 @@
tags: tags:
- Write - Write
- type: CargoOrderConsole - type: CargoOrderConsole
- type: BankClient
- type: ActivatableUI - type: ActivatableUI
verbText: qm-clipboard-computer-verb-text verbText: qm-clipboard-computer-verb-text
key: enum.CargoConsoleUiKey.Orders key: enum.CargoConsoleUiKey.Orders

View File

@@ -735,6 +735,7 @@
- map: ["computerLayerKeys"] - map: ["computerLayerKeys"]
state: tech_key state: tech_key
- type: CargoOrderConsole - type: CargoOrderConsole
- type: BankClient
- type: ActiveRadio - type: ActiveRadio
channels: channels:
- Supply - Supply