Skip to content

Commit

Permalink
refactor: snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Jul 24, 2023
1 parent 009fd52 commit 45b5b49
Show file tree
Hide file tree
Showing 11 changed files with 383 additions and 132 deletions.
111 changes: 64 additions & 47 deletions MHFZ_Overlay/Assets/Themes/CatppuccinMocha.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
// © 2023 The mhfz-overlay developers.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.
Expand Down Expand Up @@ -535,13 +535,13 @@
</Style>-->
<!-- ... Add more styles using the color resources ... -->
<!-- Snackbar-->
<Style TargetType="{x:Type ui:Snackbar}" x:Key="CatppuccinMochaSnackBar">
<Style TargetType="{x:Type ui:Snackbar}" x:Key="CatppuccinMochaSnackBar">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{StaticResource TextFillColorPrimary}" />
<SolidColorBrush Color="{StaticResource TextFillColorSecondary}" />
</Setter.Value>
</Setter>
<Setter Property="MessageForeground">
<Setter Property="ContentForeground">
<Setter.Value>
<SolidColorBrush Color="{StaticResource TextFillColorSecondary}" />
</Setter.Value>
Expand Down Expand Up @@ -599,30 +599,47 @@
Margin="0,0,12,0"
VerticalAlignment="Center"
Content="{TemplateBinding Icon}"
TextElement.FontSize="26"
TextElement.FontSize="32"
TextElement.Foreground="{TemplateBinding Foreground}" />

<StackPanel
Grid.Column="1"
VerticalAlignment="Center"
SnapsToDevicePixels="True">
<TextBlock
x:Name="TitleText"
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<ContentPresenter
x:Name="TitleContentPresenter"
Grid.Row="0"
Margin="0,0,0,4"
VerticalAlignment="Center"
FontWeight="Medium"
Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding Title}"
TextWrapping="Wrap" />
<TextBlock
FontSize="11"
Foreground="{TemplateBinding MessageForeground}"
Text="{TemplateBinding Message}"
TextWrapping="Wrap" />
</StackPanel>

<!-- We assume that Content is presented instead of Title and Message. -->
<ContentPresenter Grid.Column="1" />
Content="{TemplateBinding Title}"
ContentTemplate="{TemplateBinding TitleTemplate}"
TextElement.FontSize="20"
TextElement.FontWeight="SemiBold"
TextElement.Foreground="{TemplateBinding Foreground}">
<ContentPresenter.Resources>
<Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="WrapWithOverflow" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>

<ContentPresenter
Grid.Row="1"
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
TextElement.FontSize="14"
TextElement.FontWeight="Regular"
TextElement.Foreground="{TemplateBinding ContentForeground}">
<ContentPresenter.Resources>
<Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="WrapWithOverflow" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
</Grid>

