Chat improvements:

Improved chat box styling.
"All" button now works as a toggle for.. all buttons!
Also improved persistence of the chat box when switching to/from lobby.
This commit is contained in:
Pieter-Jan Briers
2019-07-19 01:23:16 +02:00
parent 96516fa288
commit 8621d61278
5 changed files with 64 additions and 138 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Content.Shared.Chat;
using Robust.Client.Graphics.Drawing;
using Robust.Client.Input;
@@ -10,14 +9,13 @@ using Robust.Shared.Utility;
using Robust.Shared.Localization;
using Robust.Shared.IoC;
namespace Content.Client.Chat
{
public class ChatBox : PanelContainer
public class ChatBox : MarginContainer
{
public delegate void TextSubmitHandler(ChatBox chatBox, string text);
public delegate void FilterToggledHandler(ChatBox chatBox, Button.ButtonToggledEventArgs e);
public delegate void FilterToggledHandler(ChatBox chatBox, BaseButton.ButtonToggledEventArgs e);
private const int MaxLinePixelLength = 500;
@@ -30,6 +28,7 @@ namespace Content.Client.Chat
// Buttons for filtering
public Button AllButton;
public Button LocalButton;
public Button OOCButton;
/// <summary>
@@ -56,41 +55,59 @@ namespace Content.Client.Chat
MarginLeft = -475.0f;
MarginTop = 10.0f;
MarginRight = -10.0f;
MarginBottom = 185.0f;
MarginBottom = 235.0f;
AnchorLeft = 1.0f;
AnchorRight = 1.0f;
var vBox = new VBoxContainer("VBoxContainer");
var hBox = new HBoxContainer("FilterButtonsContainer");
var outerVBox = new VBoxContainer();
var panelContainer = new PanelContainer
{
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.FromHex("#25252aaa")},
SizeFlagsVertical = SizeFlags.FillExpand
};
var vBox = new VBoxContainer();
panelContainer.AddChild(vBox);
var hBox = new HBoxContainer();
outerVBox.AddChild(panelContainer);
outerVBox.AddChild(hBox);
contents = new OutputPanel {SizeFlagsVertical = SizeFlags.FillExpand};
vBox.AddChild(contents);
Input = new LineEdit("Input");
Input = new LineEdit();
Input.OnKeyDown += InputKeyDown;
Input.OnTextEntered += Input_OnTextEntered;
vBox.AddChild(Input);
vBox.AddChild(hBox);
AllButton = new Button()
AllButton = new Button
{
Text = localize.GetString("All"),
Name = "ALL",
TextAlign = Button.AlignMode.Left,
SizeFlagsHorizontal = SizeFlags.Fill,
SizeFlagsHorizontal = SizeFlags.ShrinkEnd | SizeFlags.Expand,
SizeFlagsStretchRatio = 1,
ToggleMode = true,
Pressed = true
};
OOCButton = new Button()
LocalButton = new Button
{
Text = localize.GetString("Local"),
Name = "Local",
TextAlign = Button.AlignMode.Left,
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
@@ -102,9 +119,7 @@ namespace Content.Client.Chat
hBox.AddChild(AllButton);
hBox.AddChild(OOCButton);
AddChild(vBox);
PanelOverride = new StyleBoxFlat { BackgroundColor = Color.Gray.WithAlpha(0.5f) };
AddChild(outerVBox);
}
protected override void MouseDown(GUIMouseButtonEventArgs e)
@@ -210,7 +225,7 @@ namespace Content.Client.Chat
}
}
private void OnFilterToggled(Button.ButtonToggledEventArgs args)
private void OnFilterToggled(BaseButton.ButtonToggledEventArgs args)
{
FilterToggled?.Invoke(this, args);
}

View File

