Main menu, character menu stuff

master
AlmTech Software 5 years ago
parent 09692b8a8e
commit 7c8eabcbed
  1. 209
      gamemode/engine/derma/menus/menu_character.lua
  2. 4
      gamemode/engine/lib/server/sv_character.lua

@ -11,6 +11,8 @@ 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" )
--local mainmenu = include( GAMEMODE.FolderName .. "/gamemode/engine/derma/menus/menu_main.lua" )
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
@ -130,7 +132,11 @@ local pages = {
gender = "Male", gender = "Male",
class = "Worker", class = "Worker",
modelIndex = 1, modelIndex = 1,
name = "" name = "",
job = {
title = "Unemployed",
level = -1
}
} }
local name = vgui.Create( "DTextEntry", p ) local name = vgui.Create( "DTextEntry", p )
@ -310,10 +316,38 @@ local pages = {
surface.PlaySound( "common/wpn_denyselect.wav" ) surface.PlaySound( "common/wpn_denyselect.wav" )
return return
else else
-- send it to the server
surface.PlaySound( "UI/buttonclick.wav" ) surface.PlaySound( "UI/buttonclick.wav" )
snm.RunNetworkedFunc( "createChar", inputs ) snm.RunNetworkedFunc( "createChar", inputs )
inputs.model = Quantum.Classes[inputs.class].Models[inputs.gender][inputs.index]
table.insert( Quantum.Client.Chars, inputs ) ---- save it on the client
inputs.model = Quantum.Classes[inputs.class].Models[inputs.gender][inputs.modelIndex]
Quantum.Client.Chars[#Quantum.Client.Chars + 1] = inputs
--refresh chars in dscrollpanel--
menu.charScroll.del( Quantum.Client.CharMenuList )
Quantum.Client.charPanels = menu.charScroll.add( Quantum.Client.Chars, Quantum.Client.CharMenuList, parent.page )
Quantum.Client.selectedChar = Quantum.Client.charPanels[#Quantum.Client.charPanels] -- select the newly created char
-- switching buttons & stuff
parent.page.info:Remove()
parent.page.mdl:SetVisible(true)
parent.page.mdl:SetModel( Quantum.Client.selectedChar.char.model )
local minv, maxv = parent.page.mdl.Entity:GetRenderBounds()
local eyepos = parent.page.mdl.Entity:GetBonePosition( parent.page.mdl.Entity:LookupBone( "ValveBiped.Bip01_Head1" ) )
eyepos:Add( Vector( 40, 0, -15 ) )
parent.page.mdl:SetCamPos( eyepos - Vector( -10, 0, -2 ) )
parent.page.mdl:SetLookAt( eyepos )
parent.page.enter:SetVisible(true)
parent.page.dl:SetVisible(true)
--close the page
parent.page:SetVisible( true )
p:Remove()
end end
end end
@ -327,16 +361,17 @@ menu.charScroll.del = function( clist )
panel:Remove() panel:Remove()
end end
end end
menu.charScroll.add = function( chars, clist ) menu.charScroll.add = function( chars, clist, p )
local count = 0 local count = 0
local cpanels = {} local cpanels = {}
PrintTable(chars)
for k, v in pairs( chars ) do for k, v in pairs( chars ) do
count = count + 1 count = count + 1
cpanels[count] = vgui.Create( "DButton", clist ) cpanels[count] = vgui.Create( "DButton", clist )
cpanels[count].index = count cpanels[count].index = count
cpanels[count].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( !Quantum.Client.selectedChar ) then Quantum.Client.selectedChar = cpanels[1] end -- select the first one
cpanels[count]:SetText( "" ) cpanels[count]:SetText( "" )
cpanels[count]:SetSize( clist.w - padding, 100 * resScale ) cpanels[count]:SetSize( clist.w - padding, 100 * resScale )
@ -345,13 +380,13 @@ menu.charScroll.add = function( chars, clist )
cpanels[count].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( self == selectedChar ) then if( self == Quantum.Client.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[count].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 Quantum.Client.selectedChar = self
surface.PlaySound( "UI/buttonclick.wav" ) surface.PlaySound( "UI/buttonclick.wav" )
p.mdl:SetModel( self.char.model || errorMdl ) p.mdl:SetModel( self.char.model || errorMdl )
end end
@ -393,12 +428,6 @@ menu.charScroll.add = function( chars, clist )
return clist.panels return clist.panels
end end
menu.charScroll.replace = function( clist, chars )
menu.charScroll.del(clist)
local panels = menu.charScroll.add( chars, clist )
return panels
end
function menu.open( dt ) function menu.open( dt )
Quantum.Client.IsInMenu = true -- hide the hud Quantum.Client.IsInMenu = true -- hide the hud
Quantum.Client.Chars = dt.cont Quantum.Client.Chars = dt.cont
@ -432,31 +461,32 @@ function menu.open( dt )
Quantum.Client.Cam.Start( scene[game.GetMap()], true ) Quantum.Client.Cam.Start( scene[game.GetMap()], true )
local args = { local args = {
CloseButtonText = "Quit", CloseButtonText = "Return",
CloseButtonFont = "q_text" CloseButtonFont = "q_text"
} }
local p, c = page.New( f, args ) local p, c = page.New( f, args )
f.page = p f.page = p
f.page:SetVisible( true ) f.page:SetVisible( true )
local clist = vgui.Create( "DScrollPanel", p ) Quantum.Client.CharMenuList = vgui.Create( "DScrollPanel", p )
clist:SetSize( 380 * resScale, sh - padding*15 ) Quantum.Client.CharMenuList:SetSize( 380 * resScale, sh - padding*15 )
clist.w, clist.h = clist:GetSize() Quantum.Client.CharMenuList.w, Quantum.Client.CharMenuList.h = Quantum.Client.CharMenuList:GetSize()
clist:SetPos( (sw - clist.w) - padding*2, padding*6 ) Quantum.Client.CharMenuList:SetPos( (sw - Quantum.Client.CharMenuList.w) - padding*2, padding*6 )
clist.x, clist.y = clist:GetPos() Quantum.Client.CharMenuList.x, Quantum.Client.CharMenuList.y = Quantum.Client.CharMenuList:GetPos()
clist.Paint = function( self, w, h ) Quantum.Client.CharMenuList.Paint = function( self, w, h )
theme.blurpanel( self ) theme.blurpanel( self )
end end
local sbar = clist:GetVBar() local sbar = Quantum.Client.CharMenuList:GetVBar()
sbar:SetSize( 0, 0 ) -- Remove the scroll bar 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( (Quantum.Client.CharMenuList.x + Quantum.Client.CharMenuList.w) - cW, Quantum.Client.CharMenuList.y + Quantum.Client.CharMenuList.h + cH )
c.Paint = function( self ) theme.button( self ) end c.Paint = function( self ) theme.button( self ) end
c.DoClick = function() c.DoClick = function()
surface.PlaySound( "UI/buttonclick.wav" ) surface.PlaySound( "UI/buttonclick.wav" )
--mainmenu.open(dt)
f:Close() f:Close()
end end
--- ---
@ -473,47 +503,53 @@ function menu.open( dt )
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 + ( clist.w/2 - headerW/2 ), (clist.y - headerH) + padding/2 ) header:SetPos( Quantum.Client.CharMenuList.x + ( Quantum.Client.CharMenuList.w/2 - headerW/2 ), (Quantum.Client.CharMenuList.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
local chars = dt.cont -- set the char table local chars = dt.cont -- set the char table
local cpanels = {} local cpanels = {}
local selectedChar
if( table.Count( Quantum.Client.Chars ) >= 1 ) then
-- Char model
p.mdl = vgui.Create( "DModelPanel", p )
p.mdl:SetSize( 600 * resScale, 1000 * resScale )
p.mdl.w, p.mdl.h = p.mdl:GetSize()
p.mdl:SetPos( p.w/2 - p.mdl.w/2, p.h/2 - p.mdl.h/2 )
p.mdl:SetFOV( 55 )
function p.mdl:LayoutEntity( ent ) return end
else
local titles = { -- Char model
"404 - Characters not found :(", p.mdl = vgui.Create( "DModelPanel", p )
"No Characters Found" p.mdl:SetSize( 600 * resScale, 1000 * resScale )
} p.mdl.w, p.mdl.h = p.mdl:GetSize()
p.mdl:SetPos( p.w/2 - p.mdl.w/2, p.h/2 - p.mdl.h/2 )
p.mdl:SetFOV( 55 )
function p.mdl:LayoutEntity( ent ) return end
p.mdl:SetVisible( false )
-- No char found text
local titles = {
"404 - Characters not found :(",
"No Characters Found"
}
local info = vgui.Create( "DLabel", p ) p.info = vgui.Create( "DLabel", p )
info:SetText( titles[ math.random( 1, #titles ) ] ) p.info:SetText( titles[ math.random( 1, #titles ) ] )
info:SetFont( "q_header" ) p.info:SetFont( "q_header" )
info:SizeToContents() p.info:SizeToContents()
info.w, info.h = info:GetSize() p.info.w, p.info.h = p.info:GetSize()
info:SetPos( p.w/2 - info.w/2, p.h/2 - info.h/2 ) p.info:SetPos( p.w/2 - p.info.w/2, p.h/2 - p.info.h/2 )
p.info:SetVisible( false )
if( table.Count( Quantum.Client.Chars ) >= 1 ) then
p.mdl:SetVisible( true )
p.info:SetVisible( false )
else
p.mdl:SetVisible( false )
p.info:SetVisible( true )
end end
----------------------------------------------------- -----------------------------------------------------
menu.charScroll.add( Quantum.Client.Chars, clist ) -- add the panels Quantum.Client.charPanels = menu.charScroll.add( Quantum.Client.Chars, Quantum.Client.CharMenuList, p ) -- add the panels
Quantum.Client.selectedChar = Quantum.Client.charPanels[1]
----------------------------------------------------- -----------------------------------------------------
if( selectedChar && p.mdl ~= nil ) then if( Quantum.Client.selectedChar && p.mdl ~= nil ) then
p.mdl:SetModel( selectedChar.char.model ) -- set the char model p.mdl:SetModel( Quantum.Client.selectedChar.char.model ) -- set the char model
local minv, maxv = p.mdl.Entity:GetRenderBounds() local minv, maxv = p.mdl.Entity:GetRenderBounds()
local eyepos = p.mdl.Entity:GetBonePosition( p.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 ) )
@ -529,7 +565,7 @@ function menu.open( dt )
cr:SetTextColor( Color( 0, 0, 0, 255 ) ) cr:SetTextColor( Color( 0, 0, 0, 255 ) )
cr:SizeToContents() cr:SizeToContents()
cr.w, cr.h = cr:GetSize() 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:SetPos( Quantum.Client.CharMenuList.x + ( Quantum.Client.CharMenuList.w/2 - cr.w/2 ), Quantum.Client.CharMenuList.y + ( ( Quantum.Client.CharMenuList.h - cr.h ) - padding*2 ) )
cr.Paint = function( self ) cr.Paint = function( self )
theme.sharpbutton( self ) theme.sharpbutton( self )
end end
@ -542,42 +578,47 @@ function menu.open( dt )
cr.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end cr.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end
end end
if( selectedChar ) then -- Delete char button
-- Delete char button p.dl = vgui.Create( "DButton", p )
local dl = vgui.Create( "DButton", p ) p.dl:SetText("Delete Character")
dl:SetText("Delete Character") p.dl:SetFont( "q_text" )
dl:SetFont( "q_text" ) p.dl:SetTextColor( Color( 0, 0, 0, 255 ) )
dl:SetTextColor( Color( 0, 0, 0, 255 ) ) p.dl:SizeToContents()
dl:SizeToContents() p.dl.w, p.dl.h = p.dl:GetSize()
dl.w, dl.h = dl:GetSize() p.dl:SetPos( Quantum.Client.CharMenuList.x, Quantum.Client.CharMenuList.y + ( Quantum.Client.CharMenuList.h + p.dl.h ) )
dl:SetPos( clist.x, clist.y + ( clist.h + dl.h ) ) p.dl.Paint = function( self )
dl.Paint = function( self ) theme.button( self )
theme.button( self ) end
end p.dl.DoClick = function()
dl.DoClick = function() surface.PlaySound( "UI/buttonclick.wav" )
surface.PlaySound( "UI/buttonclick.wav" ) LocalPlayer():ChatPrint( "Comming soon!" )
LocalPlayer():ChatPrint( "Comming soon!" ) end
end
dl.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end p.dl.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end
p.dl:SetVisible(false)
-- Enter world button --
p.enter = vgui.Create( "DButton", p ) -- Enter world button --
p.enter:SetText( "Enter World" ) p.enter = vgui.Create( "DButton", p )
p.enter:SetFont( "q_button2" ) p.enter:SetText( "Enter World" )
p.enter:SetTextColor( Color( 0, 0, 0, 255 ) ) p.enter:SetFont( "q_button2" )
p.enter:SizeToContents() p.enter:SetTextColor( Color( 0, 0, 0, 255 ) )
p.enter.w, p.enter.h = p.enter:GetSize() p.enter:SizeToContents()
p.enter:SetPos( p.w/2 - p.enter.w/2, p.h*0.925 - p.enter.h/2 ) p.enter.w, p.enter.h = p.enter:GetSize()
p.enter.Paint = function( self ) theme.sharpbutton( self ) end p.enter:SetPos( p.w/2 - p.enter.w/2, p.h*0.925 - p.enter.h/2 )
p.enter.DoClick = function() p.enter.Paint = function( self ) theme.sharpbutton( self ) end
surface.PlaySound( "UI/buttonclick.wav" ) p.enter.DoClick = function()
-- enter world -- surface.PlaySound( "UI/buttonclick.wav" )
local dt = { index = selectedChar.index } -- enter world --
snm.RunNetworkedFunc( "enterWorldChar", dt ) -- FIX CRASH ISSUE ( 0xC00000FD ) local dt = { index = Quantum.Client.selectedChar.index }
f:Close() -- close the frame snm.RunNetworkedFunc( "enterWorldChar", dt ) -- FIX CRASH ISSUE ( 0xC00000FD )
end f:Close() -- close the frame
p.enter.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end end
p.enter.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end
p.enter:SetVisible(false)
if( Quantum.Client.selectedChar ) then
p.enter:SetVisible(true)
p.dl:SetVisible(true)
end end
end end
end end

@ -104,8 +104,10 @@ end
function Quantum.Server.Char.GetPlayerChars_cl( pl ) function Quantum.Server.Char.GetPlayerChars_cl( pl )
local chars = {} local chars = {}
local count = 0
for id, char in pairs( Quantum.Server.Char.GetPlayerChars( pl ) ) do for id, char in pairs( Quantum.Server.Char.GetPlayerChars( pl ) ) do
chars[id] = getBasicCharInfo( char ) count = count + 1
chars[count] = getBasicCharInfo( char )
end end
return chars return chars
end end
Loading…
Cancel
Save