Fix some lathe recipe textures showing up blank (#28683)

* Update lathes to use entity prototype

* ScrollContainer my hero

* gets rid of excess newlines

---------

Co-authored-by: plykiya <plykiya@protonmail.com>
This commit is contained in:
Plykiya
2024-06-18 20:18:45 -07:00
committed by GitHub
parent 8d52c1aeb3
commit 9cd08b84d9
4 changed files with 41 additions and 37 deletions

View File

@@ -100,12 +100,11 @@
Margin="5 0 0 0" Margin="5 0 0 0"
Text="{Loc 'lathe-menu-fabricating-message'}"> Text="{Loc 'lathe-menu-fabricating-message'}">
</Label> </Label>
<TextureRect <EntityPrototypeView
Name="Icon" Name="FabricatingEntityProto"
HorizontalExpand="True" HorizontalAlignment="Left"
SizeFlagsStretchRatio="2" Margin="100 0 0 0"
Margin="100 0 0 0"> />
</TextureRect>
<Label <Label
Name="NameLabel" Name="NameLabel"
RectClipContent="True" RectClipContent="True"
@@ -114,12 +113,15 @@
</Label> </Label>
</PanelContainer> </PanelContainer>
</BoxContainer> </BoxContainer>
<ItemList <ScrollContainer VerticalExpand="True" HScrollEnabled="False">
Name="QueueList" <BoxContainer
VerticalExpand="True" Name="QueueList"
SizeFlagsStretchRatio="3" Orientation="Vertical"
SelectMode="None"> HorizontalExpand="True"
</ItemList> VerticalExpand="True"
RectClipContent="True">
</BoxContainer>
</ScrollContainer>
</BoxContainer> </BoxContainer>
<BoxContainer <BoxContainer
VerticalExpand="True" VerticalExpand="True"

View File

@@ -105,21 +105,13 @@ public sealed partial class LatheMenu : DefaultWindow
RecipeList.Children.Clear(); RecipeList.Children.Clear();
foreach (var prototype in sortedRecipesToShow) foreach (var prototype in sortedRecipesToShow)
{ {
List<Texture> textures; EntityPrototype? recipeProto = null;
if (_prototypeManager.TryIndex(prototype.Result, out EntityPrototype? entityProto) && entityProto != null) if (_prototypeManager.TryIndex(prototype.Result, out EntityPrototype? entityProto) && entityProto != null)
{ recipeProto = entityProto;
textures = SpriteComponent.GetPrototypeTextures(entityProto, _resources).Select(o => o.Default).ToList();
}
else
{
textures = prototype.Icon == null
? new List<Texture> { _spriteSystem.GetPrototypeIcon(prototype.Result).Default }
: new List<Texture> { _spriteSystem.Frame0(prototype.Icon) };
}
var canProduce = _lathe.CanProduce(_owner, prototype, quantity); var canProduce = _lathe.CanProduce(_owner, prototype, quantity);
var control = new RecipeControl(prototype, () => GenerateTooltipText(prototype), canProduce, textures); var control = new RecipeControl(prototype, () => GenerateTooltipText(prototype), canProduce, recipeProto);
control.OnButtonPressed += s => control.OnButtonPressed += s =>
{ {
if (!int.TryParse(AmountLineEdit.Text, out var amount) || amount <= 0) if (!int.TryParse(AmountLineEdit.Text, out var amount) || amount <= 0)
@@ -216,14 +208,23 @@ public sealed partial class LatheMenu : DefaultWindow
/// <param name="queue"></param> /// <param name="queue"></param>
public void PopulateQueueList(List<LatheRecipePrototype> queue) public void PopulateQueueList(List<LatheRecipePrototype> queue)
{ {
QueueList.Clear(); QueueList.DisposeAllChildren();
var idx = 1; var idx = 1;
foreach (var recipe in queue) foreach (var recipe in queue)
{ {
var icon = recipe.Icon == null var queuedRecipeBox = new BoxContainer();
? _spriteSystem.GetPrototypeIcon(recipe.Result).Default queuedRecipeBox.Orientation = BoxContainer.LayoutOrientation.Horizontal;
: _spriteSystem.Frame0(recipe.Icon);
QueueList.AddItem($"{idx}. {recipe.Name}", icon); var queuedRecipeProto = new EntityPrototypeView();
if (_prototypeManager.TryIndex(recipe.Result, out EntityPrototype? entityProto) && entityProto != null)
queuedRecipeProto.SetPrototype(entityProto);
var queuedRecipeLabel = new Label();
queuedRecipeLabel.Text = $"{idx}. {recipe.Name}";
queuedRecipeBox.AddChild(queuedRecipeProto);
queuedRecipeBox.AddChild(queuedRecipeLabel);
QueueList.AddChild(queuedRecipeBox);
idx++; idx++;
} }
} }
@@ -233,9 +234,10 @@ public sealed partial class LatheMenu : DefaultWindow
FabricatingContainer.Visible = recipe != null; FabricatingContainer.Visible = recipe != null;
if (recipe == null) if (recipe == null)
return; return;
Icon.Texture = recipe.Icon == null
? _spriteSystem.GetPrototypeIcon(recipe.Result).Default if (_prototypeManager.TryIndex(recipe.Result, out EntityPrototype? entityProto) && entityProto != null)
: _spriteSystem.Frame0(recipe.Icon); FabricatingEntityProto.SetPrototype(entityProto);
NameLabel.Text = $"{recipe.Name}"; NameLabel.Text = $"{recipe.Name}";
} }

View File

@@ -5,14 +5,12 @@
Margin="0" Margin="0"
StyleClasses="ButtonSquare"> StyleClasses="ButtonSquare">
<BoxContainer Orientation="Horizontal"> <BoxContainer Orientation="Horizontal">
<LayeredTextureRect <EntityPrototypeView
Name="RecipeTextures" Name="RecipePrototype"
Margin="0 0 4 0" Margin="0 0 4 0"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Stretch="KeepAspectCentered"
MinSize="32 32" MinSize="32 32"
CanShrink="true"
/> />
<Label Name="RecipeName" HorizontalExpand="True" /> <Label Name="RecipeName" HorizontalExpand="True" />
</BoxContainer> </BoxContainer>

View File

@@ -4,6 +4,7 @@ using Robust.Client.Graphics;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client.Lathe.UI; namespace Content.Client.Lathe.UI;
@@ -13,12 +14,13 @@ public sealed partial class RecipeControl : Control
public Action<string>? OnButtonPressed; public Action<string>? OnButtonPressed;
public Func<string> TooltipTextSupplier; public Func<string> TooltipTextSupplier;
public RecipeControl(LatheRecipePrototype recipe, Func<string> tooltipTextSupplier, bool canProduce, List<Texture> textures) public RecipeControl(LatheRecipePrototype recipe, Func<string> tooltipTextSupplier, bool canProduce, EntityPrototype? entityPrototype = null)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
RecipeName.Text = recipe.Name; RecipeName.Text = recipe.Name;
RecipeTextures.Textures = textures; if (entityPrototype != null)
RecipePrototype.SetPrototype(entityPrototype);
Button.Disabled = !canProduce; Button.Disabled = !canProduce;
TooltipTextSupplier = tooltipTextSupplier; TooltipTextSupplier = tooltipTextSupplier;
Button.TooltipSupplier = SupplyTooltip; Button.TooltipSupplier = SupplyTooltip;