aboutsummaryrefslogtreecommitdiff
path: root/gamemode/inventorysystem/skills/cl_skills.lua
blob: c324a49ced8d7ad596eded7b7414a69280a7b657 (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
local inv = {}
--[[
inv.allskills = {
	["forageing"] = {
		"hunting",
		"butchering",
		"woodcutting",
		"plant identification",
	},
	["farming"] = {
		"domestication",
		"sowing",
		"arboriculture",
		"apiarism",
		"reaping",
		"fishing",
	},
	["artisanship"] = {
		"pottery",
		"glass blowing",
		"cooking",
		"tanning",
		"tailoring",
		"metalworking",
		"lockpicking",
		"herbalism",
		"alchemy",
		"jewlery",
	},
	["culture"] = {
		"litteracy",
		"writeing",
		"speech",
		"negotiation",
		"painting",
		"performing",
	},
	["adventuring"] = {
		"polearm",
		"axeplay",
		"swordplay",
		"knifeing",
		"fenceing",
		"lockpicking",
		"archery",
		"throwing",
	},
}
]]
--the gui elements
local elements = {}

--return level, frac
local xpmult = 1.5 --the lower, the more lvl per xp
local levelfunc = function(val)
	local curlvl = math.log(val,xpmult)
	local prevlvlxp = xpmult ^ math.floor(curlvl)
	local nextlvlxp = xpmult ^ (math.floor(curlvl) + 1)
	local sp = nextlvlxp - prevlvlxp
	local frac = (val - prevlvlxp) / ((sp ~= 0) and sp or 1) --don't divide by 0
	return math.floor(curlvl), frac
end

local set_xp_of = function(name,ammt)
	local lvl,frac = levelfunc(ammt)
	elements[name].label:SetText(string.format("%s : %d (%d%%)",name,lvl,frac))
	elements[name].bar:SetFraction(frac)
end

inv.DrawOnDPanel = function(self,panel)
	print("Drawing skills on panel")
	local sheet = vgui.Create( "DColumnSheet", panel )
	sheet:Dock( FILL )

	for k,v in pairs(self.allskills) do
		local spanel = vgui.Create("DPanel", sheet)
		spanel:Dock(FILL)
		local layout = vgui.Create("DListLayout", spanel)
		layout:MakeDroppable("skill_layout")
		for i,j in pairs(v) do
			local ipanel = vgui.Create("DListLayout",layout)
			local label = vgui.Create("DLabel",ipanel)
			label:Dock(TOP)
			label:SetDark(true)
			local bar = vgui.Create("DProgress",ipanel)
			bar:Dock(TOP)
			elements[j] = {
				["label"] = label,
				["bar" ] = bar,
			}
			set_xp_of(j,self.skills[j])
			ipanel:Add(label)
			ipanel:Add(bar)
			ipanel:InvalidateLayout()
			ipanel:SizeToChildren(true,true)
			layout:Add(ipanel)
		end
		layout:Dock(FILL)
		sheet:AddSheet(k, spanel, "icon16/cross.png")
	end

	local prox = {}
	prox.Put = function(s,position,item)
		set_xp_of(position[1],s[position[1]])
	end

	prox.Remove = function(s,position)
		set_xp_of(position[1],s[position[1]])
	end

	return prox
end

return inv