Get that button down overlay out of my HUD file

This commit is contained in:
Fesiug 2024-09-21 17:07:49 -04:00
parent 0aac95d5a0
commit bf1dd2f99b
Signed by: Fesiug
GPG Key ID: 374BFF45E1EEF243
2 changed files with 103 additions and 78 deletions

View File

@ -4,11 +4,11 @@
--------------------- ---------------------
-- Stack related -- Stack related
local function xy( x, y ) function xy( x, y )
return {x, y} return {x, y}
end end
local function hXY( x, y ) function hXY( x, y )
local rx, ry = 0, 0 local rx, ry = 0, 0
for key, value in ipairs(stack) do for key, value in ipairs(stack) do
rx = rx + value[1] rx = rx + value[1]
@ -19,20 +19,20 @@ local function hXY( x, y )
return rx, ry return rx, ry
end end
local function S_Push( x, y ) function S_Push( x, y )
stack:Push( xy( x, y ) ) stack:Push( xy( x, y ) )
end end
local function S_Pop( x, y ) function S_Pop( x, y )
stack:Pop() stack:Pop()
end end
local function hCol( r, g, b, a ) function hCol( r, g, b, a )
return surface.SetDrawColor( r, g, b, a ) return surface.SetDrawColor( r, g, b, a )
end end
local function hRect( x, y, w, h ) function hRect( x, y, w, h )
gx, gy = hXY() gx, gy = hXY()
x = (x or 0) + gx x = (x or 0) + gx
y = (y or 0) + gy y = (y or 0) + gy
@ -40,7 +40,7 @@ local function hRect( x, y, w, h )
surface.DrawRect( x, y, w, h ) surface.DrawRect( x, y, w, h )
end end
local function hRRect( x, y, w, h, r ) function hRRect( x, y, w, h, r )
gx, gy = hXY() gx, gy = hXY()
x = (x or 0) + gx x = (x or 0) + gx
y = (y or 0) + gy y = (y or 0) + gy
@ -48,7 +48,7 @@ local function hRRect( x, y, w, h, r )
draw.RoundedBox( r, x, y, w, h, surface.GetDrawColor() ) draw.RoundedBox( r, x, y, w, h, surface.GetDrawColor() )
end end
local function hTRect( x, y, w, h ) function hTRect( x, y, w, h )
gx, gy = hXY() gx, gy = hXY()
x = (x or 0) + gx x = (x or 0) + gx
y = (y or 0) + gy y = (y or 0) + gy
@ -56,7 +56,7 @@ local function hTRect( x, y, w, h )
surface.DrawTexturedRect( x, y, w, h ) surface.DrawTexturedRect( x, y, w, h )
end end
local function hTrRect( x, y, w, h, d ) function hTrRect( x, y, w, h, d )
gx, gy = hXY() gx, gy = hXY()
x = (x or 0) + gx x = (x or 0) + gx
y = (y or 0) + gy y = (y or 0) + gy
@ -64,7 +64,7 @@ local function hTrRect( x, y, w, h, d )
surface.DrawTexturedRectRotated( x, y, w, h, d ) surface.DrawTexturedRectRotated( x, y, w, h, d )
end end
local function hORect( x, y, w, h, r ) function hORect( x, y, w, h, r )
gx, gy = hXY() gx, gy = hXY()
x = (x or 0) + gx x = (x or 0) + gx
y = (y or 0) + gy y = (y or 0) + gy
@ -72,7 +72,7 @@ local function hORect( x, y, w, h, r )
surface.DrawOutlinedRect( x, y, w, h, r ) surface.DrawOutlinedRect( x, y, w, h, r )
end end
local function hScis( x, y, w, h ) function hScis( x, y, w, h )
gx, gy = hXY() gx, gy = hXY()
x = (x or 0) + gx x = (x or 0) + gx
y = (y or 0) + gy y = (y or 0) + gy
@ -80,11 +80,11 @@ local function hScis( x, y, w, h )
render.SetScissorRect( x, y, x+w, y+h, true ) render.SetScissorRect( x, y, x+w, y+h, true )
end end
local function hScisoff() function hScisoff()
render.SetScissorRect( 0, 0, 0, 0, false ) render.SetScissorRect( 0, 0, 0, 0, false )
end end
local function qt( text, font, x, y, col, xalign, yalign, col2 ) function qt( text, font, x, y, col, xalign, yalign, col2 )
draw.SimpleText( text, font, x-1, y-1, col2, xalign, yalign ) draw.SimpleText( text, font, x-1, y-1, col2, xalign, yalign )
draw.SimpleText( text, font, x, y-1, col2, xalign, yalign ) draw.SimpleText( text, font, x, y-1, col2, xalign, yalign )
draw.SimpleText( text, font, x+1, y-1, col2, xalign, yalign ) draw.SimpleText( text, font, x+1, y-1, col2, xalign, yalign )
@ -184,58 +184,16 @@ local COLOR_DARK = FACTIONS[CURRCHAR].COLOR_DARK
local CHARNAME = FACTIONS[CURRCHAR].CHARNAME local CHARNAME = FACTIONS[CURRCHAR].CHARNAME
local COLOR_BRIGHT = Color( 94, 94, 94 ) local COLOR_BRIGHT = Color( 94, 94, 94 )
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 alphabet = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} local alphabet = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
local xhair_dot = Material( "benny/hud/xhair/dotx.png", "mips smooth" ) local xhair_dot = Material( "benny/hud/xhair/dotx.png", "mips smooth" )
local xhair_dot_shadow = Material( "benny/hud/xhair/dot_s.png", "mips smooth" ) local xhair_dot_shadow = Material( "benny/hud/xhair/dot_s.png", "mips smooth" )
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
local fmlookup = { local fmlookup = {
[1] = "SEMI", [1] = "SEMI",
[math.huge] = "AUTO", [math.huge] = "AUTO",
} }
local function QuickDrawBar( BARWIDE, BARTALL, RealTeamID, TeamID, way ) local function QuickDrawBar( BARWIDE, BARTALL, RealTeamID, TeamID, way )
local faction_info = FACTIONS[ TEAMS[RealTeamID].factionid ] local faction_info = FACTIONS[ TEAMS[RealTeamID].factionid ]
@ -301,8 +259,6 @@ local function QuickDrawBar( BARWIDE, BARTALL, RealTeamID, TeamID, way )
end end
end end
local ROUNDEND = CurTime() + 62
-- Drawing -- Drawing
function GM:HUDPaint() function GM:HUDPaint()
local p = LocalPlayer() local p = LocalPlayer()
@ -321,7 +277,6 @@ function GM:HUDPaint()
local COLOR_DARK = FACTIONS[CURRCHAR].COLOR_DARK local COLOR_DARK = FACTIONS[CURRCHAR].COLOR_DARK
local CHARNAME = FACTIONS[CURRCHAR].CHARNAME local CHARNAME = FACTIONS[CURRCHAR].CHARNAME
local MP = BennyGame:GetType() == BG_GTYPE_MP local MP = BennyGame:GetType() == BG_GTYPE_MP
-- S_Push( math.random( -4, 4 ), math.random( -4, 4 ) ) -- S_Push( math.random( -4, 4 ), math.random( -4, 4 ) )
@ -403,7 +358,19 @@ function GM:HUDPaint()
S_Pop() S_Pop()
if handler then if handler then
-- Inventory
S_Push( 20, 20 ) S_Push( 20, 20 )
local x, y = hXY( 5, 65+16*0 )
draw.SimpleText( "SelectedNumber: " .. (p.SelectedNumber or 0), "HUD_16", x, y, COLOR_MAIN )
local x, y = hXY( 5, 65+16*1 )
draw.SimpleText( "DesireR: " .. tostring(handler:GetDesireR()), "HUD_16", x, y, COLOR_MAIN )
local x, y = hXY( 5, 65+16*2 )
draw.SimpleText( "ActiveR: " .. tostring(handler:GetActiveR()), "HUD_16", x, y, COLOR_MAIN )
local x, y = hXY( 5, 65+16*3 )
draw.SimpleText( "DesireL: " .. tostring(handler:GetDesireL()), "HUD_16", x, y, COLOR_MAIN )
local x, y = hXY( 5, 65+16*4 )
draw.SimpleText( "ActiveL: " .. tostring(handler:GetActiveL()), "HUD_16", x, y, COLOR_MAIN )
for i, v in ipairs( p:GetInventory():GetWeighted() ) do for i, v in ipairs( p:GetInventory():GetWeighted() ) do
hCol( v == handler:GetActiveR() and COLOR_BRIGHT or COLOR_DARK ) hCol( v == handler:GetActiveR() and COLOR_BRIGHT or COLOR_DARK )
hRect( (i-1)*(120+10), 0, 120, 60 ) hRect( (i-1)*(120+10), 0, 120, 60 )
@ -463,31 +430,12 @@ function GM:HUDPaint()
end end
end end
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
if MP then S_Push( w/2, 20 ) if MP then S_Push( w/2, 20 )
local BARWIDE, BARTALL, GAP = 240, 30, 100 local BARWIDE, BARTALL, GAP = 240, 30, 100
--hCol( Color( 255, 0, 0 ) )
--hRect( 0, 0, 1, 60 )
-- Score -- Score
local count = 1 local count = 1
do -- My team if BennyGame.RTeamID[myteam] then -- My team
local o = count-1 local o = count-1
S_Push( count%2==1 and (-BARWIDE - 1 - GAP) or (0 + 1 + GAP), (BARTALL+2+16+2)*math.floor(o/2) ) S_Push( count%2==1 and (-BARWIDE - 1 - GAP) or (0 + 1 + GAP), (BARTALL+2+16+2)*math.floor(o/2) )
QuickDrawBar( BARWIDE, BARTALL, myteam, BennyGame.RTeamID[myteam], count%2==0 ) QuickDrawBar( BARWIDE, BARTALL, myteam, BennyGame.RTeamID[myteam], count%2==0 )

