Networking stuff

master
AlmTech 5 years ago
parent 3366f68792
commit 3ef6fa6c8d
  1. 6
      gamemode/engine/core/client/cl_fonts.lua
  2. 2
      gamemode/engine/core/sh_player_binds.lua
  3. 85
      gamemode/engine/derma/menus/menu_character.lua
  4. 24
      gamemode/engine/lib/server/sv_character.lua
  5. 7
      gamemode/engine/lib/server/sv_networking.lua

@ -49,6 +49,12 @@ surface.CreateFont( "q_charNameText", {
antialias = true antialias = true
}) })
surface.CreateFont( "q_info", {
font = "Arial",
size = 30 * Quantum.Client.ResolutionScale,
antialias = true
})
surface.CreateFont( "q_header", { surface.CreateFont( "q_header", {
font = "Constantia Bold Italic", font = "Constantia Bold Italic",
size = 50 * Quantum.Client.ResolutionScale, size = 50 * Quantum.Client.ResolutionScale,

@ -13,7 +13,7 @@ if SERVER then
Quantum.Debug( tostring( pl ) .. " pressed IN_USE" ) Quantum.Debug( tostring( pl ) .. " pressed IN_USE" )
end, end,
["openCharMenu"] = function( pl ) ["openCharMenu"] = function( pl )
Quantum.Net.OpenMenu( pl, "character", Quantum.Server.Char.GetPlayerChars( pl ) ) Quantum.Net.OpenMenu( pl, "character", Quantum.Server.Char.GetPlayerChars_cl( pl ) )
end end
} }

@ -7,7 +7,7 @@
local menu = {} local menu = {}
local net = Quantum.Client.Menu.GetAPI( "net" ) local snm = Quantum.Client.Menu.GetAPI( "net" )
local page = Quantum.Client.Menu.GetAPI( "page" ) local page = Quantum.Client.Menu.GetAPI( "page" )
local theme = Quantum.Client.Menu.GetAPI( "theme" ) local theme = Quantum.Client.Menu.GetAPI( "theme" )
@ -56,9 +56,10 @@ local function checkNameString( name )
strTbl[i] = string.upper( char ) -- or if it is a space inbetween make it a capital one aswell strTbl[i] = string.upper( char ) -- or if it is a space inbetween make it a capital one aswell
end end
for n, char_ in pairs( strTbl ) do for n, char_ in pairs( strTbl ) do
if( n >= #strTbl && char == " " && strTbl[n-1] ~= " " ) then strTbl[i] = nil end -- remove the spaces at the end if( n >= #strTbl && char == " " && strTbl[n-1] ~= " " ) then strTbl[i] = " " end -- remove the spaces at the end
end end
end end
return table.concat( strTbl ) -- return the "fixed" name
end end
local pages = { local pages = {
@ -128,6 +129,7 @@ local pages = {
name:SetSize( 300 * resScale, 40 * resScale ) name:SetSize( 300 * resScale, 40 * resScale )
name.w, name.h = name:GetSize() name.w, name.h = name:GetSize()
name:SetPos( p.w/2 - name.w/2, p.h*0.85 - name.h/2 ) name:SetPos( p.w/2 - name.w/2, p.h*0.85 - name.h/2 )
name.x, name.y = name:GetPos()
name.Paint = function( self ) name.Paint = function( self )
theme.blurpanel( self ) theme.blurpanel( self )
self:DrawTextEntryText( Color( 255, 255, 255, 255 ), Color( 150, 150, 150, 255 ), Color( 100, 100, 100, 255 ) ) self:DrawTextEntryText( Color( 255, 255, 255, 255 ), Color( 150, 150, 150, 255 ), Color( 100, 100, 100, 255 ) )
@ -258,7 +260,7 @@ local pages = {
mscroll.w, mscroll.h = mscroll:GetSize() mscroll.w, mscroll.h = mscroll:GetSize()
mscroll:SetPos( 0, ip.h - mscroll.h ) mscroll:SetPos( 0, ip.h - mscroll.h )
mscroll:GetVBar():SetSize( 0, 0 ) mscroll:GetVBar():SetSize( 0, 0 )
mscroll.Paint = function( self ) theme.panel( self ) mscroll.Paint = function( self )
theme.borderpanel( self ) theme.borderpanel( self )
end end
@ -279,6 +281,22 @@ local pages = {
end end
end end
-- create char button --
local cr = vgui.Create( "DButton", p )
cr:SetText( "Create Character" )
cr:SetFont( "q_button2" )
cr:SetTextColor( Color( 0, 0, 0, 255 ) )
cr:SizeToContents()
cr.w, cr.h = cr:GetSize()
cr:SetPos( name.x + name.w/2 - cr.w/2, name.y + cr.h + padding )
cr.Paint = function( self ) theme.sharpbutton( self ) end
cr.DoClick = function( self )
surface.PlaySound( "UI/buttonclick.wav" )
-- create char
inputs.name = checkNameString( name:GetText() )
snm.RunNetworkedFunc( "createChar", inputs )
end
return p, c return p, c
end end
} }
@ -346,19 +364,22 @@ function menu.open( dt )
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
local chars = {} local chars = dt.cont -- set the char table
PrintTable( chars )
print( table.Count( chars ) )
local cpanels = {} local cpanels = {}
local selectedChar local selectedChar
if( selectedChar ) then if( table.Count( chars ) >= 1 ) then
print( "CREATE p.mdl")
-- Char model -- Char model
local mdl = vgui.Create( "DModelPanel", p ) p.mdl = vgui.Create( "DModelPanel", p )
mdl:SetSize( 600 * resScale, 1000 * resScale ) p.mdl:SetSize( 600 * resScale, 1000 * resScale )
mdl.w, mdl.h = mdl:GetSize() p.mdl.w, p.mdl.h = p.mdl:GetSize()
mdl:SetPos( p.w/2 - mdl.w/2, p.h/2 - mdl.h/2 ) p.mdl:SetPos( p.w/2 - p.mdl.w/2, p.h/2 - p.mdl.h/2 )
mdl:SetFOV( 55 ) p.mdl:SetFOV( 55 )
function mdl:LayoutEntity( ent ) return end function p.mdl:LayoutEntity( ent ) return end
else else
@ -378,41 +399,43 @@ function menu.open( dt )
end end
local count = 0
for k, v in pairs( chars ) do for k, v in pairs( chars ) do
cpanels[k] = vgui.Create( "DButton", clist ) count = count + 1
cpanels[count] = vgui.Create( "DButton", clist )
cpanels[k].char = v -- give the panel it's character cpanels[count].char = v -- give the panel it's character
if( !selectedChar ) then selectedChar = cpanels[1] end -- select the first one if( !selectedChar ) then selectedChar = cpanels[1] end -- select the first one
cpanels[k]:SetText( "" ) cpanels[count]:SetText( "" )
cpanels[k]:SetSize( clist.w - padding, 100 * resScale ) cpanels[count]:SetSize( clist.w - padding, 100 * resScale )
cpanels[k].w, cpanels[k].h = cpanels[k]:GetSize() cpanels[count].w, cpanels[count].h = cpanels[count]:GetSize()
cpanels[k]:SetPos( padding/2, (padding)*k + (cpanels[k].h * (k-1)) ) cpanels[count]:SetPos( padding/2, (padding)*count + (cpanels[count].h * (count-1)) )
cpanels[k].Paint = function( self, w, h ) cpanels[count].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 if( self == selectedChar ) then
surface.SetDrawColor( 252, 186, 3, 100 ) surface.SetDrawColor( 252, 186, 3, 100 )
surface.DrawOutlinedRect( 0, 0, w, h ) surface.DrawOutlinedRect( 0, 0, w, h )
end end
end end
cpanels[k].DoClick = function( self ) -- if you press the char, then select it cpanels[count].DoClick = function( self ) -- if you press the char, then select it
selectedChar = self selectedChar = self
surface.PlaySound( "UI/buttonclick.wav" ) surface.PlaySound( "UI/buttonclick.wav" )
mdl:SetModel( self.char.model || errorMdl ) p.mdl:SetModel( self.char.model || errorMdl )
end end
local txt = vgui.Create( "DLabel", cpanels[k] ) local txt = vgui.Create( "DLabel", cpanels[count] )
txt:SetText( v.name || "NAME" ) txt:SetText( v.name || "NAME" )
txt:SetFont( "q_charNameText" ) txt:SetFont( "q_charNameText" )
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/4 - txtH/2 ) txt:SetPos( padding, cpanels[count].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[count] )
lvl:SetText( "Level " .. v.lvl .. " Citizen" ) lvl:SetText( "Level " .. v.job.level .. " " .. v.job.title )
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()
@ -420,13 +443,13 @@ function menu.open( dt )
lvl:SetPos( txtX, txtY + lvlH ) lvl:SetPos( txtX, txtY + lvlH )
end end
if( selectedChar ) then if( selectedChar && p.mdl ~= nil ) then
mdl:SetModel( selectedChar.char.model ) -- set the char model p.mdl:SetModel( selectedChar.char.model ) -- set the char model
local minv, maxv = mdl.Entity:GetRenderBounds() local minv, maxv = p.mdl.Entity:GetRenderBounds()
local eyepos = mdl.Entity:GetBonePosition( mdl.Entity:LookupBone( "ValveBiped.Bip01_Head1" ) ) local eyepos = p.mdl.Entity:GetBonePosition( p.mdl.Entity:LookupBone( "ValveBiped.Bip01_Head1" ) )
eyepos:Add( Vector( 40, 0, -15 ) ) eyepos:Add( Vector( 40, 0, -15 ) )
mdl:SetCamPos( eyepos - Vector( -10, 0, -2 ) ) p.mdl:SetCamPos( eyepos - Vector( -10, 0, -2 ) )
mdl:SetLookAt( eyepos ) p.mdl:SetLookAt( eyepos )
end end
-- create char button -- create char button

@ -11,9 +11,10 @@ Quantum.Server.Char.Players = {}
local function CreateCharTable( args ) local function CreateCharTable( args )
return { return {
name = args.name || "UNKNOWN", name = args.name || "UNKNOWN",
class = Quantum.Classes[args.class] || Quantum.Classes[1],
maxhealth = Quantum.Server.Settings.MaxHealth, maxhealth = Quantum.Server.Settings.MaxHealth,
health = args.health || Quantum.Server.Settings.MaxHealth, health = args.health || Quantum.Server.Settings.MaxHealth,
model = args.model || "models/player.mdl", model = Quantum.Classes[args.class].Models[args.gender][args.modelIndex] || "models/player.mdl",
money = args.money || Quantum.Server.Settings.StarterMoney, money = args.money || Quantum.Server.Settings.StarterMoney,
inventory = args.inventory || {}, -- create new inventory later inventory = args.inventory || {}, -- create new inventory later
jobs = args.jobs || { jobs = args.jobs || {
@ -84,3 +85,24 @@ function Quantum.Server.Char.GetPlayerChars( pl )
end end
return chars return chars
end end
function Quantum.Server.Char.GetCharCount( pl )
return table.Count( Quantum.Server.Char.GetPlayerChars( pl ) ) || 0
end
local function getBasicCharInfo( char )
return {
name = char.name,
model = char.model,
class = char.class.Name,
job = char.jobs[1]
}
end
function Quantum.Server.Char.GetPlayerChars_cl( pl )
local chars = {}
for id, char in pairs( Quantum.Server.Char.GetPlayerChars( pl ) ) do
chars[id] = getBasicCharInfo( char )
end
return chars
end

@ -34,10 +34,10 @@ local function CacheDatatableMethod( id, datatable, ply )
end end
end end
end end
datatable.id = id -- give it the id so that the client side could handle it --datatable.id = id -- give it the id so that the client side could handle it
-- Always give the id since it is highly "valuable". -- Always give the id since it is highly "valuable".
-- Don't want the client mixing up the NPC, which this caching system could do if not handled correctly. -- Don't want the client mixing up the NPC, which this caching system could do if not handled correctly.
return datatable return { id = id, cont = datatable }
end end
local function SendDatatableToClient( client, dt, type ) local function SendDatatableToClient( client, dt, type )
@ -59,7 +59,8 @@ local funcs = {
local netfuncs = { local netfuncs = {
createChar = function( pl, args ) createChar = function( pl, args )
Quantum.Server.Char.Load( pl, 1, args ) pl.charcount = Quantum.Server.Char.GetCharCount( pl )
Quantum.Server.Char.Load( pl, pl.charcount + 1, args )
end end
} }

Loading…
Cancel
Save