Skip to content

Commit

Permalink
Fetch: Fixed refreshing of avatar icons (#1600)
Browse files Browse the repository at this point in the history
Avatar icons are now being refreshed.

It works like this:
If you don't have any icons saved then new ones will be created, cached
and used.
Otherwise the already existing icons will be deleted, then they will be
created, cached and used.

So if the player changes his avatar icon the already existing ones will
be replaced with the new one.

Tested it on v0.14 and it seemed to work.
(The part with the "exists" is not needed anymore because they are
always cached or they don't exit.)
  • Loading branch information
mexikoedi authored Sep 13, 2024
1 parent 88e6458 commit a3057d3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Added role derandomization options for perceptually fairer role distribution, enabled by default (by @nike4613)
- Added targetID to buttons (by @TimGoll)
- Added force role admin command (by @mexikoedi)
- Added `draw.RefreshAvatars(id64)` to refresh avatar icons (by @mexikoedi)

### Changed

Expand Down Expand Up @@ -110,6 +111,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Fixed markerVision elements being visible to team mates of unknown teams (such as team Innocent) (by @TimGoll)
- Fixed inverted settings being inverted twice in the equipment editor (by @TimGoll)
- Fixed OldTTT HUD sidebar elements missing translation (by @TimGoll)
- Fixed avatar icons not refreshing if they were changed on Steam (by @mexikoedi)

### Removed

Expand Down
16 changes: 0 additions & 16 deletions gamemodes/terrortown/gamemode/client/cl_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,6 @@ function GM:InitPostEntity()
self:ClearClientState()
end

-- cache players avatar
local plys = playerGetAll()
for i = 1, #plys do
local plyid64 = plys[i]:SteamID64()

-- caching
draw.CacheAvatar(plyid64, "small")
draw.CacheAvatar(plyid64, "medium")
draw.CacheAvatar(plyid64, "large")
end

timer.Create("cache_ents", 1, 0, function()
self:DoCacheEnts()
end)
Expand Down Expand Up @@ -963,11 +952,6 @@ net.Receive("TTT2PlayerAuthedShared", function(len)
steamid64 = nil
end

-- cache avatars
draw.CacheAvatar(steamid64, "small")
draw.CacheAvatar(steamid64, "medium")
draw.CacheAvatar(steamid64, "large")

---
-- @realm shared
-- stylua: ignore
Expand Down
16 changes: 16 additions & 0 deletions gamemodes/terrortown/gamemode/client/cl_player_ext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ local function UpdateEquipment()
end
net.Receive("TTT_Equipment", UpdateEquipment)

-- Deletes old avatars and caches new ones
local function CacheAllPlayerAvatars(ply)
local plys = IsPlayer(ply) and { ply } or player.GetAll()

for i = 1, #plys do
local plyid64 = plys[i]:SteamID64()
draw.RefreshAvatars(plyid64)
end
end

---
-- SetupMove is called before the engine process movements. This allows us
-- to override the players movement.
Expand Down Expand Up @@ -279,6 +289,9 @@ function GM:SetupMove(ply, mv, cmd)
-- stylua: ignore
hook.Run("OnScreenSizeChanged", oldScrW, oldScrH)
end

-- Cache avatars for all players currently on the server
CacheAllPlayerAvatars(ply)
end

net.Receive("TTT2NotifyPlayerReadyOnClients", function()
Expand All @@ -294,6 +307,9 @@ net.Receive("TTT2NotifyPlayerReadyOnClients", function()
-- @realm shared
-- stylua: ignore
hook.Run("TTT2PlayerReady", ply)

-- Cache avatar of the new player
CacheAllPlayerAvatars(ply)
end)

---
Expand Down
19 changes: 13 additions & 6 deletions lua/autorun/client/b-draw_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ local function CreateAvatarMaterial(id64, size)
return mats[renderTargetName]
end

if exists(filePath, "DATA") then
mats[renderTargetName] = Material("data/" .. filePath)

return mats[renderTargetName]
end

---
-- @realm client
-- stylua: ignore
Expand Down Expand Up @@ -149,6 +143,19 @@ local function CreateAvatarMaterial(id64, size)
return material
end

---
-- Refreshes the avatar images by deleting old cached images and generating new ones
-- @param string id64 The steamid64 of the player
-- @realm client
function draw.RefreshAvatars(id64)
draw.DropCacheAvatar(id64, "small")
draw.DropCacheAvatar(id64, "medium")
draw.DropCacheAvatar(id64, "large")
draw.CacheAvatar(id64, "small")
draw.CacheAvatar(id64, "medium")
draw.CacheAvatar(id64, "large")
end

---
-- Creates the avatar material for a steamid64
-- When an avatar is found it will be cached
Expand Down

0 comments on commit a3057d3

Please sign in to comment.