Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion source/Generic/GameRelations/GameRelationsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class GameRelationsSettings : ObservableObject

private SimilarGamesControlSettings similarGamesControlSettings = new SimilarGamesControlSettings();
public SimilarGamesControlSettings SimilarGamesControlSettings { get => similarGamesControlSettings; set => SetValue(ref similarGamesControlSettings, value); }

public int SettingsVersion = 1;
}

public class GameRelationsSettingsViewModel : ObservableObject, ISettings
Expand Down Expand Up @@ -72,10 +74,12 @@ public GameRelationsSettingsViewModel(GameRelations plugin)
if (savedSettings != null)
{
Settings = savedSettings;
UpgradeSettings();
}
else
{
Settings = new GameRelationsSettings();
SetAdvancedSectionDefaults();
}
}

Expand Down Expand Up @@ -185,6 +189,29 @@ private void RemoveSelectedItemsFromExclude(ObservableCollection<DatabaseObject>
}
}

private string GetResourceString(string key) => plugin.PlayniteApi.Resources.GetString(key);

public void SetAdvancedSectionDefaults()
{
Settings.SimilarGamesControlSettings.JacardSimilarityPerField = 0.73D;
Settings.SimilarGamesControlSettings.FieldSettings.Clear();
settings.SimilarGamesControlSettings.FieldSettings.Add(new SimilarGamesFieldSettings(GameField.TagIds, GetResourceString("LOCTagsLabel"), true, 1));
settings.SimilarGamesControlSettings.FieldSettings.Add(new SimilarGamesFieldSettings(GameField.GenreIds, GetResourceString("LOCGenresLabel"), true, 1.2));
settings.SimilarGamesControlSettings.FieldSettings.Add(new SimilarGamesFieldSettings(GameField.CategoryIds, GetResourceString("LOCCategoriesLabel"), true, 1.3));
Comment on lines +198 to +200
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the names should be set during their creation. This creates the issue that if language or source string changes, they'll stay the previous incorrect name so it would be better to resolve at runtime.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, if the settings for each field are being made separate here, in my opinion it would make sense to also move the item exclusion functionality there too:

image

}

public void UpgradeSettings()
{
int currentVersion = 2;

if (settings.SettingsVersion < 2)
{
SetAdvancedSectionDefaults();
}

Settings.SettingsVersion = currentVersion;
}

public RelayCommand AddSelectedTagsToExcludeCommand
{
get => new RelayCommand(() =>
Expand Down Expand Up @@ -233,6 +260,9 @@ public RelayCommand RemoveSelectedCategoriesFromExcludeCommand
}, () => SgExcludeCategoriesSelectedItems.Count > 0);
}


public RelayCommand SetAdvancedSectionDefaultsCommand
{
get => new RelayCommand(SetAdvancedSectionDefaults);
}
}
}
43 changes: 38 additions & 5 deletions source/Generic/GameRelations/GameRelationsSettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</StackPanel>
</StackPanel>
</DataTemplate>

<Style x:Key="ExcludeListBoxStyle" TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
<Setter Property="Margin" Value="0,5,0,0"/>
<Setter Property="DockPanel.Dock" Value="Top"/>
Expand Down Expand Up @@ -80,7 +80,7 @@
<Setter Property="Margin" Value="0,5,0,5" />
<Setter Property="Content" Value="&#xEA5C;" />
</Style>

<Style x:Key="ExclusionAllowTextBlockStyle" TargetType="TextBlock" BasedOn="{StaticResource BaseTextBlockStyle}">
<Setter Property="FontFamily" Value="{DynamicResource FontIcoFont}" />
<Setter Property="DockPanel.Dock" Value="Top" />
Expand All @@ -96,7 +96,7 @@
<Setter Property="FontSize" Value="22" />
<Setter Property="Text" Value="&#xEEDD;" />
</Style>

</UserControl.Resources>
<Grid Margin="20">
<ScrollViewer>
Expand Down Expand Up @@ -142,7 +142,7 @@
ItemsSource="{Binding SimilarGamesNotExcludeTags}"
SelectionChanged="SimilarGamesNotExcludeTagsLb_SelectionChanged" />
</DockPanel>

<StackPanel Grid.Column="1" VerticalAlignment="Center"
Margin="5,0,5,0">
<Button Style="{DynamicResource ExcludeArrowRightStyle}"
Expand Down Expand Up @@ -221,7 +221,40 @@
</DockPanel>
</Grid>
</Expander>


