Cleaner BoundUserInterfaces (#17736)
This commit is contained in:
@@ -4,14 +4,11 @@ using Content.Client.Computer;
|
||||
using Content.Shared.Solar;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.Power
|
||||
@@ -19,6 +16,7 @@ namespace Content.Client.Power
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class SolarControlWindow : DefaultWindow, IComputerWindow<SolarControlConsoleBoundInterfaceState>
|
||||
{
|
||||
[ViewVariables]
|
||||
private SolarControlConsoleBoundInterfaceState _lastState = new(0, 0, 0, 0);
|
||||
|
||||
public SolarControlWindow()
|
||||
@@ -28,9 +26,10 @@ namespace Content.Client.Power
|
||||
|
||||
public void SetupComputerWindow(ComputerBoundUserInterfaceBase cb)
|
||||
{
|
||||
PanelRotation.OnTextEntered += text => {
|
||||
double value;
|
||||
if (!double.TryParse((string?) text.Text, out value)) return;
|
||||
PanelRotation.OnTextEntered += text =>
|
||||
{
|
||||
if (!double.TryParse((string?) text.Text, out var value))
|
||||
return;
|
||||
|
||||
SolarControlConsoleAdjustMessage msg = new()
|
||||
{
|
||||
@@ -43,9 +42,11 @@ namespace Content.Client.Power
|
||||
_lastState.Rotation = msg.Rotation;
|
||||
NotARadar.UpdateState(_lastState);
|
||||
};
|
||||
PanelVelocity.OnTextEntered += text => {
|
||||
double value;
|
||||
if (!double.TryParse((string?) text.Text, out value)) return;
|
||||
|
||||
PanelVelocity.OnTextEntered += text =>
|
||||
{
|
||||
if (!double.TryParse((string?) text.Text, out var value))
|
||||
return;
|
||||
|
||||
SolarControlConsoleAdjustMessage msg = new()
|
||||
{
|
||||
@@ -61,14 +62,14 @@ namespace Content.Client.Power
|
||||
};
|
||||
}
|
||||
|
||||
private string FormatAngle(Angle d)
|
||||
private static string FormatAngle(Angle d)
|
||||
{
|
||||
return d.Degrees.ToString("F1");
|
||||
}
|
||||
|
||||
// The idea behind this is to prevent every update from the server
|
||||
// breaking the textfield.
|
||||
private void UpdateField(LineEdit field, string newValue)
|
||||
private static void UpdateField(LineEdit field, string newValue)
|
||||
{
|
||||
if (!field.HasKeyboardFocus())
|
||||
{
|
||||
@@ -92,7 +93,7 @@ namespace Content.Client.Power
|
||||
{
|
||||
// This is used for client-side prediction of the panel rotation.
|
||||
// This makes the display feel a lot smoother.
|
||||
private IGameTiming _gameTiming = IoCManager.Resolve<IGameTiming>();
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private SolarControlConsoleBoundInterfaceState _lastState = new(0, 0, 0, 0);
|
||||
|
||||
@@ -105,6 +106,7 @@ namespace Content.Client.Power
|
||||
|
||||
public SolarControlNotARadar()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
MinSize = new Vector2(SizeFull, SizeFull);
|
||||
}
|
||||
|
||||
@@ -114,7 +116,7 @@ namespace Content.Client.Power
|
||||
_lastStateTime = _gameTiming.CurTime;
|
||||
}
|
||||
|
||||
public Angle PredictedPanelRotation => _lastState.Rotation + (_lastState.AngularVelocity * ((_gameTiming.CurTime - _lastStateTime).TotalSeconds));
|
||||
public Angle PredictedPanelRotation => _lastState.Rotation + _lastState.AngularVelocity * (_gameTiming.CurTime - _lastStateTime).TotalSeconds;
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
@@ -137,7 +139,7 @@ namespace Content.Client.Power
|
||||
|
||||
for (var i = 0; i < gridLinesRadial; i++)
|
||||
{
|
||||
Angle angle = (Math.PI / gridLinesRadial) * i;
|
||||
Angle angle = Math.PI / gridLinesRadial * i;
|
||||
var aExtent = angle.ToVec() * RadiusCircle;
|
||||
handle.DrawLine(new Vector2(point, point) - aExtent, new Vector2(point, point) + aExtent, gridLines);
|
||||
}
|
||||
@@ -162,6 +164,8 @@ namespace Content.Client.Power
|
||||
[UsedImplicitly]
|
||||
public sealed class SolarControlConsoleBoundUserInterface : ComputerBoundUserInterface<SolarControlWindow, SolarControlConsoleBoundInterfaceState>
|
||||
{
|
||||
public SolarControlConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {}
|
||||
public SolarControlConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user