Skip to content

Commit

Permalink
feat: add achievements tracking option
Browse files Browse the repository at this point in the history
closes #338
  • Loading branch information
DorielRivalet committed Jun 12, 2024
1 parent 88af1fc commit 79e1d73
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 7 deletions.
3 changes: 3 additions & 0 deletions MHFZ_Overlay/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,9 @@
<setting name="FrontierServerOption" serializeAs="String">
<value>Local</value>
</setting>
<setting name="EnableAchievementsTracking" serializeAs="String">
<value>True</value>
</setting>
</MHFZ_Overlay.Settings>
</userSettings>
</configuration>
4 changes: 2 additions & 2 deletions MHFZ_Overlay/DataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public DataLoader()

// first we check if there are duplicate mhf.exe
this.CheckForExternalProcesses();
this.CheckForIllegalModifications(this);
this.CheckForIllegalModifications();

// if there aren't then this runs and sets the game folder and also the database folder if needed
GetMHFFolderLocation();
Expand Down Expand Up @@ -341,7 +341,7 @@ public void CheckForExternalProcesses()

// This checks for illegal folders or files in the game folder
// TODO: test
public void CheckForIllegalModifications(DataLoader? dataLoader)
public void CheckForIllegalModifications(DataLoader? dataLoader = null)
{
if (Program.IsVelopackUpdating)
{
Expand Down
13 changes: 13 additions & 0 deletions MHFZ_Overlay/Services/AchievementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace MHFZ_Overlay.Services;
using System.Windows;
using System.Windows.Media;
using EZlion.Mapper;
using FontAwesome.Sharp;
using MHFZ_Overlay;
using MHFZ_Overlay.Models;
using MHFZ_Overlay.Models.Collections;
Expand Down Expand Up @@ -144,6 +145,11 @@ public void LoadPlayerAchievements()
/// <inheritdoc/>
public void CheckForAchievements(SnackbarPresenter snackbarPresenter, DataLoader dataLoader, DatabaseService databaseManagerInstance, Settings s, Style style)
{
if (!s.EnableAchievementsTracking)
{
return;
}

var newAchievements = this.GetNewlyObtainedAchievements(dataLoader, databaseManagerInstance, s);

if (newAchievements.Count > 0)
Expand All @@ -161,6 +167,13 @@ public void CheckForAchievements(SnackbarPresenter snackbarPresenter, DataLoader
/// <inheritdoc/>
public void RewardAchievement(int achievementID, Snackbar snackbar, Style style)
{
var s = (Settings)Application.Current.TryFindResource("Settings");

if (!s.EnableAchievementsTracking)
{
return;
}

Achievements.IDAchievement.TryGetValue(achievementID, out var achievement);
if (achievement == null)
{
Expand Down
14 changes: 14 additions & 0 deletions MHFZ_Overlay/Services/Contracts/IAchievementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ public interface IAchievementService
{
void LoadPlayerAchievements();

/// <summary>
/// Rewards mutliple achievements.
/// </summary>
/// <param name="snackbarPresenter"></param>
/// <param name="dataLoader"></param>
/// <param name="databaseManagerInstance"></param>
/// <param name="s"></param>
/// <param name="style"></param>
void CheckForAchievements(SnackbarPresenter snackbarPresenter, DataLoader dataLoader, DatabaseService databaseManagerInstance, Settings s, Style style);

/// <summary>
/// Rewards a single achievement.
/// </summary>
/// <param name="achievementID"></param>
/// <param name="snackbar"></param>
/// <param name="style"></param>
void RewardAchievement(int achievementID, Snackbar snackbar, Style style);
}
2 changes: 1 addition & 1 deletion MHFZ_Overlay/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16821,7 +16821,7 @@ private void CheckDatabaseVersion(SQLiteConnection connection, DataLoader dataLo
var currentUserVersion = this.GetUserVersion(connection);

// this will always run the next time the user runs the program after a fresh install. So it always runs at least once.
if (true == true || Program.IsVelopackUpdating == false && ((Program.CurrentProgramVersion != null && Program.CurrentProgramVersion.Trim() != previousVersion.Trim()) || currentUserVersion == 0))
if (Program.IsVelopackUpdating == false && ((Program.CurrentProgramVersion != null && Program.CurrentProgramVersion.Trim() != previousVersion.Trim()) || currentUserVersion == 0))
{
Logger.Info(CultureInfo.InvariantCulture, "Found different program version or userVersion 0. Current: {0}, Previous: {1}, userVersion: {2}", Program.CurrentProgramVersion, previousVersion, currentUserVersion);

Expand Down
12 changes: 12 additions & 0 deletions MHFZ_Overlay/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions MHFZ_Overlay/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -1034,5 +1034,8 @@
<Setting Name="FrontierServerOption" Type="System.String" Scope="User">
<Value Profile="(Default)">Local</Value>
</Setting>
<Setting Name="EnableAchievementsTracking" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
6 changes: 5 additions & 1 deletion MHFZ_Overlay/Views/Windows/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,9 @@
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<RowDefinition Height="40"/>

</Grid.RowDefinitions>
<TextBlock Margin="5" ToolTip="{Binding Source={StaticResource Settings}, Path=GameFolderPath}" Style="{StaticResource ConfigTextBox}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" Grid.ColumnSpan="2" Text="Hover to view game folder path (automatically set by checking the folder location of the current mhf.exe at overlay startup)"/>
<TextBlock Margin="5" ToolTip="{Binding Source={StaticResource Settings}, Path=DatabaseFilePath}" Style="{StaticResource ConfigTextBox}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Text="Hover to view database file path"/>
<StackPanel Margin="5" Orientation="Horizontal" Grid.Row="2" Grid.Column="0" >
Expand Down Expand Up @@ -1672,6 +1674,8 @@
<TextBlock Margin="5" Style="{StaticResource ConfigTextBox}" Grid.Row="21" Grid.Column="0" Text="Quest Completions Counter" ToolTip="Show quest completions next to the attempts"/>
<ui:ToggleSwitch HorizontalAlignment="Center" Grid.Row="21" Grid.Column="1" IsChecked="{Binding Source={StaticResource Settings}, Path=EnableQuestCompletionsCounter}"/>
<!--TODO: speedrun mode in overlay takes into account these settings + other things-->
<TextBlock Margin="5" Grid.Row="22" Grid.Column="0" Style="{StaticResource ConfigTextBox}" Text="Achievements Tracking" ToolTip="If disabled, you won't be able to obtain achievements" />
<ui:ToggleSwitch HorizontalAlignment="Center" Grid.Row="22" Grid.Column="1" IsChecked="{Binding Source={StaticResource Settings}, Path=EnableAchievementsTracking}"/>
</Grid>
</ScrollViewer>
<customcontrols:MainConfigurationActions Grid.Row="1" Grid.ColumnSpan="1" Loaded="MainConfigurationActions_Loaded" Unloaded="MainConfigurationActions_Unloaded"/>
Expand Down
6 changes: 3 additions & 3 deletions MHFZ_Overlay/Views/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public MainWindow()
this.HideMonsterInfoWhenNotInQuest();
this.HidePlayerInfoWhenNotInQuest();
this.DataLoader.CheckForExternalProcesses();
this.DataLoader.CheckForIllegalModifications();
this.DataLoader.CheckForIllegalModifications(this.DataLoader);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -655,7 +655,7 @@ private void Timer10Seconds_Tick(object? obj, EventArgs e)
try
{
this.DataLoader.CheckForExternalProcesses();
this.DataLoader.CheckForIllegalModifications();
this.DataLoader.CheckForIllegalModifications(this.DataLoader);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1657,7 +1657,7 @@ private void OpenConfigButton_Key()
try
{
this.DataLoader.CheckForExternalProcesses();
this.DataLoader.CheckForIllegalModifications();
this.DataLoader.CheckForIllegalModifications(this.DataLoader);
}
catch (Exception ex)
{
Expand Down

0 comments on commit 79e1d73

Please sign in to comment.