/* * 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 CP14WorkbenchRequirementControl : Control { [Dependency] private readonly IEntityManager _entity = default!; [Dependency] private readonly IPrototypeManager _prototype = default!; public event Action? OnSelect; private readonly SpriteSystem _sprite; private readonly CP14WorkbenchRecipePrototype _recipePrototype; private readonly bool _craftable; public CP14WorkbenchRequirementControl(CP14WorkbenchUiRecipesEntry entry) { RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); _sprite = _entity.System(); _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); Name.Text = Loc.GetString(result.Name); } private void UpdateView() { View.Texture = _sprite.GetPrototypeIcon(_recipePrototype.Result).Default; } }