}
}
});
- button.EnableAllKeybinds = true;
+
button.AddStyleClass(ListContainer.StyleClassListContainerButton);
}
}
<ContainerButton xmlns="https://spacestation14.io"
- xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
- EnableAllKeybinds="True">
+ xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls">
<PanelContainer Name="BackgroundColorPanel"/>
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True"
<ContainerButton xmlns="https://spacestation14.io"
- xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
- EnableAllKeybinds="True">
+ xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls">
<PanelContainer Name="BackgroundColorPanel"/>
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True"
-<ContainerButton xmlns="https://spacestation14.io"
- xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
- EnableAllKeybinds="True">
+<Control xmlns="https://spacestation14.io"
+ xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls">
<PanelContainer Name="BackgroundColorPanel" Access="Public"/>
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True"
Text="{Loc player-tab-playtime}"
MouseFilter="Pass"/>
</BoxContainer>
-</ContainerButton>
+</Control>
namespace Content.Client.Administration.UI.Tabs.PlayerTab;
[GenerateTypedNameReferences]
-public sealed partial class PlayerTabHeader : ContainerButton
+public sealed partial class PlayerTabHeader : Control
{
public event Action<Header>? OnHeaderClicked;
<ContainerButton xmlns="https://spacestation14.io"
- xmlns:customControls1="clr-namespace:Content.Client.Administration.UI.CustomControls"
- EnableAllKeybinds="True">
+ xmlns:customControls1="clr-namespace:Content.Client.Administration.UI.CustomControls">
<PanelContainer Name="BackgroundColorPanel"/>
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True"
namespace Content.Client.Info.PlaytimeStats;
[GenerateTypedNameReferences]
-public sealed partial class PlaytimeStatsHeader : ContainerButton
+public sealed partial class PlaytimeStatsHeader : Control
{
public event Action<Header, SortDirection>? OnHeaderClicked;
private SortDirection _roleDirection = SortDirection.Ascending;
-<ContainerButton xmlns="https://spacestation14.io"
- xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
- EnableAllKeybinds="True">
+<Control xmlns="https://spacestation14.io"
+ xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls">
<PanelContainer Name="BackgroundColorPlaytimePanel" Access="Public"/>
<BoxContainer Orientation="Vertical"
HorizontalExpand="True">
<!-- Horizontal Separator -->
<customControls:HSeparator/>
</BoxContainer>
-</ContainerButton>
+</Control>
using System.Numerics;
using Content.Client.Resources;
using Robust.Client.ResourceManagement;
-using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
-using Robust.Shared.Input;
namespace Content.Client.UserInterface.Systems.Chat.Controls;
-public sealed class ChannelFilterButton : ContainerButton
+public sealed class ChannelFilterButton : ChatPopupButton<ChannelFilterPopup>
{
private static readonly Color ColorNormal = Color.FromHex("#7b7e9e");
private static readonly Color ColorHovered = Color.FromHex("#9699bb");
private static readonly Color ColorPressed = Color.FromHex("#789B8C");
private readonly TextureRect? _textureRect;
- public readonly ChannelFilterPopup ChatFilterPopup;
private readonly ChatUIController _chatUIController;
+
private const int FilterDropdownOffset = 120;
public ChannelFilterButton()
var filterTexture = IoCManager.Resolve<IResourceCache>()
.GetTexture("/Textures/Interface/Nano/filter.svg.96dpi.png");
- // needed for same reason as ChannelSelectorButton
- Mode = ActionMode.Press;
- EnableAllKeybinds = true;
-
AddChild(
(_textureRect = new TextureRect
{
VerticalAlignment = VAlignment.Center
})
);
- ToggleMode = true;
- OnToggled += OnFilterButtonToggled;
- ChatFilterPopup = UserInterfaceManager.CreatePopup<ChannelFilterPopup>();
- ChatFilterPopup.OnVisibilityChanged += PopupVisibilityChanged;
-
- _chatUIController.FilterableChannelsChanged += ChatFilterPopup.SetChannels;
- _chatUIController.UnreadMessageCountsUpdated += ChatFilterPopup.UpdateUnread;
- ChatFilterPopup.SetChannels(_chatUIController.FilterableChannels);
- }
-
- private void PopupVisibilityChanged(Control control)
- {
- Pressed = control.Visible;
- }
- private void OnFilterButtonToggled(ButtonToggledEventArgs args)
- {
- if (args.Pressed)
- {
- var globalPos = GlobalPosition;
- var (minX, minY) = ChatFilterPopup.MinSize;
- var box = UIBox2.FromDimensions(globalPos - new Vector2(FilterDropdownOffset, 0),
- new Vector2(Math.Max(minX, ChatFilterPopup.MinWidth), minY));
- ChatFilterPopup.Open(box);
- }
- else
- {
- ChatFilterPopup.Close();
- }
+ _chatUIController.FilterableChannelsChanged += Popup.SetChannels;
+ _chatUIController.UnreadMessageCountsUpdated += Popup.UpdateUnread;
+ Popup.SetChannels(_chatUIController.FilterableChannels);
}
- protected override void KeyBindDown(GUIBoundKeyEventArgs args)
+ protected override UIBox2 GetPopupPosition()
{
- // needed since we need EnableAllKeybinds - don't double-send both UI click and Use
- if (args.Function == EngineKeyFunctions.Use) return;
- base.KeyBindDown(args);
+ var globalPos = GlobalPosition;
+ var (minX, minY) = Popup.MinSize;
+ return UIBox2.FromDimensions(
+ globalPos - new Vector2(FilterDropdownOffset, 0),
+ new Vector2(Math.Max(minX, Popup.MinWidth), minY));
}
private void UpdateChildColors()
if (!disposing)
return;
- _chatUIController.FilterableChannelsChanged -= ChatFilterPopup.SetChannels;
- _chatUIController.UnreadMessageCountsUpdated -= ChatFilterPopup.UpdateUnread;
+ _chatUIController.FilterableChannelsChanged -= Popup.SetChannels;
+ _chatUIController.UnreadMessageCountsUpdated -= Popup.UpdateUnread;
}
}
using System.Numerics;
using Content.Shared.Chat;
-using Robust.Client.UserInterface;
-using Robust.Client.UserInterface.Controls;
-using Robust.Shared.Timing;
namespace Content.Client.UserInterface.Systems.Chat.Controls;
-public sealed class ChannelSelectorButton : Button
+public sealed class ChannelSelectorButton : ChatPopupButton<ChannelSelectorPopup>
{
- private readonly IGameTiming _gameTiming;
-
- private readonly ChannelSelectorPopup _channelSelectorPopup;
public event Action<ChatSelectChannel>? OnChannelSelect;
public ChatSelectChannel SelectedChannel { get; private set; }
private const int SelectorDropdownOffset = 38;
- private uint _frameLastPopupChanged;
-
public ChannelSelectorButton()
{
- _gameTiming = IoCManager.Resolve<IGameTiming>();
-
Name = "ChannelSelector";
- ToggleMode = true;
+ Popup.Selected += OnChannelSelected;
- OnToggled += OnSelectorButtonToggled;
- _channelSelectorPopup = UserInterfaceManager.CreatePopup<ChannelSelectorPopup>();
- _channelSelectorPopup.Selected += OnChannelSelected;
- _channelSelectorPopup.OnVisibilityChanged += OnPopupVisibilityChanged;
-
- if (_channelSelectorPopup.FirstChannel is { } firstSelector)
+ if (Popup.FirstChannel is { } firstSelector)
{
Select(firstSelector);
}
}
- private void OnChannelSelected(ChatSelectChannel channel)
+ protected override UIBox2 GetPopupPosition()
{
- Select(channel);
+ var globalLeft = GlobalPosition.X;
+ var globalBot = GlobalPosition.Y + Height;
+ return UIBox2.FromDimensions(
+ new Vector2(globalLeft, globalBot),
+ new Vector2(SizeBox.Width, SelectorDropdownOffset));
}
- private void OnPopupVisibilityChanged(Control control)
- {
- // If the popup gets closed (e.g. by clicking anywhere else on the screen)
- // We clear the button pressed state.
-
- Pressed = control.Visible;
- _frameLastPopupChanged = _gameTiming.CurFrame;
- }
-
- protected override void KeyBindDown(GUIBoundKeyEventArgs args)
+ private void OnChannelSelected(ChatSelectChannel channel)
{
- // If you try to close the popup by clicking on the button again the following would happen:
- // The UI system would see that you clicked outside a popup, and would close it.
- // Because of the above logic, that sets the button to UNPRESSED.
- // THEN, it would propagate the keyboard event to us, the chat selector...
- // And we would become pressed again.
- // As a workaround, we check the frame the popup was last dismissed (above)
- // and don't allow changing it again this frame.
- if (_frameLastPopupChanged == _gameTiming.CurFrame)
- return;
-
- base.KeyBindDown(args);
+ Select(channel);
}
public void Select(ChatSelectChannel channel)
{
- if (_channelSelectorPopup.Visible)
+ if (Popup.Visible)
{
- _channelSelectorPopup.Close();
+ Popup.Close();
}
- if (SelectedChannel == channel) return;
+ if (SelectedChannel == channel)
+ return;
SelectedChannel = channel;
OnChannelSelect?.Invoke(channel);
}
Text = radio != null ? Loc.GetString(radio.Name) : ChannelSelectorName(channel);
Modulate = radio?.Color ?? ChannelSelectColor(channel);
}
-
- private void OnSelectorButtonToggled(ButtonToggledEventArgs args)
- {
- if (args.Pressed)
- {
- var globalLeft = GlobalPosition.X;
- var globalBot = GlobalPosition.Y + Height;
- var box = UIBox2.FromDimensions(new Vector2(globalLeft, globalBot), new Vector2(SizeBox.Width, SelectorDropdownOffset));
- _channelSelectorPopup.Open(box);
- }
- else
- {
- _channelSelectorPopup.Close();
- }
- }
}
--- /dev/null
+using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.Controls;
+using Robust.Shared.Timing;
+
+namespace Content.Client.UserInterface.Systems.Chat.Controls;
+
+// NO MORE FUCKING COPY PASTING THIS SHIT
+
+/// <summary>
+/// Base class for button that toggles a popup-window.
+/// Base type of <see cref="ChannelFilterButton"/> and <see cref="ChannelSelectorButton"/>.
+/// </summary>
+public abstract class ChatPopupButton<TPopup> : Button
+ where TPopup : Popup, new()
+{
+ private readonly IGameTiming _gameTiming;
+
+ public readonly TPopup Popup;
+
+ private uint _frameLastPopupChanged;
+
+ protected ChatPopupButton()
+ {
+ _gameTiming = IoCManager.Resolve<IGameTiming>();
+
+ ToggleMode = true;
+ OnToggled += OnButtonToggled;
+
+ Popup = UserInterfaceManager.CreatePopup<TPopup>();
+ Popup.OnVisibilityChanged += OnPopupVisibilityChanged;
+ }
+
+ protected override void KeyBindDown(GUIBoundKeyEventArgs args)
+ {
+ // If you try to close the popup by clicking on the button again the following would happen:
+ // The UI system would see that you clicked outside a popup, and would close it.
+ // Because of the above logic, that sets the button to UNPRESSED.
+ // THEN, it would propagate the keyboard event to us, the chat selector...
+ // And we would become pressed again.
+ // As a workaround, we check the frame the popup was last dismissed (above)
+ // and don't allow changing it again this frame.
+ if (_frameLastPopupChanged == _gameTiming.CurFrame)
+ return;
+
+ base.KeyBindDown(args);
+ }
+
+ protected abstract UIBox2 GetPopupPosition();
+
+ private void OnButtonToggled(ButtonToggledEventArgs args)
+ {
+ if (args.Pressed)
+ {
+ Popup.Open(GetPopupPosition());
+ }
+ else
+ {
+ Popup.Close();
+ }
+ }
+
+ private void OnPopupVisibilityChanged(Control control)
+ {
+ // If the popup gets closed (e.g. by clicking anywhere else on the screen)
+ // We clear the button pressed state.
+
+ Pressed = control.Visible;
+ _frameLastPopupChanged = _gameTiming.CurFrame;
+ }
+}
ChatInput.Input.OnKeyBindDown += OnKeyBindDown;
ChatInput.Input.OnTextChanged += OnTextChanged;
ChatInput.ChannelSelector.OnChannelSelect += OnChannelSelect;
- ChatInput.FilterButton.ChatFilterPopup.OnChannelFilter += OnChannelFilter;
+ ChatInput.FilterButton.Popup.OnChannelFilter += OnChannelFilter;
_controller = UserInterfaceManager.GetUIController<ChatUIController>();
_controller.MessageAdded += OnMessageAdded;
private void OnMessageAdded(ChatMessage msg)
{
Logger.DebugS("chat", $"{msg.Channel}: {msg.Message}");
- if (!ChatInput.FilterButton.ChatFilterPopup.IsActive(msg.Channel))
+ if (!ChatInput.FilterButton.Popup.IsActive(msg.Channel))
{
return;
}