Skip to content

Commit

Permalink
Fix for not having DiscardReagents
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyyapril committed Jan 20, 2025
1 parent 7b5b033 commit 1191ca3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
41 changes: 9 additions & 32 deletions Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public sealed partial class ChemMasterWindow : FancyWindow
private const string TransferringAmountColor = "#ffa500";
private ReagentSortMethod _currentSortMethod = ReagentSortMethod.Alphabetical;
private ChemMasterBoundUserInterfaceState? _lastState;
private string _lastAmountText = "50";
private int _transferAmount = 50;


Expand Down Expand Up @@ -112,22 +111,6 @@ public ChemMasterWindow()
SortMethod.AddItem(Loc.GetString("chem-master-window-sort-method-Amount-text"), (int) ReagentSortMethod.Amount);
SortMethod.AddItem(Loc.GetString("chem-master-window-sort-method-Time-text"), (int) ReagentSortMethod.Time);
SortMethod.OnItemSelected += HandleChildPressed;

BufferTransferButton.OnPressed += HandleDiscardTransferPress;
BufferDiscardButton.OnPressed += HandleDiscardTransferPress;
}

private void HandleDiscardTransferPress(BaseButton.ButtonEventArgs args)
{
var buttons = BufferInfo.Children
.Where(c => c is Button)
.Cast<Button>();

foreach (var button in buttons)
{
var text = BufferTransferButton.Pressed ? "transfer" : "discard";
button.Text = Loc.GetString($"chem-master-window-{text}-button-text");
}
}

private void HandleSortMethodChange(int newSortMethod)
Expand Down Expand Up @@ -163,7 +146,6 @@ private bool ValidateAmount(string newText)
return false;
}

_lastAmountText = newText;
_transferAmount = amount;
OnTransferAmountChanged?.Invoke(amount);
return true;
Expand All @@ -174,10 +156,7 @@ private void SetAmount(LineEdit.LineEditEventArgs args) =>

private void SetAmountText(string newText)
{
if (newText == _lastAmountText)
return;

if (!ValidateAmount(newText))
if (newText == _transferAmount.ToString() || !ValidateAmount(newText))
return;

var localizedAmount = Loc.GetString(
Expand Down Expand Up @@ -208,10 +187,8 @@ private ReagentButton MakeReagentButton(string text, ReagentId id, bool isBuffer
if (!addReagentButtons)
return null; // Return an empty list if reagentTransferButton creation is disabled.

var text = BufferTransferButton.Pressed ? "transfer" : "discard";

var reagentTransferButton = MakeReagentButton(
Loc.GetString($"chem-master-window-{text}-button"),
Loc.GetString("chem-master-window-transfer-button"),
reagent,
isBuffer
);
Expand All @@ -238,15 +215,15 @@ public void UpdateState(BoundUserInterfaceState state)
SetAmountText(castState.TransferringAmount.ToString());

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

InputEjectButton.Disabled = castState.InputContainerInfo is null;
OutputEjectButton.Disabled = castState.OutputContainerInfo is null;
CreateBottleButton.Disabled = castState.OutputContainerInfo?.Reagents == null;
CreatePillButton.Disabled = castState.OutputContainerInfo?.Entities == null;

UpdateDosageFields(castState);
}

//assign default values for pill and bottle fields.
private void UpdateDosageFields(ChemMasterBoundUserInterfaceState castState)
{
Expand All @@ -258,7 +235,7 @@ private void UpdateDosageFields(ChemMasterBoundUserInterfaceState castState)
var bufferVolume = castState.BufferCurrentVolume?.Int() ?? 0;

PillDosage.Value = (int)Math.Min(bufferVolume, castState.PillDosageLimit);

PillTypeButtons[castState.SelectedPillType].Pressed = true;
PillNumber.IsValid = x => x >= 0 && x <= pillNumberMax;
PillDosage.IsValid = x => x > 0 && x <= castState.PillDosageLimit;
Expand Down Expand Up @@ -382,7 +359,7 @@ private void UpdatePanelInfo(ChemMasterBoundUserInterfaceState state)
}
}
}

private void BuildContainerUI(Control control, ContainerInfo? info, bool addReagentButtons)
{
control.Children.Clear();
Expand Down Expand Up @@ -430,7 +407,7 @@ private void BuildContainerUI(Control control, ContainerInfo? info, bool addReag
_prototypeManager.TryIndex(reagent.Reagent.Prototype, out ReagentPrototype? proto);
var name = proto?.LocalizedName ?? Loc.GetString("chem-master-window-unknown-reagent-text");
var reagentColor = proto?.SubstanceColor ?? default(Color);

control.Children.Add(BuildReagentRow(reagentColor, rowCount++, name, reagent.Reagent, reagent.Quantity, false, addReagentButtons));
}
}
Expand Down Expand Up @@ -491,7 +468,7 @@ private Control BuildReagentRow(Color reagentColor, int rowCount, string name, R
Children = { rowContainer }
};
}

public string LabelLine
{
get => LabelLineEdit.Text;
Expand Down
19 changes: 3 additions & 16 deletions Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@ private void UpdateUiState(Entity<ChemMasterComponent> ent, bool updateLabel = f
var bufferCurrentVolume = bufferSolution.Volume;

var state = new ChemMasterBoundUserInterfaceState(
chemMaster.Mode,
BuildInputContainerInfo(inputContainer),
BuildOutputContainerInfo(outputContainer),
bufferReagents,
bufferCurrentVolume,
chemMaster.PillType,
chemMaster.PillDosageLimit,
updateLabel,
chemMaster.SortMethod,
chemMaster.TransferringAmount);
ent.Comp.SortMethod,
ent.Comp.TransferringAmount);

_userInterfaceSystem.SetUiState(owner, ChemMasterUiKey.Key, state);
}
Expand All @@ -102,19 +101,7 @@ private void OnSetPillTypeMessage(Entity<ChemMasterComponent> chemMaster, ref Ch

private void OnReagentButtonMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterReagentAmountButtonMessage message)
{
switch (chemMaster.Comp.Mode)
{
case ChemMasterMode.Transfer:
TransferReagents(chemMaster, message.ReagentId, message.Amount, message.FromBuffer);
break;
case ChemMasterMode.Discard:
DiscardReagents(chemMaster, message.ReagentId, message.Amount, message.FromBuffer);
break;
default:
// Invalid mode.
return;
}

TransferReagents(chemMaster, message.ReagentId, chemMaster.Comp.TransferringAmount, message.FromBuffer);
ClickSound(chemMaster);
}

Expand Down

0 comments on commit 1191ca3

Please sign in to comment.