Character menu stuff

master
AlmTech 5 years ago
parent 877801e3c0
commit 188dddb558
  1. 84
      gamemode/engine/core/client/cl_hud.lua
  2. 6
      gamemode/engine/derma/lib/cl_menu_pages.lua
  3. 27
      gamemode/engine/derma/lib/cl_menu_theme.lua
  4. 57
      gamemode/engine/derma/menus/menu_character.lua

@ -21,35 +21,37 @@ local padding = 5 * scale
local sw, sh = ScrW(), ScrH() local sw, sh = ScrW(), ScrH()
function GM:HUDPaint() function GM:HUDPaint()
local hp = LocalPlayer():Health() if( !Quantum.Client.IsInMenu ) then
local lasthp = hp local hp = LocalPlayer():Health()
local maxhp = LocalPlayer():GetMaxHealth() local lasthp = hp
local maxhp = LocalPlayer():GetMaxHealth()
if( Quantum.Client.Config.EnableHUD ) then
if( !LocalPlayer():Alive() ) then if( Quantum.Client.Config.EnableHUD ) then
surface.SetDrawColor( 0, 0, 0, 255 ) if( !LocalPlayer():Alive() ) then
surface.DrawRect( 0, 0, sw, sh ) surface.SetDrawColor( 0, 0, 0, 255 )
else surface.DrawRect( 0, 0, sw, sh )
-- Health border else
surface.SetDrawColor( 0, 0, 0, 200 ) -- Health border
surface.DrawRect( sw/2 - barW/2, sh*0.9, barW, barH ) surface.SetDrawColor( 0, 0, 0, 200 )
surface.DrawRect( sw/2 - barW/2, sh*0.9, barW, barH )
-- Health bar
surface.SetDrawColor( 168, 62, 50, 255 ) -- Health bar
surface.DrawRect( ( sw/2 - barW/2 ) + padding/2, (sh*0.9) + padding/2, math.Clamp( (barW - padding) * hp/maxhp, 0, barW - padding ), barH - padding ) surface.SetDrawColor( 168, 62, 50, 255 )
surface.DrawRect( ( sw/2 - barW/2 ) + padding/2, (sh*0.9) + padding/2, math.Clamp( (barW - padding) * hp/maxhp, 0, barW - padding ), barH - padding )
-- Health Text -- Health Text
surface.SetFont( "q_HUD" ) surface.SetFont( "q_HUD" )
surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextColor( 255, 255, 255, 255 )
local hptxt = tostring( 100 * (hp/maxhp) .. "%" ) local hptxt = tostring( 100 * (hp/maxhp) .. "%" )
local txtW, txtH = surface.GetTextSize( hptxt ) local txtW, txtH = surface.GetTextSize( hptxt )
surface.SetTextPos( ( ( sw/2 - txtW/2 ) + padding/2 ), ( ( sh*0.9 - txtH/3 ) ) ) surface.SetTextPos( ( ( sw/2 - txtW/2 ) + padding/2 ), ( ( sh*0.9 - txtH/3 ) ) )
surface.DrawText( hptxt ) surface.DrawText( hptxt )
-- Crosshair -- Crosshair
if( Quantum.Client.ShowCrosshair ) then if( Quantum.Client.ShowCrosshair ) then
surface.SetDrawColor( 255, 255, 255, 200 ) surface.SetDrawColor( 255, 255, 255, 200 )
surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 ) surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 )
end
end end
end end
end end
@ -57,18 +59,20 @@ function GM:HUDPaint()
end end
hook.Add( "RenderScreenspaceEffects", "Quantum_HUD_RenderLowHealth", function() hook.Add( "RenderScreenspaceEffects", "Quantum_HUD_RenderLowHealth", function()
if( LocalPlayer():Health() / LocalPlayer():GetMaxHealth() <= 0.25 ) then if( !Quantum.Client.IsInMenu ) then
DrawMotionBlur( 0.4, 0.8, 0.1 ) if( LocalPlayer():Health() / LocalPlayer():GetMaxHealth() <= 0.25 ) then
DrawColorModify( { DrawMotionBlur( 0.4, 0.8, 0.1 )
[ "$pp_colour_addr" ] = 0, DrawColorModify( {
[ "$pp_colour_addg" ] = 0, [ "$pp_colour_addr" ] = 0,
[ "$pp_colour_addb" ] = 0, [ "$pp_colour_addg" ] = 0,
[ "$pp_colour_brightness" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), -0.25, 0 ), [ "$pp_colour_addb" ] = 0,
[ "$pp_colour_contrast" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), 0.2, 1 ), [ "$pp_colour_brightness" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), -0.25, 0 ),
[ "$pp_colour_colour" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), 0.8, 1 ), [ "$pp_colour_contrast" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), 0.2, 1 ),
[ "$pp_colour_mulr" ] = 0, [ "$pp_colour_colour" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), 0.8, 1 ),
[ "$pp_colour_mulg" ] = 0, [ "$pp_colour_mulr" ] = 0,
[ "$pp_colour_mulb" ] = 0 [ "$pp_colour_mulg" ] = 0,
} ) [ "$pp_colour_mulb" ] = 0
} )
end
end end
end) end)

