From: hgn Date: Thu, 1 May 2025 18:20:09 +0000 (+0100) Subject: profile images X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=6caf4ec80a4b1bcc22a741fe9b8ad01d6c2e1ad1;p=carveJwlIkooP6JGAAIwe30JlM.git profile images --- diff --git a/content_skaterift/textures/no_avatar.qoi b/content_skaterift/textures/no_avatar.qoi new file mode 100644 index 0000000..7b56daf Binary files /dev/null and b/content_skaterift/textures/no_avatar.qoi differ diff --git a/src/board_maker.c b/src/board_maker.c index 40ac2a3..4de3017 100644 --- a/src/board_maker.c +++ b/src/board_maker.c @@ -881,7 +881,7 @@ void _board_maker_ui( ui_context *ctx ) } ui_rect box = { vg.window_x-(400+8),8, 400,400 }; - ui_image( ctx, box, &_board_maker.compositor_fb.attachments[0].id ); + ui_image( ctx, box, &_board_maker.compositor_fb.attachments[0].id, 0 ); ui_outline( ctx, box, 1, ui_colour( ctx, k_ui_fg ), 0 ); if( quit_me ) diff --git a/src/compass.c b/src/compass.c index b780625..74a4c9a 100644 --- a/src/compass.c +++ b/src/compass.c @@ -166,6 +166,6 @@ void compass_render_imgui( ui_context *ctx ) ui_rect_center( (ui_rect){0,0,vg.window_x,100}, rect ); ui_flush( ctx, k_ui_shader_colour, NULL ); vg_ui.colour[3] = _compass.alpha; - ui_image( ctx, rect, &g_render.fb_compass->attachments[0].id ); + ui_image( ctx, rect, &g_render.fb_compass->attachments[0].id, 0 ); vg_ui.colour[3] = 1.0f; } diff --git a/src/menu.c b/src/menu.c index 0c39c1e..6c3dff8 100644 --- a/src/menu.c +++ b/src/menu.c @@ -716,7 +716,7 @@ void menu_gui( ui_context *ctx ) ui_rect img; ui_split( panel, k_ui_axis_h, 456, 0, img, panel ); - ui_image( ctx, img, &menu.prem_tex ); + ui_image( ctx, img, &menu.prem_tex, 0 ); ui_rect end = { panel[0], panel[1] + panel[3] - 48, panel[2], 48 }, a,b; ui_split_ratio( end, k_ui_axis_v, 0.5f, 2, a, b ); diff --git a/src/user_profile.c b/src/user_profile.c index 36e2586..79f1801 100644 --- a/src/user_profile.c +++ b/src/user_profile.c @@ -28,7 +28,8 @@ struct 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} }; @@ -45,6 +46,8 @@ void _user_profile_init(void) 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 ) @@ -93,12 +96,14 @@ void _user_profile_ui( ui_context *ctx, ui_rect box, u64 steamid ) { _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; @@ -111,7 +116,48 @@ void _user_profile_ui( ui_context *ctx, ui_rect box, u64 steamid ) 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 ) ); @@ -131,7 +177,7 @@ void _user_profile_ui( ui_context *ctx, ui_rect box, u64 steamid ) 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; @@ -146,12 +192,12 @@ void _user_profile_ui( ui_context *ctx, ui_rect box, u64 steamid ) 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; @@ -161,7 +207,8 @@ void _user_profile_ui( ui_context *ctx, ui_rect box, u64 steamid ) 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; diff --git a/src/workshop.c b/src/workshop.c index 89d86c0..0ac1927 100644 --- a/src/workshop.c +++ b/src/workshop.c @@ -1100,18 +1100,14 @@ static void workshop_form_gui_draw_preview( ui_context *ctx, ui_rect img_box ) enum addon_type type = workshop_form.submission.type; if( workshop_form.file_intent == k_workshop_form_file_intent_keep_old ) { - ui_image( ctx, - img_box, &g_render.fb_workshop_preview->attachments[0].id ); + ui_image( ctx, img_box, &g_render.fb_workshop_preview->attachments[0].id, 0 ); } else if( workshop_form.file_intent == k_workshop_form_file_intent_new ) { - ui_image( ctx, - img_box, &g_render.fb_workshop_preview->attachments[0].id ); + ui_image( ctx, img_box, &g_render.fb_workshop_preview->attachments[0].id, 0 ); if( type == k_addon_type_world ) - { return; - } int hover = ui_inside_rect( img_box, ctx->mouse ), target = ui_inside_rect( img_box, ctx->mouse_click ); diff --git a/src/world_map.c b/src/world_map.c index 6c1120d..05b5b42 100644 --- a/src/world_map.c +++ b/src/world_map.c @@ -857,7 +857,7 @@ void world_map_gui( ui_context *ctx, ui_rect main_area, i32 mh, i32 mv, bool *al planet_box[0] += 4; planet_box[2] = WORKSHOP_PREVIEW_WIDTH; planet_box[3] = WORKSHOP_PREVIEW_HEIGHT; - ui_image( ctx, planet_box, &g_render.fb_workshop_preview->attachments[0].id ); + ui_image( ctx, planet_box, &g_render.fb_workshop_preview->attachments[0].id, 0 ); ui_rect planet_box_title; ui_split( planet_box, k_ui_axis_h, 28, 0, planet_box_title, planet_box );