From 0034e457e46bd4f1e6c8fe4c64e85e8b0a86459a Mon Sep 17 00:00:00 2001 From: xiaoxiao921 Date: Thu, 24 Feb 2022 17:22:03 +0100 Subject: [PATCH] - add combobox in console view for filtering based on loaded mod names - fix color for warning and error log entries --- BepInEx.GUI/ViewModels/ConsoleViewModel.cs | 49 +++++++++++++++++----- BepInEx.GUI/ViewModels/GeneralViewModel.cs | 2 +- BepInEx.GUI/Views/ConsoleView.axaml | 27 ++++++++++-- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/BepInEx.GUI/ViewModels/ConsoleViewModel.cs b/BepInEx.GUI/ViewModels/ConsoleViewModel.cs index 9630c25..cceffe3 100644 --- a/BepInEx.GUI/ViewModels/ConsoleViewModel.cs +++ b/BepInEx.GUI/ViewModels/ConsoleViewModel.cs @@ -13,12 +13,14 @@ public class ConsoleViewModel : ViewModelBase public class ColoredEntry { public string Text { get; set; } - public string Color { get; set; } + public string BackgroundColor { get; set; } + public string ForegroundColor { get; set; } - public ColoredEntry(string text, string color) + public ColoredEntry(string text, string backgroundColor, string foregroundColor) { Text = text; - Color = color; + BackgroundColor = backgroundColor; + ForegroundColor = foregroundColor; } } @@ -54,6 +56,8 @@ public bool ConsoleAutoScroll } } + private bool _justChangedSelectedMod; + private string _textFilter = ""; public string TextFilter { @@ -62,6 +66,31 @@ public string TextFilter { this.RaiseAndSetIfChanged(ref _textFilter, value); UpdateConsoleBox(); + + if (_justChangedSelectedMod) + { + _justChangedSelectedMod = false; + } + else + { + SelectedModFilter = null; + } + } + } + + private Mod? _selectedModFilter; + public Mod? SelectedModFilter + { + get { return _selectedModFilter; } + set + { + this.RaiseAndSetIfChanged(ref _selectedModFilter, value); + + if (value != null) + { + _justChangedSelectedMod = true; + TextFilter = _selectedModFilter!.Name; + } } } @@ -132,24 +161,24 @@ private void UpdateConsoleBox() { var logEntryString = logEntry.ToString(); - string color = logEntry.LevelCode switch + var (backgroundColor, foregroundColor) = logEntry.LevelCode switch { - Logging.LogLevel.Fatal => "Red", - Logging.LogLevel.Error => "Red", - Logging.LogLevel.Warning => "YellowGreen", - _ => "Transparent", + Logging.LogLevel.Fatal => ("Transparent", "Red"), + Logging.LogLevel.Error => ("Transparent", "Red"), + Logging.LogLevel.Warning => ("Transparent", "Yellow"), + _ => ("Transparent", "White"), }; if (TextFilter.Length > 0) { if (logEntryString.ToLowerInvariant().Contains(TextFilter.ToLowerInvariant())) { - consoleText.Add(new ColoredEntry(logEntryString, color)); + consoleText.Add(new ColoredEntry(logEntryString, backgroundColor, foregroundColor)); } } else { - consoleText.Add(new ColoredEntry(logEntryString, color)); + consoleText.Add(new ColoredEntry(logEntryString, backgroundColor, foregroundColor)); } } } diff --git a/BepInEx.GUI/ViewModels/GeneralViewModel.cs b/BepInEx.GUI/ViewModels/GeneralViewModel.cs index 900d867..48bd067 100644 --- a/BepInEx.GUI/ViewModels/GeneralViewModel.cs +++ b/BepInEx.GUI/ViewModels/GeneralViewModel.cs @@ -20,7 +20,7 @@ public class GeneralViewModel : ViewModelBase public string TargetIsLoadingCanCloseWindow { get; } - private string _loadedModCountText; + private string _loadedModCountText = ""; public string LoadedModCountText { get { return _loadedModCountText; } diff --git a/BepInEx.GUI/Views/ConsoleView.axaml b/BepInEx.GUI/Views/ConsoleView.axaml index dc31f79..2d98422 100644 --- a/BepInEx.GUI/Views/ConsoleView.axaml +++ b/BepInEx.GUI/Views/ConsoleView.axaml @@ -22,8 +22,27 @@ -