6
StarHorizon_Public/Content.Client/_NF/BountyContracts/UI/BountyContractUiFragmentTabSet.xaml.cs
2025-11-07 12:32:48 +03:00

39 lines
1.3 KiB
C#

using Content.Shared._NF.BountyContracts;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client._NF.BountyContracts.UI;
[GenerateTypedNameReferences]
public sealed partial class BountyContractUiFragmentTabSet : TabContainer
{
[Dependency] private readonly IPrototypeManager _proto = default!;
public event Action<ProtoId<BountyContractCollectionPrototype>>? OnSelectCollection;
private Dictionary<int, ProtoId<BountyContractCollectionPrototype>> _tabsToCollections;
public BountyContractUiFragmentTabSet()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_tabsToCollections = new();
OnTabChanged += TabChanged;
}
// Note: no safety checks on tabIndex range.
public bool SetTabCollection(int tabIndex, ProtoId<BountyContractCollectionPrototype> collection)
{
if (_proto.TryIndex(collection, out var collectionProto))
SetTabTitle(tabIndex, Loc.GetString(collectionProto.Name));
return _tabsToCollections.TryAdd(tabIndex, collection);
}
public void TabChanged(int tabIndex)
{
if (_tabsToCollections.ContainsKey(tabIndex))
OnSelectCollection?.Invoke(_tabsToCollections[tabIndex]);
}
}