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:
@@ -13,6 +13,7 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
@@ -22,7 +23,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private MicrowaveMenu _menu;
|
||||
private MicrowaveMenu? _menu;
|
||||
|
||||
private readonly Dictionary<int, EntityUid> _solids = new();
|
||||
private readonly Dictionary<int, Solution.ReagentQuantity> _reagents =new();
|
||||
@@ -38,8 +39,8 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
_menu = new MicrowaveMenu(this);
|
||||
_menu.OpenCentered();
|
||||
_menu.OnClose += Close;
|
||||
_menu.StartButton.OnPressed += args => SendMessage(new SharedMicrowaveComponent.MicrowaveStartCookMessage());
|
||||
_menu.EjectButton.OnPressed += args => SendMessage(new SharedMicrowaveComponent.MicrowaveEjectMessage());
|
||||
_menu.StartButton.OnPressed += _ => SendMessage(new SharedMicrowaveComponent.MicrowaveStartCookMessage());
|
||||
_menu.EjectButton.OnPressed += _ => SendMessage(new SharedMicrowaveComponent.MicrowaveEjectMessage());
|
||||
_menu.IngredientsList.OnItemSelected += args =>
|
||||
{
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveEjectSolidIndexedMessage(_solids[args.ItemIndex]));
|
||||
@@ -55,20 +56,20 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
_menu.OnCookTimeSelected += (args,buttonIndex) =>
|
||||
{
|
||||
var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button ;
|
||||
var newTime = actualButton.CookTime;
|
||||
SendMessage(new SharedMicrowaveComponent.MicrowaveSelectCookTimeMessage(buttonIndex,actualButton.CookTime));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (!disposing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_solids?.Clear();
|
||||
|
||||
_solids.Clear();
|
||||
_menu?.Dispose();
|
||||
}
|
||||
|
||||
@@ -80,24 +81,34 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
return;
|
||||
}
|
||||
_menu.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy);
|
||||
|
||||
_menu?.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy);
|
||||
RefreshContentsDisplay(cState.ReagentQuantities, cState.ContainedSolids);
|
||||
var currentlySelectedTimeButton = (Button) _menu.CookTimeButtonVbox.GetChild(cState.ActiveButtonIndex);
|
||||
currentlySelectedTimeButton.Pressed = true;
|
||||
var label = cState.ActiveButtonIndex <= 0 ? Loc.GetString("INSTANT") : cState.CurrentCookTime.ToString();
|
||||
_menu._cookTimeInfoLabel.Text = $"{Loc.GetString("COOK TIME")}: {label}";
|
||||
|
||||
if (_menu != null)
|
||||
{
|
||||
var currentlySelectedTimeButton = (Button) _menu.CookTimeButtonVbox.GetChild(cState.ActiveButtonIndex);
|
||||
currentlySelectedTimeButton.Pressed = true;
|
||||
var label = cState.ActiveButtonIndex <= 0 ? Loc.GetString("INSTANT") : cState.CurrentCookTime.ToString();
|
||||
_menu._cookTimeInfoLabel.Text = $"{Loc.GetString("COOK TIME")}: {label}";
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshContentsDisplay(Solution.ReagentQuantity[] reagents, EntityUid[] containedSolids)
|
||||
{
|
||||
_reagents.Clear();
|
||||
|
||||
if (_menu == null) return;
|
||||
|
||||
_menu.IngredientsListReagents.Clear();
|
||||
for (var i = 0; i < reagents.Length; i++)
|
||||
{
|
||||
_prototypeManager.TryIndex(reagents[i].ReagentId, out ReagentPrototype proto);
|
||||
var reagentAdded = _menu.IngredientsListReagents.AddItem($"{reagents[i].Quantity} {proto.Name}");
|
||||
var reagentIndex = _menu.IngredientsListReagents.IndexOf(reagentAdded);
|
||||
_reagents.Add(reagentIndex, reagents[i]);
|
||||
if (_prototypeManager.TryIndex(reagents[i].ReagentId, out ReagentPrototype? proto))
|
||||
{
|
||||
var reagentAdded = _menu.IngredientsListReagents.AddItem($"{reagents[i].Quantity} {proto.Name}");
|
||||
var reagentIndex = _menu.IngredientsListReagents.IndexOf(reagentAdded);
|
||||
_reagents.Add(reagentIndex, reagents[i]);
|
||||
}
|
||||
}
|
||||
|
||||
_solids.Clear();
|
||||
@@ -108,31 +119,34 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.Deleted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Texture texture;
|
||||
if (entity.TryGetComponent(out IconComponent iconComponent))
|
||||
Texture? texture;
|
||||
if (entity.TryGetComponent(out IconComponent? iconComponent))
|
||||
{
|
||||
texture = iconComponent.Icon?.Default;
|
||||
}else if (entity.TryGetComponent(out SpriteComponent spriteComponent))
|
||||
}
|
||||
else if (entity.TryGetComponent(out SpriteComponent? spriteComponent))
|
||||
{
|
||||
texture = spriteComponent.Icon?.Default;
|
||||
}else{continue;}
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var solidItem = _menu.IngredientsList.AddItem(entity.Name, texture);
|
||||
var solidIndex = _menu.IngredientsList.IndexOf(solidItem);
|
||||
_solids.Add(solidIndex, containedSolids[j]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MicrowaveMenu : SS14Window
|
||||
{
|
||||
|
||||
public class MicrowaveCookTimeButton : Button
|
||||
{
|
||||
public uint CookTime;
|
||||
@@ -141,7 +155,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
|
||||
private MicrowaveBoundUserInterface Owner { get; set; }
|
||||
|
||||
public event Action<BaseButton.ButtonEventArgs, int> OnCookTimeSelected;
|
||||
public event Action<ButtonEventArgs, int>? OnCookTimeSelected;
|
||||
|
||||
public Button StartButton { get; }
|
||||
public Button EjectButton { get; }
|
||||
@@ -149,19 +163,19 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
public PanelContainer TimerFacePlate { get; }
|
||||
|
||||
public ButtonGroup CookTimeButtonGroup { get; }
|
||||
|
||||
public VBoxContainer CookTimeButtonVbox { get; }
|
||||
|
||||
private VBoxContainer ButtonGridContainer { get; }
|
||||
|
||||
private PanelContainer DisableCookingPanelOverlay { get; }
|
||||
|
||||
|
||||
public ItemList IngredientsList { get; }
|
||||
|
||||
public ItemList IngredientsListReagents { get; }
|
||||
public Label _cookTimeInfoLabel { get; }
|
||||
|
||||
public MicrowaveMenu(MicrowaveBoundUserInterface owner = null)
|
||||
public MicrowaveMenu(MicrowaveBoundUserInterface owner)
|
||||
{
|
||||
SetSize = MinSize = (512, 256);
|
||||
|
||||
@@ -246,7 +260,6 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
Align = BoxContainer.AlignMode.Center,
|
||||
};
|
||||
|
||||
|
||||
var index = 0;
|
||||
for (var i = 0; i <= 6; i++)
|
||||
{
|
||||
@@ -270,7 +283,6 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
var cookTimeOneSecondButton = (Button) CookTimeButtonVbox.GetChild(0);
|
||||
cookTimeOneSecondButton.Pressed = true;
|
||||
|
||||
|
||||
_cookTimeInfoLabel = new Label
|
||||
{
|
||||
Text = Loc.GetString("COOK TIME: 1"),
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#nullable enable
|
||||
using Content.Client.GameObjects.Components.Sound;
|
||||
using Content.Client.GameObjects.Components.Sound;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Content.Shared.GameObjects.Components.Sound;
|
||||
using Content.Shared.Kitchen;
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Kitchen;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Content.Shared.Kitchen;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Content.Shared.Chemistry;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Client.GameObjects;
|
||||
using static Content.Shared.Chemistry.Solution;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
@@ -18,14 +19,16 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private GrinderMenu _menu;
|
||||
private Dictionary<int, EntityUid> _chamberVisualContents = new();
|
||||
private Dictionary<int, Solution.ReagentQuantity> _beakerVisualContents = new();
|
||||
private GrinderMenu? _menu;
|
||||
private readonly Dictionary<int, EntityUid> _chamberVisualContents = new();
|
||||
private readonly Dictionary<int, ReagentQuantity> _beakerVisualContents = new();
|
||||
|
||||
public ReagentGrinderBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { }
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_menu = new GrinderMenu(this);
|
||||
_menu.OpenCentered();
|
||||
_menu.OnClose += Close;
|
||||
@@ -64,6 +67,12 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_menu == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_menu.BeakerContentBox.EjectButton.Disabled = !cState.HasBeakerIn;
|
||||
_menu.ChamberContentBox.EjectButton.Disabled = cState.ChamberContents.Length <= 0;
|
||||
_menu.GrindButton.Disabled = !cState.CanGrind || !cState.Powered;
|
||||
@@ -74,6 +83,12 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
|
||||
{
|
||||
base.ReceiveMessage(message);
|
||||
|
||||
if (_menu == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case SharedReagentGrinderComponent.ReagentGrinderWorkStartedMessage workStarted:
|
||||
@@ -95,10 +110,16 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshContentsDisplay(IList<Solution.ReagentQuantity> reagents, IReadOnlyList<EntityUid> containedSolids, bool isBeakerAttached)
|
||||
private void RefreshContentsDisplay(IList<ReagentQuantity>? reagents, IReadOnlyList<EntityUid> containedSolids, bool isBeakerAttached)
|
||||
{
|
||||
//Refresh chamber contents
|
||||
_chamberVisualContents.Clear();
|
||||
|
||||
if (_menu == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_menu.ChamberContentBox.BoxContents.Clear();
|
||||
foreach (var uid in containedSolids)
|
||||
{
|
||||
@@ -131,8 +152,8 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
{
|
||||
for (var i = 0; i < reagents.Count; i++)
|
||||
{
|
||||
var goodIndex = _prototypeManager.TryIndex(reagents[i].ReagentId, out ReagentPrototype proto);
|
||||
var reagentName = goodIndex ? Loc.GetString($"{reagents[i].Quantity} {proto.Name}") : Loc.GetString("???");
|
||||
var goodIndex = _prototypeManager.TryIndex(reagents[i].ReagentId, out ReagentPrototype? proto);
|
||||
var reagentName = goodIndex ? Loc.GetString($"{reagents[i].Quantity} {proto!.Name}") : Loc.GetString("???");
|
||||
var reagentAdded = _menu.BeakerContentBox.BoxContents.AddItem(reagentName);
|
||||
var reagentIndex = _menu.BeakerContentBox.BoxContents.IndexOf(reagentAdded);
|
||||
_beakerVisualContents.Add(reagentIndex, reagents[i]);
|
||||
@@ -167,7 +188,8 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
|
||||
public sealed class LabelledContentBox : VBoxContainer
|
||||
{
|
||||
public string LabelText { get; set; }
|
||||
public string? LabelText { get; set; }
|
||||
|
||||
public ItemList BoxContents { get; set; }
|
||||
|
||||
public Button EjectButton { get; set; }
|
||||
@@ -176,7 +198,6 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
|
||||
public LabelledContentBox(string labelText, string buttonText)
|
||||
{
|
||||
|
||||
_label = new Label
|
||||
{
|
||||
Text = labelText,
|
||||
@@ -211,7 +232,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
|
||||
}
|
||||
}
|
||||
|
||||
public GrinderMenu(ReagentGrinderBoundUserInterface owner = null)
|
||||
public GrinderMenu(ReagentGrinderBoundUserInterface owner)
|
||||
{
|
||||
SetSize = MinSize = (512, 256);
|
||||
Owner = owner;
|
||||
|
||||
Reference in New Issue
Block a user