Good Intercoms (#17950)

* crystal anomaly

* Good intercoms

* fixes

* fix construction fail

* Revert "crystal anomaly"

This reverts commit 0d9e3f62ff82c79e72f882b9c7f4ca1b9c6e6dd8.

* migration
This commit is contained in:
Nemanja
2023-07-11 19:58:18 -04:00
committed by GitHub
parent f89e85c1e9
commit 6dbfbc52c0
21 changed files with 407 additions and 98 deletions

View File

@@ -0,0 +1,58 @@
using Content.Shared.Radio;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
namespace Content.Client.Radio.Ui;
[UsedImplicitly]
public sealed class IntercomBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private IntercomMenu? _menu;
public IntercomBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_menu = new();
_menu.OnMicPressed += enabled =>
{
SendMessage(new ToggleIntercomMicMessage(enabled));
};
_menu.OnSpeakerPressed += enabled =>
{
SendMessage(new ToggleIntercomSpeakerMessage(enabled));
};
_menu.OnChannelSelected += channel =>
{
SendMessage(new SelectIntercomChannelMessage(channel));
};
_menu.OnClose += Close;
_menu.OpenCentered();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Close();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not IntercomBoundUIState msg)
return;
_menu?.Update(msg);
}
}

View File

@@ -0,0 +1,31 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'intercom-menu-title'}"
MinSize="300 170"
SetSize="300 170">
<BoxContainer Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True"
Margin="5 0 5 0">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" HorizontalAlignment="Center">
<Label Text="{Loc 'intercom-channel-label'}" HorizontalAlignment="Center"/>
<OptionButton Name="ChannelOptions" VerticalExpand="True" MinWidth="125"/>
</BoxContainer>
</BoxContainer>
<Control MinHeight="10"/>
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" HorizontalAlignment="Right" Margin="5 0 5 5">
<Button Name="MicButton" ToggleMode="True" Text="{Loc 'intercom-button-text-mic'}" StyleClasses="OpenRight" MinWidth="70"/>
<Button Name="SpeakerButton" ToggleMode="True" Text="{Loc 'intercom-button-text-speaker'}" StyleClasses="OpenLeft" MinWidth="70"/>
</BoxContainer>
<BoxContainer Orientation="Vertical">
<PanelContainer StyleClasses="LowDivider" />
<BoxContainer Orientation="Horizontal" Margin="10 2 5 0" VerticalAlignment="Bottom">
<Label Text="{Loc 'intercom-flavor-text-left'}" StyleClasses="WindowFooterText"
HorizontalAlignment="Left" HorizontalExpand="True" Margin="0 0 5 0" />
<TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered"
VerticalAlignment="Center" HorizontalAlignment="Right" SetSize="19 19"/>
</BoxContainer>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>

View File

@@ -0,0 +1,55 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.Radio;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client.Radio.Ui;
[GenerateTypedNameReferences]
public sealed partial class IntercomMenu : FancyWindow
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
public event Action<bool>? OnMicPressed;
public event Action<bool>? OnSpeakerPressed;
public event Action<string>? OnChannelSelected;
private readonly List<string> _channels = new();
public IntercomMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
MicButton.OnPressed += args => OnMicPressed?.Invoke(args.Button.Pressed);
SpeakerButton.OnPressed += args => OnSpeakerPressed?.Invoke(args.Button.Pressed);
}
public void Update(IntercomBoundUIState state)
{
MicButton.Pressed = state.MicEnabled;
SpeakerButton.Pressed = state.SpeakerEnabled;
ChannelOptions.Clear();
_channels.Clear();
for (var i = 0; i < state.AvailableChannels.Count; i++)
{
var channel = state.AvailableChannels[i];
if (!_prototype.TryIndex<RadioChannelPrototype>(channel, out var prototype))
continue;
_channels.Add(channel);
ChannelOptions.AddItem(Loc.GetString(prototype.Name), i);
if (channel == state.SelectedChannel)
ChannelOptions.Select(i);
}
ChannelOptions.OnItemSelected += args =>
{
ChannelOptions.SelectId(args.Id);
OnChannelSelected?.Invoke(_channels[args.Id]);
};
}
}