Skip to content

Commit

Permalink
Added grouped search mode-When checked will save keyword to search so…
Browse files Browse the repository at this point in the history
… the user can store a class of dinos
  • Loading branch information
jamckee authored and Rottenbeer committed Aug 4, 2019
1 parent 74cac98 commit 81fcdbe
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Common/SearchCriteria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public SearchCriteria(SearchCriteria copy)
MinLevel = copy.MinLevel;
MaxLevel = copy.MaxLevel;
Female = copy.Female;
GroupSearch = copy.GroupSearch;
}

public string Group { get; set; }
Expand All @@ -34,6 +35,7 @@ public SearchCriteria(SearchCriteria copy)
public int? MinLevel { get; set; }
public int? MaxLevel { get; set; }
public bool? Female { get; set; }
public bool GroupSearch { get; set; }

/// <summary>
/// Compares equality based only on an internal random ID assigned on creation.
Expand Down
12 changes: 9 additions & 3 deletions LarkatorGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,24 @@
</StackPanel>
<Button Width="32" FontFamily="Arial Black" FontSize="28" FontWeight="Bold" Padding="-4" Margin="16" Content="+" Click="CreateSearch_Click"
Visibility="{Binding CreateSearchAvailable, Converter={StaticResource BoolToVisibilityConverter}}"/>
<Grid Margin="16,0,16,16" Visibility="{Binding NewSearchActive, Converter={StaticResource BoolToVisibilityConverter}}" Background="#44ffffff">
<Grid Margin="16,0,16,16" Visibility="{Binding NewSearchActive, Converter={StaticResource BoolToVisibilityConverter}}" Background="#44ffffff">
<StackPanel Margin="8" Orientation="Vertical" HorizontalAlignment="Stretch" DataContext="{Binding NewSearch}">
<ComboBox x:Name="groupsCombo" Text="{Binding Group}" IsEditable="True" />
<ComboBox x:Name="speciesCombo" Text="{Binding Species}" IsEditable="True" StaysOpenOnEdit="True"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4">
<TextBlock Text="Min"/>
<TextBlock Text="Min "/>
<TextBlock Text="{Binding MinLevel, ConverterParameter=-, Converter={StaticResource OptionalIntConverter}}" MinWidth="64" MouseWheel="AdjustableInteger_MouseWheel"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4">
<TextBlock Text="Max"/>
<TextBlock Text="Max "/>
<TextBlock Text="{Binding MinLevel, ConverterParameter=-, Converter={StaticResource OptionalIntConverter}}" MinWidth="64" MouseWheel="AdjustableInteger_MouseWheel"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4">
<TextBlock Text="Grouped search "/>
<CheckBox x:Name="groupCheck" ToolTip="Keyword search for a group of dinosaurs"
IsChecked="{Binding Source={StaticResource Settings}, Path=Settings.GroupSearch, Mode=TwoWay}" HorizontalAlignment="Right"
Margin="7,4"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Width="32" FontFamily="Arial Black" FontSize="28" FontWeight="Bold" Padding="-4" Margin="4,0" Content="+" Click="SaveSearch_Click" />
<TextBlock VerticalAlignment="Center" MouseDown="CloseNewSearch_Click"><Underline><Run Text="X"/></Underline></TextBlock>
Expand Down
63 changes: 46 additions & 17 deletions LarkatorGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,38 +541,52 @@ private void SaveSearch_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.LastGroup = "Shopping List";
}
//Set and save property
Properties.Settings.Default.GroupSearch = (bool) groupCheck.IsChecked;
Properties.Settings.Default.Save();


if (NewSearchList.Count == 0) // No matches
{ //Trigger default values so the user knows we tried to match
{ //Trigger default values so the user knows we did search to match
NewSearch = null;
tempSearch = null;
NewSearchActive = false;
CreateSearchAvailable = true;
return;
}

try
ObservableCollection<SearchCriteria> tempListSearch = new ObservableCollection<SearchCriteria>(ListSearches.Where(sc => sc.Group == (String)groupsCombo.SelectedValue));
if (tempListSearch.Count > 0)
{
ObservableCollection<SearchCriteria> tempListSearch = new ObservableCollection<SearchCriteria>(ListSearches.Where(sc => sc.Group == (String) groupsCombo.SelectedValue));
if (tempListSearch.Count > 0)
{
order = (int) ListSearches.Where(sc => sc.Group == NewSearch.Group).Max(sc => sc.Order) + 100;
}
foreach (String newDino in NewSearchList)
order = (int)ListSearches.Where(sc => sc.Group == NewSearch.Group).Max(sc => sc.Order) + 100;
}
//check for group based search
if (Properties.Settings.Default.GroupSearch)
{
tempSearch = new SearchCriteria(NewSearch);
tempSearch.Species = NewSearch.Species;
tempSearch.Order = order; //Sort order
tempSearch.GroupSearch = Properties.Settings.Default.GroupSearch;
ListSearches.Add(tempSearch);
}
else {
try
{
if (tempListSearch.Count == 0 || tempListSearch.Where(dino =>dino.Species == newDino).Count() == 0) {
tempSearch = new SearchCriteria(NewSearch);
tempSearch.Species = newDino;
tempSearch.Order = order;
ListSearches.Add(tempSearch);
order += 100;
foreach (String newDino in NewSearchList)
{
if (tempListSearch.Count == 0 || tempListSearch.Where(dino => dino.Species == newDino).Count() == 0)
{
tempSearch = new SearchCriteria(NewSearch);
tempSearch.Species = newDino;
tempSearch.Order = order;
tempSearch.GroupSearch = Properties.Settings.Default.GroupSearch;
ListSearches.Add(tempSearch);
order += 100;
}
}
}
catch (InvalidOperationException) // no entries for .Max - ignore
{ }
}
catch (InvalidOperationException) // no entries for .Max - ignore
{ }


NewSearch = null;
Expand Down Expand Up @@ -762,6 +776,21 @@ private void UpdateSearchResults(IList<SearchCriteria> searches)
total += speciesDinos.Count;
}
}
else if (search.GroupSearch)
{
List<String> NewSearchList = new List<String>(AllSpecies.Where(species => species.Contains(search.Species)));
foreach (String newDino in NewSearchList)
{
if (sourceDinos.ContainsKey(newDino))
{
var dinoList = sourceDinos[newDino];
//found.AddRange(dinoList.Where(d => search.Matches(d)));
found.AddRange(dinoList);
total += dinoList.Count;
}
}

}
else
{
if (sourceDinos.ContainsKey(search.Species))
Expand Down
16 changes: 14 additions & 2 deletions LarkatorGUI/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion LarkatorGUI/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="LastGroup" Type="System.String" Scope="User">
<Value Profile="(Default)" />
<Value Profile="(Default)">Shopping List</Value>
</Setting>
<Setting Name="HideUntameable" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="GroupSearch" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
5 changes: 4 additions & 1 deletion LarkatorGUI/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@
<value>True</value>
</setting>
<setting name="LastGroup" serializeAs="String">
<value />
<value>Shopping List</value>
</setting>
<setting name="HideUntameable" serializeAs="String">
<value>False</value>
</setting>
<setting name="GroupSearch" serializeAs="String">
<value>False</value>
</setting>
</LarkatorGUI.Properties.Settings>
</userSettings>
</configuration>

0 comments on commit 81fcdbe

Please sign in to comment.