Add non-players button to log viewer (#14097)

* add include non-players button to log viewer

* breakout player filter check

* fix sending player logs with no players selected

* fix default not returning player logs, causing test issue
This commit is contained in:
Chief-Engineer
2023-02-28 10:09:35 -06:00
committed by GitHub
parent fbb23bd540
commit 8f402ee8ca
9 changed files with 84 additions and 14 deletions

View File

@@ -34,6 +34,7 @@ public sealed partial class AdminLogsControl : Control
SelectAllTypesButton.OnPressed += SelectAllTypes;
SelectNoTypesButton.OnPressed += SelectNoTypes;
IncludeNonPlayersButton.OnPressed += IncludeNonPlayers;
SelectAllPlayersButton.OnPressed += SelectAllPlayers;
SelectNoPlayersButton.OnPressed += SelectNoPlayers;
@@ -53,6 +54,7 @@ public sealed partial class AdminLogsControl : Control
public string Search => LogSearch.Text;
private int ShownLogs { get; set; }
private int TotalLogs { get; set; }
public bool IncludeNonPlayerLogs { get; set; }
public HashSet<LogType> SelectedTypes { get; } = new();
@@ -139,6 +141,13 @@ public sealed partial class AdminLogsControl : Control
UpdateLogs();
}
private void IncludeNonPlayers(ButtonEventArgs args)
{
IncludeNonPlayerLogs = args.Button.Pressed;
UpdateLogs();
}
private void SelectAllPlayers(ButtonEventArgs args)
{
SelectedPlayers.Clear();
@@ -259,12 +268,33 @@ public sealed partial class AdminLogsControl : Control
button.Text.Contains(PlayerSearch.Text, StringComparison.OrdinalIgnoreCase);
}
private bool LogMatchesPlayerFilter(AdminLogLabel label)
{
if (label.Log.Players.Length == 0)
return SelectedPlayers.Count == 0 || IncludeNonPlayerLogs;
return SelectedPlayers.Overlaps(label.Log.Players);
}
private bool ShouldShowLog(AdminLogLabel label)
{
return SelectedTypes.Contains(label.Log.Type) &&
(SelectedPlayers.Count + label.Log.Players.Length == 0 || SelectedPlayers.Overlaps(label.Log.Players)) &&
SelectedImpacts.Contains(label.Log.Impact) &&
label.Log.Message.Contains(LogSearch.Text, StringComparison.OrdinalIgnoreCase);
// Check log type
if (!SelectedTypes.Contains(label.Log.Type))
return false;
// Check players
if (!LogMatchesPlayerFilter(label))
return false;
// Check impact
if (!SelectedImpacts.Contains(label.Log.Impact))
return false;
// Check search
if (!label.Log.Message.Contains(LogSearch.Text, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
private void TypeButtonPressed(ButtonEventArgs args)
@@ -481,6 +511,7 @@ public sealed partial class AdminLogsControl : Control
SelectAllTypesButton.OnPressed -= SelectAllTypes;
SelectNoTypesButton.OnPressed -= SelectNoTypes;
IncludeNonPlayersButton.OnPressed -= IncludeNonPlayers;
SelectAllPlayersButton.OnPressed -= SelectAllPlayers;
SelectNoPlayersButton.OnPressed -= SelectNoPlayers;