public FriendControl GetFriendControl( Friend friend ) { foreach ( FriendControl fc in this.Controls ) { if ( fc.Friend.SteamID == friend.SteamID ) return fc; } return null; }
public void SetSteamID( Friend steamid ) { Friend = steamid; nameLbl.Text = steamid.GetName(); statusLbl.Text = steamid.GetStatus(); gameLbl.Text = steamid.GetGameName(); nameLbl.ForeColor = statusLbl.ForeColor = gameLbl.ForeColor = Util.GetStatusColor( steamid ); avatarBox.Image = ComposeAvatar( steamid ); }
public static Color GetStatusColor( Friend steamid ) { Color inGame = Color.FromArgb( 177, 251, 80 ); Color online = Color.FromArgb( 111, 189, 255 ); Color offline = Color.FromArgb( 137, 137, 137 ); if ( steamid.IsInGame() ) return inGame; if ( !steamid.IsOnline() ) return offline; return online; }
List<Friend> GetFriends() { List<Friend> friends = new List<Friend>(); int friendCount = SteamContext.ClientFriends.GetFriendCount( ( int )EFriendFlags.k_EFriendFlagImmediate ); for ( int x = 0 ; x < friendCount ; ++x ) { ulong friendId = SteamContext.ClientFriends.GetFriendByIndex( x, ( int )EFriendFlags.k_EFriendFlagImmediate ); Friend friend = new Friend( friendId ); friends.Add( friend ); } return friends; }
Bitmap GetAvatar( Friend steamid ) { GCHandle imgHandle = new GCHandle(); try { int avatarId = SteamContext.ClientFriends.GetSmallFriendAvatar( steamid.SteamID ); if ( avatarId == 0 ) return Resources.IconUnknown; int width = 32, height = 32; byte[] imgData = new byte[ 4 * width * height ]; if ( !SteamContext.SteamUtils.GetImageRGBA( avatarId, imgData, imgData.Length ) ) return Resources.IconUnknown; // imgData is in RGBA format, .NET expects BGRA // so lets prep the data by swapping R and B for ( int x = 0 ; x < imgData.Length ; x += 4 ) { byte r = imgData[ x ]; byte b = imgData[ x + 2 ]; imgData[ x ] = b; imgData[ x + 2 ] = r; } imgHandle = GCHandle.Alloc( imgData, GCHandleType.Pinned ); return new Bitmap( width, height, 4 * width, PixelFormat.Format32bppArgb, imgHandle.AddrOfPinnedObject() ); } catch { return Resources.IconUnknown; } finally { imgHandle.Free(); } }
Bitmap GetHolder( Friend steamid ) { if ( steamid.IsInGame() ) return Resources.IconIngame; if ( steamid.IsOnline() ) return Resources.IconOnline; return Resources.IconOffline; }
public FriendControl( Friend steamid ) : this() { SetSteamID( steamid ); }
Bitmap ComposeAvatar( Friend steamid ) { Bitmap holder = GetHolder( steamid ); Bitmap avatar = GetAvatar( steamid ); Graphics gfx = null; try { gfx = Graphics.FromImage( holder ); gfx.DrawImage( avatar, new Rectangle( 4, 4, avatar.Width, avatar.Height ) ); } finally { gfx.Dispose(); } return holder; }