Skip to content

Commit

Permalink
good enough!
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyyapril committed Feb 3, 2025
1 parent 481f5d1 commit 9d62faa
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected override void Open()
_window.OnReagentButtonPressed += (_, button, amount, isOutput) => SendMessage(new ChemMasterReagentAmountButtonMessage(button.Id, amount, button.IsBuffer, isOutput));
_window.OnSortMethodChanged += sortMethod => SendMessage(new ChemMasterSortMethodUpdated(sortMethod));
_window.OnTransferAmountChanged += amount => SendMessage(new ChemMasterTransferringAmountUpdated(amount));
_window.OnUpdateAmounts += amounts => SendMessage(new ChemMasterAmountsUpdated(amounts));
}

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion Content.Client/Chemistry/UI/ChemMasterWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,18 @@
</PanelContainer>
<RichTextLabel Name="AmountLabel" Text="{Loc 'chem-master-window-transferring-default-label'}" Margin="0 0 7 0" />
<LineEdit MinSize="140 0" Name="AmountLineEdit" Access="Public" PlaceHolder="{Loc 'chem-master-window-amount-placeholder'}" />
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Button Name="SetAmountButton" Text="{Loc 'chem-master-window-set-amount-label'}" HorizontalExpand="True" StyleClasses="OpenRight"/>
<Button Name="SaveAsFrequentButton" Text="{Loc 'chem-master-window-save-as-frequent-label'}" HorizontalExpand="True" StyleClasses="OpenLeft"/>
</BoxContainer>
<Label Text="Both of the above buttons use the textbox" />
<Control MinSize="0 5" />
<GridContainer
Name="AmountButtons"
VerticalExpand="True"
HorizontalExpand="True"
Margin="2 2 2 2"
Columns="5" />
Columns="4" />
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>
42 changes: 34 additions & 8 deletions Content.Client/Chemistry/UI/ChemMasterWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ public sealed partial class ChemMasterWindow : FancyWindow
public event Action<int>? OnAmountButtonPressed;
public event Action<int>? OnSortMethodChanged;
public event Action<int>? OnTransferAmountChanged;
public event Action<List<int>>? OnUpdateAmounts;

public readonly Button[] PillTypeButtons;

private List<int> _amounts = new();

private const string TransferringAmountColor = "#ffffff";
private ReagentSortMethod _currentSortMethod = ReagentSortMethod.Alphabetical;
private ChemMasterBoundUserInterfaceState? _lastState;
Expand All @@ -48,7 +52,9 @@ public ChemMasterWindow()

AmountLabel.HorizontalAlignment = HAlignment.Center;
AmountLineEdit.OnTextEntered += SetAmount;
AmountLineEdit.OnFocusExit += SetAmount;

SetAmountButton.OnPressed += _ => SetAmountText(AmountLineEdit.Text);
SaveAsFrequentButton.OnPressed += HandleSaveAsFrequentPressed;

// Pill type selection buttons, in total there are 20 pills.
// Pill rsi file should have states named as pill1, pill2, and so on.
Expand Down Expand Up @@ -130,15 +136,19 @@ public ChemMasterWindow()
BufferTransferButton.OnPressed += HandleDiscardTransferPress;
BufferDiscardButton.OnPressed += HandleDiscardTransferPress;

var amounts = new List<int>()
{
1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 125, 150, 175, 200, 225, 250, 275, 300, 500
};
CreateAmountButtons();

OnAmountButtonPressed += amount => SetAmountText(amount.ToString());
}

private void CreateAmountButtons()
{
AmountButtons.DisposeAllChildren();

for (int i = 0; i < amounts.Count; i++)
for (int i = 0; i < _amounts.Count; i++)
{
var styleClass = StyleBase.ButtonOpenBoth;
var amount = amounts[i];
var amount = _amounts[i];
var columns = AmountButtons.Columns;

if (i == 0 || i % columns == 0)
Expand All @@ -158,8 +168,17 @@ public ChemMasterWindow()
button.OnPressed += _ => OnAmountButtonPressed?.Invoke(amount);
AmountButtons.AddChild(button);
}
}