View File

@ -0,0 +1,77 @@
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 )
local LetterWidth = 80
local LetterGap = 4
hRect( (index-1)*(LetterWidth+4), 0, LetterWidth, 40, 2 )
hCol( thecolor )
hORect( (index-1)*(LetterWidth+4), 0, LetterWidth, 40, 2 )
local x, y = hXY( (index-1)*(LetterWidth+4) + LetterWidth/2, 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)*(LetterWidth+4) + LetterWidth/2, 20 + 6 )
draw.SimpleText( tlated, "HUD_16", x, y, thecolor, TEXT_ALIGN_CENTER )
end
end
end
hook.Add( "HUDPaint", "Benny_HUDPaint_KeyboardOverlay", function()
--if false then return end
local p = LocalPlayer()
local myteam = p:Team()
local CURRCHAR
if BennyGame:GetType() == BG_GTYPE_CAMPAIGN then
CURRCHAR = "benny"
else
CURRCHAR = TEAMS[myteam].factionid
end
local COLOR_MAIN = FACTIONS[CURRCHAR].COLOR_MAIN
local COLOR_DARK = FACTIONS[CURRCHAR].COLOR_DARK
local CHARNAME = FACTIONS[CURRCHAR].CHARNAME
stack = util.Stack()
S_Push( 100, h - 300 )
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()
if stack:Size() != 0 then print("Stack unfinished: KeyboardOverlay") end
end)