<ui:Button
x:Name="CloseButton"
Expand All @@ -643,7 +660,7 @@
<Trigger Property="Icon" Value="{x:Null}">
<Setter TargetName="CardIcon" Property="Margin" Value="0" />
</Trigger>
<Trigger Property="CloseButtonEnabled" Value="False">
<Trigger Property="IsCloseButtonEnabled" Value="False">
<Setter TargetName="CloseButton" Property="Visibility" Value="Collapsed" />
<Setter TargetName="CloseButton" Property="Margin" Value="0" />
</Trigger>
Expand Down Expand Up @@ -703,9 +720,9 @@
<SolidColorBrush Color="{StaticResource TextOnAccentFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="MessageForeground">
<Setter Property="ContentForeground">
<Setter.Value>
<SolidColorBrush Color="#313244" />
<SolidColorBrush Color="{StaticResource TextOnAccentFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="Background">
Expand All @@ -720,9 +737,9 @@
<SolidColorBrush Color="{StaticResource TextFillColorLightPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="MessageForeground">
<Setter Property="ContentForeground">
<Setter.Value>
<SolidColorBrush Color="#87cdd6f4" />
<SolidColorBrush Color="{StaticResource TextFillColorLightPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="Background">
Expand All @@ -734,29 +751,29 @@
<Trigger Property="Appearance" Value="Light">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="#E41e1e2e" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="MessageForeground">
<Setter Property="ContentForeground">
<Setter.Value>
<SolidColorBrush Color="#9E1e1e2e" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#cdd6f4" />
<SolidColorBrush Color="{StaticResource TextFillColorLightPrimary}" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Appearance" Value="Info">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="#1e1e2e" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="MessageForeground">
<Setter Property="ContentForeground">
<Setter.Value>
<SolidColorBrush Color="#313244" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="Background">
Expand All @@ -768,12 +785,12 @@
<Trigger Property="Appearance" Value="Danger">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="#1e1e2e" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="MessageForeground">
<Setter Property="ContentForeground">
<Setter.Value>
<SolidColorBrush Color="#313244" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="Background">
Expand All @@ -785,12 +802,12 @@
<Trigger Property="Appearance" Value="Success">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="#1e1e2e" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="MessageForeground">
<Setter Property="ContentForeground">
<Setter.Value>
<SolidColorBrush Color="#313244" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="Background">
Expand All @@ -802,17 +819,17 @@
<Trigger Property="Appearance" Value="Caution">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="#1e1e2e" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="MessageForeground">
<Setter Property="ContentForeground">
<Setter.Value>
<SolidColorBrush Color="#313244" />
<SolidColorBrush Color="#11111b" />
</Setter.Value>
</Setter>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{StaticResource PaletteDeepOrangeColor}" />
<SolidColorBrush Color="{StaticResource PaletteOrangeColor}" />
</Setter.Value>
</Setter>
</Trigger>
Expand Down
2 changes: 1 addition & 1 deletion MHFZ_Overlay/MHFZ_Overlay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="VirtualizingWrapPanel" Version="1.5.7" />
<PackageReference Include="WPF-UI" Version="3.0.0-preview.2" />
<PackageReference Include="WPF-UI" Version="3.0.0-preview.4" />
<PackageReference Include="WpfAnimatedGif" Version="2.0.2" />
<PackageReference Include="XamlAnimatedGif" Version="2.2.0" />
<PackageReference Include="XInputium" Version="1.2.0" />
Expand Down
10 changes: 5 additions & 5 deletions MHFZ_Overlay/Models/Achievement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace MHFZ_Overlay.Models;
using MHFZ_Overlay.Views.Windows;
using Wpf.Ui.Common;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;

/// <summary>
/// The achievements of the player.
Expand All @@ -30,7 +29,7 @@ public async Task Show(Snackbar snackbar)
}

snackbar.Title = this.Title;
snackbar.Message = this.Objective;
snackbar.Content = this.Objective;
snackbar.Icon = new SymbolIcon()
{
Symbol = SymbolRegular.Trophy32,
Expand All @@ -41,12 +40,13 @@ public async Task Show(Snackbar snackbar)
{
MainWindow.MainWindowSoundPlayer.Play();
}

await snackbar.ShowAsync();
snackbar.Timeout = SnackbarTimeOut;
snackbar.Show();
await Task.Delay(TimeSpan.FromSeconds(1)); // Delay for a certain duration
snackbar.Hide(); // Hide the snackbar
}

public TimeSpan SnackbarTimeOut { get; set; } = TimeSpan.FromSeconds(5);

/// <summary>
/// Gets the color for title and icon from rank.
/// </summary>
Expand Down
9 changes: 5 additions & 4 deletions MHFZ_Overlay/Services/AchievementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace MHFZ_Overlay.Services;
using NLog;
using Wpf.Ui.Common;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;

public sealed class AchievementService : IAchievementService
{
Expand Down Expand Up @@ -68,21 +67,23 @@ public static async Task ShowMany(Snackbar snackbar, List<int> achievementsID)
}
}

public static TimeSpan SnackbarTimeOut { get; set; } = TimeSpan.FromSeconds(5);