OnAmountButtonPressed += amount => SetAmountText(amount.ToString());
private void HandleSaveAsFrequentPressed(BaseButton.ButtonEventArgs args)
{
if (!int.TryParse(AmountLineEdit.Text, out var amount)
|| _amounts.Any(a => amount == a))
return;

_amounts.Add(amount);
_amounts.Sort();
CreateAmountButtons();
}

private void HandleDiscardTransferPress(BaseButton.ButtonEventArgs args)
Expand Down Expand Up @@ -276,6 +295,13 @@ public void UpdateState(BoundUserInterfaceState state)
HandleSortMethodChange(castState.SortMethod);
SetAmountText(castState.TransferringAmount.ToString());

if (_amounts != castState.Amounts)
{
_amounts = castState.Amounts;
_amounts.Sort();
CreateAmountButtons();
}

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

InputEjectButton.Disabled = castState.ContainerInfo is null;
Expand Down
8 changes: 7 additions & 1 deletion Content.Server/Chemistry/Components/ChemMasterComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public sealed partial class ChemMasterComponent : Component
public int SortMethod;

[DataField]
public int TransferringAmount;
public int TransferringAmount = 1;

[DataField]
public List<int> Amounts = new()
{
1, 5, 10, 15, 20, 25, 30, 50
};
}
}
7 changes: 6 additions & 1 deletion Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ public override void Initialize()
SubscribeLocalEvent<ChemMasterComponent, ChemMasterOutputToBottleMessage>(OnOutputToBottleMessage);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterSortMethodUpdated>(OnSortMethodUpdated);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterTransferringAmountUpdated>(OnTransferringAmountUpdated);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterAmountsUpdated>(OnAmountsUpdated);
}

private void OnAmountsUpdated(Entity<ChemMasterComponent> ent, ref ChemMasterAmountsUpdated args) =>
ent.Comp.Amounts = args.Amounts;

private void SubscribeUpdateUiState<T>(Entity<ChemMasterComponent> ent, ref T ev) =>
UpdateUiState(ent);

Expand Down Expand Up @@ -97,7 +101,8 @@ private void UpdateUiState(Entity<ChemMasterComponent> ent, bool updateLabel = f
chemMaster.PillDosageLimit,
updateLabel,
chemMaster.SortMethod,
chemMaster.TransferringAmount);
chemMaster.TransferringAmount,
chemMaster.Amounts);

_userInterfaceSystem.SetUiState(owner, ChemMasterUiKey.Key, state);
}
Expand Down
11 changes: 10 additions & 1 deletion Content.Shared/Chemistry/SharedChemMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public sealed class ChemMasterTransferringAmountUpdated(int transferringAmount)
public readonly int TransferringAmount = transferringAmount;
}

[Serializable, NetSerializable]
public sealed class ChemMasterAmountsUpdated(List<int> amounts) : BoundUserInterfaceMessage
{
public readonly List<int> Amounts = amounts;
}

public enum ChemMasterMode
{
Transfer,
Expand Down Expand Up @@ -152,7 +158,8 @@ public sealed class ChemMasterBoundUserInterfaceState(
uint pillDosageLimit,
bool updateLabel,
int sortMethod,
int transferringAmount)
int transferringAmount,
List<int> amounts)
: BoundUserInterfaceState
{
public readonly ContainerInfo? ContainerInfo = containerInfo;
Expand All @@ -179,6 +186,8 @@ public sealed class ChemMasterBoundUserInterfaceState(

public readonly int SortMethod = sortMethod;
public readonly int TransferringAmount = transferringAmount;

public readonly List<int> Amounts = amounts;
}

[Serializable, NetSerializable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ chem-master-window-pill-buffer-text = Pill Buffer
chem-master-window-pill-buffer-label = pill buffer:
chem-master-window-pill-buffer-empty-text = Pill buffer empty.
chem-master-window-pill-buffer-low-text = Not enough solution in pill buffer
chem-master-window-save-as-frequent-label = Save as Frequent
chem-master-window-set-amount-label = Set Amount
chem-master-window-transfer-button = Transfer
chem-master-window-sort-method-tooltip = Choose your buffer's sort method.
chem-master-window-sort-method-Time-text = Last Added
Expand Down

0 comments on commit 9d62faa

Please sign in to comment.