Chat Filter using Flag Enums. (#270)

* 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
This commit is contained in:
tentekal
2019-07-18 17:32:48 -04:00
committed by Pieter-Jan Briers
parent ce1eab9181
commit 92668432a7
4 changed files with 273 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Content.Shared.Chat;
using Robust.Client.Graphics.Drawing;
using Robust.Client.Input;
@@ -6,6 +7,9 @@ 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
{
@@ -13,12 +17,20 @@ namespace Content.Client.Chat
{
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; }
private OutputPanel contents;
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.
@@ -50,6 +62,7 @@ namespace Content.Client.Chat
AnchorRight = 1.0f;
var vBox = new VBoxContainer("VBoxContainer");
var hBox = new HBoxContainer("FilterButtonsContainer");
contents = new OutputPanel {SizeFlagsVertical = SizeFlags.FillExpand};
vBox.AddChild(contents);
@@ -59,6 +72,36 @@ namespace Content.Client.Chat
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) };
@@ -133,6 +176,8 @@ namespace Content.Client.Chat
public event TextSubmitHandler TextSubmitted;
public event FilterToggledHandler FilterToggled;
public void AddLine(string message, ChatChannel channel, Color color)
{
if (Disposed)
@@ -164,5 +209,10 @@ namespace Content.Client.Chat
Input.ReleaseKeyboardFocus();
}
}
private void OnFilterToggled(Button.ButtonToggledEventArgs args)
{
FilterToggled?.Invoke(this, args);
}
}
}