2020-08-13 14:40:27 +02:00
|
|
|
|
using Content.Shared.Chat;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Client.Graphics;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
2019-11-13 17:37:46 -05:00
|
|
|
|
using Robust.Shared.Input;
|
|
|
|
|
|
using Robust.Shared.Localization;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
|
using Robust.Shared.Utility;
|
2019-07-18 17:32:48 -04:00
|
|
|
|
|
2019-04-13 09:45:09 +02:00
|
|
|
|
namespace Content.Client.Chat
|
|
|
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
|
public class ChatBox : Control
|
2019-04-13 09:45:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
public delegate void TextSubmitHandler(ChatBox chatBox, string text);
|
|
|
|
|
|
|
2019-07-19 01:23:16 +02:00
|
|
|
|
public delegate void FilterToggledHandler(ChatBox chatBox, BaseButton.ButtonToggledEventArgs e);
|
2019-07-18 17:32:48 -04:00
|
|
|
|
|
2020-02-22 15:44:35 -08:00
|
|
|
|
public HistoryLineEdit Input { get; private set; }
|
2019-08-14 22:04:35 +02:00
|
|
|
|
public OutputPanel Contents { get; }
|
2019-07-18 17:32:48 -04:00
|
|
|
|
|
|
|
|
|
|
// Buttons for filtering
|
2019-08-14 22:04:35 +02:00
|
|
|
|
public Button AllButton { get; }
|
|
|
|
|
|
public Button LocalButton { get; }
|
|
|
|
|
|
public Button OOCButton { get; }
|
2020-07-08 05:18:16 -05:00
|
|
|
|
public Button AdminButton { get; }
|
2021-02-21 12:38:56 +01:00
|
|
|
|
public Button DeadButton { get; }
|
2019-04-13 09:45:09 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Default formatting string for the ClientChatConsole.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string DefaultChatFormat { get; set; }
|
|
|
|
|
|
|
2019-05-08 16:49:59 +02:00
|
|
|
|
public bool ReleaseFocusOnEnter { get; set; } = true;
|
|
|
|
|
|
|
2020-08-17 14:45:02 +02:00
|
|
|
|
public bool ClearOnEnter { get; set; } = true;
|
|
|
|
|
|
|
2019-08-14 22:04:35 +02:00
|
|
|
|
public ChatBox()
|
2019-04-13 09:45:09 +02:00
|
|
|
|
{
|
2020-02-20 01:19:59 -08:00
|
|
|
|
MouseFilter = MouseFilterMode.Stop;
|
2019-05-14 17:40:55 -04:00
|
|
|
|
|
2019-07-19 01:23:16 +02:00
|
|
|
|
var outerVBox = new VBoxContainer();
|
|
|
|
|
|
|
|
|
|
|
|
var panelContainer = new PanelContainer
|
|
|
|
|
|
{
|
|
|
|
|
|
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.FromHex("#25252aaa")},
|
2021-02-21 12:38:56 +01:00
|
|
|
|
VerticalExpand = true
|
2019-07-19 01:23:16 +02:00
|
|
|
|
};
|
|
|
|
|
|
var vBox = new VBoxContainer();
|
|
|
|
|
|
panelContainer.AddChild(vBox);
|
|
|
|
|
|
var hBox = new HBoxContainer();
|
|
|
|
|
|
|
|
|
|
|
|
outerVBox.AddChild(panelContainer);
|
|
|
|
|
|
outerVBox.AddChild(hBox);
|
2019-05-14 17:40:55 -04:00
|
|
|
|
|
2021-02-21 12:38:56 +01:00
|
|
|
|
Contents = new OutputPanel {Margin = new Thickness(4, 0), VerticalExpand = true};
|
|
|
|
|
|
vBox.AddChild(Contents);
|
2019-05-14 17:40:55 -04:00
|
|
|
|
|
2020-02-22 15:44:35 -08:00
|
|
|
|
Input = new HistoryLineEdit();
|
2019-08-05 22:59:37 -07:00
|
|
|
|
Input.OnKeyBindDown += InputKeyBindDown;
|
2019-04-13 09:45:09 +02:00
|
|
|
|
Input.OnTextEntered += Input_OnTextEntered;
|
2019-05-14 23:52:00 -04:00
|
|
|
|
vBox.AddChild(Input);
|
2019-04-13 09:45:09 +02:00
|
|
|
|
|
2019-07-19 01:23:16 +02:00
|
|
|
|
AllButton = new Button
|
2019-07-18 17:32:48 -04:00
|
|
|
|
{
|
2020-09-17 09:55:50 +12:00
|
|
|
|
Text = Loc.GetString("All"),
|
2019-07-18 17:32:48 -04:00
|
|
|
|
Name = "ALL",
|
2021-02-21 12:38:56 +01:00
|
|
|
|
HorizontalExpand = true,
|
|
|
|
|
|
HorizontalAlignment = HAlignment.Right,
|
2019-07-19 01:23:16 +02:00
|
|
|
|
ToggleMode = true,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
LocalButton = new Button
|
|
|
|
|
|
{
|
2020-09-17 09:55:50 +12:00
|
|
|
|
Text = Loc.GetString("Local"),
|
2019-07-19 01:23:16 +02:00
|
|
|
|
Name = "Local",
|
2019-07-18 17:32:48 -04:00
|
|
|
|
ToggleMode = true,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-07-19 01:23:16 +02:00
|
|
|
|
OOCButton = new Button
|
2019-07-18 17:32:48 -04:00
|
|
|
|
{
|
2020-09-17 09:55:50 +12:00
|
|
|
|
Text = Loc.GetString("OOC"),
|
2019-07-18 17:32:48 -04:00
|
|
|
|
Name = "OOC",
|
|
|
|
|
|
ToggleMode = true,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-11-01 23:55:55 +01:00
|
|
|
|
AdminButton = new Button
|
2020-07-08 05:18:16 -05:00
|
|
|
|
{
|
2020-11-01 23:55:55 +01:00
|
|
|
|
Text = Loc.GetString("Admin"),
|
|
|
|
|
|
Name = "Admin",
|
|
|
|
|
|
ToggleMode = true,
|
|
|
|
|
|
Visible = false
|
|
|
|
|
|
};
|
2020-07-08 05:18:16 -05:00
|
|
|
|
|
2021-01-04 05:25:33 -03:00
|
|
|
|
DeadButton = new Button
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = Loc.GetString("Dead"),
|
|
|
|
|
|
Name = "Dead",
|
|
|
|
|
|
ToggleMode = true,
|
|
|
|
|
|
Visible = false
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-07-18 17:32:48 -04:00
|
|
|
|
AllButton.OnToggled += OnFilterToggled;
|
2019-07-19 11:00:18 +02:00
|
|
|
|
LocalButton.OnToggled += OnFilterToggled;
|
2019-07-18 17:32:48 -04:00
|
|
|
|
OOCButton.OnToggled += OnFilterToggled;
|
2020-11-10 21:30:20 +01:00
|
|
|
|
AdminButton.OnToggled += OnFilterToggled;
|
2021-01-04 05:25:33 -03:00
|
|
|
|
DeadButton.OnToggled += OnFilterToggled;
|
2019-07-18 17:32:48 -04:00
|
|
|
|
|
|
|
|
|
|
hBox.AddChild(AllButton);
|
2019-07-19 11:00:18 +02:00
|
|
|
|
hBox.AddChild(LocalButton);
|
2021-01-04 05:25:33 -03:00
|
|
|
|
hBox.AddChild(DeadButton);
|
2019-07-18 17:32:48 -04:00
|
|
|
|
hBox.AddChild(OOCButton);
|
2020-11-10 21:30:20 +01:00
|
|
|
|
hBox.AddChild(AdminButton);
|
2019-07-18 17:32:48 -04:00
|
|
|
|
|
2019-07-19 01:23:16 +02:00
|
|
|
|
AddChild(outerVBox);
|
2019-04-13 09:45:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-04 16:03:51 -07:00
|
|
|
|
protected override void KeyBindDown(GUIBoundKeyEventArgs args)
|
2019-04-13 09:45:09 +02:00
|
|
|
|
{
|
2019-08-04 16:03:51 -07:00
|
|
|
|
base.KeyBindDown(args);
|
|
|
|
|
|
|
|
|
|
|
|
if (!args.CanFocus)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-04-13 09:45:09 +02:00
|
|
|
|
|
|
|
|
|
|
Input.GrabKeyboardFocus();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-05 22:59:37 -07:00
|
|
|
|
private void InputKeyBindDown(GUIBoundKeyEventArgs args)
|
2019-04-13 09:45:09 +02:00
|
|
|
|
{
|
2019-08-05 22:59:37 -07:00
|
|
|
|
if (args.Function == EngineKeyFunctions.TextReleaseFocus)
|
2019-04-13 09:45:09 +02:00
|
|
|
|
{
|
|
|
|
|
|
Input.ReleaseKeyboardFocus();
|
2019-08-05 22:59:37 -07:00
|
|
|
|
args.Handle();
|
2019-04-13 09:45:09 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public event TextSubmitHandler TextSubmitted;
|
|
|
|
|
|
|
2019-07-18 17:32:48 -04:00
|
|
|
|
public event FilterToggledHandler FilterToggled;
|
|
|
|
|
|
|
2019-04-13 09:45:09 +02:00
|
|
|
|
public void AddLine(string message, ChatChannel channel, Color color)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Disposed)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var formatted = new FormattedMessage(3);
|
|
|
|
|
|
formatted.PushColor(color);
|
|
|
|
|
|
formatted.AddText(message);
|
|
|
|
|
|
formatted.Pop();
|
2019-08-14 22:04:35 +02:00
|
|
|
|
Contents.AddMessage(formatted);
|
2019-04-13 09:45:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Input_OnTextEntered(LineEdit.LineEditEventArgs args)
|
|
|
|
|
|
{
|
2020-08-17 14:45:02 +02:00
|
|
|
|
// We set it there to true so it's set to false by TextSubmitted.Invoke if necessary
|
|
|
|
|
|
ClearOnEnter = true;
|
|
|
|
|
|
|
2019-04-13 09:45:09 +02:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(args.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
TextSubmitted?.Invoke(this, args.Text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-17 14:45:02 +02:00
|
|
|
|
if (ClearOnEnter)
|
|
|
|
|
|
{
|
|
|
|
|
|
Input.Clear();
|
|
|
|
|
|
}
|
2019-05-08 16:49:59 +02:00
|
|
|
|
|
|
|
|
|
|
if (ReleaseFocusOnEnter)
|
|
|
|
|
|
{
|
|
|
|
|
|
Input.ReleaseKeyboardFocus();
|
|
|
|
|
|
}
|
2019-04-13 09:45:09 +02:00
|
|
|
|
}
|
2019-07-18 17:32:48 -04:00
|
|
|
|
|
2019-07-19 01:23:16 +02:00
|
|
|
|
private void OnFilterToggled(BaseButton.ButtonToggledEventArgs args)
|
2019-07-18 17:32:48 -04:00
|
|
|
|
{
|
|
|
|
|
|
FilterToggled?.Invoke(this, args);
|
|
|
|
|
|
}
|
2019-04-13 09:45:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|