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"),
|
||||
|
||||
Reference in New Issue
Block a user