Predict vending machine BUI (#32376)
This commit is contained in:
@@ -23,29 +23,17 @@ namespace Content.Client.VendingMachines
|
||||
{
|
||||
base.Open();
|
||||
|
||||
var vendingMachineSys = EntMan.System<VendingMachineSystem>();
|
||||
|
||||
_cachedInventory = vendingMachineSys.GetAllInventory(Owner);
|
||||
|
||||
_menu = this.CreateWindow<VendingMachineMenu>();
|
||||
_menu.OpenCenteredLeft();
|
||||
_menu.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
|
||||
|
||||
_menu.OnItemSelected += OnItemSelected;
|
||||
|
||||
_menu.Populate(_cachedInventory);
|
||||
|
||||
_menu.OpenCenteredLeft();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
public void Refresh()
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (state is not VendingMachineInterfaceState newState)
|
||||
return;
|
||||
|
||||
_cachedInventory = newState.Inventory;
|
||||
var system = EntMan.System<VendingMachineSystem>();
|
||||
_cachedInventory = system.GetAllInventory(Owner);
|
||||
|
||||
_menu?.Populate(_cachedInventory);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ public sealed class VendingMachineSystem : SharedVendingMachineSystem
|
||||
{
|
||||
[Dependency] private readonly AnimationPlayerSystem _animationPlayer = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
||||
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -15,6 +16,15 @@ public sealed class VendingMachineSystem : SharedVendingMachineSystem
|
||||
|
||||
SubscribeLocalEvent<VendingMachineComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
||||
SubscribeLocalEvent<VendingMachineComponent, AnimationCompletedEvent>(OnAnimationCompleted);
|
||||
SubscribeLocalEvent<VendingMachineComponent, AfterAutoHandleStateEvent>(OnVendingAfterState);
|
||||
}
|
||||
|
||||
private void OnVendingAfterState(EntityUid uid, VendingMachineComponent component, ref AfterAutoHandleStateEvent args)
|
||||
{
|
||||
if (_uiSystem.TryGetOpenUi<VendingMachineBoundUserInterface>(uid, VendingMachineUiKey.Key, out var bui))
|
||||
{
|
||||
bui.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnimationCompleted(EntityUid uid, VendingMachineComponent component, AnimationCompletedEvent args)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<VendingMachineComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<VendingMachineComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<VendingMachineRestockComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
}
|
||||
|
||||
protected virtual void OnComponentInit(EntityUid uid, VendingMachineComponent component, ComponentInit args)
|
||||
protected virtual void OnMapInit(EntityUid uid, VendingMachineComponent component, MapInitEvent args)
|
||||
{
|
||||
RestockInventoryFromPrototype(uid, component, component.InitialStockQuality);
|
||||
}
|
||||
@@ -46,6 +46,7 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
|
||||
AddInventoryFromPrototype(uid, packPrototype.StartingInventory, InventoryType.Regular, component, restockQuality);
|
||||
AddInventoryFromPrototype(uid, packPrototype.EmaggedInventory, InventoryType.Emagged, component, restockQuality);
|
||||
AddInventoryFromPrototype(uid, packPrototype.ContrabandInventory, InventoryType.Contraband, component, restockQuality);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,7 +8,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
|
||||
|
||||
namespace Content.Shared.VendingMachines
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
public sealed partial class VendingMachineComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
@@ -21,7 +21,7 @@ namespace Content.Shared.VendingMachines
|
||||
/// Used by the server to determine how long the vending machine stays in the "Deny" state.
|
||||
/// Used by the client to determine how long the deny animation should be played.
|
||||
/// </summary>
|
||||
[DataField("denyDelay")]
|
||||
[DataField]
|
||||
public float DenyDelay = 2.0f;
|
||||
|
||||
/// <summary>
|
||||
@@ -29,16 +29,16 @@ namespace Content.Shared.VendingMachines
|
||||
/// The selected item is dispensed afer this delay.
|
||||
/// Used by the client to determine how long the deny animation should be played.
|
||||
/// </summary>
|
||||
[DataField("ejectDelay")]
|
||||
[DataField]
|
||||
public float EjectDelay = 1.2f;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField, AutoNetworkedField]
|
||||
public Dictionary<string, VendingMachineInventoryEntry> Inventory = new();
|
||||
|
||||
[ViewVariables]
|
||||
[DataField, AutoNetworkedField]
|
||||
public Dictionary<string, VendingMachineInventoryEntry> EmaggedInventory = new();
|
||||
|
||||
[ViewVariables]
|
||||
[DataField, AutoNetworkedField]
|
||||
public Dictionary<string, VendingMachineInventoryEntry> ContrabandInventory = new();
|
||||
|
||||
public bool Contraband;
|
||||
@@ -102,17 +102,6 @@ namespace Content.Shared.VendingMachines
|
||||
// Yoinked from: https://github.com/discordia-space/CEV-Eris/blob/35bbad6764b14e15c03a816e3e89aa1751660ba9/sound/machines/Custom_deny.ogg
|
||||
public SoundSpecifier SoundDeny = new SoundPathSpecifier("/Audio/Machines/custom_deny.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// The action available to the player controlling the vending machine
|
||||
/// </summary>
|
||||
[DataField("action", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
[AutoNetworkedField]
|
||||
public string? Action = "ActionVendingThrow";
|
||||
|
||||
[DataField("actionEntity")]
|
||||
[AutoNetworkedField]
|
||||
public EntityUid? ActionEntity;
|
||||
|
||||
public float NonLimitedEjectForce = 7.5f;
|
||||
|
||||
public float NonLimitedEjectRange = 5f;
|
||||
|
||||
@@ -2,17 +2,6 @@ using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.VendingMachines
|
||||
{
|
||||
[NetSerializable, Serializable]
|
||||
public sealed class VendingMachineInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public List<VendingMachineInventoryEntry> Inventory;
|
||||
|
||||
public VendingMachineInterfaceState(List<VendingMachineInventoryEntry> inventory)
|
||||
{
|
||||
Inventory = inventory;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class VendingMachineEjectMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
description: Just add capitalism!
|
||||
abstract: true
|
||||
components:
|
||||
- type: ActionGrant
|
||||
actions:
|
||||
- ActionVendingThrow
|
||||
- type: StationAiWhitelist
|
||||
- type: AmbientOnPowered
|
||||
- type: AmbientSound
|
||||
|
||||
Reference in New Issue
Block a user