Changed Lathe UI to two-column layout so its easier to see what materials are currently loaded (#19608)

This commit is contained in:
Thom
2023-08-29 01:36:07 +01:00
committed by GitHub
parent 15c0211fb2
commit a1029be654
10 changed files with 216 additions and 330 deletions

View File

@@ -10,13 +10,6 @@ namespace Content.Client.Lathe.UI
{
[ViewVariables]
private LatheMenu? _menu;
[ViewVariables]
private LatheQueueMenu? _queueMenu;
[ViewVariables]
private LatheMaterialsEjectionMenu? _materialsEjectionMenu;
public LatheBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
@@ -26,26 +19,8 @@ namespace Content.Client.Lathe.UI
base.Open();
_menu = new LatheMenu(this);
_queueMenu = new LatheQueueMenu();
_materialsEjectionMenu = new LatheMaterialsEjectionMenu();
_menu.OnClose += Close;
_menu.OnQueueButtonPressed += _ =>
{
if (_queueMenu.IsOpen)
_queueMenu.Close();
else
_queueMenu.OpenCenteredLeft();
};
_menu.OnMaterialsEjectionButtonPressed += _ =>
{
if (_materialsEjectionMenu.IsOpen)
_materialsEjectionMenu.Close();
else
_materialsEjectionMenu.OpenCenteredRight();
};
_menu.OnServerListButtonPressed += _ =>
{
@@ -57,7 +32,7 @@ namespace Content.Client.Lathe.UI
SendMessage(new LatheQueueRecipeMessage(recipe, amount));
};
_materialsEjectionMenu.OnEjectPressed += (material, sheetsToExtract) =>
_menu.OnEjectPressed += (material, sheetsToExtract) =>
{
SendMessage(new LatheEjectMaterialMessage(material, sheetsToExtract));
};
@@ -76,9 +51,8 @@ namespace Content.Client.Lathe.UI
_menu.Recipes = msg.Recipes;
_menu?.PopulateRecipes(Owner);
_menu?.PopulateMaterials(Owner);
_queueMenu?.PopulateList(msg.Queue);
_queueMenu?.SetInfo(msg.CurrentlyProducing);
_materialsEjectionMenu?.PopulateMaterials(Owner);
_menu?.PopulateQueueList(msg.Queue);
_menu?.SetQueueInfo(msg.CurrentlyProducing);
break;
}
}
@@ -89,8 +63,7 @@ namespace Content.Client.Lathe.UI
if (!disposing)
return;
_menu?.Dispose();
_queueMenu?.Dispose();
_materialsEjectionMenu?.Dispose();
//thom _materialsEjectionMenu?.Dispose();
}
}
}

View File

@@ -14,7 +14,7 @@
Access="Public"
HorizontalExpand="True"
ClipText="True"
Margin="0 4 0 0"/>
Margin="4 4 4 4"/>
</BoxContainer>
<!--Here go buttons which added in c#-->
</BoxContainer>

View File

@@ -1,16 +0,0 @@
<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

@@ -1,74 +0,0 @@
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

