Fix cargo product groups (#24212)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Linq;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Cargo;
|
||||
using Content.Shared.Cargo.Components;
|
||||
using Content.Shared.Cargo.Prototypes;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
@@ -14,8 +15,10 @@ namespace Content.Client.Cargo.UI
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class CargoConsoleMenu : FancyWindow
|
||||
{
|
||||
private IEntityManager _entityManager;
|
||||
private IPrototypeManager _protoManager;
|
||||
private SpriteSystem _spriteSystem;
|
||||
private EntityUid _owner;
|
||||
|
||||
public event Action<ButtonEventArgs>? OnItemSelected;
|
||||
public event Action<ButtonEventArgs>? OnOrderApproved;
|
||||
@@ -24,11 +27,13 @@ namespace Content.Client.Cargo.UI
|
||||
private readonly List<string> _categoryStrings = new();
|
||||
private string? _category;
|
||||
|
||||
public CargoConsoleMenu(IPrototypeManager protoManager, SpriteSystem spriteSystem)
|
||||
public CargoConsoleMenu(EntityUid owner, IEntityManager entMan, IPrototypeManager protoManager, SpriteSystem spriteSystem)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
_entityManager = entMan;
|
||||
_protoManager = protoManager;
|
||||
_spriteSystem = spriteSystem;
|
||||
_owner = owner;
|
||||
|
||||
Title = Loc.GetString("cargo-console-menu-title");
|
||||
|
||||
@@ -53,7 +58,21 @@ namespace Content.Client.Cargo.UI
|
||||
Categories.SelectId(id);
|
||||
}
|
||||
|
||||
public IEnumerable<CargoProductPrototype> ProductPrototypes => _protoManager.EnumeratePrototypes<CargoProductPrototype>();
|
||||
public IEnumerable<CargoProductPrototype> ProductPrototypes
|
||||
{
|
||||
get
|
||||
{
|
||||
var allowedGroups = _entityManager.GetComponentOrNull<CargoOrderConsoleComponent>(_owner)?.AllowedGroups;
|
||||
|
||||
foreach (var cargoPrototype in _protoManager.EnumeratePrototypes<CargoProductPrototype>())
|
||||
{
|
||||
if (!allowedGroups?.Contains(cargoPrototype.Group) ?? false)
|
||||
continue;
|
||||
|
||||
yield return cargoPrototype;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates the list of products that will actually be shown, using the current filters.
|
||||
@@ -80,7 +99,7 @@ namespace Content.Client.Cargo.UI
|
||||
Product = prototype,
|
||||
ProductName = { Text = prototype.Name },
|
||||
MainButton = { ToolTip = prototype.Description },
|
||||
PointCost = { Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", prototype.PointCost.ToString())) },
|
||||
PointCost = { Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", prototype.Cost.ToString())) },
|
||||
Icon = { Texture = _spriteSystem.Frame0(prototype.Icon) },
|
||||
};
|
||||
button.MainButton.OnPressed += args =>
|
||||
|
||||
Reference in New Issue
Block a user