Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new column "Global Progress" percentage per achivement #420

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions SAM.API/Wrappers/SteamUserStats013.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,32 @@ public bool GetAchievementAndUnlockTime(string name, out bool isAchieved, out ui
}
#endregion

#region GetGlobalAchievementPercantage
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private delegate bool NativeRequestGlobalAchievementPercentages(IntPtr self);

public bool RequestGlobalAchievementPercentages()
{
var call = this.GetFunction<NativeRequestGlobalAchievementPercentages>(this.Functions.RequestGlobalAchievementPercentages);
return call(this.ObjectAddress);
}
#endregion

#region GetAchievementAchievedPercent
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private delegate bool NativeGetAchievementAchievedPercent(
IntPtr self,
[MarshalAs(UnmanagedType.LPStr)] string achievementName,
out float percent
);

public bool GetAchievementAchievedPercent(string achievementName, out float percent)
{
var call = this.GetFunction<NativeGetAchievementAchievedPercent>(this.Functions.GetAchievementAchievedPercent);
return call(this.ObjectAddress, achievementName, out percent);
}
#endregion

#region StoreStats
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
[return: MarshalAs(UnmanagedType.I1)]
Expand Down
28 changes: 18 additions & 10 deletions SAM.Game/Manager.Designer.cs

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

22 changes: 17 additions & 5 deletions SAM.Game/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* distribution.
*/

using SAM.API;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -98,6 +99,8 @@ public Manager(long gameId, API.Client client)
base.Text += " | " + this._GameId.ToString(CultureInfo.InvariantCulture);
}

this._SteamClient.SteamUserStats.RequestGlobalAchievementPercentages();

this._UserStatsReceivedCallback = client.CreateAndRegisterCallback<API.Callbacks.UserStatsReceived>();
this._UserStatsReceivedCallback.OnRun += this.OnUserStatsReceived;

Expand Down Expand Up @@ -431,7 +434,7 @@ private void GetAchievements()

bool wantLocked = this._DisplayLockedOnlyButton.Checked == true;
bool wantUnlocked = this._DisplayUnlockedOnlyButton.Checked == true;

foreach (var def in this._AchievementDefinitions)
{
if (string.IsNullOrEmpty(def.Id) == true)
Expand Down Expand Up @@ -459,12 +462,18 @@ private void GetAchievements()

if (textSearch != null)
{
if (def.Name.IndexOf(textSearch, StringComparison.OrdinalIgnoreCase) < 0 ||
def.Description.IndexOf(textSearch, StringComparison.OrdinalIgnoreCase) < 0)
string[] searchTerms = textSearch.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

bool nameMatches = searchTerms.All(term => def.Name.IndexOf(term, StringComparison.OrdinalIgnoreCase) >= 0);
bool descriptionMatches = searchTerms.All(term => def.Description.IndexOf(term, StringComparison.OrdinalIgnoreCase) >= 0);

if (!nameMatches && !descriptionMatches)
Copy link
Author

@vlad-p-929 vlad-p-929 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that it was added here, I've slightly reworked Search to be able to search with spaces, like

image

image

image

I'll revert this one if needed.

{
continue;
}
}
}

_SteamClient.SteamUserStats.GetAchievementAchievedPercent(def.Id, out float percentage);

Stats.AchievementInfo info = new()
{
Expand All @@ -478,6 +487,7 @@ private void GetAchievements()
Permission = def.Permission,
Name = def.Name,
Description = def.Description,
Progress = percentage,
};

ListViewItem item = new()
Expand All @@ -504,6 +514,8 @@ private void GetAchievements()
? info.UnlockTime.Value.ToString()
: "");

item.SubItems.Add((percentage > 0 ? $"{percentage}%" : "Error").ToString());

info.ImageIndex = 0;

this.AddAchievementToIconQueue(info, false);
Expand Down Expand Up @@ -894,4 +906,4 @@ private void OnFilterUpdate(object sender, KeyEventArgs e)
this.GetAchievements();
}
}
}
}
1 change: 1 addition & 0 deletions SAM.Game/Stats/AchievementInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal class AchievementInfo
public string IconLocked;
public string Name;
public string Description;
public float Progress;
public ListViewItem Item;

#region public int ImageIndex;
Expand Down