From 188dddb55870233318a3aec177b16b3814dae77d Mon Sep 17 00:00:00 2001 From: AlmTech Date: Thu, 3 Oct 2019 14:54:00 +0200 Subject: [PATCH] Character menu stuff --- gamemode/engine/core/client/cl_hud.lua | 84 ++++++++++--------- gamemode/engine/derma/lib/cl_menu_pages.lua | 6 +- gamemode/engine/derma/lib/cl_menu_theme.lua | 27 +++++- .../engine/derma/menus/menu_character.lua | 57 +++++++++++-- 4 files changed, 124 insertions(+), 50 deletions(-) diff --git a/gamemode/engine/core/client/cl_hud.lua b/gamemode/engine/core/client/cl_hud.lua index 795a761..b861e85 100644 --- a/gamemode/engine/core/client/cl_hud.lua +++ b/gamemode/engine/core/client/cl_hud.lua @@ -21,35 +21,37 @@ local padding = 5 * scale local sw, sh = ScrW(), ScrH() function GM:HUDPaint() - local hp = LocalPlayer():Health() - local lasthp = hp - local maxhp = LocalPlayer():GetMaxHealth() - - if( Quantum.Client.Config.EnableHUD ) then - if( !LocalPlayer():Alive() ) then - surface.SetDrawColor( 0, 0, 0, 255 ) - surface.DrawRect( 0, 0, sw, sh ) - else - -- Health border - 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 ) - surface.DrawRect( ( sw/2 - barW/2 ) + padding/2, (sh*0.9) + padding/2, math.Clamp( (barW - padding) * hp/maxhp, 0, barW - padding ), barH - padding ) + if( !Quantum.Client.IsInMenu ) then + local hp = LocalPlayer():Health() + local lasthp = hp + local maxhp = LocalPlayer():GetMaxHealth() + + if( Quantum.Client.Config.EnableHUD ) then + if( !LocalPlayer():Alive() ) then + surface.SetDrawColor( 0, 0, 0, 255 ) + surface.DrawRect( 0, 0, sw, sh ) + else + -- Health border + 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 ) + 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 - surface.SetFont( "q_HUD" ) - surface.SetTextColor( 255, 255, 255, 255 ) - local hptxt = tostring( 100 * (hp/maxhp) .. "%" ) - local txtW, txtH = surface.GetTextSize( hptxt ) - surface.SetTextPos( ( ( sw/2 - txtW/2 ) + padding/2 ), ( ( sh*0.9 - txtH/3 ) ) ) - surface.DrawText( hptxt ) + -- Health Text + surface.SetFont( "q_HUD" ) + surface.SetTextColor( 255, 255, 255, 255 ) + local hptxt = tostring( 100 * (hp/maxhp) .. "%" ) + local txtW, txtH = surface.GetTextSize( hptxt ) + surface.SetTextPos( ( ( sw/2 - txtW/2 ) + padding/2 ), ( ( sh*0.9 - txtH/3 ) ) ) + surface.DrawText( hptxt ) - -- Crosshair - if( Quantum.Client.ShowCrosshair ) then - surface.SetDrawColor( 255, 255, 255, 200 ) - surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 ) + -- Crosshair + if( Quantum.Client.ShowCrosshair ) then + surface.SetDrawColor( 255, 255, 255, 200 ) + surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 ) + end end end end @@ -57,18 +59,20 @@ function GM:HUDPaint() end hook.Add( "RenderScreenspaceEffects", "Quantum_HUD_RenderLowHealth", function() - if( LocalPlayer():Health() / LocalPlayer():GetMaxHealth() <= 0.25 ) then - DrawMotionBlur( 0.4, 0.8, 0.1 ) - DrawColorModify( { - [ "$pp_colour_addr" ] = 0, - [ "$pp_colour_addg" ] = 0, - [ "$pp_colour_addb" ] = 0, - [ "$pp_colour_brightness" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), -0.25, 0 ), - [ "$pp_colour_contrast" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), 0.2, 1 ), - [ "$pp_colour_colour" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), 0.8, 1 ), - [ "$pp_colour_mulr" ] = 0, - [ "$pp_colour_mulg" ] = 0, - [ "$pp_colour_mulb" ] = 0 - } ) + if( !Quantum.Client.IsInMenu ) then + if( LocalPlayer():Health() / LocalPlayer():GetMaxHealth() <= 0.25 ) then + DrawMotionBlur( 0.4, 0.8, 0.1 ) + DrawColorModify( { + [ "$pp_colour_addr" ] = 0, + [ "$pp_colour_addg" ] = 0, + [ "$pp_colour_addb" ] = 0, + [ "$pp_colour_brightness" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), -0.25, 0 ), + [ "$pp_colour_contrast" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), 0.2, 1 ), + [ "$pp_colour_colour" ] = Lerp( LocalPlayer():Health() / LocalPlayer():GetMaxHealth(), 0.8, 1 ), + [ "$pp_colour_mulr" ] = 0, + [ "$pp_colour_mulg" ] = 0, + [ "$pp_colour_mulb" ] = 0 + } ) + end end end) diff --git a/gamemode/engine/derma/lib/cl_menu_pages.lua b/gamemode/engine/derma/lib/cl_menu_pages.lua index 1de59b4..058a0eb 100644 --- a/gamemode/engine/derma/lib/cl_menu_pages.lua +++ b/gamemode/engine/derma/lib/cl_menu_pages.lua @@ -42,7 +42,11 @@ function page.New( parent, args ) local closeW, closeH = close:GetSize() close:SetSize( closeW + padding*2, closeH ) 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 ) surface.SetDrawColor( 50, 50, 50, 255 ) surface.DrawRect( 0, 0, w, h ) diff --git a/gamemode/engine/derma/lib/cl_menu_theme.lua b/gamemode/engine/derma/lib/cl_menu_theme.lua index 0514d6a..81b563c 100644 --- a/gamemode/engine/derma/lib/cl_menu_theme.lua +++ b/gamemode/engine/derma/lib/cl_menu_theme.lua @@ -10,6 +10,21 @@ local scale = Quantum.Client.ResolutionScale local padding = 10 * 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 ) local w, h = p:GetSize() 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 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 ) 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 ) if( b:IsHovered() ) then diff --git a/gamemode/engine/derma/menus/menu_character.lua b/gamemode/engine/derma/menus/menu_character.lua index ad456c6..c46b6be 100644 --- a/gamemode/engine/derma/menus/menu_character.lua +++ b/gamemode/engine/derma/menus/menu_character.lua @@ -14,6 +14,7 @@ local theme = Quantum.Client.Menu.GetAPI( "theme" ) local resScale = Quantum.Client.ResolutionScale local sw, sh = ScrW(), ScrH() local padding = 10 * resScale +local padding_s = 4 * resScale local pages = { @@ -24,20 +25,26 @@ local pages = { } 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.w, clist.h = clist:GetSize() clist:SetPos( (sw - clist.w) - padding*2, padding*6 ) clist.x, clist.y = clist:GetPos() clist.Paint = function( self, w, h ) - theme.panel( self, Color( 0, 0, 0, 200 ) ) + theme.blurpanel( self, Color( 0, 0, 0, 200 ) ) end + local sbar = clist:GetVBar() + sbar:SetSize( 0, 0 ) -- Remove the scroll bar + --- Close/quit button stuff --- local cW, cH = c:GetSize() c:SetPos( (clist.x + clist.w) - cW, clist.y + clist.h + cH ) 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 ) @@ -45,7 +52,7 @@ local pages = { header:SetFont( "q_header" ) header:SizeToContents() 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.Paint = function( self, w, h ) end @@ -54,16 +61,31 @@ local pages = { {name="Devoe", lvl=22}, {name="Leeroy", lvl=2} } + local cpanels = {} + local selectedChar + for k, v in pairs( chars ) do 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]:SetSize( clist.w - padding, 100 * resScale ) 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 ) surface.SetDrawColor( 0, 0, 0, 0 ) 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 local txt = vgui.Create( "DLabel", cpanels[k] ) @@ -72,11 +94,11 @@ local pages = { txt:SetTextColor( Color( 200, 200, 200, 220 ) ) txt:SizeToContents() 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 lvl = vgui.Create( "DLabel", cpanels[k] ) - lvl:SetText( "Level " .. v.lvl .. " Human" ) + lvl:SetText( "Level " .. v.lvl .. " Citizen" ) lvl:SetFont( "q_text2" ) lvl:SetTextColor( Color( 180, 180, 180, 225 ) ) lvl:SizeToContents() @@ -84,6 +106,22 @@ local pages = { lvl:SetPos( txtX, txtY + lvlH ) 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 end, charCreate = function( parent ) @@ -103,7 +141,7 @@ local pages = { } function menu.open( dt ) - + Quantum.Client.IsInMenu = true -- hide the hud if( !f ) then local f = vgui.Create( "DFrame" ) f:SetTitle( "Character Menu" ) @@ -114,6 +152,9 @@ function menu.open( dt ) end f:SetDraggable( false ) f:MakePopup() + function f:OnClose() + Quantum.Client.IsInMenu = false -- show the hud when closed + end local charSel = pages.charSelect( f ) -- test end