Skip to content

Commit

Permalink
feat: implement snackbars
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Jun 9, 2023
1 parent 184ba1a commit fa87e67
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 19 deletions.
4 changes: 2 additions & 2 deletions MHFZ_Overlay/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,10 @@
<value>False</value>
</setting>
<setting name="MaxResolutionWidth" serializeAs="String">
<value>3840</value>
<value>1360</value>
</setting>
<setting name="MaxResolutionHeight" serializeAs="String">
<value>2160</value>
<value>768</value>
</setting>
<setting name="ActionsPerMinuteShown" serializeAs="String">
<value>True</value>
Expand Down
2 changes: 1 addition & 1 deletion MHFZ_Overlay/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private static void OnAppRun(SemanticVersion version, IAppTools tools, bool firs
The overlay might take some time to start due to databases. The next time you run the program, you may be asked to update the database.
It's also recommended to change the resolution of the overlay if you are using a resolution other than 4K.
It's also recommended to change the resolution of the overlay if you are using a resolution other than the default set.
Happy Hunting!", "MHF-Z Overlay Installation", MessageBoxButton.OK, MessageBoxImage.Information);

Expand Down
13 changes: 11 additions & 2 deletions MHFZ_Overlay/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,14 @@
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" Margin="5">
<TextBlock VerticalAlignment="Center" Text="YouTube ID for the Run ID" Margin="5"/>
<ui:TextBox VerticalContentAlignment="Center" Margin="5" ToolTip="Enter the YouTube video ID for the Run ID entered at the top" Width="150" Height="Auto" IsUndoEnabled="False" TextAlignment="Center" MaxLength="12" Loaded="YoutubeLinkTextBox_Loaded"/>
<ui:Button BorderThickness="0" Foreground="#f38ba8" Background="Transparent" Margin="5" Content="&#xf03d;" ToolTip="Add ID" FontFamily="/FontAwesome.Sharp;component/fonts/#Font Awesome 6 Free Solid" Click="UpdateYoutubeLink_ButtonClick" Loaded="UpdateYoutubeLink_Loaded"/>
<ui:Button BorderThickness="0" Foreground="Red" Background="Transparent" Margin="5" Content="&#xf167;" ToolTip="Open Link in Browser" FontFamily="/FontAwesome.Sharp;component/fonts/#Font Awesome 6 Brands Regular" Click="YoutubeIconButton_Click"/>
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Foreground="{StaticResource Text}" Text="Add ID"/>
<ui:Button BorderThickness="0" Foreground="#f38ba8" Background="Transparent" Margin="5" Content="&#xf03d;" FontFamily="/FontAwesome.Sharp;component/fonts/#Font Awesome 6 Free Solid" Click="UpdateYoutubeLink_ButtonClick" Loaded="UpdateYoutubeLink_Loaded"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5,0,0,0">
<TextBlock VerticalAlignment="Center" Foreground="{StaticResource Text}" Text="Open Link in Browser"/>
<ui:Button BorderThickness="0" Foreground="Red" Background="Transparent" Margin="5" Content="&#xf167;" FontFamily="/FontAwesome.Sharp;component/fonts/#Font Awesome 6 Brands Regular" Click="YoutubeIconButton_Click"/>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
Expand Down Expand Up @@ -736,6 +742,7 @@
<Color x:Key="SystemAccentColorSecondary">#f38ba8</Color>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -3490,4 +3497,6 @@ Thunder Clad, Vigorous" Text="{Binding GetActiveSkillsForImage,Mode=OneTime}" Fo
</TabItem>
</TabControl>
</Grid>
<ui:Snackbar Grid.ZIndex="2" Timeout="10000" x:Name="ConfigWindowSnackBar" Style="{StaticResource CatppuccinMochaSnackBar}"/>
</Grid>
</ui:FluentWindow>
69 changes: 66 additions & 3 deletions MHFZ_Overlay/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
using Wpf.Ui.Controls.Window;
using DataGrid = Wpf.Ui.Controls.DataGrid;
using MHFZ_Overlay.UI.CustomControls;
using Wpf.Ui.Controls.IconElements;
using Wpf.Ui.Common;
using Wpf.Ui.Contracts;
using Wpf.Ui.Services;

namespace MHFZ_Overlay;

Expand Down Expand Up @@ -550,6 +554,12 @@ public ConfigWindow(MainWindow mainWindow)
replaceAllMonsterInfoFeriasLinks();

weaponUsageData = databaseManager.CalculateTotalWeaponUsage(this, MainWindow.DataLoader);

// In your initialization or setup code
ISnackbarService snackbarService = new SnackbarService();
// Replace 'snackbarControl' with your actual snackbar control instance
snackbarService.SetSnackbarControl(ConfigWindowSnackBar);

// Stop the stopwatch
stopwatch.Stop();
// Get the elapsed time in milliseconds
Expand Down Expand Up @@ -1196,7 +1206,7 @@ private void OpenSettingsFolder_Click(object sender, RoutedEventArgs e)
catch (Exception ex)
{
logger.Error(ex);
MessageBox.Show("Could not open settings folder", Messages.ERROR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
ConfigWindowSnackBar.ShowAsync(Messages.ERROR_TITLE, "Could not open settings folder", new SymbolIcon(SymbolRegular.ErrorCircle24), ControlAppearance.Danger);
}
}

Expand Down Expand Up @@ -1440,15 +1450,68 @@ private void weaponUsageChart_Loaded(object sender, RoutedEventArgs e)
private string personalBestSelectedType = string.Empty;
private DataGrid? calendarDataGrid;

// TODO: it works. i need to put this somewhere else
private async void ShowSequentialSnackbars()
{
// Show the first snackbar
await MainWindow.MainWindowSnackBar.ShowAsync("Important message 1", "Message 1", new SymbolIcon(SymbolRegular.Accessibility24), ControlAppearance.Dark);

// Handle completion of the first snackbar
await Task.Delay(TimeSpan.FromSeconds(2)); // Delay for a certain duration
MainWindow.MainWindowSnackBar.Hide(); // Hide the first snackbar

// Show the second snackbar
await MainWindow.MainWindowSnackBar.ShowAsync("Important message 2", "Message 2", new SymbolIcon(SymbolRegular.Accessibility24), ControlAppearance.Light);

// Handle completion of the second snackbar
await Task.Delay(TimeSpan.FromSeconds(2)); // Delay for a certain duration
MainWindow.MainWindowSnackBar.Hide(); // Hide the second snackbar

// Show the third snackbar
await MainWindow.MainWindowSnackBar.ShowAsync("Important message 3", "Message 3", new SymbolIcon(SymbolRegular.Accessibility24), ControlAppearance.Primary);

// Handle completion of the third snackbar
await Task.Delay(TimeSpan.FromSeconds(2)); // Delay for a certain duration
MainWindow.MainWindowSnackBar.Hide(); // Hide the third snackbar

await MainWindow.MainWindowSnackBar.ShowAsync("Important message 4", "Message 3", new SymbolIcon(SymbolRegular.Accessibility24), ControlAppearance.Secondary);
await Task.Delay(TimeSpan.FromSeconds(2));
MainWindow.MainWindowSnackBar.Hide();

await MainWindow.MainWindowSnackBar.ShowAsync("Important message 5", "Message 3", new SymbolIcon(SymbolRegular.Accessibility24), ControlAppearance.Success);
await Task.Delay(TimeSpan.FromSeconds(2));
MainWindow.MainWindowSnackBar.Hide();

await MainWindow.MainWindowSnackBar.ShowAsync("Important message 6", "Message 3", new SymbolIcon(SymbolRegular.Accessibility24), ControlAppearance.Caution);
await Task.Delay(TimeSpan.FromSeconds(2));
MainWindow.MainWindowSnackBar.Hide();

await MainWindow.MainWindowSnackBar.ShowAsync("Important message 7", "Message 3", new SymbolIcon(SymbolRegular.Accessibility24), ControlAppearance.Danger);
await Task.Delay(TimeSpan.FromSeconds(2));
MainWindow.MainWindowSnackBar.Hide();

await MainWindow.MainWindowSnackBar.ShowAsync("Important message 8", "Message 3", new SymbolIcon(SymbolRegular.Accessibility24), ControlAppearance.Transparent);
await Task.Delay(TimeSpan.FromSeconds(2));
MainWindow.MainWindowSnackBar.Hide();

await MainWindow.MainWindowSnackBar.ShowAsync("Important message 9", "Message 3", new SymbolIcon(SymbolRegular.Accessibility24), ControlAppearance.Info);
await Task.Delay(TimeSpan.FromSeconds(2));
MainWindow.MainWindowSnackBar.Hide();
}

private void UpdateYoutubeLink_ButtonClick(object sender, RoutedEventArgs e)
{
// Get the quest ID and new YouTube link from the textboxes
long runID = long.Parse(RunIDTextBox.Text.Trim());
string youtubeLink = youtubeLinkTextBox.Text.Trim();
if (databaseManager.UpdateYoutubeLink(sender, e, runID, youtubeLink))
MessageBox.Show(String.Format("Updated run {0} with link https://youtube.com/watch?v={1}", runID, youtubeLink), "Success", MessageBoxButton.OK, MessageBoxImage.Information);
{
ConfigWindowSnackBar.ShowAsync(Messages.INFO_TITLE, String.Format("Updated run {0} with link https://youtube.com/watch?v={1}", runID, youtubeLink), new SymbolIcon(SymbolRegular.Video32), ControlAppearance.Success);
}
else
MessageBox.Show(String.Format("Could not update run {0} with link https://youtube.com/watch?v={1}. The link may have already been set to the same value, or the run ID and link input are invalid.", runID, youtubeLink), Messages.ERROR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
{
ConfigWindowSnackBar.ShowAsync(Messages.ERROR_TITLE, String.Format("Could not update run {0} with link https://youtube.com/watch?v={1}. The link may have already been set to the same value, or the run ID and link input are invalid.", runID, youtubeLink), new SymbolIcon(SymbolRegular.Video32), ControlAppearance.Danger);
}
}

private void UpdateYoutubeLink_Loaded(object sender, RoutedEventArgs e)
Expand Down
4 changes: 3 additions & 1 deletion MHFZ_Overlay/Core/Class/DataAccessLayer/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4803,7 +4803,9 @@ public bool UpdateYoutubeLink(object sender, RoutedEventArgs e, long runID, stri
}
catch (Exception ex)
{
HandleError(transaction, ex);
//HandleError(transaction, ex);
logger.Error(ex, "Could not update youtube link");
success = false;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion MHFZ_Overlay/DataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public DataLoader()
logger.Debug($"DataLoader ctor Elapsed Time: {elapsedTimeMs} ms");
}

public static bool loadedOutsideMezeporta = false;

private void CheckIfLoadedInMezeporta()
{
if (model.AreaID() != 200)
Expand All @@ -101,7 +103,7 @@ private void CheckIfLoadedInMezeporta()

Settings s = (Settings)System.Windows.Application.Current.TryFindResource("Settings");
if (s.EnableOutsideMezeportaLoadingWarning)
MessageBox.Show("It is not recommended to load the overlay outside of Mezeporta", Messages.WARNING_TITLE, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
loadedOutsideMezeporta = true;
}
}

Expand Down
17 changes: 14 additions & 3 deletions MHFZ_Overlay/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
x:Name="Window"
Title="Monster Hunter Frontier Z Overlay"
Height="{Binding Source={StaticResource Settings},Path=MaxResolutionHeight}"
Width="{Binding Source={StaticResource Settings},Path=MaxResolutionWidth}" Background="Transparent" AllowsTransparency="True" WindowStyle="None"
Width="{Binding Source={StaticResource Settings},Path=MaxResolutionWidth}"
Background="Transparent"
AllowsTransparency="True"
WindowStyle="None"
Loaded="Window_Loaded"
Style="{StaticResource WinAll}"
FontFamily="{StaticResource MesloLGM NF}"
FontFamily="{StaticResource Segoe UI Variable}"
>
<Window.Resources>
<local1:XamlIconToViewBoxConverter x:Key="XamlIconToViewBoxConverter"/>
<!--TODO: Unused Code?-->
<RoutedUICommand x:Key="ESC" Text="Escape"/>
</Window.Resources>
<Grid>
<Grid>
<ui:TitleBar Visibility="Hidden" BorderThickness="0" BorderBrush="{StaticResource Red}" x:Name="TitleBarBorder">
<ui:TitleBar.Tray>
Expand Down Expand Up @@ -724,8 +729,14 @@
<Canvas x:Name="DamageNumbers" Visibility="{Binding Source={StaticResource Settings},Path=EnableDamageNumbers, Converter={StaticResource BoolToVis}}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="{Binding Source={StaticResource Settings},Path=DamageNumbersAreaWidth}" Height="{Binding Source={StaticResource Settings},Path=DamageNumbersAreaHeight}" Canvas.Left="{Binding Source={StaticResource Settings},Path=DamageNumbersX}" Canvas.Top="{Binding Source={StaticResource Settings},Path=DamageNumbersY}"/>
<Border x:Name="DamageNumbersBorder" BorderBrush="{StaticResource Red}" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="{Binding Source={StaticResource Settings},Path=DamageNumbersAreaWidth}" Height="{Binding Source={StaticResource Settings},Path=DamageNumbersAreaHeight}" Canvas.Left="{Binding Source={StaticResource Settings},Path=DamageNumbersX}" Canvas.Top="{Binding Source={StaticResource Settings},Path=DamageNumbersY}"/>

<Button Content="Press ESC to Exit" x:Name="ExitDragAndDrop" Visibility="Hidden" HorizontalAlignment="Left" Foreground="#f5e0dc" Style="{StaticResource DefaultButton}" Click="ExitDragAndDrop_Click" Canvas.Left="850" Canvas.Top="1"/>
<Button Content="Press ESC to Exit" x:Name="ExitDragAndDrop" Visibility="Hidden" HorizontalAlignment="Left" Foreground="#f5e0dc" Style="{StaticResource DefaultButton}" Click="ExitDragAndDrop_Click" Canvas.Left="850" Canvas.Top="1"/>

</Canvas>

</Grid>
<!--https://stackoverflow.com/questions/5450985/how-to-make-overlay-control-above-all-other-controls-->
<ui:Snackbar Grid.ZIndex="2" Timeout="10000" x:Name="MainWindowSnackBar" Style="{StaticResource CatppuccinMochaSnackBar}"/>

</Grid>
<Window.InputBindings>
<KeyBinding Key="Esc" Command="{StaticResource ESC}"/>
Expand Down
14 changes: 14 additions & 0 deletions MHFZ_Overlay/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
using System.Windows.Media.Imaging;
using MHFZ_Overlay.Core.Constant;
using Wpf.Ui.Controls.TitleBarControl;
using Wpf.Ui.Contracts;
using Wpf.Ui.Services;
using System.Windows.Documents;
using Wpf.Ui.Controls.IconElements;

namespace MHFZ_Overlay;

Expand Down Expand Up @@ -328,6 +332,11 @@ public MainWindow()

logger.Info("Loaded MHF-Z Overlay {0}", App.CurrentProgramVersion);

// In your initialization or setup code
ISnackbarService snackbarService = new SnackbarService();
// Replace 'snackbarControl' with your actual snackbar control instance
snackbarService.SetSnackbarControl(MainWindowSnackBar);

splashScreen.Close(TimeSpan.FromSeconds(0.1));
// Stop the stopwatch
stopwatch.Stop();
Expand Down Expand Up @@ -1926,6 +1935,11 @@ private void MapPlayerInputImages()

#endregion

private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (DataLoader.loadedOutsideMezeporta)
MainWindowSnackBar.ShowAsync(Messages.WARNING_TITLE, "It is not recommended to load the overlay outside of Mezeporta", new SymbolIcon(SymbolRegular.Warning28), ControlAppearance.Caution);
}
}
/// <TODO>
/// [] Not Done
Expand Down
4 changes: 2 additions & 2 deletions MHFZ_Overlay/Settings.Designer.cs

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

