Chem Master & Dispenser Power Fixes (#1622)

* -ChemDispenser & Master can now open the UI without power
-Both can also eject beaker without power

* -Disables button if not powered
-Disables clear & eject buttons if no beaker

* Fix server freeze
This commit is contained in:
Exp
2020-08-10 16:30:56 +02:00
committed by GitHub
parent 9785a8e647
commit aaffd7e198
7 changed files with 119 additions and 23 deletions

View File

@@ -161,6 +161,29 @@ namespace Content.Client.GameObjects.Components.Chemistry
}
}
/// <summary>
/// This searches recursively through all the children of "parent"
/// and sets the Disabled value of any buttons found to "val"
/// </summary>
/// <param name="parent">The control which childrens get searched</param>
/// <param name="val">The value to which disabled gets set</param>
private void SetButtonDisabledRecursive(Control parent, bool val)
{
foreach (var child in parent.Children)
{
if (child is Button but)
{
but.Disabled = val;
continue;
}
if (child.Children != null)
{
SetButtonDisabledRecursive(child, val);
}
}
}
/// <summary>
/// Update the UI state when new state data is received from the server.
/// </summary>
@@ -171,6 +194,20 @@ namespace Content.Client.GameObjects.Components.Chemistry
Title = castState.DispenserName;
UpdateContainerInfo(castState);
// Disable all buttons if not powered
if (Contents.Children != null)
{
SetButtonDisabledRecursive(Contents, !castState.HasPower);
EjectButton.Disabled = false;
}
// Disable the Clear & Eject button if no beaker
if (!castState.HasBeaker)
{
ClearButton.Disabled = true;
EjectButton.Disabled = true;
}
switch (castState.SelectedDispenseAmount.Int())
{
case 1: