Added TAB bind to Inventory & Major optimizations

master
AlmTech Software 5 years ago
parent 5e92215da7
commit 48dde3981b
  1. 4
      gamemode/cl_init.lua
  2. 8
      gamemode/engine/core/client/cl_character_net.lua
  3. 17
      gamemode/engine/core/sh_player_binds.lua
  4. 55
      gamemode/engine/derma/menus/menu_charinfo.lua
  5. 2
      gamemode/engine/derma/menus/menu_main.lua
  6. 2
      gamemode/engine/lib/server/sv_inventory.lua
  7. 27
      gamemode/engine/lib/server/sv_networking.lua
  8. 2
      gamemode/settings/sv_settings.lua

@ -7,8 +7,8 @@
if CLIENT then
include( "shared.lua" )
Quantum.Client = {}
Quantum.Client.Cache = {}
Quantum.Client = Quantum.Client || {}
Quantum.Client.Cache = Quantum.Client.Cache || {}
Quantum.Client.ResolutionScale = ScrH() / 1080
Quantum.Client.ServerBannerPath = "gamemodes/" .. GM.FolderName .. "/gamemode/content/materials/quantum/server_banner.png"

@ -34,10 +34,10 @@ net.Receive( "quantum_item_action", function( len, pl ) -- used for updating the
intcodeFunctions[intcode]( index, itemid, amount )
end)
net.Receive( "quantum_item_update", function( len, pl )
local dtInv = net.ReadTable()
Quantum.Client.Inventory = dtInv || {}
Quantum.Debug( "Updated inventory." )
net.Receive( "quantum_char_update", function( len, pl )
Quantum.Client.Inventory = net.ReadTable() || {}
Quantum.Client.Character = net.ReadTable()
Quantum.Debug( "Updated character." )
end)
function Quantum.Client.InventoryNet.DropItem( itemid, index, amount )

@ -11,28 +11,11 @@ if SERVER then
local keyfuncs = {
["mainMenu"] = function( pl )
Quantum.Net.OpenMenu( pl, "main", { chars = Quantum.Server.Char.GetPlayerChars_cl( pl ), resume = true } )
end,
["charinfo"] = function( 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 = Quantum.Server.Char.GetInventory( Quantum.Server.Char.GetCurrentCharacter( pl ) ) })
end,
["charinfo_DYNAMIC"] = function( 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
} })
end
}
function GM:KeyRelease( ply, key )
if( keyfuncs[key] ) then keyfuncs[key]( ply ) end
end
function GM:ShowHelp( ply ) keyfuncs["mainMenu"]( ply ) end
function GM:ShowTeam( ply ) keyfuncs["charinfo_DYNAMIC"]( ply ) end
end

@ -29,15 +29,7 @@ local function createItemAmountLabel( icon, item )
end
function menu.open( dt )
local items = {}
if( dt.cont.items == nil ) then
if( Quantum.Client.Inventory == nil ) then Quantum.Client.Inventory = {} end
items = Quantum.Client.Inventory -- dynamic networking
else
items = dt.cont.items -- static, only sent when menu opens which is rareley in this case
Quantum.Client.Inventory = items
end
-- The dynamic part will be used more often, but sometimes we need the static/old method
local items = Quantum.Client.Inventory
if( !f ) then
Quantum.Client.IsInMenu = true
@ -59,6 +51,18 @@ function menu.open( dt )
Quantum.Client.Cam.Stop()
end
local keycodesClose = {
[KEY_ESCAPE] = true,
[KEY_F2] = true,
[KEY_TAB] = true
}
function f:OnKeyCodeReleased( keyCode )
if( keycodesClose[keyCode] ) then
self:Close()
end
end
Quantum.Client.CurMenu = f
-- Default is the inventory page --
@ -90,7 +94,7 @@ function menu.open( dt )
char:SetPos( 0, bar.h )
char.x, char.y = char:GetPos()
char:SetFOV( 25 )
char:SetModel( dt.cont.char.model || errorMdl )
char:SetModel( Quantum.Client.Character.model || errorMdl )
char:SetDirectionalLight( BOX_FRONT, Color( 116, 205, 255 ) )
local ent = char.Entity
@ -128,14 +132,6 @@ function menu.open( dt )
itemframe:SetPos( 0, 0 )
itemframe.Paint = function( self, w, h ) 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
for ii=1, maxW * maxH, 1 do -- create all of the item panels
if( ii != 1 ) then count = count + 1 end
@ -254,7 +250,7 @@ function menu.open( dt )
--Money text
local money = vgui.Create( "DLabel", inv )
money:SetText( Quantum.Format.Money( dt.cont.char.money ) )
money:SetText( Quantum.Format.Money( Quantum.Client.Character.money ) )
money:SetFont( "q_money" )
money:SetTextColor( Color( 90, 218, 132, 255 ) )
money:SizeToContents()
@ -265,10 +261,9 @@ function menu.open( dt )
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:SetText( Quantum.Client.Character.name || "ERROR: NAME=nil" )
name:SetFont( "q_name" )
name:SizeToContents()
name.w, name.h = name:GetSize()
@ -278,9 +273,23 @@ function menu.open( dt )
theme.pagetext( self )
end
end
end
hook.Add("ScoreboardShow", "Quantum_Menu_CharInfo_Open", function() --Quantum.Server.Inventory.GiveItem( Entity(1), "test2", 21 )
-- if( InventoryStartTime == nil ) then
-- InventoryStartTime = CurTime()
-- end
-- if( InventoryStartTime + 1 <= CurTime() ) then
-- menu.open()
-- InventoryStartTime = nil
-- end -- open the menu
menu.open()
return false
end)
return menu

