Benny/gamemodes/benny/gamemode/hud.lua

280 lines
7.0 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 = {
2024-04-06 09:30:09 -04:00
8, 10, 16, 24, 36, 48
2024-03-07 22:34:29 -05:00
}
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-12 18:43:31 -04:00
-- local COLOR_DARK = Color( 40, 40, 80 )
-- local COLOR_BRIGHT = Color( 80, 80, 160 )
-- local COLOR_MAIN = Color( 160, 160, 240 )
local COLOR_DARK = Color( 54, 44, 39 )
local COLOR_BRIGHT = Color( 94, 84, 79 )
local COLOR_MAIN = Color( 255, 238, 169 )
2024-03-07 21:19:30 -05:00
2024-04-06 09:30:09 -04:00
local show_letters = {
{ "q", "w", "e", "r", "t", "y" },
{ "a", "s", "d", "f", "g", "h" },
{ "shift", "z", "x", "c", "v", "b", "n" },
{ "ctrl", "alt", "space" },
}
local translate_letters = {
["e"] = "weapon 1",
["q"] = "weapon 2",
["c"] = "grenade 1",
["z"] = "grenade 2",
["r"] = "alt 1",
["t"] = "alt 2",
["x"] = "bullrush",
["shift"] = "speed",
}
local function commoncode( set )
for index, letter in ipairs( set ) do
local lettercode = input.GetKeyCode( letter )
local keydown = input.IsKeyDown( lettercode )
local thecolor = keydown and COLOR_MAIN or COLOR_DARK
local fakecolor = ColorAlpha( COLOR_BRIGHT, 60)
hCol( fakecolor )
hRect( (index-1)*(60+4), 0, 60, 40, 2 )
hCol( thecolor )
hORect( (index-1)*(60+4), 0, 60, 40, 2 )
local x, y = hXY( (index-1)*(60+4) + 30, 20+3 )
draw.SimpleText( letter:upper(), "HUD_36", x, y, thecolor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
local tlated = translate_letters[letter]
if tlated then
local x, y = hXY( (index-1)*(60+4) + 30, 20 + 6 )
draw.SimpleText( tlated, "HUD_16", x, y, thecolor, TEXT_ALIGN_CENTER )
end
end
end
2024-03-07 21:19:30 -05:00
-- Drawing
function GM:HUDPaint()
2024-03-07 22:34:29 -05:00
local p = LocalPlayer()
local w, h = ScrW(), ScrH()
2024-03-12 18:43:31 -04:00
local handler = p:HandlerCheck()
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-04-06 09:30:09 -04:00
hRect( 4, 4, (320-4-4) * p:GetHealth_Blood()/1000, 40-4-4 )
2024-03-07 22:34:29 -05:00
2024-04-06 09:30:09 -04:00
hScis( 4, 4, (320-4-4) * p:GetHealth_Blood()/1000, 40-4-4 )
2024-03-07 22:34:29 -05:00
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-12 18:43:31 -04:00
if handler then
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( (i-1)*(120+10), 0, 120, 60 )
local x, y = hXY( (i-1)*(120+10), 0 )
2024-03-25 00:48:36 -04:00
draw.SimpleText( l8( v.Class.PrintName ), "HUD_24", x + 120/2, y + 60/2 - (10), COLOR_MAIN, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
2024-04-06 09:30:09 -04:00
if v.GetClip2 then
draw.SimpleText( v:GetClip2() .. "/" .. v.Class.ClipSize2, "HUD_16", x + 10, y + 60/2 + (4), COLOR_MAIN, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER )
end
local drawer = ""
drawer = drawer .. v:GetClip()
drawer = drawer .. "+" .. (v:GetSlideState() == SLIDE_FORWARD and 1 or 0)
drawer = drawer .. "/"
drawer = drawer .. v.Class.ClipSize
draw.SimpleText( drawer, "HUD_16", x + 10, y + 60/2 + (16), COLOR_MAIN, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER )
draw.SimpleText( v:GetFiremode(), "HUD_16", x + 120 - 10, y + 60/2 + (16), COLOR_MAIN, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER )
2024-03-12 18:43:31 -04:00
end
S_Pop()
end
2024-03-07 21:19:30 -05:00
2024-04-06 09:30:09 -04:00
if false then
S_Push( 20, h - (20 + 40 + 4 + 40 + 4 + 40) )
S_Push( 0, 0 )
commoncode( show_letters[1] )
S_Pop()
S_Push( 18, 40+4 )
commoncode( show_letters[2] )
S_Pop()
S_Push( 18+24 - (40+24), 40+4+40+4 )
commoncode( show_letters[3] )
S_Pop()
S_Push( 0, 40+4+40+4+40+4 )
commoncode( show_letters[4] )
S_Pop()
S_Pop()
end
local itemcheck = handler:ItemCheckTrace()
if true then
S_Push( w - 20, h - 20 )
local hints = {}
table.insert( hints, { "[SHIFT]", "DIVE" } )
table.insert( hints, { "", "INTO PRONE", "HOLD" } )
if handler:ItemR() then
table.insert( hints, { "", "- - - - - - - - - - - -" } )
table.insert( hints, { "[M1]", "FIRE" } )
table.insert( hints, { "[C]", "FIREMODE" } )
table.insert( hints, { "[E]", "THROW" } )
table.insert( hints, { "[R]", "RELOAD" } )
table.insert( hints, { "", "RETAIN MAG", "HOLD" } )
elseif itemcheck.Entity:IsValid() and itemcheck.Entity.BennyItem then
table.insert( hints, { "", "- - - - - - - - - - - -" } )
table.insert( hints, { "[E]", "PICK UP" } )
end
local x, y = hXY( 0, (#hints-1)*(-24) )
for i, v in ipairs( hints ) do
draw.SimpleText( v[1], "HUD_24", x - 150, y - 24 + (24*(i-1)), COLOR_MAIN, TEXT_ALIGN_CENTER )
draw.SimpleText( v[2], "HUD_24", x, y - 24 + (24*(i-1)), COLOR_MAIN, TEXT_ALIGN_RIGHT )
if v[3] then
draw.SimpleText( v[3], "HUD_16", x - 150, y - 24+3 + (24*(i-1)), COLOR_MAIN, TEXT_ALIGN_CENTER )
end
end
S_Pop()
end
local trac = p:GetEyeTrace().HitPos:ToScreen()
local trac2 = util.TraceLine( {
start = CamSpot(),
endpos = CamSpot() + TPSOverride:Forward()*(2^16),
filter = p,
} ).HitPos:ToScreen()
local cx, cy = trac.x, trac.y
S_Push( cx, cy )
local size = 8
surface.SetDrawColor( color_white )
hRect( -size/2, -size/2, size, size )
local wep = handler:ItemR()
if wep and wep.Class.FirearmHelper then
local x, y = hXY( 0, 16 )
draw.SimpleText( (!wep:GetLoaded() and "Unloaded") or ((wep:GetSlideState() != SLIDE_FORWARD) and "Cycle") or "", "HUD_24", x, y, COLOR_MAIN, TEXT_ALIGN_CENTER )
end
S_Pop()
local cx, cy = trac2.x, trac2.y
S_Push( cx, cy )
local size = 4
surface.SetDrawColor( 255, 127, 127 )
hRect( -size/2, -size/2, size, size )
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