Skip to content

Commit

Permalink
Allow ChemMaster to draw from inserted container for pillmaking
Browse files Browse the repository at this point in the history
  • Loading branch information
sowelipililimute committed Nov 30, 2024
1 parent 0e2bc19 commit a12eb14
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 4 deletions.
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
17 changes: 17 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,17 @@ public void UpdateState(BoundUserInterfaceState state)
PillDosage.IsValid = x => x > 0 && x <= castState.PillDosageLimit;
BottleDosage.IsValid = x => x >= 0 && x <= bottleAmountMax;

// Begin DeltaV - chemmaster sources
switch (castState.Source) {
case ChemMasterSource.InternalBuffer:
SourceBufferButton.Pressed = true;
break;
case ChemMasterSource.InsertedContainer:
SourceInsertedButton.Pressed = true;
break;
}
// 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("source"), ViewVariables(VVAccess.ReadWrite)]
public ChemMasterSource Source = ChemMasterSource.InternalBuffer;
// End DeltaV - chemmaster sources

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

Expand Down
61 changes: 58 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,19 @@ private void OnSetModeMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMa
ClickSound(chemMaster);
}

// Begin DeltaV - chemmaster sources
private void OnSetSourceMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterSetSourceMessage message)
{
// Ensure the mode is valid, either Transfer or Discard.
if (!Enum.IsDefined(typeof(ChemMasterSource), message.ChemMasterSource))
return;

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 +278,55 @@ private void OnOutputToBottleMessage(Entity<ChemMasterComponent> chemMaster, ref
ClickSound(chemMaster);
}

// Begin DeltaV - chemmaster sources
private bool GetSourceSolution(
Entity<ChemMasterComponent> chemMaster,
[NotNullWhen(returnValue: true)] out Entity<SolutionComponent>? sourceComponent)
{
switch (chemMaster.Comp.Source) {
case ChemMasterSource.InternalBuffer: {
if (!_solutionContainerSystem.TryGetSolution(chemMaster.Owner,
SharedChemMaster.BufferSolutionName, out var component, out _))
{
sourceComponent = null;
return false;
}
sourceComponent = component;
return true;
}
case ChemMasterSource.InsertedContainer: {
var container = _itemSlotsSystem.GetItemOrNull(chemMaster, SharedChemMaster.InputSlotName);
if (container is null ||
!_solutionContainerSystem.TryGetFitsInDispenser(container.Value, out var component, out _))
{
sourceComponent = null;
return false;
}
sourceComponent = component;
return true;
}
default: {
sourceComponent = null;
return false;
}
}
}
// 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, out var component))
{
return false;
}
var solution = component.Value.Comp.Solution;
// End DeltaV - chemmaster sources

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

outputSolution = solution.SplitSolution(neededVolume);
outputSolution = _solutionContainerSystem.SplitSolution(solution.Value, neededVolume); // DeltaV - chemmaster sources

Check failure on line 346 in Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'Solution' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'Solution' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 346 in Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

'Solution' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'Solution' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 346 in Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'Solution' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'Solution' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 346 in Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'Solution' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'Solution' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 346 in Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'Solution' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'Solution' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 346 in Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'Solution' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'Solution' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 346 in Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'Solution' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'Solution' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 346 in Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

'Solution' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'Solution' could be found (are you missing a using directive or an assembly reference?)
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

0 comments on commit a12eb14

Please sign in to comment.