public static async Task ShowAchievementsTabInfo(Snackbar snackbar, int remainingAchievements)
{
var brushConverter = new BrushConverter();
var brushColor = (Brush?)brushConverter.ConvertFromString(CatppuccinMochaColors.NameHex["Crust"]);
snackbar.Title = "Too many achievements!";
snackbar.Message = $"To see the rest of the achievements unlocked ({remainingAchievements} left), see the Achievements tab in the Quests Logs section.";
snackbar.Content = $"To see the rest of the achievements unlocked ({remainingAchievements} left), see the Achievements tab in the Quests Logs section.";
snackbar.Icon = new SymbolIcon()
{
Symbol = SymbolRegular.Info28,
};
snackbar.Icon.Foreground = brushColor ?? Brushes.Black;
snackbar.Appearance = ControlAppearance.Info;
await snackbar.ShowAsync();
snackbar.Timeout = SnackbarTimeOut;
snackbar.Show();
await Task.Delay(TimeSpan.FromSeconds(1)); // Delay for a certain duration
snackbar.Hide(); // Hide the snackbar
}

public static AchievementService GetInstance()
Expand Down
24 changes: 21 additions & 3 deletions MHFZ_Overlay/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ namespace MHFZ_Overlay.Services;
using Octokit;
using Wpf.Ui.Common;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Formatting = Newtonsoft.Json.Formatting;
using MessageBox = System.Windows.MessageBox;
using MessageBoxButton = System.Windows.MessageBoxButton;
using MessageBoxResult = System.Windows.MessageBoxResult;
using Quest = Models.Quest;

/// <summary>
Expand Down Expand Up @@ -69,6 +71,8 @@ public sealed class DatabaseService

public HashSet<PlayerInventory> AllPlayerInventories { get; set; }

public TimeSpan SnackbarTimeOut { get; set; } = TimeSpan.FromSeconds(5);

private static DatabaseService? instance;

private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
Expand Down Expand Up @@ -10139,7 +10143,14 @@ INNER JOIN
if (!reader.HasRows)
{
var message = string.Format(CultureInfo.InvariantCulture, "Quest ID not found. Please use the Quest ID option in Settings and go into a quest in order to view the ID needed to search. You may also not have completed any runs for the selected Quest ID or for the selected category.\n\nQuest ID: {0}\nOverlay Mode: {1}\n{2}", questID, selectedOverlayMode, reader.ToString());
configWindow.ConfigWindowSnackBar.ShowAsync(Messages.ErrorTitle, message, new SymbolIcon(SymbolRegular.ErrorCircle24), ControlAppearance.Danger);
var snackbar = new Snackbar(configWindow.ConfigWindowSnackBarPresenter);
snackbar.Style = (Style)configWindow.FindResource("CatppuccinMochaSnackBar");
snackbar.Title = Messages.ErrorTitle;
snackbar.Content = message;
snackbar.Icon = new SymbolIcon(SymbolRegular.ErrorCircle24);
snackbar.Appearance = ControlAppearance.Danger;
snackbar.Timeout = SnackbarTimeOut;
snackbar.Show();
return;
}
else
Expand Down Expand Up @@ -10181,7 +10192,14 @@ GROUP BY
if (!reader.HasRows)
{
var message = string.Format(CultureInfo.InvariantCulture, "Quest ID not found. Please use the Quest ID option in Settings and go into a quest in order to view the ID needed to search. You may also not have completed any runs for the selected Quest ID or for the selected category.\n\nQuest ID: {0}\nOverlay Mode: {1}\n{2}", questID, selectedOverlayMode, reader.ToString());
configWindow.ConfigWindowSnackBar.ShowAsync(Messages.ErrorTitle, message, new SymbolIcon(SymbolRegular.ErrorCircle24), ControlAppearance.Danger);
var snackbar = new Snackbar(configWindow.ConfigWindowSnackBarPresenter);
snackbar.Style = (Style)configWindow.FindResource("CatppuccinMochaSnackBar");
snackbar.Title = Messages.ErrorTitle;
snackbar.Content = message;
snackbar.Icon = new SymbolIcon(SymbolRegular.ErrorCircle24);
snackbar.Appearance = ControlAppearance.Danger;
snackbar.Timeout = SnackbarTimeOut;
snackbar.Show();
return;
}

Expand Down
Loading

0 comments on commit 45b5b49

Please sign in to comment.