Skip to content

Commit

Permalink
Make text stay within screen bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
marchc1 committed Jan 12, 2025
1 parent 4767059 commit 6c3dcda
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lua/acf/core/utilities/util_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ do
if not ACF.ToolCL_InLinkState() then return end
table.Empty(HUDText)

local playerPos = LocalPlayer():GetPos()
local eyeTrace = LocalPlayer():GetEyeTrace()
local lookEnt = eyeTrace.Entity
local lookPos = eyeTrace.HitPos
Expand All @@ -1036,8 +1037,9 @@ do
local targPos = lookingAtEntity and lookEnt:GetPos() or lookPos
local entPos = ent:GetPos()

local inbetween = (entPos + targPos) / 2
local dist = entPos:Distance(targPos)
local player2targ = math.Clamp(playerPos:Distance(targPos) / 1.5, 0, dist / 2)
local inbetween = targPos + ((entPos - targPos):GetNormalized() * math.Clamp(dist, 0, player2targ))

local linkcolor = COLOR_Link
local renderOverride, renderData
Expand Down Expand Up @@ -1069,8 +1071,17 @@ do
hook.Add("HUDPaint", "ACF_HUDPaint_LinkDistanceVis", function()
if not ACF.ToolCL_InLinkState() then return end

local w, h = ScrW(), ScrH()
local padding = 16

for _, v in ipairs(HUDText) do
draw.SimpleTextOutlined(v.Text, "ACF_Title", v.X, v.Y, v.Color or color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, color_black)
surface.SetFont("ACF_Title")
local tX, tY = surface.GetTextSize(v.Text)
tX = tX / 2
tY = tY / 2
local x, y = math.Clamp(v.X, tX + padding, w - tX - padding), math.Clamp(v.Y, tY + padding, h - tY - padding)

draw.SimpleTextOutlined(v.Text, "ACF_Title", x, y, v.Color or color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, color_black)
end
end)
end

0 comments on commit 6c3dcda

Please sign in to comment.