Add lathe material ejection (#19218)

This completes PilgrimViis' (now closed) PR 16398. It addresses issue 10896, by allowing materials to be ejected from most lathes (except the ore processor and sheet-meister 2000)

* - Refinements to the material ejection UI
- Made the lathe UI default to a slightly larger size
- Fixed an offset issue with the label of the item currently being printed in the build queue UI

* Allow the materiel reclamation UI to pop if there is material left in the lathe, but not enough to print any sheets

---------

Co-authored-by: Kevin Zheng <kevinz5000@gmail.com>
This commit is contained in:
chromiumboy
2023-08-17 12:22:01 -05:00
committed by GitHub
parent 89b3231de0
commit a39fa80d58
13 changed files with 288 additions and 10 deletions

View File

@@ -14,6 +14,9 @@ namespace Content.Client.Lathe.UI
[ViewVariables]
private LatheQueueMenu? _queueMenu;
[ViewVariables]
private LatheMaterialsEjectionMenu? _materialsEjectionMenu;
public LatheBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
@@ -24,6 +27,7 @@ namespace Content.Client.Lathe.UI
_menu = new LatheMenu(this);
_queueMenu = new LatheQueueMenu();
_materialsEjectionMenu = new LatheMaterialsEjectionMenu();
_menu.OnClose += Close;
@@ -34,15 +38,30 @@ namespace Content.Client.Lathe.UI
else
_queueMenu.OpenCenteredLeft();
};
_menu.OnMaterialsEjectionButtonPressed += _ =>
{
if (_materialsEjectionMenu.IsOpen)
_materialsEjectionMenu.Close();
else
_materialsEjectionMenu.OpenCenteredRight();
};
_menu.OnServerListButtonPressed += _ =>
{
SendMessage(new ConsoleServerSelectionMessage());
};
_menu.RecipeQueueAction += (recipe, amount) =>
{
SendMessage(new LatheQueueRecipeMessage(recipe, amount));
};
_materialsEjectionMenu.OnEjectPressed += (material, sheetsToExtract) =>
{
SendMessage(new LatheEjectMaterialMessage(material, sheetsToExtract));
};
_menu.OpenCentered();
}
@@ -59,6 +78,7 @@ namespace Content.Client.Lathe.UI
_menu?.PopulateMaterials(Owner);
_queueMenu?.PopulateList(msg.Queue);
_queueMenu?.SetInfo(msg.CurrentlyProducing);
_materialsEjectionMenu?.PopulateMaterials(Owner);
break;
}
}
@@ -70,6 +90,7 @@ namespace Content.Client.Lathe.UI
return;
_menu?.Dispose();
_queueMenu?.Dispose();
_materialsEjectionMenu?.Dispose();
}
}
}

View File

@@ -0,0 +1,21 @@
<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="0 4 0 0"/>
</BoxContainer>
<!--Here go buttons which added in c#-->
</BoxContainer>
</PanelContainer>

View File

@@ -0,0 +1,64 @@
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, 30 };
foreach (int sheetsToEject in sheetsToEjectArray)
{
var button = new Button()
{
Name = $"{sheetsToEject}",
Access = AccessLevel.Public,
Text = Loc.GetString($"{sheetsToEject}"),
MinWidth = 45,
};
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 * VolumePerSheet), ("material", Loc.GetString(proto.Name)));
}
Content.AddChild(button);
}
}
}

View File

@@ -0,0 +1,16 @@
<DefaultWindow
xmlns="https://spacestation14.io"
Title="{Loc 'lathe-menu-materials-ejection-title'}"
MinSize="300 100"
SetSize="350 475">
<ScrollContainer MinHeight="80">
<BoxContainer
Name="MaterialsList"
Orientation="Vertical"
SizeFlagsStretchRatio="8"
HorizontalExpand="True"
VerticalExpand="True">
<!-- Materials populated in C# file -->
</BoxContainer>
</ScrollContainer>
</DefaultWindow>

View File

