Add cargo shuttle (#8686)

This commit is contained in:
metalgearsloth
2022-06-23 14:36:47 +10:00
committed by GitHub
parent b56b737b67
commit 77a8e16104
99 changed files with 4064 additions and 1356 deletions

View File

@@ -1,31 +1,24 @@
using System;
using System.Collections.Generic;
using Content.Client.Stylesheets;
using System.Linq;
using Content.Client.UserInterface;
using Content.Shared.Cargo;
using Content.Shared.Cargo.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BaseButton;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.Cargo.UI
{
[GenerateTypedNameReferences]
public sealed partial class CargoConsoleMenu : DefaultWindow
public sealed partial class CargoConsoleMenu : FancyWindow
{
[Dependency]
private IPrototypeManager _prototypeManager = default!;
public CargoConsoleBoundUserInterface Owner { get; private set; }
private IPrototypeManager _protoManager;
private SpriteSystem _spriteSystem;
public event Action<ButtonEventArgs>? OnItemSelected;
public event Action<ButtonEventArgs>? OnOrderApproved;
@@ -34,25 +27,18 @@ namespace Content.Client.Cargo.UI
private readonly List<string> _categoryStrings = new();
private string? _category;
public CargoConsoleMenu(CargoConsoleBoundUserInterface owner)
public CargoConsoleMenu(IPrototypeManager protoManager, SpriteSystem spriteSystem)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
Owner = owner;
_protoManager = protoManager;
_spriteSystem = spriteSystem;
Title = Loc.GetString(Owner.RequestOnly
? "cargo-console-menu-request-only-title"
: "cargo-console-menu-title");
Title = Loc.GetString("cargo-console-menu-title");
CallShuttleButton.OnPressed += OnCallShuttleButtonPressed;
SearchBar.OnTextChanged += OnSearchBarTextChanged;
Categories.OnItemSelected += OnCategoryItemSelected;
}
private void OnCallShuttleButtonPressed(ButtonEventArgs args)
{
}
private void OnCategoryItemSelected(OptionButton.ItemSelectedEventArgs args)
{
SetCategoryText(args.Id);
@@ -70,7 +56,7 @@ namespace Content.Client.Cargo.UI
Categories.SelectId(id);
}
public IEnumerable<CargoProductPrototype> ProductPrototypes => _prototypeManager.EnumeratePrototypes<CargoProductPrototype>();
public IEnumerable<CargoProductPrototype> ProductPrototypes => _protoManager.EnumeratePrototypes<CargoProductPrototype>();
/// <summary>
/// Populates the list of products that will actually be shown, using the current filters.
@@ -78,9 +64,12 @@ namespace Content.Client.Cargo.UI
public void PopulateProducts()
{
Products.RemoveAllChildren();
var products = ProductPrototypes.ToList();
products.Sort((x, y) =>
string.Compare(x.Name, y.Name, StringComparison.Ordinal));
var search = SearchBar.Text.Trim().ToLowerInvariant();
foreach (var prototype in ProductPrototypes)
foreach (var prototype in products)
{
// if no search or category
// else if search
@@ -94,7 +83,7 @@ namespace Content.Client.Cargo.UI
Product = prototype,
ProductName = { Text = prototype.Name },
PointCost = { Text = prototype.PointCost.ToString() },
Icon = { Texture = prototype.Icon.Frame0() },
Icon = { Texture = _spriteSystem.Frame0(prototype.Icon) },
};
button.MainButton.OnPressed += args =>
{
@@ -132,31 +121,20 @@ namespace Content.Client.Cargo.UI
/// <summary>
/// Populates the list of orders and requests.
/// </summary>
public void PopulateOrders()
public void PopulateOrders(IEnumerable<CargoOrderData> orders)
{
Orders.RemoveAllChildren();
Requests.RemoveAllChildren();
Orders.DisposeAllChildren();
Requests.DisposeAllChildren();
if (Owner.Orders == null)
foreach (var order in orders)
{
return;
}
foreach (var order in Owner.Orders.Orders)
{
if (!_prototypeManager.TryIndex<CargoProductPrototype>(order.ProductId, out CargoProductPrototype? product))
{
DebugTools.Assert(false);
Logger.ErrorS("cargo", $"Unable to find product name for {order.ProductId}");
continue;
}
var product = _protoManager.Index<CargoProductPrototype>(order.ProductId);
var productName = product.Name;
var row = new CargoOrderRow
{
Order = order,
Icon = { Texture = product.Icon.Frame0() },
Icon = { Texture = _spriteSystem.Frame0(product.Icon) },
ProductName =
{
Text = Loc.GetString(
@@ -177,43 +155,23 @@ namespace Content.Client.Cargo.UI
}
else
{
if (Owner.RequestOnly)
row.Approve.Visible = false;
else
row.Approve.OnPressed += (args) => { OnOrderApproved?.Invoke(args); };
// TODO: Disable based on access.
row.Approve.OnPressed += (args) => { OnOrderApproved?.Invoke(args); };
Requests.AddChild(row);
}
}
}
public void Populate()
public void UpdateCargoCapacity(int count, int capacity)
{
PopulateProducts();
PopulateCategories();
PopulateOrders();
// TODO: Rename + Loc.
ShuttleCapacityLabel.Text = $"{count}/{capacity}";
}
public void UpdateCargoCapacity()
public void UpdateBankData(string name, int points)
{
ShuttleCapacityLabel.Text = $"{Owner.ShuttleCapacity.CurrentCapacity}/{Owner.ShuttleCapacity.MaxCapacity}";
}
public void UpdateBankData()
{
AccountNameLabel.Text = Owner.BankName;
PointsLabel.Text = Owner.BankBalance.ToString();
}
/// <summary>
/// Show/Hide Call Shuttle button and Approve buttons
/// </summary>
public void UpdateRequestOnly()
{
CallShuttleButton.Visible = !Owner.RequestOnly;
foreach (CargoOrderRow row in Requests.Children)
{
row.Approve.Visible = !Owner.RequestOnly;
}
AccountNameLabel.Text = name;
PointsLabel.Text = points.ToString();
}
}
}