Revert "Remove some BUI boilerplate" (#30214)
Revert "Remove some BUI boilerplate (#28399)"
This reverts commit cbf329a82d.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Buffers;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Content.Client.Materials;
|
||||
@@ -23,6 +22,7 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private EntityUid _owner;
|
||||
private readonly SpriteSystem _spriteSystem;
|
||||
private readonly LatheSystem _lathe;
|
||||
private readonly MaterialStorageSystem _materialStorage;
|
||||
@@ -36,10 +36,9 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
|
||||
public ProtoId<LatheCategoryPrototype>? CurrentCategory;
|
||||
|
||||
public EntityUid Entity;
|
||||
|
||||
public LatheMenu()
|
||||
public LatheMenu(LatheBoundUserInterface owner)
|
||||
{
|
||||
_owner = owner.Owner;
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
@@ -47,6 +46,8 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
_lathe = _entityManager.System<LatheSystem>();
|
||||
_materialStorage = _entityManager.System<MaterialStorageSystem>();
|
||||
|
||||
Title = _entityManager.GetComponent<MetaDataComponent>(owner.Owner).EntityName;
|
||||
|
||||
SearchBar.OnTextChanged += _ =>
|
||||
{
|
||||
PopulateRecipes();
|
||||
@@ -59,13 +60,8 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
FilterOption.OnItemSelected += OnItemSelected;
|
||||
|
||||
ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a);
|
||||
}
|
||||
|
||||
public void SetEntity(EntityUid uid)
|
||||
{
|
||||
Entity = uid;
|
||||
|
||||
if (_entityManager.TryGetComponent<LatheComponent>(Entity, out var latheComponent))
|
||||
if (_entityManager.TryGetComponent<LatheComponent>(owner.Owner, out var latheComponent))
|
||||
{
|
||||
if (!latheComponent.DynamicRecipes.Any())
|
||||
{
|
||||
@@ -73,7 +69,7 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
}
|
||||
}
|
||||
|
||||
MaterialsList.SetOwner(Entity);
|
||||
MaterialsList.SetOwner(owner.Owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -106,15 +102,13 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
|
||||
var sortedRecipesToShow = recipesToShow.OrderBy(p => p.Name);
|
||||
RecipeList.Children.Clear();
|
||||
_entityManager.TryGetComponent(Entity, out LatheComponent? lathe);
|
||||
|
||||
foreach (var prototype in sortedRecipesToShow)
|
||||
{
|
||||
EntityPrototype? recipeProto = null;
|
||||
if (_prototypeManager.TryIndex(prototype.Result, out EntityPrototype? entityProto))
|
||||
if (_prototypeManager.TryIndex(prototype.Result, out EntityPrototype? entityProto) && entityProto != null)
|
||||
recipeProto = entityProto;
|
||||
|
||||
var canProduce = _lathe.CanProduce(Entity, prototype, quantity, component: lathe);
|
||||
var canProduce = _lathe.CanProduce(_owner, prototype, quantity);
|
||||
|
||||
var control = new RecipeControl(prototype, () => GenerateTooltipText(prototype), canProduce, recipeProto);
|
||||
control.OnButtonPressed += s =>
|
||||
@@ -130,20 +124,19 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
private string GenerateTooltipText(LatheRecipePrototype prototype)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
var multiplier = _entityManager.GetComponent<LatheComponent>(Entity).MaterialUseMultiplier;
|
||||
|
||||
foreach (var (id, amount) in prototype.RequiredMaterials)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex<MaterialPrototype>(id, out var proto))
|
||||
continue;
|
||||
|
||||
var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, multiplier);
|
||||
var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, _entityManager.GetComponent<LatheComponent>(_owner).MaterialUseMultiplier);
|
||||
var sheetVolume = _materialStorage.GetSheetVolume(proto);
|
||||
|
||||
var unit = Loc.GetString(proto.Unit);
|
||||
var sheets = adjustedAmount / (float) sheetVolume;
|
||||
|
||||
var availableAmount = _materialStorage.GetMaterialAmount(Entity, id);
|
||||
var availableAmount = _materialStorage.GetMaterialAmount(_owner, id);
|
||||
var missingAmount = Math.Max(0, adjustedAmount - availableAmount);
|
||||
var missingSheets = missingAmount / (float) sheetVolume;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user