This simplifies the code and makes the experience of examining contents easier without the reagent dispenser UI, as well as adding the possibility for dispensers to have items of heterogeneous sizes in them, which would allow configuring reagent dispensers to accept smaller containers such as beakers or vials in order to allow for more types of smaller quantities of reagents, or other flexibilities brought by using a standard storage component.
63 lines
2.6 KiB
C#
63 lines
2.6 KiB
C#
using Content.Client.Guidebook.Components;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.Chemistry;
|
|
using Content.Shared.Containers.ItemSlots;
|
|
using JetBrains.Annotations;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.UserInterface;
|
|
|
|
namespace Content.Client.Chemistry.UI
|
|
{
|
|
/// <summary>
|
|
/// Initializes a <see cref="ReagentDispenserWindow"/> and updates it when new server messages are received.
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
public sealed class ReagentDispenserBoundUserInterface : BoundUserInterface
|
|
{
|
|
[ViewVariables]
|
|
private ReagentDispenserWindow? _window;
|
|
|
|
public ReagentDispenserBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called each time a dispenser UI instance is opened. Generates the dispenser window and fills it with
|
|
/// relevant info. Sets the actions for static buttons.
|
|
/// <para>Buttons which can change like reagent dispense buttons have their actions set in <see cref="UpdateReagentsList"/>.</para>
|
|
/// </summary>
|
|
protected override void Open()
|
|
{
|
|
base.Open();
|
|
|
|
// Setup window layout/elements
|
|
_window = this.CreateWindow<ReagentDispenserWindow>();
|
|
_window.SetInfoFromEntity(EntMan, Owner);
|
|
|
|
// Setup static button actions.
|
|
_window.EjectButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(SharedReagentDispenser.OutputSlotName));
|
|
_window.ClearButton.OnPressed += _ => SendMessage(new ReagentDispenserClearContainerSolutionMessage());
|
|
|
|
_window.AmountGrid.OnButtonPressed += s => SendMessage(new ReagentDispenserSetDispenseAmountMessage(s));
|
|
|
|
_window.OnDispenseReagentButtonPressed += (location) => SendMessage(new ReagentDispenserDispenseReagentMessage(location));
|
|
_window.OnEjectJugButtonPressed += (location) => SendMessage(new ReagentDispenserEjectContainerMessage(location));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update the UI each time new state data is sent from the server.
|
|
/// </summary>
|
|
/// <param name="state">
|
|
/// Data of the <see cref="ReagentDispenserComponent"/> that this UI represents.
|
|
/// Sent from the server.
|
|
/// </param>
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
{
|
|
base.UpdateState(state);
|
|
|
|
var castState = (ReagentDispenserBoundUserInterfaceState) state;
|
|
_window?.UpdateState(castState); //Update window state
|
|
}
|
|
}
|
|
}
|