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

@@ -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 (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 = mat }
};
MaterialsList.AddChild(row);
}
if (MaterialsEjectionButton != null)
{
MaterialsEjectionButton.Disabled = Materials.Count == 0;
}
if (Materials.Count == 0)
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;
}
}
}