Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Chemmaster 4000 now has a separate buffer for creating tablets #32

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Content.Client/Chemistry/UI/ChemMasterBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ protected override void Open()
new ItemSlotButtonPressedEvent(SharedChemMaster.InputSlotName));
_window.OutputEjectButton.OnPressed += _ => SendMessage(
new ItemSlotButtonPressedEvent(SharedChemMaster.OutputSlotName));
_window.BufferTransferButton.OnPressed += _ => SendMessage(
new ChemMasterSetModeMessage(ChemMasterMode.Transfer));
_window.BufferStorageButton.OnPressed += _ => SendMessage(
new ChemMasterSetModeMessage(ChemMasterMode.Storage));
_window.BufferOutputButton.OnPressed += _ => SendMessage(
new ChemMasterSetModeMessage(ChemMasterMode.Output));
_window.BufferDiscardButton.OnPressed += _ => SendMessage(
new ChemMasterSetModeMessage(ChemMasterMode.Discard));
_window.OutputBufferDiscardButton.OnPressed += _ => SendMessage(
new ChemMasterDiscardBufferMessage(SharedChemMaster.OutputBufferSolutionName));
_window.CreatePillButton.OnPressed += _ => SendMessage(
new ChemMasterCreatePillsMessage(
(uint) _window.PillDosage.Value, (uint) _window.PillNumber.Value, _window.LabelLine));
Expand All @@ -53,7 +57,7 @@ protected override void Open()
_window.PillTypeButtons[i].OnPressed += _ => SendMessage(new ChemMasterSetPillTypeMessage(pillType));
}

_window.OnReagentButtonPressed += (args, button) => SendMessage(new ChemMasterReagentAmountButtonMessage(button.Id, button.Amount, button.IsBuffer));
_window.OnReagentButtonPressed += (args, button) => SendMessage(new ChemMasterReagentAmountButtonMessage(button.Id, button.Amount, button.IsBuffer, button.Origin));
}

/// <summary>
Expand Down
36 changes: 30 additions & 6 deletions Content.Client/Chemistry/UI/ChemMasterWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-buffer-text'}" />
<Control HorizontalExpand="True" />
<Button MinSize="80 0" Name="BufferTransferButton" Access="Public" Text="{Loc 'chem-master-window-transfer-button'}" ToggleMode="True" StyleClasses="OpenRight" />
<Button MinSize="80 0" Name="BufferStorageButton" Access="Public" Text="{Loc 'chem-master-window-storage-button'}" ToggleMode="True" StyleClasses="OpenRight" />
<Button MinSize="80 0" Name="BufferOutputButton" Access="Public" Text="{Loc 'chem-master-window-output-button'}" ToggleMode="True" StyleClasses="ButtonSquare" />
<Button MinSize="80 0" Name="BufferDiscardButton" Access="Public" Text="{Loc 'chem-master-window-discard-button'}" ToggleMode="True" StyleClasses="OpenLeft" />
</BoxContainer>

Expand All @@ -45,7 +46,7 @@

<ScrollContainer HorizontalExpand="True" MinSize="0 200">
<!-- Buffer reagent list -->
<BoxContainer Name="BufferInfo" Orientation="Vertical" Margin="4" HorizontalExpand="True">
<BoxContainer Name="StorageBufferInfo" Orientation="Vertical" Margin="4" HorizontalExpand="True">
<Label Text="{Loc 'chem-master-window-buffer-empty-text'}" />
</BoxContainer>
</ScrollContainer>
Expand All @@ -60,28 +61,51 @@
<Button MinSize="80 0" Name="OutputEjectButton" Access="Public" Text="{Loc 'chem-master-window-eject-button'}" />
</BoxContainer>

<PanelContainer VerticalExpand="True" MinSize="0 200">
<PanelContainer VerticalExpand="True" MinSize="0 100">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>

