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:
@@ -2,35 +2,43 @@
|
||||
using Content.Shared.GameObjects.Components.Cargo;
|
||||
using Content.Shared.Prototypes.Cargo;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Content.Shared.GameObjects.Components.Cargo.SharedCargoConsoleComponent;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Cargo
|
||||
{
|
||||
public class CargoConsoleBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[ViewVariables]
|
||||
private CargoConsoleMenu _menu;
|
||||
[ViewVariables]
|
||||
private CargoConsoleOrderMenu _orderMenu;
|
||||
private CargoConsoleMenu? _menu;
|
||||
|
||||
[ViewVariables]
|
||||
public GalacticMarketComponent Market { get; private set; }
|
||||
private CargoConsoleOrderMenu? _orderMenu;
|
||||
|
||||
[ViewVariables]
|
||||
public CargoOrderDatabaseComponent Orders { get; private set; }
|
||||
public GalacticMarketComponent? Market { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public CargoOrderDatabaseComponent? Orders { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public bool RequestOnly { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public int BankId { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public string BankName { get; private set; }
|
||||
public string? BankName { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public int BankBalance { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public (int CurrentCapacity, int MaxCapacity) ShuttleCapacity { get; private set; }
|
||||
|
||||
private CargoProductPrototype _product;
|
||||
private CargoProductPrototype? _product;
|
||||
|
||||
public CargoConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
@@ -40,8 +48,8 @@ namespace Content.Client.GameObjects.Components.Cargo
|
||||
{
|
||||
base.Open();
|
||||
|
||||
if (!Owner.Owner.TryGetComponent(out GalacticMarketComponent market)
|
||||
|| !Owner.Owner.TryGetComponent(out CargoOrderDatabaseComponent orders)) return;
|
||||
if (!Owner.Owner.TryGetComponent(out GalacticMarketComponent? market) ||
|
||||
!Owner.Owner.TryGetComponent(out CargoOrderDatabaseComponent? orders)) return;
|
||||
|
||||
Market = market;
|
||||
Orders = orders;
|
||||
@@ -57,23 +65,23 @@ namespace Content.Client.GameObjects.Components.Cargo
|
||||
Market.OnDatabaseUpdated += _menu.PopulateCategories;
|
||||
Orders.OnDatabaseUpdated += _menu.PopulateOrders;
|
||||
|
||||
_menu.CallShuttleButton.OnPressed += (args) =>
|
||||
_menu.CallShuttleButton.OnPressed += (_) =>
|
||||
{
|
||||
SendMessage(new SharedCargoConsoleComponent.CargoConsoleShuttleMessage());
|
||||
SendMessage(new CargoConsoleShuttleMessage());
|
||||
};
|
||||
_menu.OnItemSelected += (args) =>
|
||||
{
|
||||
if (args.Button.Parent is not CargoProductRow row)
|
||||
return;
|
||||
_product = row.Product;
|
||||
_orderMenu.Requester.Text = null;
|
||||
_orderMenu.Reason.Text = null;
|
||||
_orderMenu.Requester.Text = "";
|
||||
_orderMenu.Reason.Text = "";
|
||||
_orderMenu.Amount.Value = 1;
|
||||
_orderMenu.OpenCentered();
|
||||
};
|
||||
_menu.OnOrderApproved += ApproveOrder;
|
||||
_menu.OnOrderCanceled += RemoveOrder;
|
||||
_orderMenu.SubmitButton.OnPressed += (args) =>
|
||||
_orderMenu.SubmitButton.OnPressed += (_) =>
|
||||
{
|
||||
AddOrder();
|
||||
_orderMenu.Close();
|
||||
@@ -92,47 +100,63 @@ namespace Content.Client.GameObjects.Components.Cargo
|
||||
if (RequestOnly != cState.RequestOnly)
|
||||
{
|
||||
RequestOnly = cState.RequestOnly;
|
||||
_menu.UpdateRequestOnly();
|
||||
_menu?.UpdateRequestOnly();
|
||||
}
|
||||
BankId = cState.BankId;
|
||||
BankName = cState.BankName;
|
||||
BankBalance = cState.BankBalance;
|
||||
ShuttleCapacity = cState.ShuttleCapacity;
|
||||
_menu.UpdateCargoCapacity();
|
||||
_menu.UpdateBankData();
|
||||
_menu?.UpdateCargoCapacity();
|
||||
_menu?.UpdateBankData();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (!disposing) return;
|
||||
Market.OnDatabaseUpdated -= _menu.PopulateProducts;
|
||||
Market.OnDatabaseUpdated -= _menu.PopulateCategories;
|
||||
Orders.OnDatabaseUpdated -= _menu.PopulateOrders;
|
||||
|
||||
if (Market != null && _menu != null)
|
||||
{
|
||||
Market.OnDatabaseUpdated -= _menu.PopulateProducts;
|
||||
Market.OnDatabaseUpdated -= _menu.PopulateCategories;
|
||||
}
|
||||
|
||||
if (Orders != null && _menu != null)
|
||||
{
|
||||
Orders.OnDatabaseUpdated -= _menu.PopulateOrders;
|
||||
}
|
||||
|
||||
_menu?.Dispose();
|
||||
_orderMenu?.Dispose();
|
||||
}
|
||||
|
||||
internal void AddOrder()
|
||||
private void AddOrder()
|
||||
{
|
||||
SendMessage(new SharedCargoConsoleComponent.CargoConsoleAddOrderMessage(_orderMenu.Requester.Text,
|
||||
_orderMenu.Reason.Text, _product.ID, _orderMenu.Amount.Value));
|
||||
SendMessage(new CargoConsoleAddOrderMessage(
|
||||
_orderMenu?.Requester.Text ?? "",
|
||||
_orderMenu?.Reason.Text ?? "",
|
||||
_product?.ID ?? "",
|
||||
_orderMenu?.Amount.Value ?? 0));
|
||||
}
|
||||
|
||||
internal void RemoveOrder(BaseButton.ButtonEventArgs args)
|
||||
private void RemoveOrder(ButtonEventArgs args)
|
||||
{
|
||||
if (args.Button.Parent.Parent is not CargoOrderRow row)
|
||||
if (args.Button.Parent?.Parent is not CargoOrderRow row || row.Order == null)
|
||||
return;
|
||||
SendMessage(new SharedCargoConsoleComponent.CargoConsoleRemoveOrderMessage(row.Order.OrderNumber));
|
||||
|
||||
SendMessage(new CargoConsoleRemoveOrderMessage(row.Order.OrderNumber));
|
||||
}
|
||||
|
||||
internal void ApproveOrder(BaseButton.ButtonEventArgs args)
|
||||
private void ApproveOrder(ButtonEventArgs args)
|
||||
{
|
||||
if (args.Button.Parent.Parent is not CargoOrderRow row)
|
||||
if (args.Button.Parent?.Parent is not CargoOrderRow row || row.Order == null)
|
||||
return;
|
||||
|
||||
if (ShuttleCapacity.CurrentCapacity == ShuttleCapacity.MaxCapacity)
|
||||
return;
|
||||
SendMessage(new SharedCargoConsoleComponent.CargoConsoleApproveOrderMessage(row.Order.OrderNumber));
|
||||
|
||||
SendMessage(new CargoConsoleApproveOrderMessage(row.Order.OrderNumber));
|
||||
_menu?.UpdateCargoCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user