Predict vending machine BUI (#32376)
This commit is contained in:
@@ -34,10 +34,8 @@ namespace Content.Server.VendingMachines
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
||||
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _action = default!;
|
||||
[Dependency] private readonly PricingSystem _pricing = default!;
|
||||
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly SpeakOnUIClosedSystem _speakOnUIClosed = default!;
|
||||
|
||||
@@ -47,7 +45,6 @@ namespace Content.Server.VendingMachines
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<VendingMachineComponent, MapInitEvent>(OnComponentMapInit);
|
||||
SubscribeLocalEvent<VendingMachineComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<VendingMachineComponent, BreakageEventArgs>(OnBreak);
|
||||
SubscribeLocalEvent<VendingMachineComponent, GotEmaggedEvent>(OnEmagged);
|
||||
@@ -59,7 +56,6 @@ namespace Content.Server.VendingMachines
|
||||
|
||||
Subs.BuiEvents<VendingMachineComponent>(VendingMachineUiKey.Key, subs =>
|
||||
{
|
||||
subs.Event<BoundUIOpenedEvent>(OnBoundUIOpened);
|
||||
subs.Event<VendingMachineEjectMessage>(OnInventoryEjectMessage);
|
||||
});
|
||||
|
||||
@@ -70,12 +66,6 @@ namespace Content.Server.VendingMachines
|
||||
SubscribeLocalEvent<VendingMachineRestockComponent, PriceCalculationEvent>(OnPriceCalculation);
|
||||
}
|
||||
|
||||
private void OnComponentMapInit(EntityUid uid, VendingMachineComponent component, MapInitEvent args)
|
||||
{
|
||||
_action.AddAction(uid, ref component.ActionEntity, component.Action, uid);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void OnVendingPrice(EntityUid uid, VendingMachineComponent component, ref PriceCalculationEvent args)
|
||||
{
|
||||
var price = 0.0;
|
||||
@@ -94,9 +84,9 @@ namespace Content.Server.VendingMachines
|
||||
args.Price += price;
|
||||
}
|
||||
|
||||
protected override void OnComponentInit(EntityUid uid, VendingMachineComponent component, ComponentInit args)
|
||||
protected override void OnMapInit(EntityUid uid, VendingMachineComponent component, MapInitEvent args)
|
||||
{
|
||||
base.OnComponentInit(uid, component, args);
|
||||
base.OnMapInit(uid, component, args);
|
||||
|
||||
if (HasComp<ApcPowerReceiverComponent>(uid))
|
||||
{
|
||||
@@ -110,18 +100,6 @@ namespace Content.Server.VendingMachines
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void OnBoundUIOpened(EntityUid uid, VendingMachineComponent component, BoundUIOpenedEvent args)
|
||||
{
|
||||
UpdateVendingMachineInterfaceState(uid, component);
|
||||
}
|
||||
|
||||
private void UpdateVendingMachineInterfaceState(EntityUid uid, VendingMachineComponent component)
|
||||
{
|
||||
var state = new VendingMachineInterfaceState(GetAllInventory(uid, component));
|
||||
|
||||
_userInterfaceSystem.SetUiState(uid, VendingMachineUiKey.Key, state);
|
||||
}
|
||||
|
||||
private void OnInventoryEjectMessage(EntityUid uid, VendingMachineComponent component, VendingMachineEjectMessage args)
|
||||
{
|
||||
if (!this.IsPowered(uid, EntityManager))
|
||||
@@ -297,7 +275,7 @@ namespace Content.Server.VendingMachines
|
||||
_speakOnUIClosed.TrySetFlag((uid, speakComponent));
|
||||
|
||||
entry.Amount--;
|
||||
UpdateVendingMachineInterfaceState(uid, vendComponent);
|
||||
Dirty(uid, vendComponent);
|
||||
TryUpdateVisualState(uid, vendComponent);
|
||||
Audio.PlayPvs(vendComponent.SoundVend, uid);
|
||||
}
|
||||
@@ -493,7 +471,7 @@ namespace Content.Server.VendingMachines
|
||||
|
||||
RestockInventoryFromPrototype(uid, vendComponent);
|
||||
|
||||
UpdateVendingMachineInterfaceState(uid, vendComponent);
|
||||
Dirty(uid, vendComponent);
|
||||
TryUpdateVisualState(uid, vendComponent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user