v2f country_coords;
- GLuint cc_tex, map_tex, icon_tex;
+ bool has_avatar;
+ GLuint cc_tex, map_tex, icon_tex, no_avatar_tex, avatar_tex;
}
_user_profile = { .country_coords = {0.5f, 0.5f} };
vg_tex2d_load_qoi_async_file( "textures/cc.qoi", VG_TEX2D_CLAMP, &_user_profile.cc_tex );
vg_tex2d_load_qoi_async_file( "textures/world_map.qoi", VG_TEX2D_CLAMP, &_user_profile.map_tex );
vg_tex2d_load_qoi_async_file( "textures/menu_icons.qoi", VG_TEX2D_CLAMP, &_user_profile.icon_tex );
+ vg_tex2d_load_qoi_async_file( "textures/no_avatar.qoi", VG_TEX2D_CLAMP, &_user_profile.no_avatar_tex );
+ vg_tex2d_load_qoi_async_file( "textures/no_avatar.qoi", VG_TEX2D_CLAMP, &_user_profile.avatar_tex );
}
static void _profile_download_callback( void *data, u32 data_size, u64 userdata, enum request_status status )
{
_user_profile.timer -= vg.time_frame_delta;
+ bool waiting = 0;
+
if( (steamid != _user_profile.current_steamid) || (_user_profile.state == k_user_profile_state_none) )
{
if( _user_profile.timer < 0.0f )
{
_user_profile.state = k_user_profile_state_downloading;
-
+ _user_profile.has_avatar = 0;
_user_profile.current_steamid = steamid;
_user_profile.timer = 1.0f;
vg_msg_wkvstr( &data, "endpoint", "profile" );
vg_msg_wkvnum( &data, "steamid", k_vg_msg_u64, 1, &steamid );
network_send_request( packet, &data, _profile_download_callback, steamid );
+
+ u64 me_id = SteamAPI_ISteamUser_GetSteamID( SteamAPI_SteamUser() );
+ bool isme = 0;
+ if( (steamid == 0) || (steamid == me_id) )
+ {
+ steamid = me_id;
+ isme = 1;
+ }
+
+ ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
+ ISteamUtils *hSteamUtils = SteamAPI_SteamUtils();
+ if( isme || SteamAPI_ISteamFriends_HasFriend( hSteamFriends, steamid, k_EFriendFlagImmediate ) )
+ {
+ i32 avatar_handle = SteamAPI_ISteamFriends_GetMediumFriendAvatar( hSteamFriends, steamid );
+ if( avatar_handle )
+ {
+ u32 w, h;
+ if( SteamAPI_ISteamUtils_GetImageSize( hSteamUtils, avatar_handle, &w, &h ) )
+ {
+ if( w == 64 && h == 64 )
+ {
+ u8 *tmp = malloc( w*h*4 );
+
+ if( SteamAPI_ISteamUtils_GetImageRGBA( hSteamUtils, avatar_handle, tmp, w*h*4 ) )
+ {
+ glBindTexture( GL_TEXTURE_2D, _user_profile.avatar_tex );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp );
+ _user_profile.has_avatar = 1;
+ }
+ else vg_warn( "GetImageRGBA failed\n" );
+
+ free(tmp);
+ }
+ else vg_warn( "Image wrong size\n" );
+ }
+ else vg_warn( "GetImageSize failed\n" );
+ }
+ else vg_warn( "Avatar handle is 0\n" );
+ }
}
+ else
+ waiting = 1;
}
ui_fill( ctx, box, ui_opacity( GUI_COL_DARK, 0.36f ) );
inner[1] += p;
inner[3] -= p*2;
- if( _user_profile.state != k_user_profile_state_open )
+ if( waiting || (_user_profile.state != k_user_profile_state_open) )
{
bool download = _user_profile.state == k_user_profile_state_downloading;
ctx->font = &vgf_default_title;
ui_rect flag = {0,0, pfpw-p, ((pfpw-p)*2)/3 };
ui_rect_center( flagbox, flag );
+ vg_ui.frosting = 0.015f;
+ ui_flush( ctx, k_ui_shader_colour, NULL );
+ vg_ui.frosting = 0.0f;
+
if( _user_profile.country_index )
{
- vg_ui.frosting = 0.015f;
- ui_flush( ctx, k_ui_shader_colour, NULL );
- vg_ui.frosting = 0.0f;
-
u32 i = _user_profile.country_index-1,
x = (i & 0xf)*16,
y = ((i>>4) & 0xf)*16;
ui_flush( ctx, k_ui_shader_image, &inf );
}
- ui_fill( ctx, pfp, ui_colour( ctx, k_ui_blue ) );
+ ui_image( ctx, pfp, _user_profile.has_avatar? &_user_profile.avatar_tex: &_user_profile.no_avatar_tex, 1 );
+ ui_outline( ctx, pfp, 1, ui_colour( ctx, k_ui_fg ), 0 );
ui_rect a2 = { inner[0] + pfpw + p, inner[1], inner[2] - (pfpw+p), inner[3] };
ui_rect title_box;