Allow solutions to store extra reagent data (#19323)
This commit is contained in:
@@ -11,6 +11,7 @@ using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Shared.FixedPoint;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Chemistry.UI
|
||||
@@ -87,7 +88,7 @@ namespace Content.Client.Chemistry.UI
|
||||
Tabs.SetTabTitle(1, Loc.GetString("chem-master-window-output-tab"));
|
||||
}
|
||||
|
||||
private ReagentButton MakeReagentButton(string text, ChemMasterReagentAmount amount, string id, bool isBuffer, string styleClass)
|
||||
private ReagentButton MakeReagentButton(string text, ChemMasterReagentAmount amount, ReagentId id, bool isBuffer, string styleClass)
|
||||
{
|
||||
var button = new ReagentButton(text, amount, id, isBuffer, styleClass);
|
||||
button.OnPressed += args
|
||||
@@ -112,11 +113,11 @@ namespace Content.Client.Chemistry.UI
|
||||
|
||||
InputEjectButton.Disabled = castState.InputContainerInfo is null;
|
||||
OutputEjectButton.Disabled = output is null;
|
||||
CreateBottleButton.Disabled = output is null || !output.HoldsReagents;
|
||||
CreatePillButton.Disabled = output is null || output.HoldsReagents;
|
||||
CreateBottleButton.Disabled = output?.Reagents == null;
|
||||
CreatePillButton.Disabled = output?.Entities == null;
|
||||
|
||||
var remainingCapacity = output is null ? 0 : (output.MaxVolume - output.CurrentVolume).Int();
|
||||
var holdsReagents = output?.HoldsReagents ?? false;
|
||||
var holdsReagents = output?.Reagents != null;
|
||||
var pillNumberMax = holdsReagents ? 0 : remainingCapacity;
|
||||
var bottleAmountMax = holdsReagents ? remainingCapacity : 0;
|
||||
|
||||
@@ -139,13 +140,10 @@ namespace Content.Client.Chemistry.UI
|
||||
{
|
||||
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 ?? "";
|
||||
}
|
||||
|
||||
var reagent = state.BufferReagents.OrderBy(r => r.Quantity).First().Reagent;
|
||||
_prototypeManager.TryIndex(reagent.Prototype, out ReagentPrototype? proto);
|
||||
return proto?.LocalizedName ?? "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -184,10 +182,10 @@ namespace Content.Client.Chemistry.UI
|
||||
};
|
||||
bufferHBox.AddChild(bufferVol);
|
||||
|
||||
foreach (var reagent in state.BufferReagents)
|
||||
foreach (var (reagent, quantity) in state.BufferReagents)
|
||||
{
|
||||
// Try to get the prototype for the given reagent. This gives us its name.
|
||||
_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto);
|
||||
_prototypeManager.TryIndex(reagent.Prototype, out ReagentPrototype? proto);
|
||||
var name = proto?.LocalizedName ?? Loc.GetString("chem-master-window-unknown-reagent-text");
|
||||
|
||||
if (proto != null)
|
||||
@@ -200,20 +198,20 @@ namespace Content.Client.Chemistry.UI
|
||||
new Label {Text = $"{name}: "},
|
||||
new Label
|
||||
{
|
||||
Text = $"{reagent.Quantity}u",
|
||||
Text = $"{quantity}u",
|
||||
StyleClasses = {StyleNano.StyleClassLabelSecondaryColor}
|
||||
},
|
||||
|
||||
// Padding
|
||||
new Control {HorizontalExpand = true},
|
||||
|
||||
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("50", ChemMasterReagentAmount.U50, reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton("100", ChemMasterReagentAmount.U100, reagent.ReagentId, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton(Loc.GetString("chem-master-window-buffer-all-amount"), ChemMasterReagentAmount.All, reagent.ReagentId, true, StyleBase.ButtonOpenLeft),
|
||||
MakeReagentButton("1", ChemMasterReagentAmount.U1, reagent, true, StyleBase.ButtonOpenRight),
|
||||
MakeReagentButton("5", ChemMasterReagentAmount.U5, reagent, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton("10", ChemMasterReagentAmount.U10, reagent, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton("25", ChemMasterReagentAmount.U25, reagent, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton("50", ChemMasterReagentAmount.U50, reagent, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton("100", ChemMasterReagentAmount.U100, reagent, true, StyleBase.ButtonOpenBoth),
|
||||
MakeReagentButton(Loc.GetString("chem-master-window-buffer-all-amount"), ChemMasterReagentAmount.All, reagent, true, StyleBase.ButtonOpenLeft),
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -248,20 +246,29 @@ namespace Content.Client.Chemistry.UI
|
||||
}
|
||||
});
|
||||
|
||||
var contents = info.Contents
|
||||
.Select(lineItem =>
|
||||
{
|
||||
if (!info.HoldsReagents)
|
||||
return (lineItem.Id, lineItem.Id, lineItem.Quantity);
|
||||
IEnumerable<(string Name, ReagentId Id, FixedPoint2 Quantity)> contents;
|
||||
|
||||
// Try to get the prototype for the given reagent. This gives us its name.
|
||||
_prototypeManager.TryIndex(lineItem.Id, out ReagentPrototype? proto);
|
||||
var name = proto?.LocalizedName
|
||||
?? Loc.GetString("chem-master-window-unknown-reagent-text");
|
||||
if (info.Entities != null)
|
||||
{
|
||||
contents = info.Entities.Select(x => (x.Id, default(ReagentId), x.Quantity));
|
||||
}
|
||||
else if (info.Reagents != null)
|
||||
{
|
||||
contents = info.Reagents.Select(x =>
|
||||
{
|
||||
_prototypeManager.TryIndex(x.Reagent.Prototype, out ReagentPrototype? proto);
|
||||
var name = proto?.LocalizedName
|
||||
?? Loc.GetString("chem-master-window-unknown-reagent-text");
|
||||
|
||||
return (name, Id: x.Reagent, x.Quantity);
|
||||
})
|
||||
.OrderBy(r => r.Item1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return (name, lineItem.Id, lineItem.Quantity);
|
||||
})
|
||||
.OrderBy(r => r.Item1);
|
||||
|
||||
foreach (var (name, id, quantity) in contents)
|
||||
{
|
||||
@@ -326,8 +333,8 @@ namespace Content.Client.Chemistry.UI
|
||||
{
|
||||
public ChemMasterReagentAmount Amount { get; set; }
|
||||
public bool IsBuffer = true;
|
||||
public string Id { get; set; }
|
||||
public ReagentButton(string text, ChemMasterReagentAmount amount, string id, bool isBuffer, string styleClass)
|
||||
public ReagentId Id { get; set; }
|
||||
public ReagentButton(string text, ChemMasterReagentAmount amount, ReagentId id, bool isBuffer, string styleClass)
|
||||
{
|
||||
AddStyleClass(styleClass);
|
||||
Text = text;
|
||||
|
||||
@@ -48,17 +48,17 @@ namespace Content.Client.Chemistry.UI
|
||||
/// Update the button grid of reagents which can be dispensed.
|
||||
/// </summary>
|
||||
/// <param name="inventory">Reagents which can be dispensed by this dispenser</param>
|
||||
public void UpdateReagentsList(List<string> inventory)
|
||||
public void UpdateReagentsList(List<ReagentId> inventory)
|
||||
{
|
||||
if (ChemicalList == null) return;
|
||||
if (inventory == null) return;
|
||||
if (ChemicalList == null)
|
||||
return;
|
||||
|
||||
ChemicalList.Children.Clear();
|
||||
|
||||
foreach (var entry in inventory
|
||||
.OrderBy(r => {_prototypeManager.TryIndex(r, out ReagentPrototype? p); return p?.LocalizedName;}))
|
||||
.OrderBy(r => {_prototypeManager.TryIndex(r.Prototype, out ReagentPrototype? p); return p?.LocalizedName;}))
|
||||
{
|
||||
var localizedName = _prototypeManager.TryIndex(entry, out ReagentPrototype? p)
|
||||
var localizedName = _prototypeManager.TryIndex(entry.Prototype, out ReagentPrototype? p)
|
||||
? p.LocalizedName
|
||||
: Loc.GetString("reagent-dispenser-window-reagent-name-not-found-text");
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Content.Client.Chemistry.UI
|
||||
/// <param name="state">State data for the dispenser.</param>
|
||||
/// <param name="highlightedReagentId">Prototype ID of the reagent whose dispense button is currently being mouse hovered,
|
||||
/// or null if no button is being hovered.</param>
|
||||
public void UpdateContainerInfo(ReagentDispenserBoundUserInterfaceState state, string? highlightedReagentId = null)
|
||||
public void UpdateContainerInfo(ReagentDispenserBoundUserInterfaceState state, ReagentId? highlightedReagentId = null)
|
||||
{
|
||||
ContainerInfo.Children.Clear();
|
||||
|
||||
@@ -147,22 +147,22 @@ namespace Content.Client.Chemistry.UI
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var reagent in state.OutputContainer.Contents)
|
||||
foreach (var (reagent, quantity) in state.OutputContainer.Reagents!)
|
||||
{
|
||||
// Try get to the prototype for the given reagent. This gives us its name.
|
||||
var localizedName = _prototypeManager.TryIndex(reagent.Id, out ReagentPrototype? p)
|
||||
var localizedName = _prototypeManager.TryIndex(reagent.Prototype, out ReagentPrototype? p)
|
||||
? p.LocalizedName
|
||||
: Loc.GetString("reagent-dispenser-window-reagent-name-not-found-text");
|
||||
|
||||
var nameLabel = new Label {Text = $"{localizedName}: "};
|
||||
var quantityLabel = new Label
|
||||
{
|
||||
Text = Loc.GetString("reagent-dispenser-window-quantity-label-text", ("quantity", reagent.Quantity)),
|
||||
Text = Loc.GetString("reagent-dispenser-window-quantity-label-text", ("quantity", quantity)),
|
||||
StyleClasses = {StyleNano.StyleClassLabelSecondaryColor},
|
||||
};
|
||||
|
||||
// Check if the reagent is being moused over. If so, color it green.
|
||||
if (reagent.Id == highlightedReagentId) {
|
||||
if (reagent == highlightedReagentId) {
|
||||
nameLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateGood);
|
||||
quantityLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateGood);
|
||||
}
|
||||
@@ -181,9 +181,9 @@ namespace Content.Client.Chemistry.UI
|
||||
}
|
||||
|
||||
public sealed class DispenseReagentButton : Button {
|
||||
public string ReagentId { get; }
|
||||
public ReagentId ReagentId { get; }
|
||||
|
||||
public DispenseReagentButton(string reagentId, string text)
|
||||
public DispenseReagentButton(ReagentId reagentId, string text)
|
||||
{
|
||||
ReagentId = reagentId;
|
||||
Text = text;
|
||||
|
||||
Reference in New Issue
Block a user