Skip to content

Commit c0f227f

Browse files
committed
Filters: Added Producer Filter.
1 parent b7e9811 commit c0f227f

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

Happy Reader/Model/VnFilters/GeneralFilter.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public object Value
9797
IntValue = dumpItemValue.ID;
9898
_stringValue = IntValue.ToString();
9999
break;
100+
case ListedProducer producer:
101+
IntValue = producer.ID;
102+
_stringValue = IntValue.ToString();
103+
break;
100104
default:
101105
IntValue = 0;
102106
_stringValue = value?.ToString();
@@ -181,6 +185,8 @@ private Func<IDataItem<int>, bool> GetFunction()
181185
return i => ((i is CharacterItem ch && ch.ImageId != null) ||
182186
(i is ListedVN vn && StaticHelpers.LocalDatabase.GetCharactersForVN(vn.VNID).Any(chara => chara.ImageId != null)))
183187
!= Exclude;
188+
case GeneralFilterType.Producer:
189+
return i => (i is CharacterItem ch && ch.Producer?.ID == IntValue) || (i is ListedVN vn && vn.ProducerID == IntValue) != Exclude;
184190
default: throw new ArgumentOutOfRangeException();
185191
}
186192
}
@@ -220,8 +226,7 @@ public Func<VisualNovelDatabase, HashSet<int>> GetGlobalFunction(Func<VisualNove
220226
if (Type != GeneralFilterType.Staff) throw new InvalidOperationException($"Filter type {Type} should use per-item function.");
221227
return db => db.GetVnsWithStaff(IntValue);
222228
}
223-
224-
229+
225230
Func<IDataItem<int>, bool> IFilter.GetFunction()
226231
{
227232
//we determine what the filter function is only once, rather than per-item
@@ -355,6 +360,8 @@ public override string ToString()
355360
return $"{result} - {DumpFiles.GetTrait(IntValue).Name}";
356361
case GeneralFilterType.Staff:
357362
return $"{result} - {StaticHelpers.LocalDatabase.StaffAliases[StaticHelpers.LocalDatabase.StaffItems[IntValue].AliasID]}";
363+
case GeneralFilterType.Producer:
364+
return $"{result} - {StaticHelpers.LocalDatabase.Producers[IntValue]}";
358365
// ReSharper disable once RedundantCaseLabel
359366
case GeneralFilterType.Multi:
360367
default:
@@ -415,6 +422,8 @@ public enum GeneralFilterType
415422
CharacterGender = 22,
416423
[Description("Character Has Image"), TypeConverter(typeof(bool))]
417424
CharacterHasImage = 23,
425+
[Description("Producer"), TypeConverter(typeof(ListedProducer))]
426+
Producer = 24,
418427
#pragma warning restore 1591
419428
}
420429
}

Happy Reader/View/FiltersPane.xaml.cs

+21-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Windows.Data;
66
using System.Windows.Input;
77
using Happy_Apps_Core;
8+
using Happy_Apps_Core.Database;
89
using Happy_Reader.ViewModel;
910

1011
namespace Happy_Reader.View
@@ -15,7 +16,7 @@ public partial class FiltersPane : UserControl
1516
// ReSharper disable once NotAccessedField.Local
1617
private FiltersViewModel ViewModel => (FiltersViewModel)DataContext;
1718
private AutoCompleteBox _traitOrTagControl;
18-
19+
1920
public FiltersPane()
2021
{
2122
InitializeComponent();
@@ -55,12 +56,12 @@ private void FilterTypeChanged(object sender, SelectionChangedEventArgs e)
5556
if (type == null) return;
5657
FrameworkElement control;
5758
DependencyProperty bindingProperty = null;
58-
var valueBinding = new Binding($"{nameof(ViewModel.NewFilter)}.{nameof(IFilter.Value)}"){Mode = BindingMode.OneWayToSource};
59+
var valueBinding = new Binding($"{nameof(ViewModel.NewFilter)}.{nameof(IFilter.Value)}") { Mode = BindingMode.OneWayToSource };
5960
if (type.IsEnum)
6061
{
6162
control = new ComboBox
6263
{
63-
ItemsSource = StaticMethods.GetEnumValues(type),
64+
ItemsSource = StaticMethods.GetEnumValues(type),
6465
SelectedIndex = 0,
6566
SelectedValuePath = nameof(Tag)
6667
};
@@ -108,19 +109,25 @@ private void FilterTypeChanged(object sender, SelectionChangedEventArgs e)
108109
control = _traitOrTagControl;
109110
bindingProperty = AutoCompleteBox.SelectedItemProperty;
110111
}
112+
else if (type == typeof(ListedProducer))
113+
{
114+
_traitOrTagControl = new AutoCompleteBox() { ItemFilter = ProducerBoxFilter, ItemsSource = StaticHelpers.LocalDatabase.Producers };
115+
control = _traitOrTagControl;
116+
bindingProperty = AutoCompleteBox.SelectedItemProperty;
117+
}
111118
else control = new TextBlock(new System.Windows.Documents.Run(type.ToString()));
112119
}
113-
if(bindingProperty != null) control.SetBinding(bindingProperty, valueBinding);
120+
if (bindingProperty != null) control.SetBinding(bindingProperty, valueBinding);
114121
FilterValuesGrid.Children.Add(control);
115122
}
116-
123+
117124
private void RootControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
118125
{
119126
if (e.AddedItems.Count == 0) return;
120127
var selectedTraitRoot = (DumpFiles.RootTrait)((ComboBoxItem)e.AddedItems[0]).Tag;
121128
_traitOrTagControl.ItemsSource = DumpFiles.GetTraitsForRoot(selectedTraitRoot);
122129
}
123-
130+
124131
private bool TraitOrTagBoxFilter(string input, object item)
125132
{
126133
//Short input is not filtered to prevent excessive loading times
@@ -129,6 +136,14 @@ private bool TraitOrTagBoxFilter(string input, object item)
129136
return trait.Name.ToLowerInvariant().Contains(input.ToLowerInvariant());
130137
}
131138

139+
private bool ProducerBoxFilter(string input, object item)
140+
{
141+
//Short input is not filtered to prevent excessive loading times
142+
if (input.Length <= 2) return false;
143+
var producer = (ListedProducer)item;
144+
return producer.Name.ToLowerInvariant().Contains(input.ToLowerInvariant());
145+
}
146+
132147
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
133148
{
134149
var regex = new System.Text.RegularExpressions.Regex("[^0-9]+");

0 commit comments

Comments
 (0)