ChatInputBox.xaml.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Content.Client.Stylesheets;
  2. using Content.Shared.Chat;
  3. using Content.Shared.Input;
  4. using Robust.Client.UserInterface.Controls;
  5. namespace Content.Client.UserInterface.Systems.Chat.Controls;
  6. [Virtual]
  7. public class ChatInputBox : PanelContainer
  8. {
  9. public readonly ChannelSelectorButton ChannelSelector;
  10. public readonly HistoryLineEdit Input;
  11. public readonly ChannelFilterButton FilterButton;
  12. protected readonly BoxContainer Container;
  13. protected ChatChannel ActiveChannel { get; private set; } = ChatChannel.Local;
  14. public ChatInputBox()
  15. {
  16. Container = new BoxContainer
  17. {
  18. Orientation = BoxContainer.LayoutOrientation.Horizontal,
  19. SeparationOverride = 4
  20. };
  21. AddChild(Container);
  22. ChannelSelector = new ChannelSelectorButton
  23. {
  24. Name = "ChannelSelector",
  25. ToggleMode = true,
  26. StyleClasses = {"chatSelectorOptionButton"},
  27. MinWidth = 75
  28. };
  29. Container.AddChild(ChannelSelector);
  30. Input = new HistoryLineEdit
  31. {
  32. Name = "Input",
  33. PlaceHolder = GetChatboxInfoPlaceholder(),
  34. HorizontalExpand = true,
  35. StyleClasses = {"chatLineEdit"}
  36. };
  37. Container.AddChild(Input);
  38. FilterButton = new ChannelFilterButton
  39. {
  40. Name = "FilterButton",
  41. StyleClasses = {"chatFilterOptionButton"}
  42. };
  43. Container.AddChild(FilterButton);
  44. AddStyleClass(StyleNano.StyleClassChatSubPanel);
  45. ChannelSelector.OnChannelSelect += UpdateActiveChannel;
  46. }
  47. private void UpdateActiveChannel(ChatSelectChannel selectedChannel)
  48. {
  49. ActiveChannel = (ChatChannel) selectedChannel;
  50. }
  51. private static string GetChatboxInfoPlaceholder()
  52. {
  53. return (BoundKeyHelper.IsBound(ContentKeyFunctions.FocusChat), BoundKeyHelper.IsBound(ContentKeyFunctions.CycleChatChannelForward)) switch
  54. {
  55. (true, true) => Loc.GetString("hud-chatbox-info", ("talk-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.FocusChat)), ("cycle-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.CycleChatChannelForward))),
  56. (true, false) => Loc.GetString("hud-chatbox-info-talk", ("talk-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.FocusChat))),
  57. (false, true) => Loc.GetString("hud-chatbox-info-cycle", ("cycle-key", BoundKeyHelper.ShortKeyName(ContentKeyFunctions.CycleChatChannelForward))),
  58. (false, false) => Loc.GetString("hud-chatbox-info-unbound")
  59. };
  60. }
  61. }