Skip to content

Commit

Permalink
Scoreboard: Fixed Icons sometimes missing (#1382)
Browse files Browse the repository at this point in the history
This PR fixes the scoreboard being stuck open after an icon is missing.
This PR does this in two levels

- adding a safety check to make sure the scoreboard never stays stuck
- fixing the root cause that causes the breakage in the first place

## The problem

Some entities register custom projectiles (like the boomerang) that are
then registered as the inflictor. This breaks our current UI as I
expected that the weapon is always a real TTT weapon. The change in this
PR searches for an entity with the given name class, if no weapon was
found.


![image](https://github.com/TTT-2/TTT2/assets/13639408/f9944de7-8995-44eb-9df8-592fffe236ba)

![image](https://github.com/TTT-2/TTT2/assets/13639408/0ac19610-d5b3-4b27-b27e-5bcae8a14c32)

I'm pretty sure that it fixes the two linked issues.

---------

Co-authored-by: ZenBre4ker <[email protected]>
  • Loading branch information
TimGoll and ZenBre4ker authored Feb 10, 2024
1 parent 60ae11f commit 55e3703
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Fixed `GM:TTTBodySearchPopulate` using the wrong data variable (by @TimGoll)
- Fixed font initialization to not trip engine font fallback behavior (by @EntranceJew)
- Fixed the decoy producing a wrong colored icon for other teams (by @NickCloudAT)
- Fixed the scoreboard being stuck open sometimes if the inflictor was no weapon (by @TimGoll)
- Fixed door health displaying as a humongous string of decimals

### Removed
Expand Down
50 changes: 44 additions & 6 deletions lua/ttt2/libraries/bodysearch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ CORPSE_KILL_DIRECTION_SIDE = 3
-- stylua: ignore
local cvInspectConfirmMode = CreateConVar("ttt2_inspect_confirm_mode", "0", {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED})

local materialWeaponFallback = Material("vgui/ttt/missing_equip_icon")

bodysearch = {}

---
Expand Down Expand Up @@ -819,7 +821,25 @@ if CLIENT then

local function TypeToMaterial(type, data)
if type == "wep" then
return util.WeaponForClass(data.wep).iconMaterial
local wep = util.WeaponForClass(data.wep)

-- in most cases the inflictor is a weapon and the weapon has a cached
-- material that can be used
if wep.iconMaterial then
return wep.iconMaterial

-- sometimes the projectile is a custom entity that kills the player
-- which means it is not a weapon with a cached material
else
local mat = Material(wep.Icon)

if not mat:IsError() then
return mat
end

-- as a fallback use this missing texture icon
return materialWeaponFallback
end
elseif type == "dmg" then
return DamageToIconMaterial(data)
elseif type == "death_time" then
Expand Down Expand Up @@ -916,6 +936,8 @@ if CLIENT then
function bodysearch.PreprocSearch(raw)
local search = {}

local index = 1

for i = 1, #bodysearch.searchResultOrder do
local type = bodysearch.searchResultOrder[i]
local searchData = bodysearch.GetContentFromData(type, raw)
Expand All @@ -930,11 +952,27 @@ if CLIENT then
-- only use the first text entry here
local transText = LANG.GetDynamicTranslation(text[1].body, text[1].params, true)

search[type] = {
img = searchData.iconMaterial:GetName(),
text = transText,
p = i, -- sorting number
}
if searchData.iconMaterial then
-- note: GetName only returns the material name. This fails if the addon uses a
-- png for its material, we therefore have to check if the material exists on disk
local materialFile = searchData.iconMaterial:GetName()

if file.Exists("materials/" .. materialFile .. ".png", "GAME") then
materialFile = materialFile .. ".png"
elseif file.Exists("materials/" .. materialFile .. ".jpg", "GAME") then
materialFile = materialFile .. ".jpg"
elseif file.Exists("materials/" .. materialFile .. ".jpeg", "GAME") then
materialFile = materialFile .. ".jpeg"
end

search[type] = {
img = materialFile,
text = transText,
p = index, -- sorting number
}

index = index + 1
end

-- special cases with icon text
local iconTextFn = TypeToIconText(type, raw)
Expand Down

0 comments on commit 55e3703

Please sign in to comment.