* Backing up local repo before upgrading OS, minor work on chat UI * Cleaned out unnecessary modded files * Got a working version of filter toggles based on flag enums * Added localization to chatbox buttons * Should actually fix modified proj files, thanks PJB * Fixed enum operators to unset instead of toggle * Added a local client class for storing net message details * Reworked RepopulateChat to pull from a StoredChatMessage list * Fixed messages dissapearing * Re-ordered logic to be a bit more efficient with re-drawing chat
219 lines
6.1 KiB
C#
219 lines
6.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Content.Shared.Chat;
|
|
using Robust.Client.Graphics.Drawing;
|
|
using Robust.Client.Input;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Utility;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
namespace Content.Client.Chat
|
|
{
|
|
public class ChatBox : PanelContainer
|
|
{
|
|
public delegate void TextSubmitHandler(ChatBox chatBox, string text);
|
|
|
|
public delegate void FilterToggledHandler(ChatBox chatBox, Button.ButtonToggledEventArgs e);
|
|
|
|
private const int MaxLinePixelLength = 500;
|
|
|
|
private readonly IList<string> _inputHistory = new List<string>();
|
|
|
|
private ILocalizationManager localize = IoCManager.Resolve<ILocalizationManager>();
|
|
|
|
public LineEdit Input { get; private set; }
|
|
public OutputPanel contents;
|
|
|
|
// Buttons for filtering
|
|
public Button AllButton;
|
|
public Button OOCButton;
|
|
|
|
/// <summary>
|
|
/// Index while cycling through the input history. -1 means not going through history.
|
|
/// </summary>
|
|
private int _inputIndex = -1;
|
|
|
|
/// <summary>
|
|
/// Message that WAS being input before going through history began.
|
|
/// </summary>
|
|
private string _inputTemp;
|
|
|
|
/// <summary>
|
|
/// Default formatting string for the ClientChatConsole.
|
|
/// </summary>
|
|
public string DefaultChatFormat { get; set; }
|
|
|
|
public bool ReleaseFocusOnEnter { get; set; } = true;
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
MarginLeft = -475.0f;
|
|
MarginTop = 10.0f;
|
|
MarginRight = -10.0f;
|
|
MarginBottom = 185.0f;
|
|
|
|
AnchorLeft = 1.0f;
|
|
AnchorRight = 1.0f;
|
|
|
|
var vBox = new VBoxContainer("VBoxContainer");
|
|
var hBox = new HBoxContainer("FilterButtonsContainer");
|
|
|
|
contents = new OutputPanel {SizeFlagsVertical = SizeFlags.FillExpand};
|
|
vBox.AddChild(contents);
|
|
|
|
Input = new LineEdit("Input");
|
|
Input.OnKeyDown += InputKeyDown;
|
|
Input.OnTextEntered += Input_OnTextEntered;
|
|
vBox.AddChild(Input);
|
|
|
|
vBox.AddChild(hBox);
|
|
|
|
AllButton = new Button()
|
|
{
|
|
Text = localize.GetString("All"),
|
|
Name = "ALL",
|
|
TextAlign = Button.AlignMode.Left,
|
|
SizeFlagsHorizontal = SizeFlags.Fill,
|
|
SizeFlagsStretchRatio = 1,
|
|
ToggleMode = true,
|
|
Pressed = true
|
|
};
|
|
|
|
OOCButton = new Button()
|
|
{
|
|
Text = localize.GetString("OOC"),
|
|
Name = "OOC",
|
|
TextAlign = Button.AlignMode.Left,
|
|
SizeFlagsHorizontal = SizeFlags.Fill,
|
|
SizeFlagsStretchRatio = 1,
|
|
ToggleMode = true,
|
|
Pressed = true
|
|
};
|
|
|
|
AllButton.OnToggled += OnFilterToggled;
|
|
OOCButton.OnToggled += OnFilterToggled;
|
|
|
|
hBox.AddChild(AllButton);
|
|
hBox.AddChild(OOCButton);
|
|
|
|
AddChild(vBox);
|
|
|
|
PanelOverride = new StyleBoxFlat { BackgroundColor = Color.Gray.WithAlpha(0.5f) };
|
|
}
|
|
|
|
protected override void MouseDown(GUIMouseButtonEventArgs e)
|
|
{
|
|
base.MouseDown(e);
|
|
|
|
Input.GrabKeyboardFocus();
|
|
}
|
|
|
|
private void InputKeyDown(GUIKeyEventArgs e)
|
|
{
|
|
if (e.Key == Keyboard.Key.Escape)
|
|
{
|
|
Input.ReleaseKeyboardFocus();
|
|
e.Handle();
|
|
return;
|
|
}
|
|
|
|
if (e.Key == Keyboard.Key.Up)
|
|
{
|
|
if (_inputIndex == -1 && _inputHistory.Count != 0)
|
|
{
|
|
_inputTemp = Input.Text;
|
|
_inputIndex++;
|
|
}
|
|
else if (_inputIndex + 1 < _inputHistory.Count)
|
|
{
|
|
_inputIndex++;
|
|
}
|
|
|
|
if (_inputIndex != -1)
|
|
{
|
|
Input.Text = _inputHistory[_inputIndex];
|
|
}
|
|
|
|
e.Handle();
|
|
return;
|
|
}
|
|
|
|
if (e.Key == Keyboard.Key.Down)
|
|
{
|
|
if (_inputIndex == 0)
|
|
{
|
|
Input.Text = _inputTemp;
|
|
_inputTemp = "";
|
|
_inputIndex--;
|
|
}
|
|
else if (_inputIndex != -1)
|
|
{
|
|
_inputIndex--;
|
|
Input.Text = _inputHistory[_inputIndex];
|
|
}
|
|
|
|
e.Handle();
|
|
}
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
|
|
if (disposing)
|
|
{
|
|
TextSubmitted = null;
|
|
Input = null;
|
|
contents = null;
|
|
}
|
|
}
|
|
|
|
public event TextSubmitHandler TextSubmitted;
|
|
|
|
public event FilterToggledHandler FilterToggled;
|
|
|
|
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();
|
|
contents.AddMessage(formatted);
|
|
}
|
|
|
|
private void Input_OnTextEntered(LineEdit.LineEditEventArgs args)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(args.Text))
|
|
{
|
|
TextSubmitted?.Invoke(this, args.Text);
|
|
_inputHistory.Insert(0, args.Text);
|
|
}
|
|
|
|
_inputIndex = -1;
|
|
|
|
Input.Clear();
|
|
|
|
if (ReleaseFocusOnEnter)
|
|
{
|
|
Input.ReleaseKeyboardFocus();
|
|
}
|
|
}
|
|
|
|
private void OnFilterToggled(Button.ButtonToggledEventArgs args)
|
|
{
|
|
FilterToggled?.Invoke(this, args);
|
|
}
|
|
}
|
|
}
|