Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve wire_holograms_display_owners #3183

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 46 additions & 19 deletions lua/entities/gmod_wire_expression2/core/cl_hologram.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
-- Replicated from serverside, same function as the one below except this takes precedence
local holoDisplayCVar = CreateConVar("wire_holograms_display_owners_maxdist", "-1", {FCVAR_REPLICATED})

local holoDisplayCVarCL = CreateClientConVar( "wire_holograms_display_owners_maxdist_cl" , "-1", true, false,
"The maximum distance that wire_holograms_display_owners will allow names to be seen. -1 for original function.", -1, 32768)

local function WireHologramsShowOwners()
local eye = EyePos()
local entList = ents.FindByClass( "gmod_wire_hologram" )
local finalEntList = {}

local finalCVar = 0
-- Both cvars, server-replicated and clientside
local cva = holoDisplayCVar:GetInt()
Expand All @@ -18,43 +13,75 @@ local function WireHologramsShowOwners()
finalCVar = cvb
else
if cvb >= 0 then -- Use whichever value is lower, as long as the client isn't trying to get mapwide visibility of names while the server prevents it
finalCVar = math.min( cva, cvb)
finalCVar = math.min(cva, cvb)
else -- If all else fails, settle with what the server is using
finalCVar = cva
end
end

local holoDisplayDist = finalCVar ^ 2
local entList = {}

if finalCVar > 0 then -- Can't check for -1 from the above variable since it is squared, and it needs to be squared for performance reasons comparing distances
for _,ent in pairs( entList ) do
local distToEye = eye:DistToSqr( ent:GetPos() )
if distToEye < holoDisplayDist then finalEntList[ #finalEntList + 1 ] = ent end
local holoDisplayDist = finalCVar ^ 2
local eyePos = EyePos()

for _, ent in ipairs(ents.FindByClass("gmod_wire_hologram")) do
if eyePos:DistToSqr(ent:GetPos()) < holoDisplayDist then entList[#entList + 1] = ent end
end
else -- Default to the original function of showing ALL holograms
elseif finalCVar == -1 then
-- Default to the original function of showing ALL holograms
-- if, in the end, both are 0, why even bother trying to do it at all (and why is this running?)
if finalCVar == -1 then finalEntList = entList end
entList = ents.FindByClass("gmod_wire_hologram")
end

local names = setmetatable({},{__index=function(t, ply)
local name = ply:IsValid() and ply:GetName() or "(disconnected)"
local names = setmetatable({}, {__index = function(t, ply)
local name = ply:IsValid() and ply:Nick() or "(disconnected)"
t[ply] = name

return name
end})
for _, ent in pairs( finalEntList ) do

surface.SetFont("DermaDefaultBold")

for _, ent in ipairs(entList) do
local vec = ent:GetPos():ToScreen()

if vec.visible then
draw.DrawText( names[ent:GetPlayer()] .. "\n" .. ent.steamid, "DermaDefault", vec.x, vec.y, Color(255,0,0,255), 1 )
local text = names[ent:GetPlayer()]
local w, h = surface.GetTextSize(text)
--Draw nick shadow
surface.SetTextColor(0, 0, 0)
surface.SetTextPos(vec.x - w / 2 + 1, vec.y - h / 2 + 1)
surface.DrawText(text)

--Draw nick
surface.SetTextColor(255, 255, 255)
surface.SetTextPos(vec.x - w / 2, vec.y - h / 2)
surface.DrawText(text)

local text2 = ent.steamid
local w2, h2 = surface.GetTextSize(text2)
--Draw steamid shadow
surface.SetTextColor(0, 0, 0)
surface.SetTextPos(vec.x - w2 / 2 + 1, vec.y + h / 2 + 1)
surface.DrawText(text2)

--Draw steamid
surface.SetTextColor(255, 255, 255)
surface.SetTextPos(vec.x - w2 / 2, vec.y + h / 2)
surface.DrawText(text2)
end
end
end

local display_owners = false
concommand.Add( "wire_holograms_display_owners", function()

concommand.Add("wire_holograms_display_owners", function()
display_owners = not display_owners

if display_owners then
hook.Add( "HUDPaint", "wire_holograms_showowners", WireHologramsShowOwners)
hook.Add("HUDPaint", "wire_holograms_showowners", WireHologramsShowOwners)
else
hook.Remove("HUDPaint", "wire_holograms_showowners")
end
end )
end)
Loading