Fix gas cannister slider log spam. (#6628)

This commit is contained in:
Leon Friedrich
2022-02-20 08:15:47 +13:00
committed by GitHub
parent 79f722b4ca
commit 56fc6011f1
5 changed files with 38 additions and 10 deletions

View File

@@ -32,7 +32,7 @@ namespace Content.Client.Atmos.UI
_window.OnClose += Close; _window.OnClose += Close;
_window.ReleaseValveCloseButtonPressed += OnReleaseValveClosePressed; _window.ReleaseValveCloseButtonPressed += OnReleaseValveClosePressed;
_window.ReleaseValveOpenButtonPressed += OnReleaseValveOpenPressed; _window.ReleaseValveOpenButtonPressed += OnReleaseValveOpenPressed;
_window.ReleasePressureSliderChanged += OnReleasePressurePressed; _window.ReleasePressureSet += OnReleasePressureSet;
_window.TankEjectButtonPressed += OnTankEjectPressed; _window.TankEjectButtonPressed += OnTankEjectPressed;
} }
@@ -41,7 +41,7 @@ namespace Content.Client.Atmos.UI
SendMessage(new GasCanisterHoldingTankEjectMessage()); SendMessage(new GasCanisterHoldingTankEjectMessage());
} }
private void OnReleasePressurePressed(float value) private void OnReleasePressureSet(float value)
{ {
SendMessage(new GasCanisterChangeReleasePressureMessage(value)); SendMessage(new GasCanisterChangeReleasePressureMessage(value));
} }

View File

@@ -37,7 +37,7 @@
</BoxContainer> </BoxContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="15 0 0 15" SeparationOverride="5"> <BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="15 0 0 15" SeparationOverride="5">
<Slider Name="ReleasePressureSlider" HorizontalExpand="True"/> <Slider Name="ReleasePressureSlider" HorizontalExpand="True"/>
<Label Name="ReleasePressureLabel" Align="Center" HorizontalExpand="True"/> <FloatSpinBox Name="ReleasePressure" MaxWidth="150" Align="Center"/>
</BoxContainer> </BoxContainer>
</BoxContainer> </BoxContainer>
<BoxContainer Orientation="Horizontal"> <BoxContainer Orientation="Horizontal">

View File

@@ -1,9 +1,11 @@
using System; using System;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Localization; using Robust.Shared.Input;
using Range = Robust.Client.UserInterface.Controls.Range;
namespace Content.Client.Atmos.UI namespace Content.Client.Atmos.UI
{ {
@@ -16,7 +18,7 @@ namespace Content.Client.Atmos.UI
private readonly ButtonGroup _buttonGroup = new(); private readonly ButtonGroup _buttonGroup = new();
public event Action? TankEjectButtonPressed; public event Action? TankEjectButtonPressed;
public event Action<float>? ReleasePressureSliderChanged; public event Action<float>? ReleasePressureSet;
public event Action? ReleaseValveCloseButtonPressed; public event Action? ReleaseValveCloseButtonPressed;
public event Action? ReleaseValveOpenButtonPressed; public event Action? ReleaseValveOpenButtonPressed;
@@ -31,7 +33,30 @@ namespace Content.Client.Atmos.UI
ReleaseValveOpenButton.OnPressed += _ => ReleaseValveOpenButtonPressed?.Invoke(); ReleaseValveOpenButton.OnPressed += _ => ReleaseValveOpenButtonPressed?.Invoke();
TankEjectButton.OnPressed += _ => TankEjectButtonPressed?.Invoke(); TankEjectButton.OnPressed += _ => TankEjectButtonPressed?.Invoke();
ReleasePressureSlider.OnValueChanged += r => ReleasePressureSliderChanged?.Invoke(r.Value); ReleasePressureSlider.OnKeyBindUp += OnReleasePressureSliderReleased;
ReleasePressureSlider.OnValueChanged += OnReleasePressureSliderChanged;
ReleasePressure.OnValueChanged += OnReleasePressureChanged;
}
private void OnReleasePressureChanged(FloatSpinBox.FloatSpinBoxEventArgs args)
{
var value = Math.Clamp(args.Value, ReleasePressureSlider.MinValue, ReleasePressureSlider.MaxValue);
ReleasePressureSlider.SetValueWithoutEvent(value);
ReleasePressureSet?.Invoke(value);
}
private void OnReleasePressureSliderChanged(Range range)
{
ReleasePressure.Value = range.Value;
}
private void OnReleasePressureSliderReleased(GUIBoundKeyEventArgs args)
{
if (args.Function != EngineKeyFunctions.UIClick)
return;
ReleasePressureSet?.Invoke(ReleasePressureSlider.Value);
} }
public void SetCanisterLabel(string label) public void SetCanisterLabel(string label)
@@ -82,9 +107,12 @@ namespace Content.Client.Atmos.UI
public void SetReleasePressure(float pressure) public void SetReleasePressure(float pressure)
{ {
if (MathHelper.CloseTo(pressure, ReleasePressure.Value))
return;
if(!ReleasePressureSlider.Grabbed) if(!ReleasePressureSlider.Grabbed)
ReleasePressureSlider.SetValueWithoutEvent(pressure); ReleasePressureSlider.SetValueWithoutEvent(pressure);
ReleasePressureLabel.Text = Loc.GetString("comp-gas-canister-ui-pressure", ("pressure", Math.Round(pressure))); ReleasePressure.Value = pressure;
} }
public void SetReleaseValve(bool valve) public void SetReleaseValve(bool valve)

View File

@@ -191,12 +191,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
} }
} }
DirtyUI(uid, canister, nodeContainer, containerManager);
// If last pressure is very close to the current pressure, do nothing. // If last pressure is very close to the current pressure, do nothing.
if (MathHelper.CloseToPercent(canister.Air.Pressure, canister.LastPressure)) if (MathHelper.CloseToPercent(canister.Air.Pressure, canister.LastPressure))
return; return;
DirtyUI(uid, canister, nodeContainer, containerManager);
canister.LastPressure = canister.Air.Pressure; canister.LastPressure = canister.Air.Pressure;
if (canister.Air.Pressure < 10) if (canister.Air.Pressure < 10)

View File

@@ -13,7 +13,7 @@ comp-gas-canister-ui-holding-tank-pressure = Tank Pressure:
comp-gas-canister-ui-holding-tank-eject = Eject comp-gas-canister-ui-holding-tank-eject = Eject
comp-gas-canister-ui-release-valve-status = Release Valve Status comp-gas-canister-ui-release-valve-status = Release Valve Status
comp-gas-canister-ui-release-pressure = Release Pressure: comp-gas-canister-ui-release-pressure = Release Pressure (kPa):
comp-gas-canister-ui-release-valve = Release Valve: comp-gas-canister-ui-release-valve = Release Valve:
comp-gas-canister-ui-release-valve-open = Open comp-gas-canister-ui-release-valve-open = Open
comp-gas-canister-ui-release-valve-close = Close comp-gas-canister-ui-release-valve-close = Close