using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; namespace Content.Client.Instruments.UI; [GenerateTypedNameReferences] public sealed partial class BandMidiSource : InstrumentMidiSourceBase { /// /// Raised when the list of currently available bands should be refreshed. /// public event Action? RefreshBandRequest; /// /// Raised when a band should be joined. /// public event Action? JoinBandRequest; public override string ButtonName => Loc.GetString("instruments-component-menu-band-midi-source-button"); public BandMidiSource() { RobustXamlLoader.Load(this); RefreshButton.OnPressed += OnRefreshPressed; BandList.OnItemSelected += OnBandItemSelected; } protected override void VisibilityChanged(bool newVisible) { if (newVisible) RefreshBandRequest?.Invoke(); } private void OnRefreshPressed(BaseButton.ButtonEventArgs _) { RefreshBandRequest?.Invoke(); } private void OnBandItemSelected(ItemList.ItemListSelectedEventArgs args) { var instrumentEntity = (EntityUid)args.ItemList[args.ItemIndex].Metadata!; JoinBandRequest?.Invoke(instrumentEntity); } /// /// Replaces the current list of available bands with the passed one. /// /// List of available entities for band joining. public void Populate(IEnumerable<(EntityUid, string)> entities) { BandList.Clear(); foreach (var tuple in entities) { BandList.AddItem(tuple.Item2, null, true, tuple.Item1); } } }