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

Allow ChemMaster to draw from inserted container for pillmaking #2327

Closed
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
7 changes: 7 additions & 0 deletions Content.Client/Chemistry/UI/ChemMasterBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ protected override void Open()
new ChemMasterOutputToBottleMessage(
(uint) _window.BottleDosage.Value, _window.LabelLine));

// Begin DeltaV - chemmaster sources
_window.SourceBufferButton.OnPressed += _ => SendMessage(
new ChemMasterSetSourceMessage(ChemMasterSource.InternalBuffer));
_window.SourceInsertedButton.OnPressed += _ => SendMessage(
new ChemMasterSetSourceMessage(ChemMasterSource.InsertedContainer));
// End DeltaV - chemmaster sources

for (uint i = 0; i < _window.PillTypeButtons.Length; i++)
{
var pillType = i;
Expand Down
10 changes: 10 additions & 0 deletions Content.Client/Chemistry/UI/ChemMasterWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@
<SpinBox MinSize="100 0" Name="BottleDosage" Access="Public" Value="0" />
<Button MinSize="80 0" Name="CreateBottleButton" Access="Public" Text="{Loc 'chem-master-window-create-button'}" />
</BoxContainer>

<!-- Begin DeltaV - chemmaster sources -->
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'chem-master-window-source-label'}" />
<Control HorizontalExpand="True" MinSize="50 0" />

<Button MinSize="80 0" Name="SourceBufferButton" Access="Public" Text="{Loc 'chem-master-source-buffer-button'}" Pressed="True" />
<Button MinSize="80 0" Name="SourceInsertedButton" Access="Public" Text="{Loc 'chem-master-source-inserted-button'}" />
</BoxContainer>
<!-- End DeltaV - chemmaster sources -->
</BoxContainer>
</PanelContainer>
</BoxContainer>
Expand Down
14 changes: 14 additions & 0 deletions Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public ChemMasterWindow()
PillNumber.InitDefaultButtons();
BottleDosage.InitDefaultButtons();

// Begin DeltaV - chemmaster sources
var sourceGroup = new ButtonGroup(false);
SourceBufferButton.Group = sourceGroup;
SourceInsertedButton.Group = sourceGroup;
// End DeltaV - chemmaster sources

// Ensure label length is within the character limit.
LabelLineEdit.IsValid = s => s.Length <= SharedChemMaster.LabelMaxLength;

Expand Down Expand Up @@ -126,6 +132,14 @@ public void UpdateState(BoundUserInterfaceState state)
PillDosage.IsValid = x => x > 0 && x <= castState.PillDosageLimit;
BottleDosage.IsValid = x => x >= 0 && x <= bottleAmountMax;

// Begin DeltaV - chemmaster sources
var activeButton = castState.Source switch {
ChemMasterSource.InternalBuffer => SourceBufferButton,
ChemMasterSource.InsertedContainer => SourceInsertedButton,
};
activeButton.Pressed = true;
// End DeltaV - chemmaster sources

if (PillNumber.Value > pillNumberMax)
PillNumber.Value = pillNumberMax;
if (BottleDosage.Value > bottleAmountMax)
Expand Down
5 changes: 5 additions & 0 deletions Content.Server/Chemistry/Components/ChemMasterComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public sealed partial class ChemMasterComponent : Component
[DataField("mode"), ViewVariables(VVAccess.ReadWrite)]
public ChemMasterMode Mode = ChemMasterMode.Transfer;

// Begin DeltaV - chemmaster sources
[DataField, ViewVariables(VVAccess.ReadWrite)]
public ChemMasterSource Source = ChemMasterSource.InternalBuffer;
// End DeltaV - chemmaster sources

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

Expand Down
51 changes: 48 additions & 3 deletions Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public override void Initialize()
SubscribeLocalEvent<ChemMasterComponent, BoundUIOpenedEvent>(SubscribeUpdateUiState);

SubscribeLocalEvent<ChemMasterComponent, ChemMasterSetModeMessage>(OnSetModeMessage);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterSetSourceMessage>(OnSetSourceMessage); // DeltaV - chemmaster sources
SubscribeLocalEvent<ChemMasterComponent, ChemMasterSetPillTypeMessage>(OnSetPillTypeMessage);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterReagentAmountButtonMessage>(OnReagentButtonMessage);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterCreatePillsMessage>(OnCreatePillsMessage);
Expand All @@ -75,9 +76,12 @@ private void UpdateUiState(Entity<ChemMasterComponent> ent, bool updateLabel = f
var bufferReagents = bufferSolution.Contents;
var bufferCurrentVolume = bufferSolution.Volume;

// Begin DeltaV - chemmaster sources
var state = new ChemMasterBoundUserInterfaceState(
chemMaster.Mode, BuildInputContainerInfo(inputContainer), BuildOutputContainerInfo(outputContainer),
bufferReagents, bufferCurrentVolume, chemMaster.PillType, chemMaster.PillDosageLimit, updateLabel);
bufferReagents, bufferCurrentVolume, chemMaster.PillType, chemMaster.PillDosageLimit, updateLabel,
chemMaster.Source);
// End DeltaV - chemmaster sources