@ -42,7 +42,11 @@ function page.New( parent, args )
local closeW, closeH = close:GetSize() local closeW, closeH = close:GetSize()
close:SetSize( closeW + padding*2, closeH ) close:SetSize( closeW + padding*2, closeH )
close:SetPos( args.closeX, args.closeY ) close:SetPos( args.closeX, args.closeY )
close.DoClick = function() p:Remove() end close.DoClick = function()
surface.PlaySound( "UI/buttonclick.wav" )
p:Remove()
end
close.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end
close.Paint = args.CloseButtonPaint || function( self, w, h ) close.Paint = args.CloseButtonPaint || function( self, w, h )
surface.SetDrawColor( 50, 50, 50, 255 ) surface.SetDrawColor( 50, 50, 50, 255 )
surface.DrawRect( 0, 0, w, h ) surface.DrawRect( 0, 0, w, h )

@ -10,6 +10,21 @@ local scale = Quantum.Client.ResolutionScale
local padding = 10 * scale local padding = 10 * scale
local padding_s = 4 * scale local padding_s = 4 * scale
local blur = Material("pp/blurscreen")
local function renderBlur( p, a, d )
local x, y = p:LocalToScreen( 0, 0 )
surface.SetDrawColor( 255, 255, 255 )
surface.SetMaterial( blur )
for i = 1, d do
blur:SetFloat( "$blur", (i / d) * a )
blur:Recompute()
render.UpdateScreenEffectTexture()
surface.DrawTexturedRect( x * -1, y * -1, ScrW(), ScrH() )
end
end
function theme.panel( p, color ) function theme.panel( p, color )
local w, h = p:GetSize() local w, h = p:GetSize()
local clr = color || Color( 0, 0, 0, 100 ) local clr = color || Color( 0, 0, 0, 100 )
@ -19,9 +34,19 @@ function theme.panel( p, color )
draw.RoundedBox( 4, padding_s/2, padding_s/2, w - padding_s, h - padding_s, clr ) -- inner draw.RoundedBox( 4, padding_s/2, padding_s/2, w - padding_s, h - padding_s, clr ) -- inner
end end
function theme.blurpanel( p, color )
local w, h = p:GetSize()
local clr = color || Color( 0, 0, 0, 100 )
local bclr = Color( 50, 50, 50, 105 )
renderBlur( p, 2, 7 )
draw.RoundedBox( 6, 0, 0, w, h, bclr ) -- border
draw.RoundedBox( 4, padding_s/2, padding_s/2, w - padding_s, h - padding_s, clr ) -- inner
end
function theme.button( b, color ) function theme.button( b, color )
local w, h = b:GetSize() local w, h = b:GetSize()
local clr = color || Color( 225, 44, 52, 255 ) local clr = color || Color( 235, 64, 52, 255 )
local bclr = Color( 50, 50, 50, 255 ) local bclr = Color( 50, 50, 50, 255 )
if( b:IsHovered() ) then if( b:IsHovered() ) then

