Predict vending machine BUI (#32376)
This commit is contained in:
@@ -23,29 +23,17 @@ namespace Content.Client.VendingMachines
|
|||||||
{
|
{
|
||||||
base.Open();
|
base.Open();
|
||||||
|
|
||||||
var vendingMachineSys = EntMan.System<VendingMachineSystem>();
|
|
||||||
|
|
||||||
_cachedInventory = vendingMachineSys.GetAllInventory(Owner);
|
|
||||||
|
|
||||||
_menu = this.CreateWindow<VendingMachineMenu>();
|
_menu = this.CreateWindow<VendingMachineMenu>();
|
||||||
_menu.OpenCenteredLeft();
|
_menu.OpenCenteredLeft();
|
||||||
_menu.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
|
_menu.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
|
||||||
|
|
||||||
_menu.OnItemSelected += OnItemSelected;
|
_menu.OnItemSelected += OnItemSelected;
|
||||||
|
Refresh();
|
||||||
_menu.Populate(_cachedInventory);
|
|
||||||
|
|
||||||
_menu.OpenCenteredLeft();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateState(BoundUserInterfaceState state)
|
public void Refresh()
|
||||||
{
|
{
|
||||||
base.UpdateState(state);
|
var system = EntMan.System<VendingMachineSystem>();
|
||||||
|
_cachedInventory = system.GetAllInventory(Owner);
|
||||||
if (state is not VendingMachineInterfaceState newState)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_cachedInventory = newState.Inventory;
|
|
||||||
|
|
||||||
_menu?.Populate(_cachedInventory);
|
_menu?.Populate(_cachedInventory);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public sealed class VendingMachineSystem : SharedVendingMachineSystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly AnimationPlayerSystem _animationPlayer = default!;
|
[Dependency] private readonly AnimationPlayerSystem _animationPlayer = default!;
|
||||||
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
||||||
|
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -15,6 +16,15 @@ public sealed class VendingMachineSystem : SharedVendingMachineSystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<VendingMachineComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
SubscribeLocalEvent<VendingMachineComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
||||||
SubscribeLocalEvent<VendingMachineComponent, AnimationCompletedEvent>(OnAnimationCompleted);
|
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)
|
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 IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
||||||
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
|
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
|
||||||
[Dependency] private readonly SharedActionsSystem _action = default!;
|
|
||||||
[Dependency] private readonly PricingSystem _pricing = default!;
|
[Dependency] private readonly PricingSystem _pricing = default!;
|
||||||
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
|
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
|
||||||
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
|
||||||
[Dependency] private readonly IGameTiming _timing = default!;
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
[Dependency] private readonly SpeakOnUIClosedSystem _speakOnUIClosed = default!;
|
[Dependency] private readonly SpeakOnUIClosedSystem _speakOnUIClosed = default!;
|
||||||
|
|
||||||
@@ -47,7 +45,6 @@ namespace Content.Server.VendingMachines
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<VendingMachineComponent, MapInitEvent>(OnComponentMapInit);
|
|
||||||
SubscribeLocalEvent<VendingMachineComponent, PowerChangedEvent>(OnPowerChanged);
|
SubscribeLocalEvent<VendingMachineComponent, PowerChangedEvent>(OnPowerChanged);
|
||||||
SubscribeLocalEvent<VendingMachineComponent, BreakageEventArgs>(OnBreak);
|
SubscribeLocalEvent<VendingMachineComponent, BreakageEventArgs>(OnBreak);
|
||||||
SubscribeLocalEvent<VendingMachineComponent, GotEmaggedEvent>(OnEmagged);
|
SubscribeLocalEvent<VendingMachineComponent, GotEmaggedEvent>(OnEmagged);
|
||||||
@@ -59,7 +56,6 @@ namespace Content.Server.VendingMachines
|
|||||||
|
|
||||||
Subs.BuiEvents<VendingMachineComponent>(VendingMachineUiKey.Key, subs =>
|
Subs.BuiEvents<VendingMachineComponent>(VendingMachineUiKey.Key, subs =>
|
||||||
{
|
{
|
||||||
subs.Event<BoundUIOpenedEvent>(OnBoundUIOpened);
|
|
||||||
subs.Event<VendingMachineEjectMessage>(OnInventoryEjectMessage);
|
subs.Event<VendingMachineEjectMessage>(OnInventoryEjectMessage);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -70,12 +66,6 @@ namespace Content.Server.VendingMachines
|
|||||||
SubscribeLocalEvent<VendingMachineRestockComponent, PriceCalculationEvent>(OnPriceCalculation);
|
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)
|
private void OnVendingPrice(EntityUid uid, VendingMachineComponent component, ref PriceCalculationEvent args)
|
||||||
{
|
{
|
||||||
var price = 0.0;
|
var price = 0.0;
|
||||||
@@ -94,9 +84,9 @@ namespace Content.Server.VendingMachines
|
|||||||
args.Price += price;
|
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))
|
if (HasComp<ApcPowerReceiverComponent>(uid))
|
||||||
{
|
{
|
||||||
@@ -110,18 +100,6 @@ namespace Content.Server.VendingMachines
|
|||||||
args.Cancel();
|
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)
|
private void OnInventoryEjectMessage(EntityUid uid, VendingMachineComponent component, VendingMachineEjectMessage args)
|
||||||
{
|
{
|
||||||
if (!this.IsPowered(uid, EntityManager))
|
if (!this.IsPowered(uid, EntityManager))
|
||||||
@@ -297,7 +275,7 @@ namespace Content.Server.VendingMachines
|
|||||||
_speakOnUIClosed.TrySetFlag((uid, speakComponent));
|
_speakOnUIClosed.TrySetFlag((uid, speakComponent));
|
||||||
|
|
||||||
entry.Amount--;
|
entry.Amount--;
|
||||||
UpdateVendingMachineInterfaceState(uid, vendComponent);
|
Dirty(uid, vendComponent);
|
||||||
TryUpdateVisualState(uid, vendComponent);
|
TryUpdateVisualState(uid, vendComponent);
|
||||||
Audio.PlayPvs(vendComponent.SoundVend, uid);
|
Audio.PlayPvs(vendComponent.SoundVend, uid);
|
||||||
}
|
}
|
||||||
@@ -493,7 +471,7 @@ namespace Content.Server.VendingMachines
|
|||||||
|
|
||||||
RestockInventoryFromPrototype(uid, vendComponent);
|
RestockInventoryFromPrototype(uid, vendComponent);
|
||||||
|
|
||||||
UpdateVendingMachineInterfaceState(uid, vendComponent);
|
Dirty(uid, vendComponent);
|
||||||
TryUpdateVisualState(uid, vendComponent);
|
TryUpdateVisualState(uid, vendComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<VendingMachineComponent, ComponentInit>(OnComponentInit);
|
SubscribeLocalEvent<VendingMachineComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<VendingMachineRestockComponent, AfterInteractEvent>(OnAfterInteract);
|
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);
|
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.StartingInventory, InventoryType.Regular, component, restockQuality);
|
||||||
AddInventoryFromPrototype(uid, packPrototype.EmaggedInventory, InventoryType.Emagged, component, restockQuality);
|
AddInventoryFromPrototype(uid, packPrototype.EmaggedInventory, InventoryType.Emagged, component, restockQuality);
|
||||||
AddInventoryFromPrototype(uid, packPrototype.ContrabandInventory, InventoryType.Contraband, component, restockQuality);
|
AddInventoryFromPrototype(uid, packPrototype.ContrabandInventory, InventoryType.Contraband, component, restockQuality);
|
||||||
|
Dirty(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
|
|||||||
|
|
||||||
namespace Content.Shared.VendingMachines
|
namespace Content.Shared.VendingMachines
|
||||||
{
|
{
|
||||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||||
public sealed partial class VendingMachineComponent : Component
|
public sealed partial class VendingMachineComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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 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.
|
/// Used by the client to determine how long the deny animation should be played.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("denyDelay")]
|
[DataField]
|
||||||
public float DenyDelay = 2.0f;
|
public float DenyDelay = 2.0f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -29,16 +29,16 @@ namespace Content.Shared.VendingMachines
|
|||||||
/// The selected item is dispensed afer this delay.
|
/// The selected item is dispensed afer this delay.
|
||||||
/// Used by the client to determine how long the deny animation should be played.
|
/// Used by the client to determine how long the deny animation should be played.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("ejectDelay")]
|
[DataField]
|
||||||
public float EjectDelay = 1.2f;
|
public float EjectDelay = 1.2f;
|
||||||
|
|
||||||
[ViewVariables]
|
[DataField, AutoNetworkedField]
|
||||||
public Dictionary<string, VendingMachineInventoryEntry> Inventory = new();
|
public Dictionary<string, VendingMachineInventoryEntry> Inventory = new();
|
||||||
|
|
||||||
[ViewVariables]
|
[DataField, AutoNetworkedField]
|
||||||
public Dictionary<string, VendingMachineInventoryEntry> EmaggedInventory = new();
|
public Dictionary<string, VendingMachineInventoryEntry> EmaggedInventory = new();
|
||||||
|
|
||||||
[ViewVariables]
|
[DataField, AutoNetworkedField]
|
||||||
public Dictionary<string, VendingMachineInventoryEntry> ContrabandInventory = new();
|
public Dictionary<string, VendingMachineInventoryEntry> ContrabandInventory = new();
|
||||||
|
|
||||||
public bool Contraband;
|
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
|
// 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");
|
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 NonLimitedEjectForce = 7.5f;
|
||||||
|
|
||||||
public float NonLimitedEjectRange = 5f;
|
public float NonLimitedEjectRange = 5f;
|
||||||
|
|||||||
@@ -2,17 +2,6 @@ using Robust.Shared.Serialization;
|
|||||||
|
|
||||||
namespace Content.Shared.VendingMachines
|
namespace Content.Shared.VendingMachines
|
||||||
{
|
{
|
||||||
[NetSerializable, Serializable]
|
|
||||||
public sealed class VendingMachineInterfaceState : BoundUserInterfaceState
|
|
||||||
{
|
|
||||||
public List<VendingMachineInventoryEntry> Inventory;
|
|
||||||
|
|
||||||
public VendingMachineInterfaceState(List<VendingMachineInventoryEntry> inventory)
|
|
||||||
{
|
|
||||||
Inventory = inventory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class VendingMachineEjectMessage : BoundUserInterfaceMessage
|
public sealed class VendingMachineEjectMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
description: Just add capitalism!
|
description: Just add capitalism!
|
||||||
abstract: true
|
abstract: true
|
||||||
components:
|
components:
|
||||||
|
- type: ActionGrant
|
||||||
|
actions:
|
||||||
|
- ActionVendingThrow
|
||||||
- type: StationAiWhitelist
|
- type: StationAiWhitelist
|
||||||
- type: AmbientOnPowered
|
- type: AmbientOnPowered
|
||||||
- type: AmbientSound
|
- type: AmbientSound
|
||||||
|
|||||||
Reference in New Issue
Block a user