@@ -1,62 +0,0 @@
using Robust.Client.Graphics;
using Robust.Client.Graphics.Drawing;
using Robust.Client.Interfaces.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.Utility;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables;
using Content.Client.Chat;
namespace Content.Client.Chat
{
public class ChatFilterUI : SS14Window
{
protected override void Initialize()
{
base.Initialize();
Title = "Filter Channels";
var margin = new MarginContainer()
{
MarginTop = 5f,
MarginLeft = 5f,
MarginRight = -5f,
MarginBottom = -5f,
};
margin.SetAnchorAndMarginPreset(LayoutPreset.TopRight);
var vbox = new VBoxContainer();
vbox.SetAnchorAndMarginPreset(LayoutPreset.TopRight);
var descMargin = new MarginContainer()
{
MarginTop = 5f,
MarginLeft = 5f,
MarginRight = -5f,
MarginBottom = -5f,
SizeFlagsHorizontal = SizeFlags.Fill,
SizeFlagsStretchRatio = 2,
};
var hbox = new HBoxContainer()
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
};
var vboxInfo = new VBoxContainer()
{
SizeFlagsVertical = SizeFlags.FillExpand,
SizeFlagsStretchRatio = 3,
};
}
}
}

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Net;
using Content.Client.Interfaces.Chat;
using Content.Shared.Chat;
using Robust.Client.Console;
@@ -22,9 +20,9 @@ namespace Content.Client.Chat
public List<StoredChatMessage> filteredHistory = new List<StoredChatMessage>();
// Filter Button States
private bool _ALLstate;
private bool _Localstate;
private bool _OOCstate;
private bool _allState;
private bool _localState;
private bool _oocState;
// Flag Enums for holding filtered channels
private ChatChannel _filteredChannels;
@@ -55,6 +53,11 @@ namespace Content.Client.Chat
_currentChatBox.TextSubmitted += _onChatBoxTextSubmitted;
_currentChatBox.FilterToggled += _onFilterButtonToggled;
}
RepopulateChat(filteredHistory);
_currentChatBox.AllButton.Pressed = !_allState;
_currentChatBox.LocalButton.Pressed = !_localState;
_currentChatBox.OOCButton.Pressed = !_oocState;
}
private void WriteChatMessage(StoredChatMessage message)
@@ -127,14 +130,13 @@ namespace Content.Client.Chat
}
}
private void _onFilterButtonToggled(ChatBox chatBox, Button.ButtonToggledEventArgs e)
private void _onFilterButtonToggled(ChatBox chatBox, BaseButton.ButtonToggledEventArgs e)
{
// TODO make toggled ALL button flip all button states programatically + visually
switch (e.Button.Name)
{
case "Local":
_Localstate = !_Localstate;
if (_Localstate)
_localState = !_localState;
if (_localState)
{
_filteredChannels |= ChatChannel.Local;
break;
@@ -146,8 +148,8 @@ namespace Content.Client.Chat
}
case "OOC":
_OOCstate = !_OOCstate;
if (_OOCstate)
_oocState = !_oocState;
if (_oocState)
{
_filteredChannels |= ChatChannel.OOC;
break;
@@ -158,36 +160,24 @@ namespace Content.Client.Chat
break;
}
default:
_ALLstate = !_ALLstate;
if (_ALLstate)
{
_filteredChannels = ChatChannel.OOC | ChatChannel.Local;
case "ALL":
chatBox.LocalButton.Pressed ^= true;
chatBox.OOCButton.Pressed ^= true;
_allState = !_allState;
break;
}
else
{
_filteredChannels &= ~ChatChannel.OOC;
_filteredChannels &= ~ChatChannel.Local;
break;
}
}
RepopulateChat(filteredHistory);
}
private void RepopulateChat(List<StoredChatMessage> filteredMessages)
private void RepopulateChat(IEnumerable<StoredChatMessage> filteredMessages)
{
_currentChatBox.contents.Clear();
// Copy list for enumeration
List<StoredChatMessage> filteredMessagesCopy = new List<StoredChatMessage>(filteredMessages);
foreach (StoredChatMessage msg in filteredMessagesCopy)
foreach (var msg in filteredMessages)
{
WriteChatMessage(msg);
}
}
private void _onChatMessage(MsgChatMessage msg)
@@ -202,14 +192,8 @@ namespace Content.Client.Chat
private bool IsFiltered(ChatChannel channel)
{
if (_filteredChannels.HasFlag(channel))
{
return true;
}
else
{
return false;
}
// _ALLstate works as inverter.
return _allState ^ _filteredChannels.HasFlag(channel);
}
}
}

View File

@@ -1,14 +1,4 @@
using System;
using System.Collections.Generic;
using Content.Client.Interfaces.Chat;
using Content.Shared.Chat;
using Robust.Client.Console;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Chat
{
@@ -35,12 +25,11 @@ namespace Content.Client.Chat
/// </summary>
public string MessageWrap { get; set; }
public StoredChatMessage(MsgChatMessage netMsg)
{
/// <summary>
/// Constructor to copy a net message into stored client variety
/// </summary>
public StoredChatMessage(MsgChatMessage netMsg)
{
Message = netMsg.Message;
Channel = netMsg.Channel;
MessageWrap = netMsg.MessageWrap;

View File

@@ -28,7 +28,7 @@ namespace Content.Client.UserInterface
});
SetAnchorAndMarginPreset(LayoutPreset.TopRight);
MarginTop = 200;
MarginTop = 250;
MarginRight = 10;
}