SubscribeLocalEvent<CargoOrderConsoleComponent, BoundUIOpenedEvent>(OnOrderUIOpened);
SubscribeLocalEvent<CargoOrderConsoleComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<CargoOrderConsoleComponent, InteractUsingEvent>(OnInteractUsing);
+ SubscribeLocalEvent<CargoOrderConsoleComponent, BankBalanceUpdatedEvent>(OnOrderBalanceUpdated);
Reset();
}
#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 ||
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);
}
}
}
--- /dev/null
+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);
- type: RadarConsole
followEntity: true
- type: CargoOrderConsole
+ - type: BankClient
- type: CrewMonitoringConsole
- type: GeneralStationRecordConsole
canDeleteEntries: true
tags:
- Write
- type: CargoOrderConsole
+ - type: BankClient
- type: ActivatableUI
verbText: qm-clipboard-computer-verb-text
key: enum.CargoConsoleUiKey.Orders
- map: ["computerLayerKeys"]
state: tech_key
- type: CargoOrderConsole
+ - type: BankClient
- type: ActiveRadio
channels:
- Supply