@@ -0,0 +1,74 @@
using Content.Shared.Materials;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using System.Linq;
namespace Content.Client.Lathe.UI;
[GenerateTypedNameReferences]
public sealed partial class LatheMaterialsEjectionMenu : DefaultWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private readonly SpriteSystem _spriteSystem;
public event Action<string, int>? OnEjectPressed;
public LatheMaterialsEjectionMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_spriteSystem = _entityManager.EntitySysManager.GetEntitySystem<SpriteSystem>();
}
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 name = Loc.GetString(material.Name);
int volumePerSheet = 0;
int maxEjectableSheets = 0;
if (material.StackEntity != null)
{
var proto = _prototypeManager.Index<EntityPrototype>(material.StackEntity);
name = proto.Name;
if (proto.TryGetComponent<PhysicalCompositionComponent>(out var composition))
{
volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == materialId).Value;
maxEjectableSheets = (int) MathF.Floor(volume / volumePerSheet);
}
}
var row = new LatheMaterialEjector(materialId, OnEjectPressed, volumePerSheet, maxEjectableSheets)
{
Icon = { Texture = _spriteSystem.Frame0(material.Icon) },
ProductName = { Text = name }
};
MaterialsList.AddChild(row);
}
if (MaterialsList.ChildCount == 0)
{
Close();
}
}
}

View File

@@ -1,9 +1,9 @@
<DefaultWindow
<DefaultWindow
xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'lathe-menu-title'}"
MinSize="300 450"
SetSize="300 450">
SetSize="350 475">
<BoxContainer
Orientation="Vertical"
VerticalExpand="True"
@@ -79,6 +79,13 @@
VerticalExpand="True">
</ItemList>
</BoxContainer>
<Button
Name="MaterialsEjectionButton"
Text="{Loc 'lathe-menu-materials-ejection'}"
TextAlign="Center"
Mode="Press"
StyleClasses="OpenRight">
</Button>
</BoxContainer>
</DefaultWindow>

View File

@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Text;
using Content.Client.Stylesheets;
using Content.Shared.Lathe;
@@ -22,6 +22,7 @@ public sealed partial class LatheMenu : DefaultWindow
private readonly LatheSystem _lathe;
public event Action<BaseButton.ButtonEventArgs>? OnQueueButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnMaterialsEjectionButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnServerListButtonPressed;
public event Action<string, int>? RecipeQueueAction;
@@ -47,6 +48,7 @@ public sealed partial class LatheMenu : DefaultWindow
};
QueueButton.OnPressed += a => OnQueueButtonPressed?.Invoke(a);
MaterialsEjectionButton.OnPressed += a => OnMaterialsEjectionButtonPressed?.Invoke(a);
ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a);
if (_entityManager.TryGetComponent<LatheComponent>(owner.Owner, out var latheComponent))
@@ -57,6 +59,11 @@ public sealed partial class LatheMenu : DefaultWindow
QueueButton.RemoveStyleClass(StyleBase.ButtonOpenRight);
//QueueButton.AddStyleClass(StyleBase.ButtonSquare);
}
if (MaterialsEjectionButton != null && !latheComponent.CanEjectStoredMaterials)
{
MaterialsEjectionButton.Dispose();
}
}
}
@@ -69,14 +76,24 @@ public sealed partial class LatheMenu : DefaultWindow
foreach (var (id, amount) in materials.Storage)
{
if (amount <= 0)
continue;
if (!_prototypeManager.TryIndex(id, out MaterialPrototype? material))
continue;
var name = Loc.GetString(material.Name);
var mat = Loc.GetString("lathe-menu-material-display",
("material", name), ("amount", amount));
Materials.AddItem(mat, _spriteSystem.Frame0(material.Icon), false);
}
if (MaterialsEjectionButton != null)
{
MaterialsEjectionButton.Disabled = Materials.Count == 0;
}
if (Materials.Count == 0)
{
var noMaterialsMsg = Loc.GetString("lathe-menu-no-materials-message");
@@ -132,9 +149,7 @@ public sealed partial class LatheMenu : DefaultWindow
var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, component.MaterialUseMultiplier);
sb.Append(adjustedAmount);
sb.Append(' ');
sb.Append(Loc.GetString(proto.Name));
sb.Append(Loc.GetString("lathe-menu-tooltip-display", ("amount", adjustedAmount), ("material", Loc.GetString(proto.Name))));
}
var icon = prototype.Icon == null

View File

@@ -1,8 +1,8 @@
<DefaultWindow
<DefaultWindow
xmlns="https://spacestation14.io"
Title="{Loc 'lathe-queue-menu-title'}"
MinSize="300 450"
SetSize="300 450">
SetSize="350 475">
<BoxContainer Orientation="Vertical">
<BoxContainer
Orientation="Horizontal"
@@ -19,7 +19,8 @@
SizeFlagsStretchRatio="3">
<Label
Name="NameLabel"
RectClipContent="True">
RectClipContent="True"
Margin="36 0 0 0">
</Label>
<Label
Name="Description"