From 9657f3b32e16df59e873cb36beaa3bae806db4c1 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Tue, 9 May 2017 20:41:16 +0100 Subject: [PATCH] Icon loading --- .../Client/Achievements.cs | 6 ++++ Facepunch.Steamworks/Client/Achievements.cs | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Facepunch.Steamworks.Test/Client/Achievements.cs b/Facepunch.Steamworks.Test/Client/Achievements.cs index f4d4912..79dbf3c 100644 --- a/Facepunch.Steamworks.Test/Client/Achievements.cs +++ b/Facepunch.Steamworks.Test/Client/Achievements.cs @@ -57,6 +57,12 @@ namespace Facepunch.Steamworks.Test Console.WriteLine( " - - " + ach.State ); Console.WriteLine( " - - " + ach.UnlockTime ); Console.WriteLine( " - - " + ach.Percentage ); + + if ( ach.Icon != null ) + { + Console.WriteLine( " - - " + ach.Icon.Width + " x " + ach.Icon.Height ); + } + Console.WriteLine( "" ); } } diff --git a/Facepunch.Steamworks/Client/Achievements.cs b/Facepunch.Steamworks/Client/Achievements.cs index 34c3246..7e4137d 100644 --- a/Facepunch.Steamworks/Client/Achievements.cs +++ b/Facepunch.Steamworks/Client/Achievements.cs @@ -87,6 +87,8 @@ namespace Facepunch.Steamworks /// public DateTime UnlockTime { get; private set; } + private int iconId { get; set; } = -1; + /// /// If this achievement is linked to a stat this will return the progress. /// @@ -106,6 +108,30 @@ namespace Facepunch.Steamworks } } + private Image _icon; + + public Image Icon + { + get + { + if ( iconId <= 0 ) return null; + + if ( _icon == null ) + { + _icon = new Image(); + _icon.Id = iconId; + } + + if ( _icon.IsLoaded ) + return _icon; + + if ( !_icon.TryLoad( client.native.utils ) ) + return null; + + return _icon; + } + } + public Achievement( Client client, int index ) { this.client = client; @@ -114,6 +140,8 @@ namespace Facepunch.Steamworks Name = client.native.userstats.GetAchievementDisplayAttribute( Id, "name" ); Description = client.native.userstats.GetAchievementDisplayAttribute( Id, "desc" ); + iconId = client.native.userstats.GetAchievementIcon( Id ); + Refresh(); }