Show materials as sheets, tweak lathe ui (#19709)

This commit is contained in:
Nemanja
2023-09-01 01:28:08 -04:00
committed by GitHub
parent 22d4d704ee
commit 6695ac2ad6
6 changed files with 71 additions and 60 deletions

View File

@@ -1,3 +1,4 @@
using Content.Client.Stylesheets;
using Content.Shared.Materials;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
@@ -10,7 +11,6 @@ namespace Content.Client.Lathe.UI;
/// <summary>
/// This widget is one row in the lathe eject menu.
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class LatheMaterialEjector : PanelContainer
{
@@ -34,19 +34,28 @@ public sealed partial class LatheMaterialEjector : PanelContainer
public void PopulateButtons(int maxEjectableSheets)
{
int[] sheetsToEjectArray = { 1, 5, 10, 30 };
int[] sheetsToEjectArray = { 1, 5, 10 };
foreach (int sheetsToEject in sheetsToEjectArray)
for (var i = 0; i < sheetsToEjectArray.Length; i++)
{
var button = new Button()
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 += (_) =>
button.OnPressed += _ =>
{
OnEjectPressed?.Invoke(Material, sheetsToEject);
};
@@ -55,7 +64,7 @@ public sealed partial class LatheMaterialEjector : PanelContainer
if (_prototypeManager.TryIndex<MaterialPrototype>(Material, out var proto))
{
button.ToolTip = Loc.GetString("lathe-menu-tooltip-display", ("amount", sheetsToEject * VolumePerSheet), ("material", Loc.GetString(proto.Name)));
button.ToolTip = Loc.GetString("lathe-menu-tooltip-display", ("amount", sheetsToEject), ("material", Loc.GetString(proto.Name)));
}
Content.AddChild(button);

View File

@@ -18,18 +18,6 @@
VerticalExpand="True"
HorizontalExpand="True"
SeparationOverride="5">
<BoxContainer
Orientation="Horizontal"
Align="End"
HorizontalExpand="True">
<Button
Name="ServerListButton"
Text="{Loc 'lathe-menu-server-list'}"
TextAlign="Center"
Mode="Press"
StyleClasses="OpenLeft">
</Button>
</BoxContainer>
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True">
<LineEdit
@@ -77,17 +65,28 @@
</BoxContainer>
</BoxContainer>
</BoxContainer>
<BoxContainer MinWidth="5"/>
<!-- Right Col-->
<BoxContainer
Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True"
SeparationOverride="5"
>
<BoxContainer Orientation="Vertical" MinHeight="225">
SeparationOverride="5">
<BoxContainer Orientation="Vertical" MinHeight="225">
<BoxContainer
Orientation="Horizontal"
Align="End"
HorizontalExpand="True">
<Button
Name="ServerListButton"
Text="{Loc 'lathe-menu-server-list'}"
TextAlign="Center"
Mode="Press">
</Button>
</BoxContainer>
<Label Text="{Loc 'lathe-menu-queue-title'}" Margin="5 5 5 5" HorizontalAlignment="Center"/>
<BoxContainer
Name="FabricatingContainer"
Orientation="Horizontal"
HorizontalExpand="True"
SizeFlagsStretchRatio="2">
@@ -99,16 +98,16 @@
<gfx:StyleBoxFlat BackgroundColor="#408040" />
</PanelContainer.PanelOverride>
<Label
Name="FabricatingActiveLabel"
RectClipContent="False"
HorizontalAlignment="Left"
Margin="5 0 0 0">
RectClipContent="False"
HorizontalAlignment="Left"
Margin="5 0 0 0"
Text="{Loc 'lathe-menu-fabricating-message'}">
</Label>
<TextureRect
Name="Icon"
HorizontalExpand="True"
SizeFlagsStretchRatio="2"
Margin="100 0 0 0">
Name="Icon"
HorizontalExpand="True"
SizeFlagsStretchRatio="2"
Margin="100 0 0 0">
</TextureRect>
<Label
Name="NameLabel"

View File

@@ -1,12 +1,11 @@
using System.Linq;
using System.Text;
using Content.Client.Stylesheets;
using Content.Shared.FixedPoint;
using Content.Shared.Lathe;
using Content.Shared.Materials;
using Content.Shared.Research.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
@@ -22,7 +21,6 @@ public sealed partial class LatheMenu : DefaultWindow
private readonly SpriteSystem _spriteSystem;
private readonly LatheSystem _lathe;
// public event Action<BaseButton.ButtonEventArgs>? OnMaterialsEjectionButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnServerListButtonPressed;
public event Action<string, int>? RecipeQueueAction;
public event Action<string, int>? OnEjectPressed;
@@ -47,7 +45,6 @@ public sealed partial class LatheMenu : DefaultWindow
PopulateRecipes(owner.Owner);
};
//MaterialsEjectionButton.OnPressed += a => OnMaterialsEjectionButtonPressed?.Invoke(a);
ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a);
if (_entityManager.TryGetComponent<LatheComponent>(owner.Owner, out var latheComponent))
@@ -76,19 +73,18 @@ public sealed partial class LatheMenu : DefaultWindow
var name = Loc.GetString(material.Name);
var mat = Loc.GetString("lathe-menu-material-display",
("material", name), ("amount", volume));
int volumePerSheet = 0;
int maxEjectableSheets = 0;
("material", name), ("amount", volume / 100));
var volumePerSheet = 0;
var 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);
maxEjectableSheets = (int) MathF.Floor((float) volume / volumePerSheet);
}
}
@@ -156,7 +152,9 @@ public sealed partial class LatheMenu : DefaultWindow
var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, component.MaterialUseMultiplier);
sb.Append(Loc.GetString("lathe-menu-tooltip-display", ("amount", adjustedAmount), ("material", Loc.GetString(proto.Name))));
sb.Append(Loc.GetString("lathe-menu-tooltip-display",
("amount", MathF.Round(adjustedAmount / 100f, 2)),
("material", Loc.GetString(proto.Name))));
}
var icon = prototype.Icon == null
@@ -195,19 +193,12 @@ public sealed partial class LatheMenu : DefaultWindow
public void SetQueueInfo(LatheRecipePrototype? recipe)
{
if (recipe != null)
{
Icon.Texture = recipe.Icon == null
? _spriteSystem.GetPrototypeIcon(recipe.Result).Default
: _spriteSystem.Frame0(recipe.Icon);
FabricatingActiveLabel.Text = "Fabricating...";
NameLabel.Text = $"{recipe.Name}";
}
else
{
Icon.Texture = Texture.Transparent;
FabricatingActiveLabel.Text = String.Empty;
NameLabel.Text = String.Empty;
}
FabricatingContainer.Visible = recipe != null;
if (recipe == null)
return;
Icon.Texture = recipe.Icon == null
? _spriteSystem.GetPrototypeIcon(recipe.Result).Default
: _spriteSystem.Frame0(recipe.Icon);
NameLabel.Text = $"{recipe.Name}";
}
}