<ScrollContainer HorizontalExpand="True" MinSize="0 200">
<ScrollContainer HorizontalExpand="True" MinSize="0 100">
<!-- Initially empty, when server sends state data this will have container contents and fill volume.-->
<BoxContainer Name="OutputContainerInfo" Orientation="Vertical" Margin="4" HorizontalExpand="True">
<Label Text="{Loc 'chem-master-window-no-container-loaded-text'}" />
</BoxContainer>
</ScrollContainer>
</PanelContainer>

<!-- Padding -->
<Control MinSize="0 10" />

<!-- Output Buffer Reagent List -->
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-output-buffer-text'}" />
<Control HorizontalExpand="True" />
<Button MinSize="80 0" Name="OutputBufferDiscardButton" Access="Public" Text="{Loc 'chem-master-window-discard-button'}" ToggleMode="False" StyleClasses="OpenRight" />
</BoxContainer>

<PanelContainer VerticalExpand="True" MinSize="0 100">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>

<ScrollContainer HorizontalExpand="True" MinSize="0 100">
<!-- Initially empty, when server sends state data this will have container contents and fill volume.-->
<BoxContainer Name="OutputBufferInfo" Orientation="Vertical" Margin="4" HorizontalExpand="True">
<Label Text="{Loc 'chem-master-window-buffer-empty-text'}" />
</BoxContainer>
</ScrollContainer>
</PanelContainer>

<!-- Padding -->
<Control MinSize="0 10" />

<!-- Packaging -->
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-packaging-text'}" />
<Control HorizontalExpand="True"/>
<Label Text="{Loc 'chem-master-window-buffer-label'}" />
<Label Name="BufferCurrentVolume" StyleClasses="LabelSecondaryColor" />
<!-- <Label Text="{Loc 'chem-master-window-buffer-label'}" />
<Label Name="BufferOutputVolume" StyleClasses="LabelSecondaryColor" /> -->
</BoxContainer>

<!-- Wrap the packaging info-->
Expand Down
89 changes: 48 additions & 41 deletions Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public ChemMasterWindow()
Tabs.SetTabTitle(1, Loc.GetString("chem-master-window-output-tab"));
}

