Skip to content

Commit

Permalink
fix: achievements search
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Jul 24, 2023
1 parent 45b5b49 commit 28c9102
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 50 deletions.
172 changes: 171 additions & 1 deletion MHFZ_Overlay/Assets/Themes/CatppuccinMocha.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml">
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:system="clr-namespace:System;assembly=netstandard">
<!-- Define color resources for the theme -->
<SolidColorBrush x:Key="Rosewater" Color="#f5e0dc" />
<SolidColorBrush x:Key="Flamingo" Color="#f2cdcd" />
Expand Down Expand Up @@ -835,6 +835,176 @@
</Trigger>
</Style.Triggers>
</Style>

<!-- AutoSuggestBox -->
<Thickness x:Key="AutoSuggestBoxBorderThemeThickness">1,1,1,0</Thickness>
<Thickness x:Key="AutoSuggestBoxAccentBorderThemeThickness">0,0,0,1</Thickness>
<Thickness x:Key="AutoSuggestBoxLeftIconMargin">10,8,0,0</Thickness>
<Thickness x:Key="AutoSuggestBoxRightIconMargin">0,8,10,0</Thickness>
<Thickness x:Key="AutoSuggestBoxClearButtonMargin">0,5,4,0</Thickness>
<Thickness x:Key="AutoSuggestBoxClearButtonPadding">0,0,0,0</Thickness>
<system:Double x:Key="AutoSuggestBoxClearButtonHeight">24</system:Double>
<system:Double x:Key="AutoSuggestBoxClearButtonIconSize">14</system:Double>

<Style x:Key="DefaultAutoSuggestBoxItemContainerStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{StaticResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Margin" Value="0,0,0,2" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border
x:Name="ContentBorder"
Margin="4,0,4,0"
Padding="6,10"
BorderBrush="Transparent"
BorderThickness="0"
CornerRadius="6">
<Border.Background>
<SolidColorBrush Opacity="0.0" Color="{StaticResource SubtleFillColorSecondary}" />
</Border.Background>
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="ContentBorder" Property="Background">
<Setter.Value>
<SolidColorBrush Color="{StaticResource SubtleFillColorSecondary}" />
</Setter.Value>
</Setter>
</Trigger>

<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>

<MultiTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ContentBorder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Opacity)"
From="0.0"
To="1.0"
Duration="00:00:00.167" />
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ContentBorder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Opacity)"
From="1.0"
To="0.0"
Duration="00:00:00.167" />
</Storyboard>
</BeginStoryboard>
</MultiTrigger.ExitActions>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="DefaultUiAutoSuggestBoxStyle" TargetType="{x:Type ui:AutoSuggestBox}">
<Setter Property="MaxSuggestionListHeight" Value="240" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="Padding" Value="4" />
<Setter Property="Border.CornerRadius" Value="4" />
<Setter Property="BorderBrush" Value="{StaticResource ControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource AutoSuggestBoxBorderThemeThickness}" />
<Setter Property="FontSize" Value="16" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="ItemContainerStyle" Value="{StaticResource DefaultAutoSuggestBoxItemContainerStyle}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Icon">
<Setter.Value>
<ui:IconSourceElement>
<ui:IconSourceElement.IconSource>
<ui:SymbolIconSource Symbol="Search24" />
</ui:IconSourceElement.IconSource>
</ui:IconSourceElement>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ui:AutoSuggestBox}">
<Grid>
<ui:TextBox
x:Name="PART_TextBox"
Grid.Row="0"
Icon="{TemplateBinding Icon}"
IconPlacement="Right"
PlaceholderText="{TemplateBinding PlaceholderText}"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" />

<Popup
x:Name="PART_SuggestionsPopup"
MinWidth="{TemplateBinding ActualWidth}"
Margin="0"
HorizontalAlignment="Stretch"
AllowsTransparency="True"
Focusable="False"
IsOpen="{TemplateBinding IsSuggestionListOpen}"
Placement="Bottom"
PopupAnimation="Slide">
<Border
Margin="0"
Padding="0,6,0,6"
HorizontalAlignment="Stretch"
BorderBrush="{StaticResource SurfaceStrokeColorFlyoutBrush}"
BorderThickness="1"
CornerRadius="8"
SnapsToDevicePixels="True">
<Border.Background>
<SolidColorBrush Color="{StaticResource SolidBackgroundFillColorTertiary}" />
</Border.Background>
<ListView
x:Name="PART_SuggestionsList"
MaxHeight="{TemplateBinding MaxSuggestionListHeight}"
DisplayMemberPath="{TemplateBinding DisplayMemberPath}"
ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
ItemTemplate="{TemplateBinding ItemTemplate}"
ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}"
ItemsSource="{TemplateBinding ItemsSource}"
KeyboardNavigation.DirectionalNavigation="Cycle"
SelectionMode="Single">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel
IsItemsHost="True"
IsVirtualizing="True"
VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</Border>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!--<Style BasedOn="{DynamicResource DefaultUiAutoSuggestBoxStyle}" TargetType="{x:Type ui:AutoSuggestBox}" />-->

<!-- Define other resources specific to the theme -->
<!-- ... Add other resources here ... -->




