/// <summary> /// Update the ui each time new state data is sent from the server. /// </summary> /// <param name="state"> /// Data of the <see cref="SharedReagentDispenserComponent"/> that this ui represents. /// Sent from the server. /// </param> protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); var castState = (ReagentDispenserBoundUserInterfaceState)state; _lastState = castState; UpdateReagentsList(castState.Inventory); //Update reagents list & reagent button actions _window?.UpdateState(castState); //Update window state }
/// <summary> /// Update the fill state and list of reagents held by the current reagent container, if applicable. /// <para>Also highlights a reagent if it's dispense button is being mouse hovered.</para> /// </summary> /// <param name="state">State data for the dispenser.</param> /// <param name="highlightedReagentId">Prototype id of the reagent whose dispense button is currently being mouse hovered.</param> public void UpdateContainerInfo(ReagentDispenserBoundUserInterfaceState state, string highlightedReagentId = "") { ContainerInfo.Children.Clear(); if (!state.HasBeaker) { ContainerInfo.Children.Add(new Label { Text = Loc.GetString("reagent-dispenser-window-no-container-loaded-text") }); return; } ContainerInfo.Children.Add(new BoxContainer // Name of the container and its fill status (Ex: 44/100u) { Orientation = LayoutOrientation.Horizontal, Children = { new Label { Text = $"{state.ContainerName}: " }, new Label { Text = $"{state.BeakerCurrentVolume}/{state.BeakerMaxVolume}", StyleClasses ={ StyleNano.StyleClassLabelSecondaryColor } } } }); if (state.ContainerReagents == null) { return; } foreach (var reagent in state.ContainerReagents) { var name = Loc.GetString("reagent-dispenser-window-unknown-reagent-text"); //Try to the prototype for the given reagent. This gives us it's name. if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto)) { name = proto.Name; } //Check if the reagent is being moused over. If so, color it green. if (proto != null && proto.ID == highlightedReagentId) { ContainerInfo.Children.Add(new BoxContainer { Orientation = LayoutOrientation.Horizontal, Children = { new Label { Text = $"{name}: ", StyleClasses ={ StyleNano.StyleClassPowerStateGood } }, new Label { Text = Loc.GetString("reagent-dispenser-window-quantity-label-text", ("quantity", reagent.Quantity)), StyleClasses ={ StyleNano.StyleClassPowerStateGood } } } });