_userInterfaceSystem.SetUiState(owner, ChemMasterUiKey.Key, state);
}
Expand All @@ -93,6 +97,15 @@ private void OnSetModeMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMa
ClickSound(chemMaster);
}

// Begin DeltaV - chemmaster sources
private void OnSetSourceMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterSetSourceMessage message)
{
chemMaster.Comp.Source = message.ChemMasterSource;
UpdateUiState(chemMaster);
ClickSound(chemMaster);
}
// End DeltaV - chemmaster sources

private void OnSetPillTypeMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterSetPillTypeMessage message)
{
// Ensure valid pill type. There are 20 pills selectable, 0-19.
Expand Down Expand Up @@ -261,17 +274,49 @@ private void OnOutputToBottleMessage(Entity<ChemMasterComponent> chemMaster, ref
ClickSound(chemMaster);
}

// Begin DeltaV - chemmaster sources
private Entity<SolutionComponent>? GetSourceSolution(
Entity<ChemMasterComponent> chemMaster)
{
switch (chemMaster.Comp.Source) {
case ChemMasterSource.InternalBuffer: {
if (!_solutionContainerSystem.TryGetSolution(chemMaster.Owner,
SharedChemMaster.BufferSolutionName, out var component, out _))
{
return null;
}
return component;
}
case ChemMasterSource.InsertedContainer: {
var container = _itemSlotsSystem.GetItemOrNull(chemMaster, SharedChemMaster.InputSlotName);
if (container is null ||
!_solutionContainerSystem.TryGetFitsInDispenser(container.Value, out var component, out _))
{
return null;
}
return component;
}
default: {
return null;
}
}
}
// End DeltaV - chemmaster sources

private bool WithdrawFromBuffer(
Entity<ChemMasterComponent> chemMaster,
FixedPoint2 neededVolume, EntityUid? user,
[NotNullWhen(returnValue: true)] out Solution? outputSolution)
{
outputSolution = null;

if (!_solutionContainerSystem.TryGetSolution(chemMaster.Owner, SharedChemMaster.BufferSolutionName, out _, out var solution))
// Begin DeltaV - chemmaster sources
if (GetSourceSolution(chemMaster) is not {} source)
{
return false;
}
var solution = source.Comp.Solution;
// End DeltaV - chemmaster sources

if (solution.Volume == 0)
{
Expand All @@ -288,7 +333,7 @@ private bool WithdrawFromBuffer(
return false;
}

outputSolution = solution.SplitSolution(neededVolume);
outputSolution = _solutionContainerSystem.SplitSolution(source, neededVolume); // DeltaV - chemmaster sources
return true;
}

Expand Down
25 changes: 24 additions & 1 deletion Content.Shared/Chemistry/SharedChemMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ public ChemMasterSetModeMessage(ChemMasterMode mode)
}
}

// Begin DeltaV - chemmaster sources
[Serializable, NetSerializable]
public sealed class ChemMasterSetSourceMessage : BoundUserInterfaceMessage
{
public readonly ChemMasterSource ChemMasterSource;

public ChemMasterSetSourceMessage(ChemMasterSource source)
{
ChemMasterSource = source;
}
}
// End DeltaV - chemmaster sources

[Serializable, NetSerializable]
public sealed class ChemMasterSetPillTypeMessage : BoundUserInterfaceMessage
{
Expand Down Expand Up @@ -83,6 +96,14 @@ public ChemMasterOutputToBottleMessage(uint dosage, string label)
}
}

// Begin DeltaV - chemmaster sources
public enum ChemMasterSource
{
InternalBuffer,
InsertedContainer,
}
// End DeltaV - chemmaster sources

public enum ChemMasterMode
{
Transfer,
Expand Down Expand Up @@ -159,6 +180,7 @@ public sealed class ChemMasterBoundUserInterfaceState : BoundUserInterfaceState
public readonly IReadOnlyList<ReagentQuantity> BufferReagents;

public readonly ChemMasterMode Mode;
public readonly ChemMasterSource Source; // DeltaV - chemmaster sources

public readonly FixedPoint2? BufferCurrentVolume;
public readonly uint SelectedPillType;
Expand All @@ -170,7 +192,7 @@ public sealed class ChemMasterBoundUserInterfaceState : BoundUserInterfaceState
public ChemMasterBoundUserInterfaceState(
ChemMasterMode mode, ContainerInfo? inputContainerInfo, ContainerInfo? outputContainerInfo,
IReadOnlyList<ReagentQuantity> bufferReagents, FixedPoint2 bufferCurrentVolume,
uint selectedPillType, uint pillDosageLimit, bool updateLabel)
uint selectedPillType, uint pillDosageLimit, bool updateLabel, ChemMasterSource source) // DeltaV - chemmaster sources
{
InputContainerInfo = inputContainerInfo;
OutputContainerInfo = outputContainerInfo;
Expand All @@ -180,6 +202,7 @@ public ChemMasterBoundUserInterfaceState(
SelectedPillType = selectedPillType;
PillDosageLimit = pillDosageLimit;
UpdateLabel = updateLabel;
Source = source; // DeltaV - chemmaster sources
}
}

Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/deltav/chemistry/chem-master.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chem-master-window-source-label = Draw from:
chem-master-source-buffer-button = Internal Buffer
chem-master-source-inserted-button = Inserted Container
Loading