From ab0598a4a91adc988a79c42323fce9bfa43347e3 Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Mon, 30 Dec 2019 01:29:50 +0100 Subject: [PATCH] Inventory backend & menu stuff --- gamemode/engine/core/client/cl_fonts.lua | 12 +++++ gamemode/engine/core/sh_player_binds.lua | 7 ++- gamemode/engine/derma/lib/cl_menu_theme.lua | 8 +-- gamemode/engine/derma/menus/menu_charinfo.lua | 54 ++++++++++++++----- gamemode/engine/lib/server/sv_character.lua | 3 +- gamemode/engine/lib/sh_format.lua | 31 +++++++++++ gamemode/init.lua | 3 +- gamemode/settings/sh_settings.lua | 9 +++- 8 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 gamemode/engine/lib/sh_format.lua diff --git a/gamemode/engine/core/client/cl_fonts.lua b/gamemode/engine/core/client/cl_fonts.lua index 8f3c272..07e500b 100644 --- a/gamemode/engine/core/client/cl_fonts.lua +++ b/gamemode/engine/core/client/cl_fonts.lua @@ -77,4 +77,16 @@ surface.CreateFont( "q_subtitle", { font = "Cambria Bold", size = 38 * Quantum.Client.ResolutionScale, antialias = true +}) + +surface.CreateFont( "q_name", { + font = "Cambria Bold", + size = 38 * Quantum.Client.ResolutionScale, + antialias = true +}) + +surface.CreateFont( "q_money", { + font = "Cambria Bold", + size = 42 * Quantum.Client.ResolutionScale, + antialias = true }) \ No newline at end of file diff --git a/gamemode/engine/core/sh_player_binds.lua b/gamemode/engine/core/sh_player_binds.lua index 3f887bc..bdf4d53 100644 --- a/gamemode/engine/core/sh_player_binds.lua +++ b/gamemode/engine/core/sh_player_binds.lua @@ -13,7 +13,12 @@ if SERVER then Quantum.Net.OpenMenu( pl, "main", { chars = Quantum.Server.Char.GetPlayerChars_cl( pl ), resume = true } ) end, ["charinfo"] = function( pl ) - Quantum.Net.OpenMenu( pl, "charinfo", { char = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ) } ) + Quantum.Net.OpenMenu( pl, "charinfo", { char = { + model = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).model, + name = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).name, + money = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).money + + }, items = {} } ) end } diff --git a/gamemode/engine/derma/lib/cl_menu_theme.lua b/gamemode/engine/derma/lib/cl_menu_theme.lua index 0dc8f89..ac05564 100644 --- a/gamemode/engine/derma/lib/cl_menu_theme.lua +++ b/gamemode/engine/derma/lib/cl_menu_theme.lua @@ -126,10 +126,10 @@ function theme.skipbutton( b, inClr ) surface.DrawRect( padding_s/2, padding_s/2, w - padding_s, h - padding_s ) end -function theme.pagetitle( b ) - local w, h = b:GetSize() +function theme.pagetext( p ) + local w, h = p:GetSize() - b:SetTextColor( Color( 205, 205, 205, 255 ) ) + p:SetTextColor( Color( 205, 205, 205, 255 ) ) surface.SetDrawColor( Color( 0, 0, 0, 0 ) ) surface.DrawRect( 0, 0, w, h ) @@ -143,7 +143,7 @@ function theme.itempanel( p ) if( p:IsHovered() ) then theme.borderpanel( p, Color( 116, 185, 255, 90 ) ) else - theme.borderpanel( p, Color( 255, 255, 255, 150 ) ) + theme.borderpanel( p, Color( 255, 255, 255, 200 ) ) end end diff --git a/gamemode/engine/derma/menus/menu_charinfo.lua b/gamemode/engine/derma/menus/menu_charinfo.lua index df4a521..7713a20 100644 --- a/gamemode/engine/derma/menus/menu_charinfo.lua +++ b/gamemode/engine/derma/menus/menu_charinfo.lua @@ -55,7 +55,7 @@ function menu.open( dt ) title:SetFont( "q_header_s" ) title:SetTextColor( Color( 255, 255, 255, 255 ) ) title.Paint = function( self ) - theme.pagetitle( self ) + theme.pagetext( self ) end title:SizeToContents() @@ -80,15 +80,6 @@ function menu.open( dt ) ent:SetEyeTarget( eyepos + Vector( 40, -5, 2 ) ) function char:LayoutEntity( Entity ) return end - - ---- TEMPORARY: REMOVE WHEN THE MENU IS DONE ---- - local close = vgui.Create( "DButton", f ) - close:SetText( "DEV CLOSE" ) - close:SizeToContents() - close.w, close.h = close:GetSize() - close:SetPos( 0, f.h - close.h ) - close.DoClick = function( self ) f:Close() end - ---- Inventory panel ---- local inv = vgui.Create( "DPanel", f ) -- section for all of the item panels @@ -100,7 +91,7 @@ function menu.open( dt ) surface.DrawRect( 0, 0, w, h ) end - local itemWidth, itemHeight = 70 * resScale, 70 * resScale + local itemWidth, itemHeight = 65 * resScale, 65 * resScale local maxW, maxH = Quantum.Inventory.Width, Quantum.Inventory.Height local itempanels = {} @@ -115,7 +106,7 @@ function menu.open( dt ) itemframe:SetSize( inv:GetSize() ) itemframe:SetPos( 0, 0 ) itemframe.Paint = function( self, w, h ) - surface.SetDrawColor( 0, 0, 0, 10 ) + surface.SetDrawColor( 0, 0, 0, 0 ) surface.DrawRect( 0, 0, w, h ) end @@ -148,7 +139,44 @@ function menu.open( dt ) local iwidth, iheight = (itempanels[maxW].x - xbasepos) + itemWidth, (itempanels[#itempanels].y - ybasepos) + itemHeight itemframe:SetSize( iwidth, iheight ) -- set the frames dimensions to all of the items dimensions combined. itemframe.w, itemframe.h = itemframe:GetSize() - itemframe:SetPos( inv.w/2 - itemframe.w/2, inv.h/2 - itemframe.h/2 ) -- center the item panels + itemframe:SetPos( inv.w/2 - itemframe.w/2, inv.h/2 - itemframe.h/2 + padding*8 ) -- center the item panels + itemframe.x, itemframe.y = itemframe:GetPos() + + ----CHAR INFO---- + + --Money text + local money = vgui.Create( "DLabel", inv ) + money:SetText( Quantum.Format.Money( dt.cont.char.money ) ) + money:SetFont( "q_money" ) + money:SetTextColor( Color( 90, 218, 132, 255 ) ) + money:SizeToContents() + money.w, money.h = money:GetSize() + money:SetPos( itemframe.x, itemframe.y - money.h - padding ) + money.x, money.y = money:GetPos() + money.Paint = function( self, w, h ) + draw.RoundedBox( 5, 0, 0, w, h, Color( 0, 0, 0, 90 ) ) + end + + + --Name text + local name = vgui.Create( "DLabel", inv ) + name:SetText( dt.cont.char.name || "ERROR: NAME=nil" ) + name:SetFont( "q_name" ) + name:SizeToContents() + name.w, name.h = name:GetSize() + name:SetPos( itemframe.x, money.y - name.h - padding ) + name.Paint = function( self, w, h ) + draw.RoundedBox( 5, 0, 0, w, h, Color( 0, 0, 0, 90 ) ) + theme.pagetext( self ) + end + + ---- TEMPORARY: REMOVE WHEN THE MENU IS DONE ---- + local close = vgui.Create( "DButton", f ) + close:SetText( "DEV CLOSE" ) + close:SizeToContents() + close.w, close.h = close:GetSize() + close:SetPos( 0, f.h - close.h ) + close.DoClick = function( self ) f:Close() end end end diff --git a/gamemode/engine/lib/server/sv_character.lua b/gamemode/engine/lib/server/sv_character.lua index db5e8bd..274d821 100644 --- a/gamemode/engine/lib/server/sv_character.lua +++ b/gamemode/engine/lib/server/sv_character.lua @@ -99,7 +99,8 @@ function Quantum.Server.Char.getBasicCharInfo( char ) name = char.name, model = char.model, class = char.class.Name, - job = char.jobs[1] + job = char.jobs[1], + money = char.money } end diff --git a/gamemode/engine/lib/sh_format.lua b/gamemode/engine/lib/sh_format.lua new file mode 100644 index 0000000..8170a24 --- /dev/null +++ b/gamemode/engine/lib/sh_format.lua @@ -0,0 +1,31 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +Quantum.Format = {} + +local function addMoneyVal( num ) + return Quantum.Money.Prefix .. tostring( num ) .. Quantum.Money.Surfix +end + +function Quantum.Format.Money( num ) + if( num == nil ) then return addMoneyVal( 0 ) end + if( num >= 1e14 ) then + return addMoneyVal( num ) + elseif( num <= -1e14 ) then + return addMoneyVal( "-" .. tostring( math.abs( num ) ) ) + end + + num = tostring( math.abs( num ) ) + local sep = sep || "," + local dp = string.find( num, "%." ) || #num + 1 + + for i = dp - 4, 1, -3 do + num = num:sub( 1, i ) .. sep .. num:sub( i + 1 ) + end + + return ( negative && "-" || "" ) .. addMoneyVal( num ) +end \ No newline at end of file diff --git a/gamemode/init.lua b/gamemode/init.lua index eb7af43..d17307f 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -106,6 +106,7 @@ if SERVER then loadLibFiles() addAllDermaMenus() end - + Quantum.Server.Load() + MsgC( "\n" ) end diff --git a/gamemode/settings/sh_settings.lua b/gamemode/settings/sh_settings.lua index ed88a71..13f91c9 100644 --- a/gamemode/settings/sh_settings.lua +++ b/gamemode/settings/sh_settings.lua @@ -13,8 +13,13 @@ Quantum.DiscordInvite = "https://discord.gg/heUJB4B" Quantum.WorkshopLink = "https://steamcommunity.com/sharedfiles/filedetails/?id=1842234130" Quantum.Inventory = { - Height = 12, -- NOTE: MAX HEIGHT=12 - Width = 18 -- NOTE: MAX WIDTH=18 + Height = 10, -- NOTE: MAX HEIGHT=12 + Width = 16 -- NOTE: MAX WIDTH=18 +} + +Quantum.Money = { + Prefix = "$", + Surfix = "" } Quantum.Models = {