ChemMaster ECS (#11052)
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
using JetBrains.Annotations;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
|
||||
namespace Content.Client.Chemistry.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class ChemMasterSystem : SharedChemMasterSystem
|
||||
{
|
||||
// gotta love empty client side systems that exist purely because theres one specific thing that can only be
|
||||
// done server-side which prevents the whole system from being in shared.
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Dispenser;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using static Content.Shared.Chemistry.Components.SharedChemMasterComponent;
|
||||
|
||||
namespace Content.Client.Chemistry.UI
|
||||
{
|
||||
@@ -27,7 +27,7 @@ namespace Content.Client.Chemistry.UI
|
||||
{
|
||||
base.Open();
|
||||
|
||||
//Setup window layout/elements
|
||||
// Setup window layout/elements
|
||||
_window = new ChemMasterWindow
|
||||
{
|
||||
Title = Loc.GetString("chem-master-bound-user-interface-title"),
|
||||
@@ -36,20 +36,20 @@ namespace Content.Client.Chemistry.UI
|
||||
_window.OpenCentered();
|
||||
_window.OnClose += Close;
|
||||
|
||||
//Setup static button actions.
|
||||
_window.EjectButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(BeakerSlotId));
|
||||
_window.BufferTransferButton.OnPressed += _ => PrepareData(UiAction.Transfer, null, null, null, null, null);
|
||||
_window.BufferDiscardButton.OnPressed += _ => PrepareData(UiAction.Discard, null, null, null, null, null);
|
||||
_window.CreatePillButton.OnPressed += _ => PrepareData(UiAction.CreatePills, null, _window.LabelLine, null, _window.PillAmount.Value, null);
|
||||
_window.CreateBottleButton.OnPressed += _ => PrepareData(UiAction.CreateBottles, null, _window.LabelLine, null, null, _window.BottleAmount.Value);
|
||||
// Setup static button actions.
|
||||
_window.EjectButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(SharedChemMaster.ContainerSlotName));
|
||||
_window.BufferTransferButton.OnPressed += _ => SendMessage(new ChemMasterSetModeMessage(ChemMasterMode.Transfer));
|
||||
_window.BufferDiscardButton.OnPressed += _ => SendMessage(new ChemMasterSetModeMessage(ChemMasterMode.Discard));
|
||||
_window.CreatePillButton.OnPressed += _ => SendMessage(new ChemMasterCreatePillsMessage(((uint)_window.PillAmount.Value), _window.LabelLine));
|
||||
_window.CreateBottleButton.OnPressed += _ => SendMessage(new ChemMasterCreateBottlesMessage(((uint)_window.BottleAmount.Value), _window.LabelLine));
|
||||
|
||||
for(uint i = 0; i < _window.PillTypeButtons.Length; i++)
|
||||
for (uint i = 0; i < _window.PillTypeButtons.Length; i++)
|
||||
{
|
||||
uint type = i;
|
||||
_window.PillTypeButtons[i].OnPressed += _ => PrepareData(UiAction.SetPillType, null, null, type + 1, null, null);
|
||||
var pillType = i;
|
||||
_window.PillTypeButtons[i].OnPressed += _ => SendMessage(new ChemMasterSetPillTypeMessage(pillType));
|
||||
}
|
||||
|
||||
_window.OnChemButtonPressed += (args, button) => PrepareData(UiAction.ChemButton, button, null, null, null, null);
|
||||
_window.OnReagentButtonPressed += (args, button) => SendMessage(new ChemMasterReagentAmountButtonMessage(button.Id, button.Amount, button.IsBuffer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,19 +65,7 @@ namespace Content.Client.Chemistry.UI
|
||||
|
||||
var castState = (ChemMasterBoundUserInterfaceState) state;
|
||||
|
||||
_window?.UpdateState(castState); //Update window state
|
||||
}
|
||||
|
||||
private void PrepareData(UiAction action, ChemButton? button, string? label, uint? pillType, int? pillAmount, int? bottleAmount)
|
||||
{
|
||||
if (button != null)
|
||||
{
|
||||
SendMessage(new UiActionMessage(action, button.Amount, button.Id, button.IsBuffer, null, null, null, null));
|
||||
}
|
||||
else
|
||||
{
|
||||
SendMessage(new UiActionMessage(action, null, null, null, label, pillType, pillAmount, bottleAmount));
|
||||
}
|
||||
_window?.UpdateState(castState); // Update window state
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using static Content.Shared.Chemistry.Components.SharedChemMasterComponent;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Chemistry.UI
|
||||
@@ -29,17 +21,11 @@ namespace Content.Client.Chemistry.UI
|
||||
public sealed partial class ChemMasterWindow : DefaultWindow
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
public event Action<string>? OnLabelEntered;
|
||||
public event Action<BaseButton.ButtonEventArgs, ChemButton>? OnChemButtonPressed;
|
||||
public event Action<BaseButton.ButtonEventArgs, ReagentButton>? OnReagentButtonPressed;
|
||||
public readonly Button[] PillTypeButtons;
|
||||
|
||||
private const string PillsRsiPath = "/Textures/Objects/Specific/Chemistry/pills.rsi";
|
||||
|
||||
private static bool IsSpinValid(int n)
|
||||
{
|
||||
return n is > 0 and <= MaxEntitySpawns;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create and initialize the chem master UI client-side. Creates the basic layout,
|
||||
/// actual data isn't filled in until the server sends data about the chem master.
|
||||
@@ -48,17 +34,16 @@ namespace Content.Client.Chemistry.UI
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
LabelLineEdit.OnTextEntered += e => OnLabelEntered?.Invoke(e.Text);
|
||||
|
||||
//Pill type selection buttons, in total there are 20 pills.
|
||||
//Pill rsi file should have states named as pill1, pill2, and so on.
|
||||
// Pill type selection buttons, in total there are 20 pills.
|
||||
// Pill rsi file should have states named as pill1, pill2, and so on.
|
||||
var resourcePath = new ResourcePath(PillsRsiPath);
|
||||
var pillTypeGroup = new ButtonGroup();
|
||||
PillTypeButtons = new Button[20];
|
||||
for (uint i = 0; i < PillTypeButtons.Length; i++)
|
||||
{
|
||||
//For every button decide which stylebase to have
|
||||
//Every row has 10 buttons
|
||||
// For every button decide which stylebase to have
|
||||
// Every row has 10 buttons
|
||||
String styleBase = StyleBase.ButtonOpenBoth;
|
||||
uint modulo = i % 10;
|
||||
if (i > 0 && modulo == 0)
|
||||
@@ -68,7 +53,7 @@ namespace Content.Client.Chemistry.UI
|
||||
else if (i == 0)
|
||||
styleBase = StyleBase.ButtonOpenRight;
|
||||
|
||||
//Generate buttons
|
||||
// Generate buttons
|
||||
PillTypeButtons[i] = new Button
|
||||
{
|
||||
Access = AccessLevel.Public,
|
||||
@@ -77,7 +62,7 @@ namespace Content.Client.Chemistry.UI
|
||||
Group = pillTypeGroup
|
||||
};
|
||||
|
||||
//Generate buttons textures
|
||||
// Generate buttons textures
|
||||
var specifier = new SpriteSpecifier.Rsi(resourcePath, "pill" + (i + 1));
|
||||
TextureRect pillTypeTexture = new TextureRect
|
||||
{
|
||||
@@ -90,17 +75,15 @@ namespace Content.Client.Chemistry.UI
|
||||
Grid.AddChild(PillTypeButtons[i]);
|
||||
}
|
||||
|
||||
PillAmount.IsValid = IsSpinValid;
|
||||
BottleAmount.IsValid = IsSpinValid;
|
||||
PillAmount.InitDefaultButtons();
|
||||
BottleAmount.InitDefaultButtons();
|
||||
}
|
||||
|
||||
private ChemButton MakeChemButton(string text, FixedPoint2 amount, string id, bool isBuffer, string styleClass)
|
||||
private ReagentButton MakeReagentButton(string text, ChemMasterReagentAmount amount, string id, bool isBuffer, string styleClass)
|
||||
{
|
||||
var button = new ChemButton(text, amount, id, isBuffer, styleClass);
|
||||
var button = new ReagentButton(text, amount, id, isBuffer, styleClass);
|
||||
button.OnPressed += args
|
||||
=> OnChemButtonPressed?.Invoke(args, button);
|
||||
=> OnReagentButtonPressed?.Invoke(args, button);
|
||||
return button;
|
||||
}
|
||||
|
||||
@@ -112,15 +95,34 @@ namespace Content.Client.Chemistry.UI
|
||||
{
|
||||
var castState = (ChemMasterBoundUserInterfaceState) state;
|
||||
Title = castState.DispenserName;
|
||||
LabelLine = castState.Label;
|
||||
if (castState.UpdateLabel)
|
||||
LabelLine = GenerateLabel(castState);
|
||||
UpdatePanelInfo(castState);
|
||||
if (Contents.Children != null)
|
||||
{
|
||||
ButtonHelpers.SetButtonDisabledRecursive(Contents, !castState.HasPower);
|
||||
EjectButton.Disabled = !castState.HasBeaker;
|
||||
EjectButton.Disabled = !castState.HasContainer();
|
||||
}
|
||||
|
||||
PillTypeButtons[castState.SelectedPillType].Pressed = true;
|
||||
PillAmount.IsValid = x => x > 0 && x <= castState.PillProductionLimit;
|
||||
BottleAmount.IsValid = x => x > 0 && x <= castState.BottleProductionLimit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a product label based on reagents in the buffer.
|
||||
/// </summary>
|
||||
/// <param name="state">State data sent by the server.</param>
|
||||
private string GenerateLabel(ChemMasterBoundUserInterfaceState state)
|
||||
{
|
||||
if (state.BufferCurrentVolume == 0)
|
||||
return "";
|
||||
else
|
||||
{
|
||||
var reagent = state.BufferReagents.OrderBy(r => r.Quantity).First();
|
||||
_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto);
|
||||
return proto?.LocalizedName ?? "";
|
||||
}
|
||||
|
||||
PillTypeButtons[castState.SelectedPillType - 1].Pressed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,13 +131,12 @@ namespace Content.Client.Chemistry.UI
|
||||
/// <param name="state">State data for the dispenser.</param>
|
||||
private void UpdatePanelInfo(ChemMasterBoundUserInterfaceState state)
|
||||
{
|
||||
var bufferModeTransfer = state.BufferModeTransfer;
|
||||
BufferTransferButton.Pressed = bufferModeTransfer;
|
||||
BufferDiscardButton.Pressed = !bufferModeTransfer;
|
||||
BufferTransferButton.Pressed = state.Mode == Shared.Chemistry.ChemMasterMode.Transfer;
|
||||
BufferDiscardButton.Pressed = state.Mode == Shared.Chemistry.ChemMasterMode.Discard;
|
||||
|
||||
ContainerInfo.Children.Clear();
|
||||
|
||||
if (!state.HasBeaker)
|
||||
if (!state.HasContainer())
|
||||
{
|
||||
ContainerInfo.Children.Add(new Label {Text = Loc.GetString("chem-master-window-no-container-loaded-text") });
|
||||
}
|
||||
@@ -149,49 +150,49 @@ namespace Content.Client.Chemistry.UI
|
||||
new Label {Text = $"{state.ContainerName}: "},
|
||||
new Label
|
||||
{
|
||||
Text = $"{state.BeakerCurrentVolume}/{state.BeakerMaxVolume}",
|
||||
Text = $"{state.ContainerCurrentVolume}/{state.ContainerMaxVolume}",
|
||||
StyleClasses = {StyleNano.StyleClassLabelSecondaryColor}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var reagent in state.ContainerReagents)
|
||||
{
|
||||
var name = Loc.GetString("chem-master-window-unknown-reagent-text");
|
||||
//Try to the prototype for the given reagent. This gives us it's name.
|
||||
if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto))
|
||||
foreach (var reagent in state.ContainerReagents!.OrderBy(
|
||||
r => {_prototypeManager.TryIndex(r.ReagentId, out ReagentPrototype? p); return p?.LocalizedName;}))
|
||||
{
|
||||
name = proto.LocalizedName;
|
||||
}
|
||||
// Try to get the prototype for the given reagent. This gives us its name.
|
||||
_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto);
|
||||
var name = proto?.LocalizedName ?? Loc.GetString("chem-master-window-unknown-reagent-text");
|
||||
|
||||
if (proto != null)
|
||||
{
|
||||
ContainerInfo.Children.Add(new BoxContainer
|
||||
if (proto != null)
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
ContainerInfo.Children.Add(new BoxContainer
|
||||
{
|
||||
new Label {Text = $"{name}: "},
|
||||
new Label
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
Text = $"{reagent.Quantity}u",
|
||||
StyleClasses = {StyleNano.StyleClassLabelSecondaryColor}
|
||||
},
|
||||
new Label {Text = $"{name}: "},
|
||||
new Label
|
||||
{
|
||||
Text = $"{reagent.Quantity}u",
|
||||
StyleClasses = {StyleNano.StyleClassLabelSecondaryColor}
|
||||
},
|
||||
|
||||
//Padding
|
||||
new Control {HorizontalExpand = true},
|
||||
// Padding
|
||||
new Control {HorizontalExpand = true},
|
||||
|
||||
MakeChemButton("1", FixedPoint2.New(1), reagent.ReagentId, false, StyleBase.ButtonOpenRight),
|
||||
MakeChemButton("5", FixedPoint2.New(5), reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("10", FixedPoint2.New(10), reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("25", FixedPoint2.New(25), reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), FixedPoint2.New(-1), reagent.ReagentId, false, StyleBase.ButtonOpenLeft),
|
||||
}
|
||||
});
|
||||
MakeReagentButton("1", ChemMasterReagentAmount.U1, reagent.ReagentId, false, StyleBase.ButtonOpenRight),
|
||||
MakeReagentButton("5", ChemMasterReagentAmount.U5, reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton("10", ChemMasterReagentAmount.U10, reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton("25", ChemMasterReagentAmount.U25, reagent.ReagentId, false, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton(Loc.GetString("chem-master-window-buffer-all-amount"), ChemMasterReagentAmount.All, reagent.ReagentId, false, StyleBase.ButtonOpenLeft),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
BufferInfo.Children.Clear();
|
||||
|
||||
if (!state.BufferReagents.Any())
|
||||
@@ -218,19 +219,15 @@ namespace Content.Client.Chemistry.UI
|
||||
|
||||
foreach (var reagent in state.BufferReagents)
|
||||
{
|
||||
var name = Loc.GetString("chem-master-window-unknown-reagent-text");
|
||||
//Try to the prototype for the given reagent. This gives us it's name.
|
||||
if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto))
|
||||
{
|
||||
name = proto.LocalizedName;
|
||||
}
|
||||
// Try to get the prototype for the given reagent. This gives us its name.
|
||||
_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto);
|
||||
var name = proto?.LocalizedName ?? Loc.GetString("chem-master-window-unknown-reagent-text");
|
||||
|
||||
if (proto != null)
|
||||
{
|
||||
BufferInfo.Children.Add(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
//SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
|
||||
Children =
|
||||
{
|
||||
new Label {Text = $"{name}: "},
|
||||
@@ -240,14 +237,14 @@ namespace Content.Client.Chemistry.UI
|
||||
StyleClasses = {StyleNano.StyleClassLabelSecondaryColor}
|
||||
},
|
||||
|
||||
//Padding
|
||||
// Padding
|
||||
new Control {HorizontalExpand = true},
|
||||
|
||||
MakeChemButton("1", FixedPoint2.New(1), reagent.ReagentId, true, StyleBase.ButtonOpenRight),
|
||||
MakeChemButton("5", FixedPoint2.New(5), reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("10", FixedPoint2.New(10), reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton("25", FixedPoint2.New(25), reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeChemButton(Loc.GetString("chem-master-window-buffer-all-amount"), FixedPoint2.New(-1), reagent.ReagentId, true, StyleBase.ButtonOpenLeft),
|
||||
MakeReagentButton("1", ChemMasterReagentAmount.U1, reagent.ReagentId, true, StyleBase.ButtonOpenRight),
|
||||
MakeReagentButton("5", ChemMasterReagentAmount.U5, reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton("10", ChemMasterReagentAmount.U10, reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton("25", ChemMasterReagentAmount.U25, reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton(Loc.GetString("chem-master-window-buffer-all-amount"), ChemMasterReagentAmount.All, reagent.ReagentId, true, StyleBase.ButtonOpenLeft),
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -267,12 +264,12 @@ namespace Content.Client.Chemistry.UI
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ChemButton : Button
|
||||
public sealed class ReagentButton : Button
|
||||
{
|
||||
public FixedPoint2 Amount { get; set; }
|
||||
public ChemMasterReagentAmount Amount { get; set; }
|
||||
public bool IsBuffer = true;
|
||||
public string Id { get; set; }
|
||||
public ChemButton(string text, FixedPoint2 amount, string id, bool isBuffer, string styleClass)
|
||||
public ReagentButton(string text, ChemMasterReagentAmount amount, string id, bool isBuffer, string styleClass)
|
||||
{
|
||||
AddStyleClass(styleClass);
|
||||
Text = text;
|
||||
|
||||
@@ -66,7 +66,6 @@ namespace Content.Client.Entry
|
||||
factory.RegisterClass<SharedLatheComponent>();
|
||||
factory.RegisterClass<SharedSpawnPointComponent>();
|
||||
factory.RegisterClass<SharedReagentDispenserComponent>();
|
||||
factory.RegisterClass<SharedChemMasterComponent>();
|
||||
factory.RegisterClass<SharedGravityGeneratorComponent>();
|
||||
factory.RegisterClass<SharedAMEControllerComponent>();
|
||||
// Do not add to the above, they are legacy
|
||||
|
||||
Reference in New Issue
Block a user