Files
crystall-punk-14/Content.Client/_CP14/Workbench/CP14WorkbenchWindow.xaml.cs
Ed 37a4068334 CLA license update (#429)
* pupu

* Update LICENSE.TXT

* CLA

* CLA!

* Revert "CLA!"

This reverts commit f999e341a1.

* CLA2

* Update rsi.json

* CLA3

* Workbench sublicense
2024-08-29 18:23:33 +03:00

110 lines
3.3 KiB
C#

/*
* This file is sublicensed under MIT License
* https://github.com/space-wizards/space-station-14/blob/master/LICENSE.TXT
*/
using Content.Shared._CP14.Workbench;
using Content.Shared._CP14.Workbench.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client._CP14.Workbench;
[GenerateTypedNameReferences]
public sealed partial class CP14WorkbenchWindow : DefaultWindow
{
[Dependency] private readonly IEntityManager _entity = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
public event Action<CP14WorkbenchUiRecipesEntry>? OnCraft;
private readonly SpriteSystem _sprite;
private CP14WorkbenchUiRecipesEntry? _selectedEntry ;
public CP14WorkbenchWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_sprite = _entity.System<SpriteSystem>();
CraftButton.OnPressed += _ =>
{
if (_selectedEntry is null)
return;
OnCraft?.Invoke(_selectedEntry.Value);
};
}
public void UpdateRecipes(CP14WorkbenchUiRecipesState recipesState)
{
CraftsContainer.RemoveAllChildren();
List<CP14WorkbenchUiRecipesEntry> uncraftableList = new();
foreach (var entry in recipesState.Recipes)
{
if (entry.Craftable)
{
var control = new CP14WorkbenchRequirementControl(entry);
control.OnSelect += RecipeSelect;
CraftsContainer.AddChild(control);
}
else
uncraftableList.Add(entry);
}
foreach (var entry in uncraftableList)
{
var control = new CP14WorkbenchRequirementControl(entry);
control.OnSelect += RecipeSelect;
CraftsContainer.AddChild(control);
}
if (_selectedEntry is not null && recipesState.Recipes.Contains(_selectedEntry.Value))
{
RecipeSelect(_selectedEntry.Value, _prototype.Index(_selectedEntry.Value.ProtoId));
return;
}
RecipeSelect(recipesState);
}
private void RecipeSelect(CP14WorkbenchUiRecipesState recipesState)
{
foreach (var entry in recipesState.Recipes)
{
RecipeSelect(entry, _prototype.Index(entry.ProtoId));
break;
}
}
private void RecipeSelect(CP14WorkbenchUiRecipesEntry entry, CP14WorkbenchRecipePrototype recipe)
{
_selectedEntry = entry;
var result = _prototype.Index(recipe.Result);
ItemView.Texture = _sprite.GetPrototypeIcon(recipe.Result).Default;
ItemName.Text = result.Name;
ItemDescription.Text = result.Description;
ItemRequirements.RemoveAllChildren();
foreach (var (entProtoId, count) in recipe.Entities)
{
ItemRequirements.AddChild(new CP14WorkbenchRecipeControl(_prototype.Index(entProtoId), count));
}
foreach (var (stackProtoId, count) in recipe.Stacks)
{
ItemRequirements.AddChild(new CP14WorkbenchRecipeControl(_prototype.Index(stackProtoId), count));
}
CraftButton.Disabled = !entry.Craftable;
}
}