profile images
authorhgn <hgodden00@gmail.com>
Thu, 1 May 2025 18:20:09 +0000 (19:20 +0100)
committerhgn <hgodden00@gmail.com>
Thu, 1 May 2025 18:20:09 +0000 (19:20 +0100)
content_skaterift/textures/no_avatar.qoi [new file with mode: 0644]
src/board_maker.c
src/compass.c
src/menu.c
src/user_profile.c
src/workshop.c
src/world_map.c

diff --git a/content_skaterift/textures/no_avatar.qoi b/content_skaterift/textures/no_avatar.qoi
new file mode 100644 (file)
index 0000000..7b56daf
Binary files /dev/null and b/content_skaterift/textures/no_avatar.qoi differ
index 40ac2a36d58cd2eaffd2d308464ee63d43b8d0dd..4de30173d0be9d4cb70f83b78c598a4fdeed9848 100644 (file)
@@ -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 )
index b78062565e206a421a06bbb6c289aae7279c5909..74a4c9a254ab6b327fb04e57c685282109b22190 100644 (file)
@@ -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;
 }
index 0c39c1eb10915b2166b97040d4451f8e289bd753..6c3dff89eb3a2b3598ecffad74bdb159ffc8c44f 100644 (file)
@@ -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 );
index 36e258601da20a93475c2acd55a73dcf8adc7d51..79f1801c0d068a92a26acf3b2ac23c2d86b79134 100644 (file)
@@ -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;
index 89d86c08d06b55c185c981ec021b0d6c89f75c29..0ac1927adf6976b47ba7fdf83ad5c993afcc4955 100644 (file)
@@ -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 );
index 6c1120d3f49398dcc7528d29beeac4a852ce3076..05b5b42e7f567bf20c7de0b97445c52a6bc04181 100644 (file)
@@ -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 );