Files
tbd-station-14/Content.Client/Lathe/UI/LatheMenu.cs
Chris V 94a0bc92b7 Salvage mining, ore processing, and material clean-up (#7406)
* adding stuff cuz new computer

* removed unused materials

* remove unused materials and such, lathe things

* material volume no longer hardcoded

* fixed mining system

* add 5 stacks of materials, and add them to the ore processor

* fix copyright for ores and handdrill

* comma momma

* whyyyyy

* more fixes to make the yaml linter happy

* i should get my eyes checked

* silver proper

* more cleanup

* leftovers

* remove more references to material doors

* couldn't bear to be without bearhide

* added uranium, added more lathe recipes

* copyright fix, stack fix

* ore processor sprite and such

* ore processing some binches

* MaterialCotton removal

* 1 uranium ore means 1 sheet

* fix merge conflict? idk

* time to ketchup

* lathe recognizes material volume again

* yaml cleanup

* forgot to remove adamantine lol

* re-added diamond for now

* diamond stacks

* functional ore processor

* added ignoreColor to lathe visuals

* ore processor machine board

* add board to industrial tech and circuit printer

* provided lathes their whitelists

* fix wonky ore spawning, added insert sound to lathe, adjusted ore chance

* re-added ore processor

* typos and cleanup

* Update Content.Client/Lathe/LatheSystem.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Update Content.Server/Lathe/LatheSystem.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* revert mapchange

* VV ignorecolor, pass entitymanager, move canceltoken to pickaxe, removed foreach from orespawn

* actually null canceltoken

* remove five-stacks, ore processor produces full stacks or single sheets/ingots

* VV proper

* adjust ore chances

* readd Cotton

* Update Content.Server/Mining/MineableSystem.cs

* tweaks

* Material is now dict (material, volume)

* removed unused property

* Space crystal -> space quartz

* forgor asteroid space quartz

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2022-04-28 20:41:04 +10:00

239 lines
7.3 KiB
C#

using System.Collections.Generic;
using Content.Client.Lathe.Components;
using Content.Shared.Lathe;
using Content.Shared.Materials;
using Content.Shared.Research.Prototypes;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.Utility;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.Lathe.UI
{
public sealed class LatheMenu : DefaultWindow
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private readonly ItemList _items;
private readonly ItemList _materials;
private readonly LineEdit _amountLineEdit;
private readonly LineEdit _searchBar;
public Button QueueButton;
public Button ServerConnectButton;
public Button ServerSyncButton;
public LatheBoundUserInterface Owner { get; }
private readonly List<LatheRecipePrototype> _shownRecipes = new();
public LatheMenu(LatheBoundUserInterface owner)
{
SetSize = MinSize = (300, 450);
IoCManager.InjectDependencies(this);
Owner = owner;
Title = "Lathe Menu"; // TODO Replace this with the name of the lathe itself
var vBox = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
VerticalExpand = true,
SeparationOverride = 5,
};
var hBoxButtons = new BoxContainer
{
Orientation = LayoutOrientation.Horizontal,
HorizontalExpand = true,
VerticalExpand = true,
SizeFlagsStretchRatio = 1,
};
QueueButton = new Button()
{
Text = "Queue",
TextAlign = Label.AlignMode.Center,
SizeFlagsStretchRatio = 1,
};
ServerConnectButton = new Button()
{
Text = "Server list",
TextAlign = Label.AlignMode.Center,
SizeFlagsStretchRatio = 1,
};
ServerSyncButton = new Button()
{
Text = "Sync",
TextAlign = Label.AlignMode.Center,
SizeFlagsStretchRatio = 1,
};
var spacer = new Control()
{
HorizontalExpand = true,
SizeFlagsStretchRatio = 3,
};
var hBoxFilter = new BoxContainer
{
Orientation = LayoutOrientation.Horizontal,
HorizontalExpand = true,
VerticalExpand = true,
SizeFlagsStretchRatio = 1
};
_searchBar = new LineEdit()
{
PlaceHolder = "Search Designs",
HorizontalExpand = true,
SizeFlagsStretchRatio = 3
};
_searchBar.OnTextChanged += Populate;
var filterButton = new Button()
{
Text = "Filter",
TextAlign = Label.AlignMode.Center,
SizeFlagsStretchRatio = 1,
Disabled = true,
};
_items = new ItemList()
{
SizeFlagsStretchRatio = 8,
VerticalExpand = true,
SelectMode = ItemList.ItemListSelectMode.Button,
};
_items.OnItemSelected += ItemSelected;
_amountLineEdit = new LineEdit()
{
PlaceHolder = "Amount",
Text = "1",
HorizontalExpand = true,
};
_amountLineEdit.OnTextChanged += PopulateDisabled;
_materials = new ItemList()
{
VerticalExpand = true,
SizeFlagsStretchRatio = 3
};
hBoxButtons.AddChild(spacer);
if (Owner.Database is ProtolatheDatabaseComponent database)
{
hBoxButtons.AddChild(ServerConnectButton);
hBoxButtons.AddChild(ServerSyncButton);
database.OnDatabaseUpdated += Populate;
}
hBoxButtons.AddChild(QueueButton);
hBoxFilter.AddChild(_searchBar);
hBoxFilter.AddChild(filterButton);
vBox.AddChild(hBoxButtons);
vBox.AddChild(hBoxFilter);
vBox.AddChild(_items);
vBox.AddChild(_amountLineEdit);
vBox.AddChild(_materials);
Contents.AddChild(vBox);
}
public void ItemSelected(ItemList.ItemListSelectedEventArgs args)
{
int.TryParse(_amountLineEdit.Text, out var quantity);
if (quantity <= 0) quantity = 1;
Owner.Queue(_shownRecipes[args.ItemIndex], quantity);
}
public void PopulateMaterials()
{
_materials.Clear();
if (Owner.Storage == null) return;
foreach (var (id, amount) in Owner.Storage)
{
if (!_prototypeManager.TryIndex(id, out MaterialPrototype? materialPrototype)) continue;
var material = materialPrototype;
_materials.AddItem($"{material.Name} {amount} cm³", material.Icon.Frame0(), false);
}
}
/// <summary>
/// Disables or enables shown recipes depending on whether there are enough materials for it or not.
/// </summary>
public void PopulateDisabled()
{
int.TryParse(_amountLineEdit.Text, out var quantity);
if (quantity <= 0) quantity = 1;
for (var i = 0; i < _shownRecipes.Count; i++)
{
var prototype = _shownRecipes[i];
_items[i].Disabled = !Owner.Lathe?.CanProduce(prototype, quantity) ?? true;
}
}
/// <inheritdoc cref="PopulateDisabled()"/>
public void PopulateDisabled(LineEdit.LineEditEventArgs args)
{
PopulateDisabled();
}
/// <summary>
/// Adds shown recipes to the ItemList control.
/// </summary>
public void PopulateList()
{
_items.Clear();
foreach (var prototype in _shownRecipes)
{
_items.AddItem(prototype.Name, prototype.Icon.Frame0());
}
PopulateDisabled();
}
/// <summary>
/// Populates the list of recipes that will actually be shown, using the current filters.
/// </summary>
public void Populate()
{
_shownRecipes.Clear();
if (Owner.Database == null) return;
foreach (var prototype in Owner.Database)
{
if (_searchBar.Text.Trim().Length != 0)
{
if (prototype.Name.ToLowerInvariant().Contains(_searchBar.Text.Trim().ToLowerInvariant()))
_shownRecipes.Add(prototype);
continue;
}
_shownRecipes.Add(prototype);
}
PopulateList();
}
/// <inheritdoc cref="Populate"/>
public void Populate(LineEdit.LineEditEventArgs args)
{
Populate();
}
}
}