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 Content.Shared.Materials;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
@@ -10,7 +11,6 @@ namespace Content.Client.Lathe.UI;
/// <summary> /// <summary>
/// This widget is one row in the lathe eject menu. /// This widget is one row in the lathe eject menu.
/// </summary> /// </summary>
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class LatheMaterialEjector : PanelContainer public sealed partial class LatheMaterialEjector : PanelContainer
{ {
@@ -34,19 +34,28 @@ public sealed partial class LatheMaterialEjector : PanelContainer
public void PopulateButtons(int maxEjectableSheets) 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}", Name = $"{sheetsToEject}",
Access = AccessLevel.Public, Access = AccessLevel.Public,
Text = Loc.GetString($"{sheetsToEject}"), Text = Loc.GetString($"{sheetsToEject}"),
MinWidth = 45, MinWidth = 45,
StyleClasses = { styleClass }
}; };
button.OnPressed += (_) => button.OnPressed += _ =>
{ {
OnEjectPressed?.Invoke(Material, sheetsToEject); OnEjectPressed?.Invoke(Material, sheetsToEject);
}; };
@@ -55,7 +64,7 @@ public sealed partial class LatheMaterialEjector : PanelContainer
if (_prototypeManager.TryIndex<MaterialPrototype>(Material, out var proto)) 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); Content.AddChild(button);

View File

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

View File

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

View File

@@ -64,7 +64,7 @@ namespace Content.Server.Lathe
if (!_prototypeManager.TryIndex<MaterialPrototype>(message.Material, out var material)) if (!_prototypeManager.TryIndex<MaterialPrototype>(message.Material, out var material))
return; return;
int volume = 0; var volume = 0;
if (material.StackEntity != null) if (material.StackEntity != null)
{ {
@@ -73,14 +73,20 @@ namespace Content.Server.Lathe
return; return;
var volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == message.Material).Value; var volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == message.Material).Value;
int sheetsToExtract = Math.Min(message.SheetsToExtract, _stack.GetMaxCount(material.StackEntity)); var sheetsToExtract = Math.Min(message.SheetsToExtract, _stack.GetMaxCount(material.StackEntity));
volume = sheetsToExtract * volumePerSheet; volume = sheetsToExtract * volumePerSheet;
} }
if (volume > 0 && _materialStorage.TryChangeMaterialAmount(uid, message.Material, -volume)) if (volume > 0 && _materialStorage.TryChangeMaterialAmount(uid, message.Material, -volume))
{ {
_materialStorage.SpawnMultipleFromMaterial(volume, material, Transform(uid).Coordinates, out var overflow); var mats = _materialStorage.SpawnMultipleFromMaterial(volume, material, Transform(uid).Coordinates, out _);
foreach (var mat in mats)
{
if (TerminatingOrDeleted(mat))
continue;
_stack.TryMergeToContacts(mat);
}
} }
} }

View File

@@ -5,8 +5,15 @@ lathe-menu-sync = Sync
lathe-menu-search-designs = Search designs lathe-menu-search-designs = Search designs
lathe-menu-search-filter = Filter lathe-menu-search-filter = Filter
lathe-menu-amount = Amount: lathe-menu-amount = Amount:
lathe-menu-material-display = {$material} ({$amount} cm³) lathe-menu-material-display = {$material} ({ $amount ->
lathe-menu-tooltip-display = {$amount} cm³ of {$material} [1] {NATURALFIXED($amount, 2)} sheet
*[other] {NATURALFIXED($amount, 2)} sheets
})
lathe-menu-tooltip-display = { $amount ->
[1] {NATURALFIXED($amount, 2)} sheet
*[other] {NATURALFIXED($amount, 2)} sheets
} of {$material}
lathe-menu-no-materials-message = No materials loaded. lathe-menu-no-materials-message = No materials loaded.
lathe-menu-fabricating-message = Fabricating...
lathe-menu-materials-title = Materials lathe-menu-materials-title = Materials
lathe-menu-queue-title = Build Queue lathe-menu-queue-title = Build Queue

View File

@@ -1 +0,0 @@
1 sheet = 100cm3 of material