<Expander Margin="0,10,0,0" Header="Advanced">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock VerticalAlignment="Center">Jacard similarity requirement per field:</TextBlock>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing translation string

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the string should remain only as "Minimum similarity to match games" with a more detailed explanation in a tooltip, including saying that it uses Jacard.

<TextBox VerticalAlignment="Center" IsReadOnly="True" MinWidth="35" Margin="10,0"
Text="{Binding Settings.SimilarGamesControlSettings.JacardSimilarityPerField}" />
<Slider Minimum="0.4" Maximum="1" IsSnapToTickEnabled="True" TickFrequency="0.01"
Value="{Binding Settings.SimilarGamesControlSettings.JacardSimilarityPerField}"
Width="200" VerticalAlignment="Center"/>
</StackPanel>

<TextBlock Text="Fields enabled/weights:" Margin="0,10,0,0"/>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like much the text here. Perhaps it should say "Individual fields settings"


<ItemsControl ItemsSource="{Binding Settings.SimilarGamesControlSettings.FieldSettings}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="10,10,0,0">
<CheckBox IsChecked="{Binding Enabled}" Content="{Binding Name}"
VerticalAlignment="Center" MinWidth="150"/>
<TextBox VerticalAlignment="Center" IsReadOnly="True" MinWidth="35"
Margin="10,0" Text="{Binding Weight}"
IsEnabled="{Binding Enabled}"/>
<Slider Minimum="0.5" Maximum="2" TickFrequency="0.01"
Value="{Binding Weight}" IsEnabled="{Binding Enabled}"
Width="150" VerticalAlignment="Center" IsSnapToTickEnabled="True"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

<Button Content="Reset to defaults" Command="{Binding SetAdvancedSectionDefaultsCommand}" Padding="5" Width="200" HorizontalAlignment="Left" Margin="0,10,0,0"/>
</StackPanel>
</Expander>
</StackPanel>
</Expander>

Expand Down
16 changes: 1 addition & 15 deletions source/Generic/GameRelations/GameRelationsSettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
using Playnite.SDK.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GameRelations
{
Expand Down
41 changes: 36 additions & 5 deletions source/Generic/GameRelations/Models/SimilarGamesControlSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using Playnite.SDK;
using Playnite.SDK.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Windows;

namespace GameRelations.Models
{
Expand All @@ -12,16 +13,46 @@ public class SimilarGamesControlSettings : GameRelationsControlSettings
public HashSet<Guid> CategoriesToIgnore = new HashSet<Guid>();
public HashSet<Guid> GenresToIgnore = new HashSet<Guid>();

public ObservableCollection<SimilarGamesFieldSettings> FieldSettings { get; set; } = new ObservableCollection<SimilarGamesFieldSettings>();

public SimilarGamesFieldSettings Tags = new SimilarGamesFieldSettings();
public SimilarGamesFieldSettings Genres = new SimilarGamesFieldSettings();
public SimilarGamesFieldSettings Categories = new SimilarGamesFieldSettings();

private bool excludeGamesSameSeries = true;
public bool ExcludeGamesSameSeries { get => excludeGamesSameSeries; set => SetValue(ref excludeGamesSameSeries, value); }

private double jacardSimilarityPerField = 0.73D;
public double JacardSimilarityPerField { get => jacardSimilarityPerField; set => SetValue(ref jacardSimilarityPerField, value); }

public SimilarGamesControlSettings()
{

}

public SimilarGamesControlSettings(bool displayGameNames, int maxItems, bool isEnabled) : base(displayGameNames, maxItems, isEnabled)
{
}
}

public class SimilarGamesFieldSettings : ObservableObject
{
public GameField Field { get; set; }
public string Name { get; set; }

private bool enabled = true;
public bool Enabled { get => enabled; set=> SetValue(ref enabled, value); }

private double weight = 1.0;
public double Weight { get => weight; set => SetValue(ref weight, value); }

public SimilarGamesFieldSettings() { }

public SimilarGamesFieldSettings(GameField field, string name, bool enabled, double weight)
{
Field = field;
Name = name;
Enabled = enabled;
Weight = weight;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using TemporaryCache;

namespace GameRelations.PlayniteControls
{
Expand Down Expand Up @@ -213,7 +204,7 @@ protected static decimal CalculateListHashSetMatchPercentage<T>(IEnumerable<T> l
}

// Rounding is done to prevent errors when doing arithmetic operations
var matchPercent = Math.Round(commonCount / (decimal)Math.Max(listToMatch.Count(), hashSet.Count), 3);
var matchPercent = Math.Round(commonCount / (decimal)Math.Max(listToMatch.Count(), hashSet.Count), 3);
return matchPercent;
}

Expand Down
Loading