2023-07-08 14:08:32 +10:00
|
|
|
using System.Numerics;
|
2023-02-19 06:27:56 +13:00
|
|
|
using Content.Shared.Chat;
|
2022-10-12 01:16:23 -07:00
|
|
|
|
|
|
|
|
namespace Content.Client.UserInterface.Systems.Chat.Controls;
|
|
|
|
|
|
2023-12-13 03:02:19 +01:00
|
|
|
public sealed class ChannelSelectorButton : ChatPopupButton<ChannelSelectorPopup>
|
2022-10-12 01:16:23 -07:00
|
|
|
{
|
|
|
|
|
public event Action<ChatSelectChannel>? OnChannelSelect;
|
|
|
|
|
|
|
|
|
|
public ChatSelectChannel SelectedChannel { get; private set; }
|
|
|
|
|
|
|
|
|
|
private const int SelectorDropdownOffset = 38;
|
|
|
|
|
|
|
|
|
|
public ChannelSelectorButton()
|
|
|
|
|
{
|
|
|
|
|
Name = "ChannelSelector";
|
2023-12-09 03:15:06 +01:00
|
|
|
|
2023-12-13 03:02:19 +01:00
|
|
|
Popup.Selected += OnChannelSelected;
|
2023-12-09 03:15:06 +01:00
|
|
|
|
2023-12-13 03:02:19 +01:00
|
|
|
if (Popup.FirstChannel is { } firstSelector)
|
2022-10-12 01:16:23 -07:00
|
|
|
{
|
|
|
|
|
Select(firstSelector);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 03:02:19 +01:00
|
|
|
protected override UIBox2 GetPopupPosition()
|
2022-10-12 01:16:23 -07:00
|
|
|
{
|
2023-12-13 03:02:19 +01:00
|
|
|
var globalLeft = GlobalPosition.X;
|
|
|
|
|
var globalBot = GlobalPosition.Y + Height;
|
|
|
|
|
return UIBox2.FromDimensions(
|
|
|
|
|
new Vector2(globalLeft, globalBot),
|
|
|
|
|
new Vector2(SizeBox.Width, SelectorDropdownOffset));
|
2022-10-12 01:16:23 -07:00
|
|
|
}
|
|
|
|
|
|
2023-12-13 03:02:19 +01:00
|
|
|
private void OnChannelSelected(ChatSelectChannel channel)
|
2022-10-12 01:16:23 -07:00
|
|
|
{
|
2023-12-13 03:02:19 +01:00
|
|
|
Select(channel);
|
2022-10-12 01:16:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Select(ChatSelectChannel channel)
|
|
|
|
|
{
|
2023-12-13 03:02:19 +01:00
|
|
|
if (Popup.Visible)
|
2022-10-12 01:16:23 -07:00
|
|
|
{
|
2023-12-13 03:02:19 +01:00
|
|
|
Popup.Close();
|
2022-10-12 01:16:23 -07:00
|
|
|
}
|
|
|
|
|
|
2023-12-13 03:02:19 +01:00
|
|
|
if (SelectedChannel == channel)
|
|
|
|
|
return;
|
2022-10-12 01:16:23 -07:00
|
|
|
SelectedChannel = channel;
|
|
|
|
|
OnChannelSelect?.Invoke(channel);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 06:27:56 +13:00
|
|
|
public static string ChannelSelectorName(ChatSelectChannel channel)
|
2022-10-12 01:16:23 -07:00
|
|
|
{
|
|
|
|
|
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,
|
2022-12-19 21:39:01 -06:00
|
|
|
ChatSelectChannel.Admin => Color.HotPink,
|
2024-01-31 14:01:35 +00:00
|
|
|
ChatSelectChannel.Changeling => Color.Purple,
|
2024-01-27 15:19:52 +03:00
|
|
|
ChatSelectChannel.Cult => Color.DarkRed,
|
2022-10-12 01:16:23 -07:00
|
|
|
_ => Color.DarkGray
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 06:27:56 +13:00
|
|
|
public void UpdateChannelSelectButton(ChatSelectChannel channel, Shared.Radio.RadioChannelPrototype? radio)
|
2022-10-12 01:16:23 -07:00
|
|
|
{
|
2023-02-19 06:27:56 +13:00
|
|
|
Text = radio != null ? Loc.GetString(radio.Name) : ChannelSelectorName(channel);
|
|
|
|
|
Modulate = radio?.Color ?? ChannelSelectColor(channel);
|
2022-10-12 01:16:23 -07:00
|
|
|
}
|
|
|
|
|
}
|