4 changes: 2 additions & 2 deletions MHFZ_Overlay/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,10 @@
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="MaxResolutionWidth" Type="System.Int32" Scope="User">
<Value Profile="(Default)">3840</Value>
<Value Profile="(Default)">1360</Value>
</Setting>
<Setting Name="MaxResolutionHeight" Type="System.String" Scope="User">
<Value Profile="(Default)">2160</Value>
<Value Profile="(Default)">768</Value>
</Setting>
<Setting Name="ActionsPerMinuteShown" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
Expand Down
88 changes: 88 additions & 0 deletions MHFZ_Overlay/UI/Class/Achievement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wpf.Ui.Common;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;

namespace MHFZ_Overlay.UI.Class;

/// <summary>
/// TODO: add GHC carve sound when obtaining and displaying snackbar
/// </summary>
public class Achievement
{
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
public string Title { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the description of the snackbar.
/// </summary>
/// <value>
/// The description.
/// </value>
public string Description { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the snackbar icon.
/// </summary>
/// <value>
/// The icon.
/// </value>
public IconElement Icon { get; set; } = new SymbolIcon(SymbolRegular.Fluent24);
/// <summary>
/// Gets or sets the appearance.
/// </summary>
/// <value>
/// The appearance.
/// </value>
public ControlAppearance Appearance { get; set; } = ControlAppearance.Secondary;
/// <summary>
/// Gets or sets the completion date.
/// </summary>
/// <value>
/// The completion date.
/// </value>
public DateTime CompletionDate { get; set; } = DateTime.MinValue;
/// <summary>
/// Gets or sets the objective description to obtain this achievement.
/// </summary>
/// <value>
/// The objective.
/// </value>
public string Objective { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the image of the achievement when displayed.
/// </summary>
/// <value>
/// The image.
/// </value>
public string Image { get; set; } = string.Empty;
/// <summary>
/// Gets or sets a value indicating whether this instance is secret. If it is secret, it shows everything as ?, otherwise it shows the Objective and everything else but grayed out.
/// </summary>
/// <value>
/// <c>true</c> if this instance is secret; otherwise, <c>false</c>.
/// </value>
public bool IsSecret { get; set; } = false;
/// <summary>
/// Gets or sets the hint, which replaces the Objective if the achievement is secret.
/// </summary>
/// <value>
/// The hint.
/// </value>
public string Hint { get; set; } = string.Empty;
/// <summary>
/// Gets or sets a value indicating whether this instance is unlocked.
/// </summary>
/// <value>
/// <c>true</c> if this instance is unlocked; otherwise, <c>false</c>.
/// </value>
public bool IsUnlocked { get; set; } = false;
// Additional properties or methods related to achievements can be added here
}
Loading

0 comments on commit fa87e67

Please sign in to comment.