private ReagentButton MakeReagentButton(string text, ChemMasterReagentAmount amount, ReagentId id, bool isBuffer, string styleClass)
private ReagentButton MakeReagentButton(string text, ChemMasterReagentAmount amount, ReagentId id, bool isBuffer, string origin, string styleClass)
{
var button = new ReagentButton(text, amount, id, isBuffer, styleClass);
var button = new ReagentButton(text, amount, id, isBuffer, origin, styleClass);
button.OnPressed += args
=> OnReagentButtonPressed?.Invoke(args, button);
return button;
Expand All @@ -109,7 +109,7 @@ public void UpdateState(BoundUserInterfaceState state)

var output = castState.OutputContainerInfo;

BufferCurrentVolume.Text = $" {castState.BufferCurrentVolume?.Int() ?? 0}u";
//BufferOutputVolume.Text = $" {castState.BufferOutputVolume?.Int() ?? 0}u";

InputEjectButton.Disabled = castState.InputContainerInfo is null;
OutputEjectButton.Disabled = output is null;
Expand Down Expand Up @@ -138,59 +138,47 @@ public void UpdateState(BoundUserInterfaceState state)
/// <param name="state">State data sent by the server.</param>
private string GenerateLabel(ChemMasterBoundUserInterfaceState state)
{
if (state.BufferCurrentVolume == 0)
if (state.BufferOutputVolume == 0)
return "";

var reagent = state.BufferReagents.OrderBy(r => r.Quantity).First().Reagent;
var reagent = state.BufferOutputReagents.OrderBy(r => r.Quantity).Last().Reagent;
_prototypeManager.TryIndex(reagent.Prototype, out ReagentPrototype? proto);
return proto?.LocalizedName ?? "";
}

/// <summary>
/// Update the container, buffer, and packaging panels.
/// </summary>
/// <param name="state">State data for the dispenser.</param>
private void UpdatePanelInfo(ChemMasterBoundUserInterfaceState state)
private void UpdateBufferInfo(BoxContainer bufferInfo, IReadOnlyList<ReagentQuantity> bufferReagents, FixedPoint2? bufferVolume, bool isStorageBuffer, string bufferName)
{
BufferTransferButton.Pressed = state.Mode == ChemMasterMode.Transfer;
BufferDiscardButton.Pressed = state.Mode == ChemMasterMode.Discard;
bufferInfo.Children.Clear();

BuildContainerUI(InputContainerInfo, state.InputContainerInfo, true);
BuildContainerUI(OutputContainerInfo, state.OutputContainerInfo, false);

BufferInfo.Children.Clear();

if (!state.BufferReagents.Any())
if (!bufferReagents.Any())
{
BufferInfo.Children.Add(new Label { Text = Loc.GetString("chem-master-window-buffer-empty-text") });

bufferInfo.Children.Add(new Label { Text = Loc.GetString("chem-master-window-buffer-empty-text") });
return;
}

var bufferHBox = new BoxContainer
{
Orientation = LayoutOrientation.Horizontal
};
BufferInfo.AddChild(bufferHBox);
bufferInfo.AddChild(bufferHBox);

var bufferLabel = new Label { Text = $"{Loc.GetString("chem-master-window-buffer-label")} " };
bufferHBox.AddChild(bufferLabel);
var bufferVol = new Label
{
Text = $"{state.BufferCurrentVolume}u",
StyleClasses = {StyleNano.StyleClassLabelSecondaryColor}
Text = $"{bufferVolume}u",
StyleClasses = { StyleNano.StyleClassLabelSecondaryColor }
};
bufferHBox.AddChild(bufferVol);

foreach (var (reagent, quantity) in state.BufferReagents)
foreach (var (reagent, quantity) in bufferReagents)
{
// Try to get the prototype for the given reagent. This gives us its name.
_prototypeManager.TryIndex(reagent.Prototype, out ReagentPrototype? proto);
var name = proto?.LocalizedName ?? Loc.GetString("chem-master-window-unknown-reagent-text");

if (proto != null)
{
BufferInfo.Children.Add(new BoxContainer
bufferInfo.Children.Add(new BoxContainer
{
Orientation = LayoutOrientation.Horizontal,
Children =
Expand All @@ -205,19 +193,36 @@ private void UpdatePanelInfo(ChemMasterBoundUserInterfaceState state)
// Padding
new Control {HorizontalExpand = true},

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),
MakeReagentButton("1", ChemMasterReagentAmount.U1, reagent, isStorageBuffer, bufferName, StyleBase.ButtonOpenRight),
MakeReagentButton("5", ChemMasterReagentAmount.U5, reagent, isStorageBuffer, bufferName, StyleBase.ButtonOpenBoth),
MakeReagentButton("10", ChemMasterReagentAmount.U10, reagent, isStorageBuffer, bufferName, StyleBase.ButtonOpenBoth),
MakeReagentButton("25", ChemMasterReagentAmount.U25, reagent, isStorageBuffer, bufferName, StyleBase.ButtonOpenBoth),
MakeReagentButton("50", ChemMasterReagentAmount.U50, reagent, isStorageBuffer, bufferName, StyleBase.ButtonOpenBoth),
MakeReagentButton("100", ChemMasterReagentAmount.U100, reagent, isStorageBuffer, bufferName, StyleBase.ButtonOpenBoth),
MakeReagentButton(Loc.GetString("chem-master-window-buffer-all-amount"), ChemMasterReagentAmount.All, reagent, isStorageBuffer, bufferName, StyleBase.ButtonOpenLeft),
}
});
}
}
}

/// <summary>
/// Update the container, buffer, and packaging panels.
/// </summary>
/// <param name="state">State data for the dispenser.</param>
private void UpdatePanelInfo(ChemMasterBoundUserInterfaceState state)
{
BufferStorageButton.Pressed = state.Mode == ChemMasterMode.Storage;
BufferOutputButton.Pressed = state.Mode == ChemMasterMode.Output;
BufferDiscardButton.Pressed = state.Mode == ChemMasterMode.Discard;

BuildContainerUI(InputContainerInfo, state.InputContainerInfo, true);
BuildContainerUI(OutputContainerInfo, state.OutputContainerInfo, false);

UpdateBufferInfo(StorageBufferInfo, state.BufferStorageReagents, state.BufferStorageVolume, true, SharedChemMaster.StorageBufferSolutionName);
UpdateBufferInfo(OutputBufferInfo, state.BufferOutputReagents, state.BufferOutputVolume, false, SharedChemMaster.OutputBufferSolutionName);
}