@ -14,6 +14,7 @@ local theme = Quantum.Client.Menu.GetAPI( "theme" )
local resScale = Quantum.Client.ResolutionScale local resScale = Quantum.Client.ResolutionScale
local sw, sh = ScrW(), ScrH() local sw, sh = ScrW(), ScrH()
local padding = 10 * resScale local padding = 10 * resScale
local padding_s = 4 * resScale
local pages = { local pages = {
@ -24,20 +25,26 @@ local pages = {
} }
local p, c = page.New( parent, args ) local p, c = page.New( parent, args )
local clist = vgui.Create( "DPanel", p ) local clist = vgui.Create( "DScrollPanel", p )
clist:SetSize( 380 * resScale, sh - padding*15 ) clist:SetSize( 380 * resScale, sh - padding*15 )
clist.w, clist.h = clist:GetSize() clist.w, clist.h = clist:GetSize()
clist:SetPos( (sw - clist.w) - padding*2, padding*6 ) clist:SetPos( (sw - clist.w) - padding*2, padding*6 )
clist.x, clist.y = clist:GetPos() clist.x, clist.y = clist:GetPos()
clist.Paint = function( self, w, h ) clist.Paint = function( self, w, h )
theme.panel( self, Color( 0, 0, 0, 200 ) ) theme.blurpanel( self, Color( 0, 0, 0, 200 ) )
end end
local sbar = clist:GetVBar()
sbar:SetSize( 0, 0 ) -- Remove the scroll bar
--- Close/quit button stuff --- --- Close/quit button stuff ---
local cW, cH = c:GetSize() local cW, cH = c:GetSize()
c:SetPos( (clist.x + clist.w) - cW, clist.y + clist.h + cH ) c:SetPos( (clist.x + clist.w) - cW, clist.y + clist.h + cH )
c.Paint = function( self ) theme.button( self ) end c.Paint = function( self ) theme.button( self ) end
c.DoClick = function() parent:Close() end c.DoClick = function()
surface.PlaySound( "UI/buttonclick.wav" )
parent:Close()
end
--- ---
local header = vgui.Create( "DLabel", p ) local header = vgui.Create( "DLabel", p )
@ -45,7 +52,7 @@ local pages = {
header:SetFont( "q_header" ) header:SetFont( "q_header" )
header:SizeToContents() header:SizeToContents()
local headerW, headerH = header:GetSize() local headerW, headerH = header:GetSize()
header:SetPos( (clist.x + headerW/2) - padding, (clist.y - headerH) + padding/2 ) header:SetPos( clist.x + ( clist.w/2 - headerW/2 ), (clist.y - headerH) + padding/2 )
header:SetTextColor( Color( 255, 255, 255, 255 ) ) header:SetTextColor( Color( 255, 255, 255, 255 ) )
header.Paint = function( self, w, h ) end header.Paint = function( self, w, h ) end
@ -54,16 +61,31 @@ local pages = {
{name="Devoe", lvl=22}, {name="Devoe", lvl=22},
{name="Leeroy", lvl=2} {name="Leeroy", lvl=2}
} }
local cpanels = {} local cpanels = {}
local selectedChar
for k, v in pairs( chars ) do for k, v in pairs( chars ) do
cpanels[k] = vgui.Create( "DButton", clist ) cpanels[k] = vgui.Create( "DButton", clist )
cpanels[k].char = v -- give the panel it's character
if( !selectedChar ) then selectedChar = cpanels[1] end -- select the first one
cpanels[k]:SetText( "" ) cpanels[k]:SetText( "" )
cpanels[k]:SetSize( clist.w - padding, 100 * resScale ) cpanels[k]:SetSize( clist.w - padding, 100 * resScale )
cpanels[k].w, cpanels[k].h = cpanels[k]:GetSize() cpanels[k].w, cpanels[k].h = cpanels[k]:GetSize()
cpanels[k]:SetPos( padding/2, (padding/2)*k + (cpanels[k].h * (k-1)) ) cpanels[k]:SetPos( padding/2, (padding)*k + (cpanels[k].h * (k-1)) )
cpanels[k].Paint = function( self, w, h ) cpanels[k].Paint = function( self, w, h )
surface.SetDrawColor( 0, 0, 0, 0 ) surface.SetDrawColor( 0, 0, 0, 0 )
surface.DrawRect( 0, 0, w, h ) surface.DrawRect( 0, 0, w, h )
if( cpanels[k] == selectedChar ) then
surface.SetDrawColor( 252, 186, 3, 100 )
surface.DrawOutlinedRect( 0, 0, w, h )
end
end
cpanels[k].DoClick = function( self ) -- if you press the char, then select it
selectedChar = self
surface.PlaySound( "UI/buttonclick.wav" )
end end
local txt = vgui.Create( "DLabel", cpanels[k] ) local txt = vgui.Create( "DLabel", cpanels[k] )
@ -72,11 +94,11 @@ local pages = {
txt:SetTextColor( Color( 200, 200, 200, 220 ) ) txt:SetTextColor( Color( 200, 200, 200, 220 ) )
txt:SizeToContents() txt:SizeToContents()
local txtW, txtH = txt:GetSize() local txtW, txtH = txt:GetSize()
txt:SetPos( padding, cpanels[k].h/2 - txtH/2 ) txt:SetPos( padding, cpanels[k].h/4 - txtH/2 )
local txtX, txtY = txt:GetPos() local txtX, txtY = txt:GetPos()
local lvl = vgui.Create( "DLabel", cpanels[k] ) local lvl = vgui.Create( "DLabel", cpanels[k] )
lvl:SetText( "Level " .. v.lvl .. " Human" ) lvl:SetText( "Level " .. v.lvl .. " Citizen" )
lvl:SetFont( "q_text2" ) lvl:SetFont( "q_text2" )
lvl:SetTextColor( Color( 180, 180, 180, 225 ) ) lvl:SetTextColor( Color( 180, 180, 180, 225 ) )
lvl:SizeToContents() lvl:SizeToContents()
@ -84,6 +106,22 @@ local pages = {
lvl:SetPos( txtX, txtY + lvlH ) lvl:SetPos( txtX, txtY + lvlH )
end end
-- create char button
local cr = vgui.Create( "DButton", p )
cr:SetText("Create New Character")
cr:SetFont( "q_text2" )
cr:SetTextColor( Color( 0, 0, 0, 255 ) )
cr:SizeToContents()
cr.w, cr.h = cr:GetSize()
cr:SetPos( clist.x + ( clist.w/2 - cr.w/2 ), clist.y + ( ( clist.h - cr.h ) - padding*2 ) )
cr.Paint = function( self )
theme.button( self )
end
cr.DoClick = function()
surface.PlaySound( "UI/buttonclick.wav" )
end
cr.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end
return p return p
end, end,
charCreate = function( parent ) charCreate = function( parent )
@ -103,7 +141,7 @@ local pages = {
} }
function menu.open( dt ) function menu.open( dt )
Quantum.Client.IsInMenu = true -- hide the hud
if( !f ) then if( !f ) then
local f = vgui.Create( "DFrame" ) local f = vgui.Create( "DFrame" )
f:SetTitle( "Character Menu" ) f:SetTitle( "Character Menu" )
@ -114,6 +152,9 @@ function menu.open( dt )
end end
f:SetDraggable( false ) f:SetDraggable( false )
f:MakePopup() f:MakePopup()
function f:OnClose()
Quantum.Client.IsInMenu = false -- show the hud when closed
end
local charSel = pages.charSelect( f ) -- test local charSel = pages.charSelect( f ) -- test
end end

Loading…
Cancel
Save