Benny/gamemodes/benny/gamemode/hud.lua

142 lines
2.7 KiB
Lua
Raw Normal View History

2024-03-07 21:19:30 -05:00
---------------------
-- Your Name is Benny
---------------------
-- Stack related
local function xy( x, y )
return {x, y}
end
local function hXY( x, y )
local rx, ry = 0, 0
for key, value in ipairs(stack) do
rx = rx + value[1]
ry = ry + value[2]
end
if x then rx = rx + x end
if y then ry = ry + y end
return rx, ry
end
local function S_Push( x, y )
stack:Push( xy( x, y ) )
end
local function S_Pop( x, y )
stack:Pop()
end
local function hCol( r, g, b, a )
return surface.SetDrawColor( r, g, b, a )
end
local function hRect( x, y, w, h )
gx, gy = hXY()
x = (x or 0) + gx
y = (y or 0) + gy
surface.DrawRect( x, y, w, h )
end
local function hORect( x, y, w, h, r )
gx, gy = hXY()
x = (x or 0) + gx
y = (y or 0) + gy
surface.DrawOutlinedRect( x, y, w, h, r )
end
2024-03-07 22:34:29 -05:00
local function hScis( x, y, w, h )
gx, gy = hXY()
x = (x or 0) + gx
y = (y or 0) + gy
render.SetScissorRect( x, y, x+w, y+h, true )
end
local function hScisoff()
render.SetScissorRect( 0, 0, 0, 0, false )
end
local sizes = {
8, 10, 16, 24, 48
}
local function regenfonts()
for index, scale in ipairs( sizes ) do
surface.CreateFont("HUD_" .. scale, {
font = "Carbon Plus Bold",
size = scale,
weight = 0,
extended = false,
italic = false,
antialias = true,
})
end
end
regenfonts()
2024-03-07 21:19:30 -05:00
local COLOR_DARK = Color( 40, 40, 80 )
local COLOR_BRIGHT = Color( 80, 80, 160 )
local COLOR_MAIN = Color( 160, 160, 240 )
-- Drawing
function GM:HUDPaint()
2024-03-07 22:34:29 -05:00
local p = LocalPlayer()
local w, h = ScrW(), ScrH()
2024-03-07 21:19:30 -05:00
stack = util.Stack()
2024-03-07 22:34:29 -05:00
S_Push( 20, 20 )
2024-03-07 21:19:30 -05:00
hCol( COLOR_DARK )
2024-03-07 22:34:29 -05:00
hRect( 0, 0, 320, 40 )
local x, y = hXY( 6, 0 )
draw.SimpleText( "BENNY", "HUD_48", x, y, COLOR_MAIN )
2024-03-07 21:19:30 -05:00
hCol( COLOR_MAIN )
2024-03-07 22:34:29 -05:00
hRect( 4, 4, (320-4-4) * math.abs( math.sin(CurTime()) ), 40-4-4 )
hScis( 4, 4, (320-4-4) * math.abs( math.sin(CurTime()) ), 40-4-4 )
local x, y = hXY( 6, 0 )
draw.SimpleText( "BENNY", "HUD_48", x, y, COLOR_DARK )
hScisoff()
2024-03-07 21:19:30 -05:00
S_Pop()
2024-03-07 22:34:29 -05:00
S_Push( 20, h - 60 - 20 )
for i, v in ipairs( p:GetInventory():GetWeighted() ) do
hCol( COLOR_DARK )
hRect( 0, 0, 120, 60 )
local x, y = hXY( 0, 0 )
draw.SimpleText( l8( v.Class.PrintName ), "HUD_24", x + 120/2, y + 60/2, COLOR_MAIN, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
S_Pop()
2024-03-07 21:19:30 -05:00
if stack:Size() != 0 then print("Stack unfinished.") end
return
end
-- Not drawing
local hide = {
["CHudHealth"] = true,
["CHudBattery"] = true,
["CHudAmmo"] = true,
["CHudSecondaryAmmo"] = true,
["CHudDamageIndicator"] = true,
["CHudCloseCaption"] = true,
["CHudCrosshair"] = true,
["CHudSuitPower"] = true,
["CHUDQuickInfo"] = true,
["CHudZoom"] = true,
}
function GM:HUDShouldDraw( name )
if hide[ name ] then
return false
else
return true
end
end