Intercom buffs and fixes (#29580)

* Intercom buffs and fixes

* remove unused bui state

* mild sec intercom buff

* reinforce sec intercoms
This commit is contained in:
Nemanja
2024-07-07 10:19:10 -04:00
committed by GitHub
parent 063c5de985
commit 0e9ed36b85
22 changed files with 338 additions and 136 deletions

View File

@@ -1,8 +1,9 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.Radio;
using Content.Shared.Radio.Components;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Client.Radio.Ui;
@@ -17,38 +18,54 @@ public sealed partial class IntercomMenu : FancyWindow
private readonly List<string> _channels = new();
public IntercomMenu()
public IntercomMenu(Entity<IntercomComponent> entity)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
MicButton.OnPressed += args => OnMicPressed?.Invoke(args.Button.Pressed);
SpeakerButton.OnPressed += args => OnSpeakerPressed?.Invoke(args.Button.Pressed);
Update(entity);
}
public void Update(IntercomBoundUIState state)
public void Update(Entity<IntercomComponent> entity)
{
MicButton.Pressed = state.MicEnabled;
SpeakerButton.Pressed = state.SpeakerEnabled;
MicButton.Pressed = entity.Comp.MicrophoneEnabled;
SpeakerButton.Pressed = entity.Comp.SpeakerEnabled;
MicButton.Disabled = entity.Comp.SupportedChannels.Count == 0;
SpeakerButton.Disabled = entity.Comp.SupportedChannels.Count == 0;
ChannelOptions.Disabled = entity.Comp.SupportedChannels.Count == 0;
ChannelOptions.Clear();
_channels.Clear();
for (var i = 0; i < state.AvailableChannels.Count; i++)
for (var i = 0; i < entity.Comp.SupportedChannels.Count; i++)
{
var channel = state.AvailableChannels[i];
if (!_prototype.TryIndex<RadioChannelPrototype>(channel, out var prototype))
var channel = entity.Comp.SupportedChannels[i];
if (!_prototype.TryIndex(channel, out var prototype))
continue;
_channels.Add(channel);
ChannelOptions.AddItem(Loc.GetString(prototype.Name), i);
if (channel == state.SelectedChannel)
if (channel == entity.Comp.CurrentChannel)
ChannelOptions.Select(i);
}
if (entity.Comp.SupportedChannels.Count == 0)
{
ChannelOptions.AddItem(Loc.GetString("intercom-options-none"), 0);
ChannelOptions.Select(0);
}
ChannelOptions.OnItemSelected += args =>
{
if (!_channels.TryGetValue(args.Id, out var proto))
return;
ChannelOptions.SelectId(args.Id);
OnChannelSelected?.Invoke(_channels[args.Id]);
OnChannelSelected?.Invoke(proto);
};
}
}