@@ -2,8 +2,17 @@
xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'lathe-menu-title'}"
MinSize="300 450"
SetSize="350 475">
MinSize="550 450"
SetSize="750 500">
<BoxContainer
Orientation="Horizontal"
VerticalExpand="True"
HorizontalExpand="True"
SeparationOverride="5">
<!-- Left Col-->
<BoxContainer
VerticalExpand="True"
HorizontalExpand="True">
<BoxContainer
Orientation="Vertical"
VerticalExpand="True"
@@ -13,13 +22,6 @@
Orientation="Horizontal"
Align="End"
HorizontalExpand="True">
<Button
Name="QueueButton"
Text="{Loc 'lathe-menu-queue'}"
TextAlign="Center"
Mode="Press"
StyleClasses="OpenRight">
</Button>
<Button
Name="ServerListButton"
Text="{Loc 'lathe-menu-server-list'}"
@@ -73,20 +75,79 @@
Text="1"
HorizontalExpand="True" />
</BoxContainer>
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True">
</BoxContainer>
</BoxContainer>
<!-- Right Col-->
<BoxContainer
Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True"
SeparationOverride="5"
>
<BoxContainer Orientation="Vertical" MinHeight="225">
<Label Text="{Loc 'lathe-menu-queue-title'}" Margin="5 5 5 5" HorizontalAlignment="Center"/>
<BoxContainer
Orientation="Horizontal"
HorizontalExpand="True"
SizeFlagsStretchRatio="2">
<PanelContainer
VerticalExpand="True"
HorizontalExpand="True"
SizeFlagsStretchRatio="3">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#408040" />
</PanelContainer.PanelOverride>
<Label
Name="FabricatingActiveLabel"
RectClipContent="False"
HorizontalAlignment="Left"
Margin="5 0 0 0">
</Label>
<TextureRect
Name="Icon"
HorizontalExpand="True"
SizeFlagsStretchRatio="2"
Margin="100 0 0 0">
</TextureRect>
<Label
Name="NameLabel"
RectClipContent="True"
HorizontalAlignment="Left"
Margin="130 0 0 0">
</Label>
</PanelContainer>
</BoxContainer>
<ItemList
Name="Materials"
VerticalExpand="True">
Name="QueueList"
VerticalExpand="True"
SizeFlagsStretchRatio="3"
SelectMode="None">
</ItemList>
</BoxContainer>
<Button
Name="MaterialsEjectionButton"
Text="{Loc 'lathe-menu-materials-ejection'}"
TextAlign="Center"
Mode="Press"
StyleClasses="OpenRight">
</Button>
<BoxContainer
VerticalExpand="True"
HorizontalExpand="True"
Orientation="Vertical"
MinHeight="225"
>
<Label Text="{Loc 'lathe-menu-materials-title'}" Margin="5 5 5 5" HorizontalAlignment="Center"/>
<BoxContainer
Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True">
<BoxContainer
Name="MaterialsList"
Orientation="Vertical"
SizeFlagsStretchRatio="8"
HorizontalExpand="True"
VerticalExpand="True">
<!-- Materials populated in C# file -->
</BoxContainer>
</BoxContainer>
</BoxContainer>
</BoxContainer>
</BoxContainer>
</DefaultWindow>

View File

@@ -6,6 +6,7 @@ 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;
@@ -21,11 +22,10 @@ public sealed partial class LatheMenu : DefaultWindow
private readonly SpriteSystem _spriteSystem;
private readonly LatheSystem _lathe;
public event Action<BaseButton.ButtonEventArgs>? OnQueueButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnMaterialsEjectionButtonPressed;
// public event Action<BaseButton.ButtonEventArgs>? OnMaterialsEjectionButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnServerListButtonPressed;
public event Action<string, int>? RecipeQueueAction;
public event Action<string, int>? OnEjectPressed;
public List<string> Recipes = new();
public LatheMenu(LatheBoundUserInterface owner)
@@ -47,8 +47,7 @@ public sealed partial class LatheMenu : DefaultWindow
PopulateRecipes(owner.Owner);
};
QueueButton.OnPressed += a => OnQueueButtonPressed?.Invoke(a);
MaterialsEjectionButton.OnPressed += a => OnMaterialsEjectionButtonPressed?.Invoke(a);
//MaterialsEjectionButton.OnPressed += a => OnMaterialsEjectionButtonPressed?.Invoke(a);
ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a);
if (_entityManager.TryGetComponent<LatheComponent>(owner.Owner, out var latheComponent))
@@ -56,13 +55,6 @@ public sealed partial class LatheMenu : DefaultWindow
if (!latheComponent.DynamicRecipes.Any())
{
ServerListButton.Visible = false;
QueueButton.RemoveStyleClass(StyleBase.ButtonOpenRight);
//QueueButton.AddStyleClass(StyleBase.ButtonSquare);
}
if (MaterialsEjectionButton != null && !latheComponent.CanEjectStoredMaterials)
{
MaterialsEjectionButton.Dispose();
}
}
}
@@ -72,37 +64,52 @@ public sealed partial class LatheMenu : DefaultWindow
if (!_entityManager.TryGetComponent<MaterialStorageComponent>(lathe, out var materials))
return;
Materials.Clear();
MaterialsList.DisposeAllChildren();
foreach (var (id, amount) in materials.Storage)
foreach (var (materialId, volume) in materials.Storage)
{
if (amount <= 0)
if (volume <= 0)
continue;
if (!_prototypeManager.TryIndex(id, out MaterialPrototype? material))
if (!_prototypeManager.TryIndex(materialId, out MaterialPrototype? material))
continue;
var name = Loc.GetString(material.Name);
var mat = Loc.GetString("lathe-menu-material-display",
("material", name), ("amount", amount));
("material", name), ("amount", volume));
int volumePerSheet = 0;
int maxEjectableSheets = 0;
Materials.AddItem(mat, _spriteSystem.Frame0(material.Icon), false);
}
if (MaterialsEjectionButton != null)
if (material.StackEntity != null)
{
MaterialsEjectionButton.Disabled = Materials.Count == 0;
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);
}
}
if (Materials.Count == 0)
var row = new LatheMaterialEjector(materialId, OnEjectPressed, volumePerSheet, 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");
Materials.AddItem(noMaterialsMsg, null, false);
var noItemRow = new Label();
noItemRow.Text = noMaterialsMsg;
noItemRow.Align = Label.AlignMode.Center;
MaterialsList.AddChild(noItemRow);
}
PopulateRecipes(lathe);
}
/// <summary>
/// Populates the list of all the recipes
/// </summary>
@@ -167,4 +174,40 @@ public sealed partial class LatheMenu : DefaultWindow
RecipeList.AddChild(control);
}
}
/// <summary>
/// Populates the build queue list with all queued items
/// </summary>
/// <param name="queue"></param>
public void PopulateQueueList(List<LatheRecipePrototype> queue)
{
QueueList.Clear();
var idx = 1;
foreach (var recipe in queue)
{
var icon = recipe.Icon == null
? _spriteSystem.GetPrototypeIcon(recipe.Result).Default
: _spriteSystem.Frame0(recipe.Icon);
QueueList.AddItem($"{idx}. {recipe.Name}", icon);
idx++;
}
}
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;
}
}
}

