Enable nullability in Content.Client (#3257)

* Enable nullability in Content.Client

* Remove #nullable enable

* Merge fixes

* Remove Debug.Assert

* Merge fixes

* Fix build

* Fix build
This commit is contained in:
DrSmugleaf
2021-03-10 14:48:29 +01:00
committed by GitHub
parent 4f9bd4e802
commit 902aa128c2
270 changed files with 1774 additions and 1550 deletions

View File

@@ -9,11 +9,10 @@ namespace Content.Client.GameObjects.Components.Power.AME
[UsedImplicitly]
public class AMEControllerBoundUserInterface : BoundUserInterface
{
private AMEWindow _window;
private AMEWindow? _window;
public AMEControllerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
}
protected override void Open()
@@ -31,7 +30,6 @@ namespace Content.Client.GameObjects.Components.Power.AME
_window.RefreshPartsButton.OnPressed += _ => ButtonPressed(UiButton.RefreshParts);
}
/// <summary>
/// Update the ui each time new state data is sent from the server.
/// </summary>
@@ -58,7 +56,7 @@ namespace Content.Client.GameObjects.Components.Power.AME
if (disposing)
{
_window.Dispose();
_window?.Dispose();
}
}
}

View File

@@ -17,7 +17,7 @@ namespace Content.Client.GameObjects.Components.Power.AME
public Button IncreaseFuelButton { get; set; }
public Button DecreaseFuelButton { get; set; }
public Button RefreshPartsButton { get; set; }
public ProgressBar FuelMeter { get; set; }
public ProgressBar? FuelMeter { get; set; }
public Label FuelAmount { get; set; }
public Label InjectionAmount { get; set; }
public Label CoreCount { get; set; }
@@ -89,10 +89,8 @@ namespace Content.Client.GameObjects.Components.Power.AME
}
}
});
}
/// <summary>
/// This searches recursively through all the children of "parent"
/// and sets the Disabled value of any buttons found to "val"
@@ -162,7 +160,6 @@ namespace Content.Client.GameObjects.Components.Power.AME
CoreCount.Text = $"{castState.CoreCount}";
InjectionAmount.Text = $"{castState.InjectionAmount}";
}
}
}

View File

@@ -14,10 +14,10 @@ namespace Content.Client.GameObjects.Components.Power
[UsedImplicitly]
public class ApcBoundUserInterface : BoundUserInterface
{
private ApcWindow _window;
private BaseButton _breakerButton;
private Label _externalPowerStateLabel;
private ProgressBar _chargeBar;
private ApcWindow? _window;
private BaseButton? _breakerButton;
private Label? _externalPowerStateLabel;
private ProgressBar? _chargeBar;
protected override void Open()
{
@@ -44,33 +44,52 @@ namespace Content.Client.GameObjects.Components.Power
var castState = (ApcBoundInterfaceState) state;
_breakerButton.Pressed = castState.MainBreaker;
switch (castState.ApcExternalPower)
if (_breakerButton != null)
{
case ApcExternalPowerState.None:
_externalPowerStateLabel.Text = "None";
_externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
break;
case ApcExternalPowerState.Low:
_externalPowerStateLabel.Text = "Low";
_externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateLow);
break;
case ApcExternalPowerState.Good:
_externalPowerStateLabel.Text = "Good";
_externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateGood);
break;
default:
throw new ArgumentOutOfRangeException();
_breakerButton.Pressed = castState.MainBreaker;
}
_chargeBar.Value = castState.Charge;
UpdateChargeBarColor(castState.Charge);
var chargePercentage = (castState.Charge / _chargeBar.MaxValue) * 100.0f;
_window.ChargePercentage.Text = " " + chargePercentage.ToString("0.00") + "%";
if (_externalPowerStateLabel != null)
{
switch (castState.ApcExternalPower)
{
case ApcExternalPowerState.None:
_externalPowerStateLabel.Text = "None";
_externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone);
break;
case ApcExternalPowerState.Low:
_externalPowerStateLabel.Text = "Low";
_externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateLow);
break;
case ApcExternalPowerState.Good:
_externalPowerStateLabel.Text = "Good";
_externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateGood);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
if (_chargeBar != null)
{
_chargeBar.Value = castState.Charge;
UpdateChargeBarColor(castState.Charge);
if (_window != null)
{
var chargePercentage = (castState.Charge / _chargeBar.MaxValue) * 100.0f;
_window.ChargePercentage.Text = " " + chargePercentage.ToString("0.00") + "%";
}
}
}
private void UpdateChargeBarColor(float charge)
{
if (_chargeBar == null)
{
return;
}
var normalizedCharge = charge / _chargeBar.MaxValue;
const float leftHue = 0.0f; // Red
@@ -97,10 +116,7 @@ namespace Content.Client.GameObjects.Components.Power
}
// Check if null first to avoid repeatedly creating this.
if (_chargeBar.ForegroundStyleBoxOverride == null)
{
_chargeBar.ForegroundStyleBoxOverride = new StyleBoxFlat();
}
_chargeBar.ForegroundStyleBoxOverride ??= new StyleBoxFlat();
var foregroundStyleBoxOverride = (StyleBoxFlat) _chargeBar.ForegroundStyleBoxOverride;
foregroundStyleBoxOverride.BackgroundColor =
@@ -113,7 +129,7 @@ namespace Content.Client.GameObjects.Components.Power
if (disposing)
{
_window.Dispose();
_window?.Dispose();
}
}

