Files
OldThink/Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs

79 lines
2.2 KiB
C#
Raw Normal View History

using System.Numerics;
2023-02-19 06:27:56 +13:00
using Content.Shared.Chat;
namespace Content.Client.UserInterface.Systems.Chat.Controls;
public sealed class ChannelSelectorButton : ChatPopupButton<ChannelSelectorPopup>
{
public event Action<ChatSelectChannel>? OnChannelSelect;
public ChatSelectChannel SelectedChannel { get; private set; }
private const int SelectorDropdownOffset = 38;
public ChannelSelectorButton()
{
Name = "ChannelSelector";
Popup.Selected += OnChannelSelected;
if (Popup.FirstChannel is { } firstSelector)
{
Select(firstSelector);
}
}
protected override UIBox2 GetPopupPosition()
{
var globalLeft = GlobalPosition.X;
var globalBot = GlobalPosition.Y + Height;
return UIBox2.FromDimensions(
new Vector2(globalLeft, globalBot),
new Vector2(SizeBox.Width, SelectorDropdownOffset));
}
private void OnChannelSelected(ChatSelectChannel channel)
{
Select(channel);
}
public void Select(ChatSelectChannel channel)
{
if (Popup.Visible)
{
Popup.Close();
}
if (SelectedChannel == channel)
return;
SelectedChannel = channel;
OnChannelSelect?.Invoke(channel);
}
2023-02-19 06:27:56 +13:00
public static string ChannelSelectorName(ChatSelectChannel channel)
{
return Loc.GetString($"hud-chatbox-select-channel-{channel}");
}
public Color ChannelSelectColor(ChatSelectChannel channel)
{
return channel switch
{
ChatSelectChannel.Radio => Color.LimeGreen,
ChatSelectChannel.LOOC => Color.MediumTurquoise,
ChatSelectChannel.OOC => Color.LightSkyBlue,
ChatSelectChannel.Dead => Color.MediumPurple,
ChatSelectChannel.Admin => Color.HotPink,
ChatSelectChannel.Changeling => Color.Purple,
2024-01-27 15:19:52 +03:00
ChatSelectChannel.Cult => Color.DarkRed,
_ => Color.DarkGray
};
}
2023-02-19 06:27:56 +13:00
public void UpdateChannelSelectButton(ChatSelectChannel channel, Shared.Radio.RadioChannelPrototype? radio)
{
2023-02-19 06:27:56 +13:00
Text = radio != null ? Loc.GetString(radio.Name) : ChannelSelectorName(channel);
Modulate = radio?.Color ?? ChannelSelectColor(channel);
}
}