Skip to content

Commit cdddade

Browse files
committed
Pre-flip steam avatars
1 parent 41fc16c commit cdddade

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Source/Client/Networking/SteamIntegration.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public static class SteamImages
124124
{
125125
public static Dictionary<int, Texture2D> cache = new();
126126

127-
// Remember to flip it
128127
public static Texture2D GetTexture(int id)
129128
{
130129
if (cache.TryGetValue(id, out Texture2D tex))
@@ -147,12 +146,31 @@ public static Texture2D GetTexture(int id)
147146

148147
tex = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false);
149148
tex.LoadRawTextureData(data);
149+
FlipVertically(tex);
150150
tex.Apply();
151151

152152
cache[id] = tex;
153153

154154
return tex;
155155
}
156+
157+
private static void FlipVertically(Texture2D tex)
158+
{
159+
var pixels = tex.GetPixels32();
160+
161+
for (int y = 0; y < tex.height / 2; y++)
162+
{
163+
for (int x = 0; x < tex.width; x++)
164+
{
165+
int top = y * tex.width + x;
166+
int bottom = (tex.height - y - 1) * tex.width + x;
167+
168+
(pixels[top], pixels[bottom]) = (pixels[bottom], pixels[top]);
169+
}
170+
}
171+
172+
tex.SetPixels32(pixels);
173+
}
156174
}
157175

158176
}

Source/Client/Windows/PendingPlayerWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public override void DoWindowContents(Rect inRect)
132132
var avatarRect = new Rect(0, 0, 80, 80).CenteredOnYIn(inRect).Right(4);
133133
InvisibleOpenSteamProfileButton(avatarRect, req.steamId, doMouseoverSound: false);
134134
if (avatarTex != null)
135-
GUI.DrawTextureWithTexCoords(avatarRect, avatarTex, new Rect(0, 1, 1, -1));
135+
GUI.DrawTexture(avatarRect, avatarTex);
136136
inRect.xMin = avatarRect.xMax + 6f;
137137
}
138138
else

Source/Client/Windows/ServerBrowser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ private void DrawSteam(Rect inRect)
457457
Widgets.DrawAltRect(entryRect);
458458

459459
if (Event.current.type == EventType.Repaint)
460-
GUI.DrawTextureWithTexCoords(new Rect(5, entryRect.y + 4, 32, 32), SteamImages.GetTexture(friend.avatar), new Rect(0, 1, 1, -1));
460+
GUI.DrawTexture(new Rect(5, entryRect.y + 4, 32, 32), SteamImages.GetTexture(friend.avatar));
461461

462462
using (MpStyle.Set(TextAnchor.MiddleLeft))
463463
Widgets.Label(entryRect.Right(45).Up(5), friend.username);

0 commit comments

Comments
 (0)