View File

@@ -1,11 +1,8 @@
using System.Diagnostics;
using Content.Shared.GameObjects.Components.Power;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Power
{
@@ -13,7 +10,7 @@ namespace Content.Client.GameObjects.Components.Power
public class PowerCellVisualizer : AppearanceVisualizer
{
[DataField("prefix")]
private string _prefix;
private string? _prefix;
public override void InitializeEntity(IEntity entity)
{
@@ -21,8 +18,11 @@ namespace Content.Client.GameObjects.Components.Power
var sprite = entity.GetComponent<ISpriteComponent>();
sprite.LayerMapSet(Layers.Charge, sprite.AddLayerState($"{_prefix}_100"));
sprite.LayerSetShader(Layers.Charge, "unshaded");
if (_prefix != null)
{
sprite.LayerMapSet(Layers.Charge, sprite.AddLayerState($"{_prefix}_100"));
sprite.LayerSetShader(Layers.Charge, "unshaded");
}
}
public override void OnChangeData(AppearanceComponent component)

View File

@@ -16,9 +16,9 @@ namespace Content.Client.GameObjects.Components.Power
[UsedImplicitly]
public class SolarControlConsoleBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IGameTiming _gameTiming = default;
[Dependency] private readonly IGameTiming _gameTiming = default!;
private SolarControlWindow _window;
private SolarControlWindow? _window;
private SolarControlConsoleBoundInterfaceState _lastState = new(0, 0, 0, 0);
protected override void Open()
@@ -73,6 +73,11 @@ namespace Content.Client.GameObjects.Components.Power
{
base.UpdateState(state);
if (_window == null)
{
return;
}
SolarControlConsoleBoundInterfaceState scc = (SolarControlConsoleBoundInterfaceState) state;
_lastState = scc;
_window.NotARadar.UpdateState(scc);
@@ -88,7 +93,7 @@ namespace Content.Client.GameObjects.Components.Power
if (disposing)
{
_window.Dispose();
_window?.Dispose();
}
}
@@ -180,27 +185,27 @@ namespace Content.Client.GameObjects.Components.Power
protected override void Draw(DrawingHandleScreen handle)
{
int point = SizeFull / 2;
Color fakeAA = new Color(0.08f, 0.08f, 0.08f);
Color gridLines = new Color(0.08f, 0.08f, 0.08f);
int panelExtentCutback = 4;
int gridLinesRadial = 8;
int gridLinesEquatorial = 8;
var point = SizeFull / 2;
var fakeAA = new Color(0.08f, 0.08f, 0.08f);
var gridLines = new Color(0.08f, 0.08f, 0.08f);
var panelExtentCutback = 4;
var gridLinesRadial = 8;
var gridLinesEquatorial = 8;
// Draw base
handle.DrawCircle((point, point), RadiusCircle + 1, fakeAA);
handle.DrawCircle((point, point), RadiusCircle, Color.Black);
// Draw grid lines
for (int i = 0; i < gridLinesEquatorial; i++)
for (var i = 0; i < gridLinesEquatorial; i++)
{
handle.DrawCircle((point, point), (RadiusCircle / gridLinesEquatorial) * i, gridLines, false);
}
for (int i = 0; i < gridLinesRadial; i++)
for (var i = 0; i < gridLinesRadial; i++)
{
Angle angle = (Math.PI / gridLinesRadial) * i;
Vector2 aExtent = angle.ToVec() * RadiusCircle;
var aExtent = angle.ToVec() * RadiusCircle;
handle.DrawLine((point, point) - aExtent, (point, point) + aExtent, gridLines);
}
@@ -209,12 +214,12 @@ namespace Content.Client.GameObjects.Components.Power
Angle predictedPanelRotation = _lastState.Rotation + (_lastState.AngularVelocity * ((_gameTiming.CurTime - _lastStateTime).TotalSeconds));
Vector2 extent = predictedPanelRotation.ToVec() * rotMul * RadiusCircle;
var extent = predictedPanelRotation.ToVec() * rotMul * RadiusCircle;
Vector2 extentOrtho = (extent.Y, -extent.X);
handle.DrawLine((point, point) - extentOrtho, (point, point) + extentOrtho, Color.White);
handle.DrawLine((point, point) + (extent / panelExtentCutback), (point, point) + extent - (extent / panelExtentCutback), Color.DarkGray);
Vector2 sunExtent = _lastState.TowardsSun.ToVec() * rotMul * RadiusCircle;
var sunExtent = _lastState.TowardsSun.ToVec() * rotMul * RadiusCircle;
handle.DrawLine((point, point) + sunExtent, (point, point), Color.Yellow);
}
}