Skip to content

Commit

Permalink
- add combobox in console view for filtering based on loaded mod names
Browse files Browse the repository at this point in the history
- fix color for warning and error log entries
  • Loading branch information
xiaoxiao921 committed Feb 24, 2022
1 parent e43a640 commit 0034e45
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 15 deletions.
49 changes: 39 additions & 10 deletions BepInEx.GUI/ViewModels/ConsoleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -54,6 +56,8 @@ public bool ConsoleAutoScroll
}
}

private bool _justChangedSelectedMod;

private string _textFilter = "";
public string TextFilter
{
Expand All @@ -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;
}
}
}

Expand Down Expand Up @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion BepInEx.GUI/ViewModels/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GeneralViewModel : ViewModelBase

public string TargetIsLoadingCanCloseWindow { get; }

private string _loadedModCountText;
private string _loadedModCountText = "";
public string LoadedModCountText
{
get { return _loadedModCountText; }
Expand Down
27 changes: 23 additions & 4 deletions BepInEx.GUI/Views/ConsoleView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,27 @@
<ColumnDefinition Width="0.25*" />
</Grid.ColumnDefinitions>

<Label Grid.Column="0" Content="Text Filter" FontSize="22" Target="{Binding ElementName=TextBoxTextFilter}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>

<Grid Grid.Column="0" Margin="0, 0, 0, 20">

<Grid.RowDefinitions>
<RowDefinition Height="0.50*" />
<RowDefinition Height="0.50*" />
</Grid.RowDefinitions>

<Label Grid.Row="0" Content="Text Filter" FontSize="22" Target="{Binding ElementName=TextBoxTextFilter}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>

<StackPanel Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center">
<ComboBox Items="{Binding GeneralViewModel.Mods}" SelectedItem="{Binding ConsoleViewModel.SelectedModFilter}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>

</Grid>

<TextBox Grid.Column="1" Name="TextBoxTextFilter" Text="{Binding ConsoleViewModel.TextFilter, Mode=TwoWay}" Margin="0, 20, 0, 20"/>

<StackPanel Grid.Column="2" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
Expand All @@ -48,8 +67,8 @@
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<StackPanel>
<Border Background="{Binding Color}" CornerRadius="4" Padding="0">
<TextBox IsReadOnly="True" Text="{Binding Text}" TextWrapping="Wrap" DoubleTapped="OnLogEntryDoubleClick" MaxHeight="40" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
<Border Background="{Binding BackgroundColor}" CornerRadius="4" Padding="0">
<TextBox IsReadOnly="True" Text="{Binding Text}" Foreground="{Binding ForegroundColor}" TextWrapping="Wrap" DoubleTapped="OnLogEntryDoubleClick" MaxHeight="40" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
</Border>
</StackPanel>
</DataTemplate>
Expand Down

0 comments on commit 0034e45

Please sign in to comment.