private void BuildContainerUI(Control control, ContainerInfo? info, bool addReagentButtons)
{
control.Children.Clear();
Expand Down Expand Up @@ -294,20 +299,20 @@ private void BuildContainerUI(Control control, ContainerInfo? info, bool addReag
cs.Add(new Control { HorizontalExpand = true });

cs.Add(MakeReagentButton(
"1", ChemMasterReagentAmount.U1, id, false, StyleBase.ButtonOpenRight));
"1", ChemMasterReagentAmount.U1, id, false, SharedChemMaster.InputSlotName, StyleBase.ButtonOpenRight));
cs.Add(MakeReagentButton(
"5", ChemMasterReagentAmount.U5, id, false, StyleBase.ButtonOpenBoth));
"5", ChemMasterReagentAmount.U5, id, false, SharedChemMaster.InputSlotName, StyleBase.ButtonOpenBoth));
cs.Add(MakeReagentButton(
"10", ChemMasterReagentAmount.U10, id, false, StyleBase.ButtonOpenBoth));
"10", ChemMasterReagentAmount.U10, id, false, SharedChemMaster.InputSlotName, StyleBase.ButtonOpenBoth));
cs.Add(MakeReagentButton(
"25", ChemMasterReagentAmount.U25, id, false, StyleBase.ButtonOpenBoth));
"25", ChemMasterReagentAmount.U25, id, false, SharedChemMaster.InputSlotName, StyleBase.ButtonOpenBoth));
cs.Add(MakeReagentButton(
"50", ChemMasterReagentAmount.U50, id, false, StyleBase.ButtonOpenBoth));
"50", ChemMasterReagentAmount.U50, id, false, SharedChemMaster.InputSlotName, StyleBase.ButtonOpenBoth));
cs.Add(MakeReagentButton(
"100", ChemMasterReagentAmount.U100, id, false, StyleBase.ButtonOpenBoth));
"100", ChemMasterReagentAmount.U100, id, false, SharedChemMaster.InputSlotName, StyleBase.ButtonOpenBoth));
cs.Add(MakeReagentButton(
Loc.GetString("chem-master-window-buffer-all-amount"),
ChemMasterReagentAmount.All, id, false, StyleBase.ButtonOpenLeft));
ChemMasterReagentAmount.All, id, false, SharedChemMaster.InputSlotName, StyleBase.ButtonOpenLeft));
}

control.Children.Add(inner);
Expand All @@ -333,13 +338,15 @@ public sealed class ReagentButton : Button
{
public ChemMasterReagentAmount Amount { get; set; }
public bool IsBuffer = true;
public string Origin { get; set; }
public ReagentId Id { get; set; }
public ReagentButton(string text, ChemMasterReagentAmount amount, ReagentId id, bool isBuffer, string styleClass)
public ReagentButton(string text, ChemMasterReagentAmount amount, ReagentId id, bool isBuffer, string origin, string styleClass)
{
AddStyleClass(styleClass);
Text = text;
Amount = amount;
Id = id;
Origin = origin;
IsBuffer = isBuffer;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Chemistry/Components/ChemMasterComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed partial class ChemMasterComponent : Component
public uint PillType = 0;

[DataField("mode"), ViewVariables(VVAccess.ReadWrite)]
public ChemMasterMode Mode = ChemMasterMode.Transfer;
public ChemMasterMode Mode = ChemMasterMode.Storage;

[DataField("pillDosageLimit", required: true), ViewVariables(VVAccess.ReadWrite)]
public uint PillDosageLimit;
Expand Down
Loading
Loading