2022-09-06 07:06:47 +02:00
|
|
|
using Content.Shared.Chemistry;
|
2022-03-28 17:03:03 +13:00
|
|
|
using Content.Shared.Containers.ItemSlots;
|
2020-07-17 15:41:19 -05:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.GameObjects;
|
2024-07-21 14:48:13 +10:00
|
|
|
using Robust.Client.UserInterface;
|
2020-07-17 15:41:19 -05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Chemistry.UI
|
2020-07-17 15:41:19 -05:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a <see cref="ChemMasterWindow"/> and updates it when new server messages are received.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ChemMasterBoundUserInterface : BoundUserInterface
|
2020-07-17 15:41:19 -05:00
|
|
|
{
|
2023-07-08 09:02:17 -07:00
|
|
|
[ViewVariables]
|
2020-07-17 15:41:19 -05:00
|
|
|
private ChemMasterWindow? _window;
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
public ChemMasterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
2020-07-17 15:41:19 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called each time a chem master UI instance is opened. Generates the window and fills it with
|
|
|
|
|
/// relevant info. Sets the actions for static buttons.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
|
|
|
|
|
2022-09-06 07:06:47 +02:00
|
|
|
// Setup window layout/elements
|
2024-07-21 14:48:13 +10:00
|
|
|
_window = this.CreateWindow<ChemMasterWindow>();
|
|
|
|
|
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
|
2020-07-17 15:41:19 -05:00
|
|
|
|
2022-09-06 07:06:47 +02:00
|
|
|
// Setup static button actions.
|
2022-09-14 17:10:12 -07:00
|
|
|
_window.InputEjectButton.OnPressed += _ => SendMessage(
|
|
|
|
|
new ItemSlotButtonPressedEvent(SharedChemMaster.InputSlotName));
|
|
|
|
|
_window.OutputEjectButton.OnPressed += _ => SendMessage(
|
|
|
|
|
new ItemSlotButtonPressedEvent(SharedChemMaster.OutputSlotName));
|
|
|
|
|
_window.BufferTransferButton.OnPressed += _ => SendMessage(
|
|
|
|
|
new ChemMasterSetModeMessage(ChemMasterMode.Transfer));
|
|
|
|
|
_window.BufferDiscardButton.OnPressed += _ => SendMessage(
|
|
|
|
|
new ChemMasterSetModeMessage(ChemMasterMode.Discard));
|
|
|
|
|
_window.CreatePillButton.OnPressed += _ => SendMessage(
|
|
|
|
|
new ChemMasterCreatePillsMessage(
|
2023-07-08 09:02:17 -07:00
|
|
|
(uint) _window.PillDosage.Value, (uint) _window.PillNumber.Value, _window.LabelLine));
|
2022-09-14 17:10:12 -07:00
|
|
|
_window.CreateBottleButton.OnPressed += _ => SendMessage(
|
2023-07-08 09:02:17 -07:00
|
|
|
new ChemMasterOutputToBottleMessage(
|
|
|
|
|
(uint) _window.BottleDosage.Value, _window.LabelLine));
|
2020-07-17 15:41:19 -05:00
|
|
|
|
2022-09-06 07:06:47 +02:00
|
|
|
for (uint i = 0; i < _window.PillTypeButtons.Length; i++)
|
2021-11-26 22:44:36 -08:00
|
|
|
{
|
2022-09-06 07:06:47 +02:00
|
|
|
var pillType = i;
|
|
|
|
|
_window.PillTypeButtons[i].OnPressed += _ => SendMessage(new ChemMasterSetPillTypeMessage(pillType));
|
2021-11-26 22:44:36 -08:00
|
|
|
}
|
|
|
|
|
|
2022-09-06 07:06:47 +02:00
|
|
|
_window.OnReagentButtonPressed += (args, button) => SendMessage(new ChemMasterReagentAmountButtonMessage(button.Id, button.Amount, button.IsBuffer));
|
2020-07-17 15:41:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update the ui each time new state data is sent from the server.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">
|
|
|
|
|
/// Data of the <see cref="SharedReagentDispenserComponent"/> that this ui represents.
|
|
|
|
|
/// Sent from the server.
|
|
|
|
|
/// </param>
|
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateState(state);
|
|
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
var castState = (ChemMasterBoundUserInterfaceState) state;
|
2020-07-17 15:41:19 -05:00
|
|
|
|
2022-09-06 07:06:47 +02:00
|
|
|
_window?.UpdateState(castState); // Update window state
|
2020-07-17 15:41:19 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|