Less idiotic repeating caption stuff

This commit is contained in:
Fesiug 2023-11-12 19:19:59 -05:00
parent a6bcd70c86
commit a8bd4a2b49
1 changed files with 8 additions and 9 deletions

View File

@ -191,16 +191,14 @@ function AddCaption( name, color, text, time_to_type, lifetime )
if captions[#captions] and captions[#captions].name == name then if captions[#captions] and captions[#captions].name == name then
local weh = captions[#captions] local weh = captions[#captions]
local wehlast = weh.lines[#weh.lines] local wehlast = weh.lines[#weh.lines]
local patty = string.gsub(wehlast.text, " %((x%d+)%)", "") if wehlast.text == text then
if patty == text then wehlast.repeated = wehlast.repeated + 1
wehlast.repeated = (wehlast.repeated or 1) + 1
wehlast.text = patty .. " (x" .. wehlast.repeated .. ")"
else else
table.insert( weh.lines, { text = text, time_to_type=time_to_type, starttime=CurTime() } ) table.insert( weh.lines, { text = text, time_to_type=time_to_type, starttime=CurTime(), repeated = 1 } )
end end
weh.lifetime = math.max( CurTime() + lifetime, weh.lifetime ) weh.lifetime = math.max( CurTime() + lifetime, weh.lifetime )
else else
table.insert( captions, { name = name, color=color, lifetime=CurTime()+lifetime, lines = { { text=text, time_to_type=time_to_type, starttime=CurTime() } } }) table.insert( captions, { name = name, color=color, lifetime=CurTime()+lifetime, lines = { { text=text, time_to_type=time_to_type, starttime=CurTime(), repeated = 1 } } })
end end
end end
@ -305,7 +303,6 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
surface.SetTextColor( scheme["fg"] ) surface.SetTextColor( scheme["fg"] )
surface.SetTextPos( sw/2 - tox/2, sh/2 + ss( 96 ) - toy/2 ) surface.SetTextPos( sw/2 - tox/2, sh/2 + ss( 96 ) - toy/2 )
surface.DrawText( tex ) surface.DrawText( tex )
end end
end end
@ -690,7 +687,8 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
surface.SetFont("Benny_Caption_9") surface.SetFont("Benny_Caption_9")
local tw = 0 local tw = 0
for i, v in pairs( caption.lines ) do for i, v in pairs( caption.lines ) do
tw = math.max( tw, surface.GetTextSize( v.text ) ) local repeater = ( v.repeated > 1 and (" (x" .. v.repeated .. ")") or "" )
tw = math.max( tw, surface.GetTextSize( v.text .. repeater ) )
end end
surface.SetFont("Benny_10") surface.SetFont("Benny_10")
tw = math.max( tw, surface.GetTextSize( caption.name ) ) tw = math.max( tw, surface.GetTextSize( caption.name ) )
@ -702,6 +700,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
-- PROTO: Would be nice to be able to change italics or bold inline. -- PROTO: Would be nice to be able to change italics or bold inline.
for i, v in SortedPairsByMemberValue( caption.lines, "starttime" ) do for i, v in SortedPairsByMemberValue( caption.lines, "starttime" ) do
local repeater = ( v.repeated > 1 and (" (x" .. v.repeated .. ")") or "" )
surface.SetFont("Benny_Caption_9I") surface.SetFont("Benny_Caption_9I")
surface.SetTextColor( color_white ) surface.SetTextColor( color_white )
surface.SetTextPos( (sw/2) - (tw/2), sh - space + ss(10) + (ss(8)*(i-1)) ) surface.SetTextPos( (sw/2) - (tw/2), sh - space + ss(10) + (ss(8)*(i-1)) )
@ -709,7 +708,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
for i=1, #v.text do for i=1, #v.text do
waah = waah .. ( ((i-1)/#v.text) <= math.TimeFraction( v.starttime, v.starttime + v.time_to_type, CurTime() ) and v.text[i] or " ") waah = waah .. ( ((i-1)/#v.text) <= math.TimeFraction( v.starttime, v.starttime + v.time_to_type, CurTime() ) and v.text[i] or " ")
end end
surface.DrawText( waah ) surface.DrawText( waah .. repeater )
end end
surface.SetTextColor( caption.color ) surface.SetTextColor( caption.color )