aboutsummaryrefslogtreecommitdiff
path: root/gamemode/client/cl_inventory.lua
blob: b1f57282c146e12dd1cd957aaec74da4a0dc74b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
--[[
    Displays the inventory, for more information see /gamemode/shared/inventory.lua
]]
--[[
	Reserved inventory id's
	1 - Equipment
	2 - Prayers
	3 - Skills
	4 - Quests
]]
local qinv = nrequire("cl_qinventory.lua")
local state = nrequire("cl_state.lua") --Holds weather or not player is in inventory
--local qpray = nrequire("cl_qprayers.lua")

print("Hello from cl_inventory.lua")
--debug.Trace()

local prayerequiped = {
	false,false,false,false,false
}

net.Receive("equiphelpprayer",function()
	print("equiphelp received client side!")
	prayerequiped[4] = "Noob Help"
end)

local lastpanel = lastpanel or 1

local qframe = nil	--The master frame
local qtabs = {}	--The tabs

local width = ScrW()
local height = ScrH()

local player_data --The data the player needs to show the q panel
net.Receive("art_load_player_data",function()
	print("Got player data")
	player_data = net.ReadTable()
	print("It was")
	PrintTable(player_data)
end)

local function BuildInventory()
	print("Building inventory")
	if qframe then return end
	if not player_data then print("no player data!") return end
	qframe = vgui.Create("DFrame")
	qframe:SetPos(0,0)
	qframe:SetSize(width / 4, height)
	qframe:SetTitle("Inventory")
	qframe:SetDraggable(true)
	qframe:MakePopup()
	qframe.OnClose = function(self)
		state.invopen = false
		self:Hide()
		return
	end
	qframe.Remove = function(self)
		state.invopen = false
		self:Hide()
		return
	end
	local tabsheet = vgui.Create("DPropertySheet",qframe)
	tabsheet:Dock(FILL)

	local invsheet = qinv.CreateInventorySheet(tabsheet)
	--qpray.CreatePrayerSheet(tabsheet)
	invsheet.id = #qtabs + 1
	qtabs[#qtabs + 1] = invsheet
	--prasheet.id = #qtabs + 1
	--qtabs[#qtabs + 1] = prasheet
	tabsheet:AddSheet("Inventory",invsheet,"icon16/user.png")
	--tabsheet:AddSheet("Prayers",prasheet,"icon16/user.png")

end

local function ShowInventory()
	print("qframe is ", qframe)
	if not qframe then BuildInventory()
	else qframe:Show() end
	state.invopen = true
end



hook.Add("OnSpawnMenuOpen","ArteryOpenInventory",ShowInventory)
hook.Add("OnSpawnMenuClose","ArteryCloseInventory",function()
	state.invopen = false
	qframe:Hide()
	if (not sheet) or (not sheet:GetActiveTab()) or (not sheet:GetActiveTab():GetPanel()) then return end
	lastpanel = sheet:GetActiveTab():GetPanel().sheetnum
	for k,v in pairs(LocalPlayer().invdisplays) do
		if not v.panel:IsValid() then continue end
		--PrintTable(v)
		v.panel:Close()
		LocalPlayer().invdisplays[k] = nil
	end
end)

concommand.Add("showinventory",ShowInventory)
local viewdistance = 100
local rotatespeed = 65
local bone = nil
local previousheadscale = Vector(1,1,1)
hook.Add("CalcView","ArteryInventoryView",function(ply,pos,ang,fov,nearz,farz)
	if bone == nil then
		bone = LocalPlayer():LookupBone("ValveBiped.Bip01_Head1")
	end
	local view = {}
	--view.origin = LocalPlayer():GetBonePosition(bone) + LocalPlayer():GetUp() * 2
	view.origin = pos
	if state.invopen then
		local trot = math.rad(CurTime() * rotatespeed)
		local xoff = viewdistance * math.sin(trot)
		local yoff = viewdistance * math.cos(trot)
		view.origin = view.origin + Vector(xoff,yoff,10)
		ang.pitch = 20
		ang.yaw = (-CurTime() * rotatespeed) - 90
	end
	view.angles = ang
	view.fov = fov
	if not state.invopen then
		LocalPlayer():ManipulateBoneScale(bone,Vector(0,0,0))
	else
		LocalPlayer():ManipulateBoneScale(bone,previousheadscale)
	end
	view.drawviewer = state.invopen

	return view
end)