@ -50,6 +50,8 @@ local scenes = {
function main.open(dt)
if( !f ) then
if( IsValid( Quantum.Client.CurMenu ) ) then Quantum.Client.CurMenu:Close() end
Quantum.Client.IsInMenu = true -- hide the hud
local resScale = Quantum.Client.ResolutionScale

@ -222,7 +222,7 @@ function Quantum.Server.Inventory.DropItem( pl, index, amount ) -- Quantum.Serve
local itemEnt = ents.Create( "q_item" )
if( IsValid( itemEnt ) ) then
itemEnt:SetModel( item.model )
itemEnt:SetPos( pl:GetPos() + pl:GetForward() )
itemEnt:SetPos( pl:GetPos() + ( pl:GetForward() * 40 ) + Vector( 0, 0, 40 ) )
itemEnt.amount = amount
itemEnt.itemid = itemid
itemEnt:Spawn()

@ -9,7 +9,7 @@ Quantum.Net = {}
util.AddNetworkString( "quantum_menu_net" )
util.AddNetworkString( "quantum_menu_button_net" )
util.AddNetworkString( "quantum_item_action" )
util.AddNetworkString( "quantum_item_update" )
util.AddNetworkString( "quantum_char_update")
local function checkCacheTable( ply, cache_id, dt )
Quantum.Debug( "Checking cache tables (" .. tostring(ply) .. " | " .. tostring(cache_id) .. " | " .. tostring(dt) .. ")" )
@ -132,9 +132,14 @@ function Quantum.Net.Inventory.SetItem( pl, index, itemid, amount ) -- sends a i
end
function Quantum.Net.Inventory.Update( pl )
Quantum.Debug( "Updating " .. tostring(pl) .. " inventory." )
net.Start( "quantum_item_update" )
net.WriteTable( Quantum.Server.Char.GetInventory( Quantum.Server.Char.GetCurrentCharacter( pl ) ) )
Quantum.Debug( "Updating " .. tostring(pl) .. " character." )
local charTbl = Quantum.Server.Char.GetCurrentCharacter( pl )
local char = { money = charTbl.money, model = charTbl.model, name = charTbl.name }
net.Start( "quantum_char_update" )
net.WriteTable( Quantum.Server.Char.GetInventory( charTbl ) )
net.WriteTable( char )
net.Send( pl )
end
@ -156,3 +161,17 @@ net.Receive( "quantum_item_action", function( len, pl )
intcodeFunctions[intcode]( pl, index, itemid, amount )
end)
local function UpdateAllPlayers()
for i, pl in pairs( player.GetHumans() ) do
pl.isloaded = false
pl:KillSilent()
pl:Spawn()
Quantum.Net.Inventory.Update( pl )
end
end
if( !Quantum.Server.Settings.DeveloperMode ) then
UpdateAllPlayers() -- Update the players on auto-refresh / lua-refresh
end

@ -7,6 +7,8 @@
Quantum.Server.Settings = {}
Quantum.Server.Settings.DeveloperMode = false
Quantum.Server.Settings.VoiceChatRange = 400
Quantum.Server.Settings.MaxHealth = 100

Loading…
Cancel
Save