Make the material ejection control completely generic (#23308)
* Finish decoupling material ejection from lathes * commented
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using Content.Shared.Lathe;
|
||||
using Content.Shared.Materials;
|
||||
using Content.Shared.Research.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Lathe.UI
|
||||
{
|
||||
@@ -33,11 +31,6 @@ namespace Content.Client.Lathe.UI
|
||||
SendMessage(new LatheQueueRecipeMessage(recipe, amount));
|
||||
};
|
||||
|
||||
_menu.OnEjectPressed += (material, sheetsToExtract) =>
|
||||
{
|
||||
SendMessage(new EjectMaterialMessage(material, sheetsToExtract));
|
||||
};
|
||||
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
|
||||
@@ -51,7 +44,6 @@ namespace Content.Client.Lathe.UI
|
||||
if (_menu != null)
|
||||
_menu.Recipes = msg.Recipes;
|
||||
_menu?.PopulateRecipes(Owner);
|
||||
_menu?.PopulateMaterials(Owner);
|
||||
_menu?.PopulateQueueList(msg.Queue);
|
||||
_menu?.SetQueueInfo(msg.CurrentlyProducing);
|
||||
break;
|
||||
@@ -64,7 +56,6 @@ namespace Content.Client.Lathe.UI
|
||||
if (!disposing)
|
||||
return;
|
||||
_menu?.Dispose();
|
||||
//thom _materialsEjectionMenu?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<PanelContainer xmlns="https://spacestation14.io"
|
||||
HorizontalExpand="True">
|
||||
<BoxContainer Name="Content"
|
||||
Orientation="Horizontal"
|
||||
HorizontalExpand="True">
|
||||
<TextureRect Name="Icon"
|
||||
Access="Public"
|
||||
MinSize="32 32"
|
||||
RectClipContent="True" />
|
||||
<BoxContainer Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="False">
|
||||
<Label Name="ProductName"
|
||||
Access="Public"
|
||||
HorizontalExpand="True"
|
||||
ClipText="True"
|
||||
Margin="4 4 4 4"/>
|
||||
</BoxContainer>
|
||||
<!--Here go buttons which added in c#-->
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
@@ -1,73 +0,0 @@
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared.Materials;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Lathe.UI;
|
||||
|
||||
/// <summary>
|
||||
/// This widget is one row in the lathe eject menu.
|
||||
/// </summary>
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class LatheMaterialEjector : PanelContainer
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public string Material;
|
||||
public Action<string, int>? OnEjectPressed;
|
||||
public int VolumePerSheet;
|
||||
|
||||
public LatheMaterialEjector(string material, Action<string, int>? onEjectPressed, int volumePerSheet, int maxEjectableSheets)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
Material = material;
|
||||
OnEjectPressed = onEjectPressed;
|
||||
VolumePerSheet = volumePerSheet;
|
||||
|
||||
PopulateButtons(maxEjectableSheets);
|
||||
}
|
||||
|
||||
public void PopulateButtons(int maxEjectableSheets)
|
||||
{
|
||||
int[] sheetsToEjectArray = { 1, 5, 10 };
|
||||
|
||||
for (var i = 0; i < sheetsToEjectArray.Length; i++)
|
||||
{
|
||||
var sheetsToEject = sheetsToEjectArray[i];
|
||||
|
||||
var styleClass = StyleBase.ButtonOpenBoth;
|
||||
if (i == 0)
|
||||
styleClass = StyleBase.ButtonOpenRight;
|
||||
else if (i == sheetsToEjectArray.Length - 1)
|
||||
styleClass = StyleBase.ButtonOpenLeft;
|
||||
|
||||
var button = new Button
|
||||
{
|
||||
Name = $"{sheetsToEject}",
|
||||
Access = AccessLevel.Public,
|
||||
Text = Loc.GetString($"{sheetsToEject}"),
|
||||
MinWidth = 45,
|
||||
StyleClasses = { styleClass }
|
||||
};
|
||||
|
||||
button.OnPressed += _ =>
|
||||
{
|
||||
OnEjectPressed?.Invoke(Material, sheetsToEject);
|
||||
};
|
||||
|
||||
button.Disabled = maxEjectableSheets < sheetsToEject;
|
||||
|
||||
if (_prototypeManager.TryIndex<MaterialPrototype>(Material, out var proto))
|
||||
{
|
||||
button.ToolTip = Loc.GetString("lathe-menu-tooltip-display", ("amount", sheetsToEject), ("material", Loc.GetString(proto.Name)));
|
||||
}
|
||||
|
||||
Content.AddChild(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<DefaultWindow
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
xmlns:ui="clr-namespace:Content.Client.Materials.UI"
|
||||
Title="{Loc 'lathe-menu-title'}"
|
||||
MinSize="550 450"
|
||||
SetSize="750 500">
|
||||
@@ -135,14 +136,7 @@
|
||||
Orientation="Vertical"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True">
|
||||
<BoxContainer
|
||||
Name="MaterialsList"
|
||||
Orientation="Vertical"
|
||||
SizeFlagsStretchRatio="8"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
<!-- Materials populated in C# file -->
|
||||
</BoxContainer>
|
||||
<ui:MaterialStorageControl Name="MaterialsList" SizeFlagsStretchRatio="8"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Content.Client.Materials;
|
||||
using Content.Shared.Lathe;
|
||||
using Content.Shared.Materials;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
@@ -19,16 +20,12 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
private readonly SpriteSystem _spriteSystem;
|
||||
private readonly LatheSystem _lathe;
|
||||
private readonly MaterialStorageSystem _materialStorage;
|
||||
|
||||
public event Action<BaseButton.ButtonEventArgs>? OnServerListButtonPressed;
|
||||
public event Action<string, int>? RecipeQueueAction;
|
||||
public event Action<string, int>? OnEjectPressed;
|
||||
public List<ProtoId<LatheRecipePrototype>> Recipes = new();
|
||||
|
||||
/// <summary>
|
||||
/// Default volume for a sheet if the material's entity prototype has no material composition.
|
||||
/// </summary>
|
||||
private const int DEFAULT_SHEET_VOLUME = 100;
|
||||
public List<ProtoId<LatheRecipePrototype>> Recipes = new();
|
||||
|
||||
public LatheMenu(LatheBoundUserInterface owner)
|
||||
{
|
||||
@@ -37,6 +34,7 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
|
||||
_spriteSystem = _entityManager.System<SpriteSystem>();
|
||||
_lathe = _entityManager.System<LatheSystem>();
|
||||
_materialStorage = _entityManager.System<MaterialStorageSystem>();
|
||||
|
||||
Title = _entityManager.GetComponent<MetaDataComponent>(owner.Owner).EntityName;
|
||||
|
||||
@@ -58,50 +56,10 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
ServerListButton.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
MaterialsList.SetOwner(owner.Owner);
|
||||
}
|
||||
|
||||
public void PopulateMaterials(EntityUid lathe)
|
||||
{
|
||||
if (!_entityManager.TryGetComponent<MaterialStorageComponent>(lathe, out var materials))
|
||||
return;
|
||||
|
||||
MaterialsList.DisposeAllChildren();
|
||||
|
||||
foreach (var (materialId, volume) in materials.Storage)
|
||||
{
|
||||
if (volume <= 0)
|
||||
continue;
|
||||
|
||||
if (!_prototypeManager.TryIndex(materialId, out MaterialPrototype? material))
|
||||
continue;
|
||||
|
||||
var sheetVolume = SheetVolume(material);
|
||||
var sheets = (float) volume / sheetVolume;
|
||||
var maxEjectableSheets = (int) MathF.Floor(sheets);
|
||||
|
||||
var unit = Loc.GetString(material.Unit);
|
||||
var amountText = Loc.GetString("lathe-menu-material-amount", ("amount", sheets), ("unit", unit));
|
||||
var name = Loc.GetString(material.Name);
|
||||
var mat = Loc.GetString("lathe-menu-material-display", ("material", name), ("amount", amountText));
|
||||
|
||||
var row = new LatheMaterialEjector(materialId, OnEjectPressed, sheetVolume, maxEjectableSheets)
|
||||
{
|
||||
Icon = { Texture = _spriteSystem.Frame0(material.Icon) },
|
||||
ProductName = { Text = mat }
|
||||
};
|
||||
|
||||
MaterialsList.AddChild(row);
|
||||
}
|
||||
|
||||
if (MaterialsList.ChildCount == 0)
|
||||
{
|
||||
var noMaterialsMsg = Loc.GetString("lathe-menu-no-materials-message");
|
||||
var noItemRow = new Label();
|
||||
noItemRow.Text = noMaterialsMsg;
|
||||
noItemRow.Align = Label.AlignMode.Center;
|
||||
MaterialsList.AddChild(noItemRow);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Populates the list of all the recipes
|
||||
/// </summary>
|
||||
@@ -147,7 +105,7 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
sb.Append('\n');
|
||||
|
||||
var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, component.MaterialUseMultiplier);
|
||||
var sheetVolume = SheetVolume(proto);
|
||||
var sheetVolume = _materialStorage.GetSheetVolume(proto);
|
||||
|
||||
var unit = Loc.GetString(proto.Unit);
|
||||
// rounded in locale not here
|
||||
@@ -204,17 +162,4 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
: _spriteSystem.Frame0(recipe.Icon);
|
||||
NameLabel.Text = $"{recipe.Name}";
|
||||
}
|
||||
|
||||
private int SheetVolume(MaterialPrototype material)
|
||||
{
|
||||
if (material.StackEntity == null)
|
||||
return DEFAULT_SHEET_VOLUME;
|
||||
|
||||
var proto = _prototypeManager.Index<EntityPrototype>(material.StackEntity);
|
||||
|
||||
if (!proto.TryGetComponent<PhysicalCompositionComponent>(out var composition))
|
||||
return DEFAULT_SHEET_VOLUME;
|
||||
|
||||
return composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == material.ID).Value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user