Files
crystall-punk-14/Content.Client/_CP14/Workbench/CP14WorkbenchRequirementControl.xaml.cs
Ed b3eed32588 Workbench Refactor (#826)
* Workbench refactor

* fixes

* update all recipes protos

* scrap resprite

* scrap melting

* scrap weapon drop

* demiplane loot update

* weapon parts melting

* fix

* boilerplate

* material localization
2025-01-31 14:47:51 +03:00

66 lines
1.9 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;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client._CP14.Workbench;
[GenerateTypedNameReferences]
public sealed partial class CP14WorkbenchRecipeControl : Control
{
[Dependency] private readonly IEntityManager _entity = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
public event Action<CP14WorkbenchUiRecipesEntry, CP14WorkbenchRecipePrototype>? OnSelect;
private readonly SpriteSystem _sprite;
private readonly CP14WorkbenchRecipePrototype _recipePrototype;
private readonly bool _craftable;
public CP14WorkbenchRecipeControl(CP14WorkbenchUiRecipesEntry entry)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_sprite = _entity.System<SpriteSystem>();
_recipePrototype = _prototype.Index(entry.ProtoId);
_craftable = entry.Craftable;
Button.OnPressed += _ => OnSelect?.Invoke(entry, _recipePrototype);
UpdateColor();
UpdateName();
UpdateView();
}
private void UpdateColor()
{
if (_craftable)
return;
Button.ModulateSelfOverride = Color.FromHex("#302622");
}
private void UpdateName()
{
var result = _prototype.Index(_recipePrototype.Result);
var counter = _recipePrototype.ResultCount > 1 ? $" x{_recipePrototype.ResultCount}" : "";
Name.Text = $"{Loc.GetString(result.Name)} {counter}" ;
}
private void UpdateView()
{
View.SetPrototype(_recipePrototype.Result);
}
}