Files
tbd-station-14/Content.Client/Lathe/UI/LatheBoundUserInterface.cs
chromiumboy a39fa80d58 Add lathe material ejection (#19218)
This completes PilgrimViis' (now closed) PR 16398. It addresses issue 10896, by allowing materials to be ejected from most lathes (except the ore processor and sheet-meister 2000)

* - Refinements to the material ejection UI
- Made the lathe UI default to a slightly larger size
- Fixed an offset issue with the label of the item currently being printed in the build queue UI

* Allow the materiel reclamation UI to pop if there is material left in the lathe, but not enough to print any sheets

---------

Co-authored-by: Kevin Zheng <kevinz5000@gmail.com>
2023-08-17 09:22:01 -08:00

97 lines
2.8 KiB
C#

using Content.Shared.Lathe;
using Content.Shared.Research.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
namespace Content.Client.Lathe.UI
{
[UsedImplicitly]
public sealed class LatheBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private LatheMenu? _menu;
[ViewVariables]
private LatheQueueMenu? _queueMenu;
[ViewVariables]
private LatheMaterialsEjectionMenu? _materialsEjectionMenu;
public LatheBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
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 += _ =>
{
SendMessage(new ConsoleServerSelectionMessage());
};
_menu.RecipeQueueAction += (recipe, amount) =>
{
SendMessage(new LatheQueueRecipeMessage(recipe, amount));
};
_materialsEjectionMenu.OnEjectPressed += (material, sheetsToExtract) =>
{
SendMessage(new LatheEjectMaterialMessage(material, sheetsToExtract));
};
_menu.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
switch (state)
{
case LatheUpdateState msg:
if (_menu != null)
_menu.Recipes = msg.Recipes;
_menu?.PopulateRecipes(Owner);
_menu?.PopulateMaterials(Owner);
_queueMenu?.PopulateList(msg.Queue);
_queueMenu?.SetInfo(msg.CurrentlyProducing);
_materialsEjectionMenu?.PopulateMaterials(Owner);
break;
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
_queueMenu?.Dispose();
_materialsEjectionMenu?.Dispose();
}
}
}