* Apply patch 1777eea9a4..6b32bb2b14
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* make red squiggly line go away
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Add todo list
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Add palette to `TextureButton`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Rename `PalettedButtonSheetlet` to `NTButtonSheetlet` and move useful methods to `ButtonSheetlet`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* migrate `ContextMenu` styles
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Update todo
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* tweak NT colors
* New stylesheet: `InterfaceStylesheet` & `InterfaceTooltipSheetlet`
* Move inheritance of `IButtonConfig` to `NanotransenStylesheet.Buttons`
* move `MenuButtonSheetlet` & actually implement `InterfaceStylesheet` correctly
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* tweak color & update todo
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* chat is this real (update chat palette)
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Update todo
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* `SmallButton` and remove some obsolete things from `StyleNano`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* rename `StyleClasses` to `StyleClass` so `Stylesheets.Redux.StyleClasses` syntax is dead
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* replace `ButtonColorGreen` with `Positive`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* `Placeholder`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Examine popup buttons
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* move over more things & cleanup `StyleNano` more (under 1000 lines!!!!)
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Remove some more redundant stuff
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Undo style change for chat window
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* paper editing works now
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* `OptionButton` styles
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* `ListContainer`, move `DefaultWindow` styles (for now) & more cleanup
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* fix `ActionButton` not having highlighting
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* remove imports of `Robust.Client.UserInterface.StylesheetHelpers` & format
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* `ButtonBig` and more cleanup
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Move items inheriting from `ISheetletConfig` into their own directory
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Cleanup & move `Label` styles
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Action search box styles
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Moved, stuff is
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* rename `LabelSubtext` to `LabelSubText` & move more stuff (were almost there!!)
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* yap & move over MORE stuff (just like one thing left!!!)
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Change status classes to appropriate existing classes
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* remove remaining references to `StyleNano`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Fix some hardcoding & broken code, `GetFromControl`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Scrollbars!
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* chores
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* clean up `StyleClass.cs`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* `ItemListSheetlet` refactor
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* more chores!
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Consistency w/ directory structure
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Move `MainMenuSheetlet`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* `ColorPalette`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* whoopsie
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Remove most sheet-specific sheetlets
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* fix warnings, cleanup, & fix scrollbar (this is why we fix warnings boys)
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* yap
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* MASSIVE resharper skill issue
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* actually use `ISheetletConfig`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* have specific sheetlet be specific
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* `GetResourceOr`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* cleanup & move / remove `IPalette`s
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* actually do specific stylesheets correctly & fix tooltips
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* cleanup & logging
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* Move `FontKind` and `FontKindExtensions` to their own files
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* rename `InterfaceStylesheet` to `SystemStylesheet`
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* change `ButtonHovered` etc to `PseudoHovered` etc
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* give the palettes fun names
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* `StyleSpace` is no more
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* It should compile now! I am now going to bed (fr) if it fails it fails
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* make squiggly red line go away
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
* add additional type restrictions to sheetlets
* `CommonStylesheet`
* minor cleanup
* Make `GetSheetletRules` not horrible
* wait this was duplicating style rules. oops!
* move some sheetlets to their associated xamls
* oh wait apparently that was important
* review pass 1
* review pass 2 (font & color stuff)
* review pass 3: remove unused stuff / filename fix
* fix warnings & "replace cast with explicit variable type"
* move `Palette` stuff to its own directory
* tweak colors (they're different now that I actually fixed the OKlab thing)
* review pass 4: little things
* make window close button grey before hovering
* refactor `HLine` to make it less terrible and allow it to be styled
* fix `NanoHeading` (it's been broken for a while whoops) and cleanup hardcoding
* band-aid missing references in `StyleNano`
* move `StyleBox` generating functions out of `IButtonSheetlet` into `StyleBoxHelper`
* remove dictionary field from `IStylesheetManager`
* Add check for unloaded sheetlets
* style tweaks to satisfy OCD
* I somehow missed this: `Caution` styleclass replaced with `negative`, refactor `PowerChargeWindow`
* tweak palettes for like the fourth time
* construct `StyleNano` / `StyleSpace` in `StylesheetManager` and mark them as obsolete
* rename `BackgroundPanel` classes for consistency
* tweak window / `ListContainer`
* oh right you use `///` not `/**`
* font system is bad, make it temporary
* acknowledge Divider funkyness
* remove use of class `Disabled`
* `ColorPalette` allow overriding colors with brace initialization
* review pass again
* tweak disabled button colors
* `StatusPalette` tweaks
* typo
* Make squiggly red line go away
* Delete `Redux`
* Remove all references to `Redux`
* make red less radioactive
* Store stylesheet name inside stylesheet class
* fix merge errors
* use RT's Oklab support instead
* shuffle around `StylesheetManager` fields
* apply stylesheets based off `StylesheetComponent`
* simplify `ColorPalette` construction
* add todo for `SheetletConfigType`
* `OptionButton` has a background color now
* fix disabled buttons
* sigh (red color palette fixed)
* make `ItemList` use primary palette
* Revert "apply stylesheets based off `StylesheetComponent`"
This reverts commit c05b147da845f6e04ff33d1cbd91a18a92c676d7.
* dead code removal
* buttons are green when pressed (we need togglebuttons)
---------
Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com>
Co-authored-by: Janet Blackquill <uhhadd@gmail.com>
434 lines
18 KiB
C#
434 lines
18 KiB
C#
using Content.Client.Stylesheets;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.Chemistry;
|
|
using Content.Shared.Chemistry.Reagent;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Utility;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using Content.Shared.FixedPoint;
|
|
using Robust.Client.Graphics;
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
|
using Robust.Client.GameObjects;
|
|
|
|
namespace Content.Client.Chemistry.UI
|
|
{
|
|
/// <summary>
|
|
/// Client-side UI used to control a <see cref="SharedChemMasterComponent"/>
|
|
/// </summary>
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class ChemMasterWindow : FancyWindow
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
private readonly SpriteSystem _sprite;
|
|
|
|
public event Action<BaseButton.ButtonEventArgs, ReagentButton>? OnReagentButtonPressed;
|
|
public readonly Button[] PillTypeButtons;
|
|
|
|
private const string PillsRsiPath = "/Textures/Objects/Specific/Chemistry/pills.rsi";
|
|
|
|
/// <summary>
|
|
/// Create and initialize the chem master UI client-side. Creates the basic layout,
|
|
/// actual data isn't filled in until the server sends data about the chem master.
|
|
/// </summary>
|
|
public ChemMasterWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_sprite = _entityManager.System<SpriteSystem>();
|
|
|
|
// Pill type selection buttons, in total there are 20 pills.
|
|
// Pill rsi file should have states named as pill1, pill2, and so on.
|
|
var resourcePath = new ResPath(PillsRsiPath);
|
|
var pillTypeGroup = new ButtonGroup();
|
|
PillTypeButtons = new Button[20];
|
|
for (uint i = 0; i < PillTypeButtons.Length; i++)
|
|
{
|
|
// For every button decide which stylebase to have
|
|
// Every row has 10 buttons
|
|
String styleBase = StyleClass.ButtonOpenBoth;
|
|
uint modulo = i % 10;
|
|
if (i > 0 && modulo == 0)
|
|
styleBase = StyleClass.ButtonOpenRight;
|
|
else if (i > 0 && modulo == 9)
|
|
styleBase = StyleClass.ButtonOpenLeft;
|
|
else if (i == 0)
|
|
styleBase = StyleClass.ButtonOpenRight;
|
|
|
|
// Generate buttons
|
|
PillTypeButtons[i] = new Button
|
|
{
|
|
Access = AccessLevel.Public,
|
|
StyleClasses = { styleBase },
|
|
MaxSize = new Vector2(42, 28),
|
|
Group = pillTypeGroup
|
|
};
|
|
|
|
// Generate buttons textures
|
|
var specifier = new SpriteSpecifier.Rsi(resourcePath, "pill" + (i + 1));
|
|
TextureRect pillTypeTexture = new TextureRect
|
|
{
|
|
Texture = _sprite.Frame0(specifier),
|
|
TextureScale = new Vector2(1.75f, 1.75f),
|
|
Stretch = TextureRect.StretchMode.KeepCentered,
|
|
};
|
|
|
|
PillTypeButtons[i].AddChild(pillTypeTexture);
|
|
Grid.AddChild(PillTypeButtons[i]);
|
|
}
|
|
|
|
PillDosage.InitDefaultButtons();
|
|
PillNumber.InitDefaultButtons();
|
|
BottleDosage.InitDefaultButtons();
|
|
|
|
// Ensure label length is within the character limit.
|
|
LabelLineEdit.IsValid = s => s.Length <= SharedChemMaster.LabelMaxLength;
|
|
|
|
Tabs.SetTabTitle(0, Loc.GetString("chem-master-window-input-tab"));
|
|
Tabs.SetTabTitle(1, Loc.GetString("chem-master-window-output-tab"));
|
|
}
|
|
|
|
private ReagentButton MakeReagentButton(string text, ChemMasterReagentAmount amount, ReagentId id, bool isBuffer, string styleClass)
|
|
{
|
|
var reagentTransferButton = new ReagentButton(text, amount, id, isBuffer, styleClass);
|
|
reagentTransferButton.OnPressed += args
|
|
=> OnReagentButtonPressed?.Invoke(args, reagentTransferButton);
|
|
return reagentTransferButton;
|
|
}
|
|
/// <summary>
|
|
/// Conditionally generates a set of reagent buttons based on the supplied boolean argument.
|
|
/// This was moved outside of BuildReagentRow to facilitate conditional logic, stops indentation depth getting out of hand as well.
|
|
/// </summary>
|
|
private List<ReagentButton> CreateReagentTransferButtons(ReagentId reagent, bool isBuffer, bool addReagentButtons)
|
|
{
|
|
if (!addReagentButtons)
|
|
return new List<ReagentButton>(); // Return an empty list if reagentTransferButton creation is disabled.
|
|
|
|
var buttonConfigs = new (string text, ChemMasterReagentAmount amount, string styleClass)[]
|
|
{
|
|
("1", ChemMasterReagentAmount.U1, StyleClass.ButtonOpenBoth),
|
|
("5", ChemMasterReagentAmount.U5, StyleClass.ButtonOpenBoth),
|
|
("10", ChemMasterReagentAmount.U10, StyleClass.ButtonOpenBoth),
|
|
("15", ChemMasterReagentAmount.U15, StyleClass.ButtonOpenBoth),
|
|
("20", ChemMasterReagentAmount.U20, StyleClass.ButtonOpenBoth),
|
|
("25", ChemMasterReagentAmount.U25, StyleClass.ButtonOpenBoth),
|
|
("30", ChemMasterReagentAmount.U30, StyleClass.ButtonOpenBoth),
|
|
("50", ChemMasterReagentAmount.U50, StyleClass.ButtonOpenBoth),
|
|
("100", ChemMasterReagentAmount.U100, StyleClass.ButtonOpenBoth),
|
|
(Loc.GetString("chem-master-window-buffer-all-amount"), ChemMasterReagentAmount.All, StyleClass.ButtonOpenLeft),
|
|
};
|
|
|
|
var buttons = new List<ReagentButton>();
|
|
|
|
foreach (var (text, amount, styleClass) in buttonConfigs)
|
|
{
|
|
var reagentTransferButton = MakeReagentButton(text, amount, reagent, isBuffer, styleClass);
|
|
buttons.Add(reagentTransferButton);
|
|
}
|
|
|
|
return buttons;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update the UI state when new state data is received from the server.
|
|
/// </summary>
|
|
/// <param name="state">State data sent by the server.</param>
|
|
public void UpdateState(BoundUserInterfaceState state)
|
|
{
|
|
var castState = (ChemMasterBoundUserInterfaceState)state;
|
|
|
|
if (castState.UpdateLabel)
|
|
LabelLine = GenerateLabel(castState);
|
|
|
|
// 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 output = castState.OutputContainerInfo;
|
|
var remainingCapacity = output is null ? 0 : (output.MaxVolume - output.CurrentVolume).Int();
|
|
var holdsReagents = output?.Reagents != null;
|
|
var pillNumberMax = holdsReagents ? 0 : remainingCapacity;
|
|
var bottleAmountMax = holdsReagents ? remainingCapacity : 0;
|
|
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;
|
|
|
|
if (PillNumber.Value > pillNumberMax)
|
|
PillNumber.Value = pillNumberMax;
|
|
if (BottleDosage.Value > bottleAmountMax)
|
|
BottleDosage.Value = bottleAmountMax;
|
|
|
|
// Avoid division by zero
|
|
if (PillDosage.Value > 0)
|
|
{
|
|
PillNumber.Value = Math.Min(bufferVolume / PillDosage.Value, pillNumberMax);
|
|
}
|
|
else
|
|
{
|
|
PillNumber.Value = 0;
|
|
}
|
|
|
|
BottleDosage.Value = Math.Min(bottleAmountMax, bufferVolume);
|
|
}
|
|
/// <summary>
|
|
/// Generate a product label based on reagents in the buffer.
|
|
/// </summary>
|
|
/// <param name="state">State data sent by the server.</param>
|
|
private string GenerateLabel(ChemMasterBoundUserInterfaceState state)
|
|
{
|
|
if (state.BufferCurrentVolume == 0)
|
|
return "";
|
|
|
|
var reagent = state.BufferReagents.OrderBy(r => r.Quantity).First().Reagent;
|
|
_prototypeManager.TryIndex(reagent.Prototype, out ReagentPrototype? proto);
|
|
return proto?.LocalizedName ?? "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update the container, buffer, and packaging panels.
|
|
/// </summary>
|
|
/// <param name="state">State data for the dispenser.</param>
|
|
private void UpdatePanelInfo(ChemMasterBoundUserInterfaceState state)
|
|
{
|
|
BufferTransferButton.Pressed = state.Mode == ChemMasterMode.Transfer;
|
|
BufferDiscardButton.Pressed = state.Mode == ChemMasterMode.Discard;
|
|
|
|
BuildContainerUI(InputContainerInfo, state.InputContainerInfo, true);
|
|
BuildContainerUI(OutputContainerInfo, state.OutputContainerInfo, false);
|
|
|
|
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") });
|
|
|
|
return;
|
|
}
|
|
|
|
var bufferHBox = new BoxContainer
|
|
{
|
|
Orientation = LayoutOrientation.Horizontal
|
|
};
|
|
BufferInfo.AddChild(bufferHBox);
|
|
|
|
var bufferLabel = new Label { Text = $"{Loc.GetString("chem-master-window-buffer-label")} " };
|
|
bufferHBox.AddChild(bufferLabel);
|
|
var bufferVol = new Label
|
|
{
|
|
Text = $"{state.BufferCurrentVolume}u",
|
|
StyleClasses = { StyleClass.LabelWeak }
|
|
};
|
|
bufferHBox.AddChild(bufferVol);
|
|
|
|
// 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);
|
|
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();
|
|
|
|
if (info is null)
|
|
{
|
|
control.Children.Add(new Label
|
|
{
|
|
Text = Loc.GetString("chem-master-window-no-container-loaded-text")
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Name of the container and its fill status (Ex: 44/100u)
|
|
control.Children.Add(new BoxContainer
|
|
{
|
|
Orientation = LayoutOrientation.Horizontal,
|
|
Children =
|
|
{
|
|
new Label { Text = $"{info.DisplayName}: " },
|
|
new Label
|
|
{
|
|
Text = $"{info.CurrentVolume}/{info.MaxVolume}",
|
|
StyleClasses = { StyleClass.LabelWeak }
|
|
}
|
|
}
|
|
});
|
|
// Initialises rowCount to allow for striped rows
|
|
var rowCount = 0;
|
|
|
|
// Handle entities if they are not null
|
|
if (info.Entities != null)
|
|
{
|
|
foreach (var (id, quantity) in info.Entities.Select(x => (x.Id, x.Quantity)))
|
|
{
|
|
control.Children.Add(BuildReagentRow(default(Color), rowCount++, id, default(ReagentId), quantity, false, addReagentButtons));
|
|
}
|
|
}
|
|
|
|
// Handle reagents if they are not null
|
|
if (info.Reagents != null)
|
|
{
|
|
foreach (var reagent in info.Reagents)
|
|
{
|
|
_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));
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Take reagent/entity data and present rows, labels, and buttons appropriately. todo sprites?
|
|
/// </summary>
|
|
private Control BuildReagentRow(Color reagentColor, int rowCount, string name, ReagentId reagent, FixedPoint2 quantity, bool isBuffer, bool addReagentButtons)
|
|
{
|
|
//Colors rows and sets fallback for reagentcolor to the same as background, this will hide colorPanel for entities hopefully
|
|
var rowColor1 = Color.FromHex("#1B1B1E");
|
|
var rowColor2 = Color.FromHex("#202025");
|
|
var currentRowColor = (rowCount % 2 == 1) ? rowColor1 : rowColor2;
|
|
if ((reagentColor == default(Color))|(!addReagentButtons))
|
|
{
|
|
reagentColor = currentRowColor;
|
|
}
|
|
//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
|
|
{
|
|
Orientation = LayoutOrientation.Horizontal,
|
|
Children =
|
|
{
|
|
new Label { Text = $"{name}: " },
|
|
new Label
|
|
{
|
|
Text = $"{quantity}u",
|
|
StyleClasses = { StyleClass.LabelWeak }
|
|
},
|
|
|
|
// Padding
|
|
new Control { HorizontalExpand = true },
|
|
// Colored panels for reagents
|
|
new PanelContainer
|
|
{
|
|
Name = "colorPanel",
|
|
VerticalExpand = true,
|
|
MinWidth = 4,
|
|
PanelOverride = new StyleBoxFlat
|
|
{
|
|
BackgroundColor = reagentColor
|
|
},
|
|
Margin = new Thickness(0, 1)
|
|
}
|
|
}
|
|
};
|
|
|
|
// Add the reagent buttons after the color panel
|
|
foreach (var reagentTransferButton in reagentButtonConstructors)
|
|
{
|
|
rowContainer.AddChild(reagentTransferButton);
|
|
}
|
|
//Apply panencontainer to allow for striped rows
|
|
return new PanelContainer
|
|
{
|
|
PanelOverride = new StyleBoxFlat(currentRowColor),
|
|
Children = { rowContainer }
|
|
};
|
|
}
|
|
|
|
public string LabelLine
|
|
{
|
|
get => LabelLineEdit.Text;
|
|
set => LabelLineEdit.Text = value;
|
|
}
|
|
}
|
|
|
|
public sealed class ReagentButton : Button
|
|
{
|
|
public ChemMasterReagentAmount Amount { get; set; }
|
|
public bool IsBuffer = true;
|
|
public ReagentId Id { get; set; }
|
|
public ReagentButton(string text, ChemMasterReagentAmount amount, ReagentId id, bool isBuffer, string styleClass)
|
|
{
|
|
AddStyleClass(styleClass);
|
|
Text = text;
|
|
Amount = amount;
|
|
Id = id;
|
|
IsBuffer = isBuffer;
|
|
}
|
|
}
|
|
}
|