Benny/gamemodes/benny/gamemode/hud.lua

143 lines
2.8 KiB
Lua

---------------------
-- 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
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()
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()
local p = LocalPlayer()
local w, h = ScrW(), ScrH()
local handler = p:BennyCheck()
stack = util.Stack()
S_Push( 20, 20 )
hCol( COLOR_DARK )
hRect( 0, 0, 320, 40 )
local x, y = hXY( 6, 0 )
draw.SimpleText( "BENNY", "HUD_48", x, y, COLOR_MAIN )
hCol( COLOR_MAIN )
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()
S_Pop()
S_Push( 20, h - 60 - 20 )
for i, v in ipairs( p:GetInventory():GetWeighted() ) do
hCol( v == handler:GetActiveR() and COLOR_BRIGHT or COLOR_DARK )
hRect( 0, 0, 120, 60 )
local x, y = hXY( 0, 0 )
draw.SimpleText( l8( v.Class.PrintName ) .. "(" .. v:GetClip() .. "/" .. v.Class.ClipSize .. ")", "HUD_24", x + 120/2, y + 60/2, COLOR_MAIN, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
S_Pop()
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