Demonstration HUD, A new element for developers

[release]Demonstration HUD

A new HUD element, “CHudDemonstrationText”, which presents a nifty little title, and shows what map you’re on for the demo. This HUD element is mainly for screenshots and videos, or for other types of proof of concept snapshots.[/release]

New elements:
“CHudDemonstrationText”

New ConVars:
cl_demonstration_text - The title or text to be displayed.

Examples (taken from Incendiary Shotgun?):

Screenshot:

Video
[hd]http://www.youtube.com/watch?v=CPSXM2x_SEQ[/hd]

[lua]
local r_drawhud = CreateClientConVar( “r_drawhud”, 1, true, false )

function surface.ScreenScale( size )
return size * ( ScrH() / 480.0 )
end

surface.SScale = surface.ScreenScale

FgColor = Color( 255, 220, 0, 200 )
BgColor = Color( 0, 0, 0, 76 )

Panel = Panel || {}
Panel.FgColor = FgColor
Panel.BgColor = BgColor

local function R_DrawHud( name )

if ( r_drawhud:GetBool() ) then return end

// So we can change weapons
if (name == "CHudWeaponSelection") then return true end
if (name == "CHudChat") then return true end
if (name == "CHudGMod") then return true end

return false;

end

hook.Add( “HUDShouldDraw”, “R_DrawHud”, R_DrawHud )[/lua]

[lua]
surface.CreateFont( “Verdana”, surface.SScale( 16 ), 0, true, true, “HudPresentationText” )

local cl_demonstration_text = CreateClientConVar( “cl_demonstration_text”, “”, false, false )

local function CHudDemonstrationText()

local player	= LocalPlayer()
local weapon	= player:GetActiveWeapon()

if ( cl_demonstration_text:GetString() == "" ) then return end
if ( weapon:IsValid() && weapon:GetClass() == "gmod_tool" ) then return end

// Ask the gamemode if it's ok to do this
if ( !gamemode.Call( "HUDShouldDraw", "CHudDemonstrationText" ) ) then return end

local text_font			= "HudPresentationText"

surface.SetFont( text_font )

local TEXT				= cl_demonstration_text:GetString()
local Width, Height		= surface.GetTextSize( TEXT )

local text_font			= "HudSelectionText"

surface.SetFont( text_font )

local MAP				= "On " .. game.GetMap()
MAP						= MAP:upper()
local Width2, Height2	= surface.GetTextSize( MAP )

local xpos	= surface.SScale( 16 )
local ypos	= surface.SScale( 16 )
local wide	= surface.SScale( 8 ) + Width + surface.SScale( 8 )
local tall	= surface.SScale( 5 ) + Height + surface.SScale( 5 ) + Height2 + surface.SScale( 5 )

draw.RoundedBox( 8, xpos, ypos, wide, tall, Panel.BgColor )

local text_font			= "HudPresentationText"

surface.SetFont( text_font )

local text_xpos			= xpos + surface.SScale( 8 )
local text_ypos			= ypos + surface.SScale( 5 )

draw.DrawText( TEXT,	text_font, text_xpos, text_ypos, Panel.FgColor, TEXT_ALIGN_LEFT )

local text_font			= "HudSelectionText"

surface.SetFont( text_font )

text_ypos				= text_ypos + Height + surface.SScale( 5 )

draw.DrawText( MAP,		text_font, text_xpos, text_ypos, Panel.FgColor, TEXT_ALIGN_LEFT )

end

hook.Add( “HUDPaint”, “CHudDemonstrationText”, CHudDemonstrationText )

[/lua]

Cool idea :slight_smile: Thanks

:smile: Yes! Success! I’ve helped someone! :v:

You’ve helped plenty of people I’m sure. You have very good ideas. Don’t let the flamers get you down. Your gmod+ idea is cool. Facepunch people are just twats in general.

:slight_smile: Thanks.

http://www.facepunch.com/fp/rating/heart.png

Also. I misspelt incendiary.

Do the box dance. :derp:

[editline]02:39PM[/editline]

Revised code, slightly. The element was down 4 scaled pixels too far. (Perfectionism.)

Great idea!

You could take it even further by creating a suite - make a quick menu. Users could define SWEPs, NPCs, props, and SWEP selection shortcuts for the quick menu and arrange them in a particular order. That way, we wouldn’t have to see the spawn menu so much and it makes rehearsal much easier.

The nice thing about having the user experience values and measurements to work with is that I can replicate HUD style for new HUD elements. I was thinking about a Crysis-styled quick-tool menu.

It was a request given to me a while back.

My todo list is MASSIVE.