2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Graphics;
5 using System.Collections.Generic;
16 private string msgFilter;
18 private bool reverseOrder =
false;
20 private bool OnReverseClicked(
GUIButton btn,
object obj)
22 SetMessageReversal(!reverseOrder);
31 OnClicked = (btn, userdata) => {
if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock)
LogFrame =
null;
return true; }
49 List<GUITickBox> tickBoxes =
new List<GUITickBox>();
52 var tickBox =
new GUITickBox(
new RectTransform(
new Point(tickBoxContainer.Rect.Width, 30), tickBoxContainer.RectTransform), TextManager.Get(
"ServerLog." + messageTypeName[msgType]), font: GUIStyle.SmallFont)
55 TextColor = messageColor[msgType],
58 msgTypeHidden[(int)msgType] = !tb.Selected;
63 tickBox.TextBlock.SelectedTextColor = tickBox.TextBlock.TextColor;
64 tickBox.Selected = !msgTypeHidden[(int)msgType];
65 tickBoxes.Add(tickBox);
70 tickBoxes.Last().TextBlock.RectTransform.SizeChanged += () =>
80 RelativeSpacing = 0.02f
84 isHorizontal:
true, childAnchor:
Anchor.CenterLeft);
87 font: GUIStyle.SubHeadingFont);
95 GUI.KeyboardDispatcher.Subscriber = searchBox;
101 RelativeSpacing = 0.0f
105 reverseButton.
Children.ForEach(c => c.SpriteEffects = reverseOrder ? SpriteEffects.FlipVertically : SpriteEffects.None);
106 reverseButton.
OnClicked = OnReverseClicked;
112 OnClicked = (button, userData) =>
119 rightColumn.Recalculate();
121 var currLines = lines.ToList();
122 foreach (LogMessage line
in currLines)
146 List<GUITickBox> tickBoxes =
new List<GUITickBox>();
149 var tickBox =
new GUITickBox(
new RectTransform(
new Point(tickBoxContainer.Rect.Width, (
int)(25 * GUI.Scale)), tickBoxContainer.RectTransform),
150 TextManager.Get(
"ServerLog." + messageTypeName[msgType]).Fallback(messageTypeName[msgType]),
151 font: GUIStyle.SmallFont)
154 TextColor = messageColor[msgType],
157 msgTypeHidden[(int)msgType] = !tb.Selected;
162 tickBox.TextBlock.SelectedTextColor = tickBox.TextBlock.TextColor;
163 tickBox.Selected = !msgTypeHidden[(int)msgType];
164 tickBoxes.Add(tickBox);
166 tickBoxes.Last().TextBlock.RectTransform.SizeChanged += () =>
171 inListBox.ClearChildren();
174 reverseButton = inReverseButton;
175 reverseButton.
Children.ForEach(c => c.SpriteEffects = reverseOrder ? SpriteEffects.FlipVertically : SpriteEffects.None);
176 reverseButton.
OnClicked = OnReverseClicked;
178 var currLines = lines.ToList();
179 foreach (LogMessage line
in currLines)
188 private void AddLine(LogMessage line)
190 float prevSize = listBox.
BarSize;
197 if (richString !=
null && richString.
RichTextData.HasValue)
201 Client client = data.ExtractClient();
202 if (client !=
null && client.
Karma < 40.0f)
205 style:
null, color:
new Color(0xff111155))
209 anchor =
Anchor.CenterLeft;
210 pivot =
Pivot.CenterLeft;
216 var textBlock =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.0f), (textContainer ?? listBox.
Content).RectTransform, anchor, pivot),
217 line.Text, wrap:
true, font: GUIStyle.SmallFont)
219 TextColor = messageColor[line.Type],
220 Visible = !msgTypeHidden[(int)line.Type],
221 CanBeFocused =
false,
225 if (textContainer !=
null)
228 textBlock.SetTextPos();
234 textBlock.RectTransform.SetAsFirstChild();
237 if (richString !=
null && richString.
RichTextData.HasValue)
241 textBlock.ClickableAreas.Add(
new GUITextBlock.ClickableArea()
244 OnClick = GameMain.NetLobbyScreen.SelectPlayer,
245 OnSecondaryClick = GameMain.NetLobbyScreen.ShowPlayerContextMenu
253 private bool FilterMessages()
255 string filter = msgFilter ==
null ?
"" : msgFilter.ToLower();
259 if (!(child is GUITextBlock textBlock)) {
continue; }
260 child.Visible =
true;
261 if (msgTypeHidden[(
int)((LogMessage)child.UserData).Type])
263 child.Visible =
false;
267 textBlock.Visible =
string.IsNullOrEmpty(filter) || textBlock.Text.ToLower().Contains(filter);
275 private void SetMessageReversal(
bool reverse)
277 if (reverseOrder == reverse) {
return; }
279 reverseOrder = reverse;
280 reverseButton.
Children.ForEach(c => c.SpriteEffects = reverseOrder ? SpriteEffects.FlipVertically : SpriteEffects.None);
288 if (searchBox !=
null) { searchBox.
Text =
""; }
virtual void ClearChildren()
RectTransform RectTransform
IEnumerable< GUIComponent > Children
GUIFrame Content
A frame that contains the contents of the listbox. The frame itself is not rendered.
void UpdateScrollBarSize()
static void AutoScaleAndNormalize(params GUITextBlock[] textBlocks)
Set the text scale of the GUITextBlocks so that they all use the same scale and can fit the text with...
OnTextChangedHandler OnTextChanged
Don't set the Text property on delegates that register to this event, because modifying the Text will...
bool ClearFilter(GUIComponent button, object _)
void AssignLogFrame(GUIButton inReverseButton, GUIListBox inListBox, GUIComponent tickBoxContainer, GUITextBox searchBox)
ImmutableArray< RichTextData >? RichTextData