Files
crystall-punk-14/Content.Client/_CP14/ResearchTable/CP14ResearchRecipeControl.xaml.cs

61 lines
1.7 KiB
C#
Raw Normal View History

using Content.Shared._CP14.Skill;
using Content.Shared._CP14.Skill.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.ResearchTable;
[GenerateTypedNameReferences]
public sealed partial class CP14ResearchRecipeControl : Control
{
[Dependency] private readonly IEntityManager _entity = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
public event Action<CP14ResearchUiEntry, CP14SkillPrototype>? OnResearch;
private readonly SpriteSystem _sprite;
private readonly CP14SharedSkillSystem _skillSystem;
private readonly CP14SkillPrototype _skillPrototype;
private readonly bool _craftable;
public CP14ResearchRecipeControl(CP14ResearchUiEntry entry)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_sprite = _entity.System<SpriteSystem>();
_skillSystem = _entity.System<CP14SharedSkillSystem>();
_skillPrototype = _prototype.Index(entry.ProtoId);
_craftable = entry.Craftable;
Button.OnPressed += _ => OnResearch?.Invoke(entry, _skillPrototype);
UpdateColor();
UpdateName();
UpdateView();
}
private void UpdateColor()
{
if (_craftable)
return;
Button.ModulateSelfOverride = Color.FromHex("#302622");
}
private void UpdateName()
{
Name.Text = $"{Loc.GetString(_skillSystem.GetSkillName(_skillPrototype))}" ;
}
private void UpdateView()
{
View.Texture =_sprite.Frame0(_skillPrototype.Icon);
}
}