diff --git a/Subsurface/Source/GUI/GUIListBox.cs b/Subsurface/Source/GUI/GUIListBox.cs index b0230cb88..a30f03c8d 100644 --- a/Subsurface/Source/GUI/GUIListBox.cs +++ b/Subsurface/Source/GUI/GUIListBox.cs @@ -406,7 +406,7 @@ namespace Barotrauma private bool IsChildVisible(GUIComponent child) { - if (child == null || !child.Visible) return false; + if (child == null) return false; if (scrollBar.IsHorizontal) { diff --git a/Subsurface/Source/GUI/GUITickBox.cs b/Subsurface/Source/GUI/GUITickBox.cs index c2037d65b..1f895dfd3 100644 --- a/Subsurface/Source/GUI/GUITickBox.cs +++ b/Subsurface/Source/GUI/GUITickBox.cs @@ -54,6 +54,12 @@ namespace Barotrauma } } + public Color TextColor + { + get { return text.TextColor; } + set { text.TextColor = value; } + } + public override Rectangle MouseRect { get { return box.Rect; } diff --git a/Subsurface/Source/Networking/ServerLog.cs b/Subsurface/Source/Networking/ServerLog.cs index 8b91da750..03d2b69e9 100644 --- a/Subsurface/Source/Networking/ServerLog.cs +++ b/Subsurface/Source/Networking/ServerLog.cs @@ -52,6 +52,9 @@ namespace Barotrauma.Networking private int unsavedLineCount; + private string msgFilter; + private bool[] msgTypeHidden = new bool[Enum.GetValues(typeof(MessageType)).Length]; + public int LinesPerFile { get { return linesPerFile; } @@ -99,21 +102,43 @@ namespace Barotrauma.Networking { LogFrame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f); - GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 500, 420), null, Alignment.Center, "", LogFrame); + GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 600, 420), null, Alignment.Center, "", LogFrame); innerFrame.Padding = new Vector4(10.0f, 20.0f, 10.0f, 20.0f); new GUITextBlock(new Rectangle(-200, 0, 100, 15), "Filter", "", Alignment.TopRight, Alignment.CenterRight, innerFrame, false, GUI.SmallFont); GUITextBox searchBox = new GUITextBox(new Rectangle(-20, 0, 180, 15), Alignment.TopRight, "", innerFrame); searchBox.Font = GUI.SmallFont; - searchBox.OnTextChanged = FilterMessages; + searchBox.OnTextChanged = (textBox, text) => + { + msgFilter = text; + FilterMessages(); + return true; + }; GUIComponent.KeyboardDispatcher.Subscriber = searchBox; var clearButton = new GUIButton(new Rectangle(0, 0, 15, 15), "x", Alignment.TopRight, "", innerFrame); clearButton.OnClicked = ClearFilter; clearButton.UserData = searchBox; - listBox = new GUIListBox(new Rectangle(0, 30, 0, 340), "", innerFrame); + listBox = new GUIListBox(new Rectangle(0, 30, 450, 340), "", Alignment.TopRight, innerFrame); + + int y = 30; + foreach (MessageType msgType in Enum.GetValues(typeof(MessageType))) + { + var tickBox = new GUITickBox(new Rectangle(0,y,20,20), msgType.ToString(), Alignment.TopLeft, GUI.SmallFont, innerFrame); + tickBox.Selected = true; + tickBox.TextColor = MessageColor[(int)msgType]; + + tickBox.OnSelected += (GUITickBox tb) => + { + msgTypeHidden[(int)msgType] = !tb.Selected; + FilterMessages(); + return true; + }; + + y += 20; + } var currLines = lines.ToList(); @@ -132,6 +157,8 @@ namespace Barotrauma.Networking LogFrame = null; return true; }; + + msgFilter = ""; } private void AddLine(LogMessage line) @@ -139,30 +166,32 @@ namespace Barotrauma.Networking float prevSize = listBox.BarSize; var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), line.Text, "", Alignment.TopLeft, Alignment.TopLeft, listBox, true, GUI.SmallFont); - textBlock.Rect = new Rectangle(textBlock.Rect.X, textBlock.Rect.Y, textBlock.Rect.Width, Math.Max(13, textBlock.Rect.Height)); - + textBlock.Rect = new Rectangle(textBlock.Rect.X, textBlock.Rect.Y, textBlock.Rect.Width, Math.Max(13, textBlock.Rect.Height)); textBlock.TextColor = MessageColor[(int)line.Type]; textBlock.CanBeFocused = false; + textBlock.UserData = line; if ((prevSize == 1.0f && listBox.BarScroll == 0.0f) || (prevSize < 1.0f && listBox.BarScroll == 1.0f)) listBox.BarScroll = 1.0f; } - private bool FilterMessages(GUITextBox textBox, string text) + private bool FilterMessages() { - if (string.IsNullOrWhiteSpace(text)) - { - listBox.children.ForEach( c => c.Visible = true); - return true; - } - - text = text.ToLower(); + string filter = msgFilter == null ? "" : msgFilter.ToLower(); foreach (GUIComponent child in listBox.children) { var textBlock = child as GUITextBlock; if (textBlock == null) continue; - textBlock.Visible = textBlock.Text.ToLower().Contains(text); + child.Visible = true; + + if (msgTypeHidden[(int)((LogMessage)child.UserData).Type]) + { + child.Visible = false; + continue; + } + + textBlock.Visible = string.IsNullOrEmpty(filter) || textBlock.Text.ToLower().Contains(filter); } listBox.BarScroll = 0.0f; @@ -172,11 +201,12 @@ namespace Barotrauma.Networking public bool ClearFilter(GUIComponent button, object obj) { - FilterMessages(null, ""); - var searchBox = button.UserData as GUITextBox; if (searchBox != null) searchBox.Text = ""; + msgFilter = ""; + FilterMessages(); + return true; }