// Ensure the Panel Info is updated, including UI elements for Buffer Volume, Output Container and so on
UpdatePanelInfo(castState);
-
+
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)
{
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;
BottleDosage.IsValid = x => x >= 0 && x <= bottleAmountMax;
BufferInfo.Children.Clear();
+ // This has to happen here due to people possibly
+ // setting sorting before putting any chemicals
+ BufferSortButton.Text = state.SortingType switch
+ {
+ ChemMasterSortingType.Alphabetical => Loc.GetString("chem-master-window-sort-type-alphabetical"),
+ ChemMasterSortingType.Quantity => Loc.GetString("chem-master-window-sort-type-quantity"),
+ ChemMasterSortingType.Latest => Loc.GetString("chem-master-window-sort-type-latest"),
+ _ => Loc.GetString("chem-master-window-sort-type-none")
+ };
+
+
if (!state.BufferReagents.Any())
{
BufferInfo.Children.Add(new Label { Text = Loc.GetString("chem-master-window-buffer-empty-text") });
};
bufferHBox.AddChild(bufferVol);
- // initialises rowCount to allow for striped rows
-
- var rowCount = 0;
+ // This sets up the needed data for sorting later in a list
+ // Its done this way to not repeat having to use same code twice (once for sorting
+ // and once for displaying)
+ var reagentList = new List<(ReagentId reagentId, string name, Color color, FixedPoint2 quantity)>();
foreach (var (reagent, quantity) in state.BufferReagents)
{
var reagentId = reagent;
_prototypeManager.TryIndex(reagentId.Prototype, out ReagentPrototype? proto);
var name = proto?.LocalizedName ?? Loc.GetString("chem-master-window-unknown-reagent-text");
var reagentColor = proto?.SubstanceColor ?? default(Color);
- BufferInfo.Children.Add(BuildReagentRow(reagentColor, rowCount++, name, reagentId, quantity, true, true));
+ reagentList.Add(new (reagentId, name, reagentColor, quantity));
+ }
+
+ // We sort here since we need sorted list to be filled first.
+ // You can easily add any new params you need to it.
+ switch (state.SortingType)
+ {
+ case ChemMasterSortingType.Alphabetical:
+ reagentList = reagentList.OrderBy(x => x.name).ToList();
+ break;
+
+ case ChemMasterSortingType.Quantity:
+ reagentList = reagentList.OrderByDescending(x => x.quantity).ToList();
+ break;
+ case ChemMasterSortingType.Latest:
+ reagentList = Enumerable.Reverse(reagentList).ToList();
+ break;
+
+ case ChemMasterSortingType.None:
+ default:
+ // This case is pointless but it is there for readability
+ break;
+ }
+
+ // initialises rowCount to allow for striped rows
+ var rowCount = 0;
+ foreach (var reagent in reagentList)
+ {
+ BufferInfo.Children.Add(BuildReagentRow(reagent.color, rowCount++, reagent.name, reagent.reagentId, reagent.quantity, true, true));
}
}
-
+
private void BuildContainerUI(Control control, ContainerInfo? info, bool addReagentButtons)
{
control.Children.Clear();
_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));
}
}
}
//this calls the separated button builder, and stores the return to render after labels
var reagentButtonConstructors = CreateReagentTransferButtons(reagent, isBuffer, addReagentButtons);
-
+
// Create the row layout with the color panel
var rowContainer = new BoxContainer
{
Children = { rowContainer }
};
}
-
+
public string LabelLine
{
get => LabelLineEdit.Text;
SubscribeLocalEvent<ChemMasterComponent, BoundUIOpenedEvent>(SubscribeUpdateUiState);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterSetModeMessage>(OnSetModeMessage);
+ SubscribeLocalEvent<ChemMasterComponent, ChemMasterSortingTypeCycleMessage>(OnCycleSortingTypeMessage);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterSetPillTypeMessage>(OnSetPillTypeMessage);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterReagentAmountButtonMessage>(OnReagentButtonMessage);
SubscribeLocalEvent<ChemMasterComponent, ChemMasterCreatePillsMessage>(OnCreatePillsMessage);
var bufferCurrentVolume = bufferSolution.Volume;
var state = new ChemMasterBoundUserInterfaceState(
- chemMaster.Mode, BuildInputContainerInfo(inputContainer), BuildOutputContainerInfo(outputContainer),
+ chemMaster.Mode, chemMaster.SortingType, BuildInputContainerInfo(inputContainer), BuildOutputContainerInfo(outputContainer),
bufferReagents, bufferCurrentVolume, chemMaster.PillType, chemMaster.PillDosageLimit, updateLabel);
_userInterfaceSystem.SetUiState(owner, ChemMasterUiKey.Key, state);
ClickSound(chemMaster);
}
+ private void OnCycleSortingTypeMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterSortingTypeCycleMessage message)
+ {
+ chemMaster.Comp.SortingType++;
+ if (chemMaster.Comp.SortingType > ChemMasterSortingType.Latest)
+ chemMaster.Comp.SortingType = ChemMasterSortingType.None;
+ UpdateUiState(chemMaster);
+ ClickSound(chemMaster);
+ }
+
private void OnSetPillTypeMessage(Entity<ChemMasterComponent> chemMaster, ref ChemMasterSetPillTypeMessage message)
{
// Ensure valid pill type. There are 20 pills selectable, 0-19.
Discard,
}
+ public enum ChemMasterSortingType : byte
+ {
+ None = 0,
+ Alphabetical = 1,
+ Quantity = 2,
+ Latest = 3,
+ }
+
+ [Serializable, NetSerializable]
+ public sealed class ChemMasterSortingTypeCycleMessage : BoundUserInterfaceMessage;
+
+
public enum ChemMasterReagentAmount
{
U1 = 1,
public readonly ChemMasterMode Mode;
+ public readonly ChemMasterSortingType SortingType;
+
public readonly FixedPoint2? BufferCurrentVolume;
public readonly uint SelectedPillType;
public readonly bool UpdateLabel;
public ChemMasterBoundUserInterfaceState(
- ChemMasterMode mode, ContainerInfo? inputContainerInfo, ContainerInfo? outputContainerInfo,
+ ChemMasterMode mode, ChemMasterSortingType sortingType, ContainerInfo? inputContainerInfo, ContainerInfo? outputContainerInfo,
IReadOnlyList<ReagentQuantity> bufferReagents, FixedPoint2 bufferCurrentVolume,
uint selectedPillType, uint pillDosageLimit, bool updateLabel)
{
OutputContainerInfo = outputContainerInfo;
BufferReagents = bufferReagents;
Mode = mode;
+ SortingType = sortingType;
BufferCurrentVolume = bufferCurrentVolume;
SelectedPillType = selectedPillType;
PillDosageLimit = pillDosageLimit;