View File

@@ -1,42 +0,0 @@
<DefaultWindow
xmlns="https://spacestation14.io"
Title="{Loc 'lathe-queue-menu-title'}"
MinSize="300 450"
SetSize="350 475">
<BoxContainer Orientation="Vertical">
<BoxContainer
Orientation="Horizontal"
HorizontalExpand="True"
SizeFlagsStretchRatio="2">
<TextureRect
Name="Icon"
HorizontalExpand="True"
SizeFlagsStretchRatio="2">
</TextureRect>
<BoxContainer
Orientation="Vertical"
VerticalExpand="True"
SizeFlagsStretchRatio="3">
<Label
Name="NameLabel"
RectClipContent="True"
Margin="36 0 0 0">
</Label>
<Label
Name="Description"
RectClipContent="True"
VerticalAlignment="Stretch"
VerticalExpand="True">
</Label>
</BoxContainer>
</BoxContainer>
<ItemList
Name="QueueList"
VerticalExpand="True"
SizeFlagsStretchRatio="3"
SelectMode="None">
</ItemList>
</BoxContainer>
</DefaultWindow>

View File

@@ -1,57 +0,0 @@
using Content.Shared.Research.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.Lathe.UI
{
[GenerateTypedNameReferences]
public sealed partial class LatheQueueMenu : DefaultWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private readonly SpriteSystem _spriteSystem;
public LatheQueueMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_spriteSystem = _entityManager.EntitySysManager.GetEntitySystem<SpriteSystem>();
SetInfo(null);
}
public void SetInfo(LatheRecipePrototype? recipe)
{
if (recipe != null)
{
Icon.Texture = recipe.Icon == null
? _spriteSystem.GetPrototypeIcon(recipe.Result).Default
: _spriteSystem.Frame0(recipe.Icon);
NameLabel.Text = recipe.Name;
Description.Text = recipe.Description;
}
else
{
Icon.Texture = Texture.Transparent;
NameLabel.Text = string.Empty;
Description.Text = Loc.GetString("lathe-queue-menu-not-producing-text");
}
}
public void PopulateList(List<LatheRecipePrototype> queue)
{
QueueList.Clear();
var idx = 1;
foreach (var recipe in queue)
{
var icon =recipe.Icon == null
? _spriteSystem.GetPrototypeIcon(recipe.Result).Default
: _spriteSystem.Frame0(recipe.Icon);
QueueList.AddItem($"{idx}. {recipe.Name}", icon);
idx++;
}
}
}
}

View File

@@ -7,6 +7,6 @@ lathe-menu-search-filter = Filter
lathe-menu-amount = Amount:
lathe-menu-material-display = {$material} ({$amount} cm³)
lathe-menu-tooltip-display = {$amount} cm³ of {$material}
lathe-menu-no-materials-message = No materials loaded
lathe-menu-materials-ejection = Eject materials
lathe-menu-materials-ejection-title = Eject materials
lathe-menu-no-materials-message = No materials loaded.
lathe-menu-materials-title = Materials
lathe-menu-queue-title = Build Queue

View File

@@ -1,2 +0,0 @@
lathe-queue-menu-title = Lathe Queue
lathe-queue-menu-not-producing-text = Not producing anything.