</ResourceDictionary>
15 changes: 13 additions & 2 deletions MHFZ_Overlay/Views/Windows/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,18 @@
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="3">
<ui:AutoSuggestBox TextChanged="AchievementsAutoSuggestBox_TextChanged" DisplayMemberPath="Title" x:Name="AchievementsAutoSuggestBox" PlaceholderText="Search achievement title..." SuggestionChosen="AchievementsAutoSuggestBox_SuggestionChosen" OriginalItemsSource="{Binding PlayerAchievements}"/>
<Grid ToolTip="Search achievement title">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<ui:Button x:Name="AchievementsSearchButton" Grid.Column="0" BorderThickness="0" Background="Transparent" Width="48" Height="40" Click="AchievementsSearchButton_Click">
<Button.Content>
<ui:SymbolIcon Symbol="Search32" Foreground="{StaticResource Green}" FontSize="24"/>
</Button.Content>
</ui:Button>
<ComboBox DisplayMemberPath="Title" IsTextSearchEnabled="True" IsTextSearchCaseSensitive="False" Grid.Column="1" x:Name="AchievementsSearchComboBox" ItemsSource="{Binding PlayerAchievements, Mode=OneWay}" IsEditable="True" Text="Search achievement title..."/>
</Grid>
</Grid>
<ListView Margin="5" x:Name="AchievementsListView" Grid.RowSpan="3" Grid.ColumnSpan="2" Loaded="AchievementsListView_Loaded" SelectionChanged="AchievementsListView_SelectionChanged"
VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard">
Expand Down Expand Up @@ -4031,6 +4042,6 @@ Thunder Clad, Vigorous" Text="{Binding GetActiveSkillsForImage,Mode=OneTime}" Fo
</TabItem>
</TabControl>
</Grid>
<ui:SnackbarPresenter Grid.ZIndex="2" x:Name="ConfigWindowSnackBarPresenter"/>
<ui:SnackbarPresenter Grid.ZIndex="2" x:Name="ConfigWindowSnackBarPresenter" d:Visibility="Hidden"/>
</Grid>
</ui:FluentWindow>
49 changes: 3 additions & 46 deletions MHFZ_Overlay/Views/Windows/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4364,24 +4364,10 @@ private void HunterNotesGridMenuItem_Click(object sender, RoutedEventArgs e)
}
}

private void AchievementsAutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
private void AchievementsSearchButton_Click(object sender, RoutedEventArgs e)
{
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
// Get the user input from the AutoSuggestBox
string userInput = sender.Text;

// Filter the achievements based on the user input
List<Achievement> filteredAchievements = MainWindow.dataLoader.model.PlayerAchievements
.Where(achievement => achievement.Title.Contains(userInput, StringComparison.OrdinalIgnoreCase))
.ToList();

// Update the ItemsSource of the AutoSuggestBox with the filtered achievements
sender.ItemsSource = filteredAchievements;
}

// Check if the text in the AutoSuggestBox is empty
if (string.IsNullOrWhiteSpace(AchievementsAutoSuggestBox.Text))
if (string.IsNullOrWhiteSpace(AchievementsSearchComboBox.Text))
{
// If the text is empty, show the original list in the ListView
AchievementsListView.ItemsSource = MainWindow.dataLoader.model.PlayerAchievements;
Expand All @@ -4392,42 +4378,13 @@ private void AchievementsAutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoS
AchievementsListView.ItemsSource = null;

// Then, set the ItemsSource back to the filtered achievements list based on the user's input
string userInput = AchievementsAutoSuggestBox.Text;
string userInput = AchievementsSearchComboBox.Text;
List<Achievement> filteredAchievements = MainWindow.dataLoader.model.PlayerAchievements
.Where(achievement => achievement.Title.Contains(userInput, StringComparison.OrdinalIgnoreCase))
.ToList();
AchievementsListView.ItemsSource = filteredAchievements;
}
}

private void AchievementsAutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
// This event is fired when the user selects an item from the suggestions list.
// You can access the selected item using args.SelectedItem, which will be of type Achievement.
// For example, you can do something like:
Achievement? selectedAchievement = args.SelectedItem as Achievement;
if (selectedAchievement != null)
{
// Do something with the selected achievement, if needed.
// For example, display more details about the selected achievement.
AchievementsListView.ItemsSource = new List<Achievement>()
{
{
new Achievement
{
Title = selectedAchievement.Title,
Hint = selectedAchievement.Hint,
CompletionDate = selectedAchievement.CompletionDate,
Description = selectedAchievement.Description,
IsSecret = selectedAchievement.IsSecret,
Image = selectedAchievement.Image,
Objective = selectedAchievement.Objective,
Rank = selectedAchievement.Rank,
}
},
};
}
}
}

/* LoadConfig on startup
Expand Down
2 changes: 1 addition & 1 deletion MHFZ_Overlay/Views/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@

</Grid>
<!--https://stackoverflow.com/questions/5450985/how-to-make-overlay-control-above-all-other-controls-->
<ui:SnackbarPresenter Grid.ZIndex="2" x:Name="MainWindowSnackBarPresenter"/>
<ui:SnackbarPresenter Grid.ZIndex="2" x:Name="MainWindowSnackBarPresenter" d:Visibility="Hidden"/>
</Grid>
<Window.InputBindings>
<KeyBinding Key="Esc" Command="{StaticResource ESC}"/>
Expand Down

0 comments on commit 28c9102

Please sign in to comment.