summaryrefslogtreecommitdiff
path: root/gamemode/cl_hud/vgui/mbtree.lua
blob: e2be877bbf9bff16ad5d14fe40c61df6715e8236 (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
local PANEL = {}

function PANEL:Init()
	self.bgcol 	  = MAIN_COLOR2
	self.hovercol = MAIN_COLORD
	self.foldecol = MAIN_COLORD2
	self.selecCol = MAIN_GREENCOLOR

	self.VBar.Paint 		= function(s) end
	self.VBar.btnGrip.Paint = function(s) DrawRect( 2 , 0 , s:GetWide()-4 , s:GetTall() , self.bgcol ) end
	self.VBar.btnDown.Paint = function(s) DrawRect( 2 , 2 , s:GetWide()-4 , s:GetTall()-4 , self.bgcol ) end
	self.VBar.btnUp.Paint 	= function(s) DrawRect( 2 , 2 , s:GetWide()-4 , s:GetTall()-4 , self.bgcol ) end
	
	self.Delta 		= 0
	self.Smooth 	= 0
	self.BGEnabled 	= true
end

function PANEL:OnMouseWheeled(Delta)
	self.Delta = self.Delta+Delta
end

function PANEL:SetVScroll(num)
	self.VBar:SetScroll(num)
end

function PANEL:AddVScroll(num)
	self.VBar:AddScroll(num)
end

function PANEL:SetBGColor( col )
	self.bgcol = col
end

function PANEL:EnableNodeBG( bool ) 
	self.BGEnabled = bool
end

function PANEL:AddNode( text )
	local V = self.BaseClass.AddNode( self, text )
	 
	V.BGEnabled = self.BGEnabled
	
	V.FolCol   	= self.foldecol
	V.HovCol   	= self.hovercol
	V.SelCol 	= self.selecCol
	V.OAddNode 	= V.AddNode
	
	V.Label:SetFont("Trebuchet18")
	V.Label.Paint = function(s,w,h) 
		if (V:HasChildren() and V.BGEnabled) then DrawRect( 0 , 1 , w , h-2 , V.FolCol )
		elseif (!V:HasChildren() and self:GetSelectedItem()==V) then DrawRect( 0 , 1 , w , h-2 , V.SelCol )
		elseif (V.Hovered) then DrawRect( 0 , 1 , w , h-2 , V.HovCol ) end 
	end
		
	V.AddNode  = function(s,txt)
		local D = s.OAddNode(s,txt)
		
		D.FolCol  	= s.FolCol
		D.HovCol  	= s.HovCol
		D.SelCol 	= s.SelCol
		D.BGEnabled = s.BGEnabled
		
		D.Label:SetFont("Trebuchet18")
		
		D.Label.Paint = function(p,w,h) 
			if (D:HasChildren() and D.BGEnabled) then DrawRect( 0 , 1 , w , h-2 , D.FolCol ) 
			elseif (!D:HasChildren() and self:GetSelectedItem()==D) then DrawRect( 0 , 1 , w , h-2 , D.SelCol )
			elseif (D.Hovered) then DrawRect( 0 , 1 , w , h-2 , D.HovCol ) end
		end
		
		D.OAddNode = D.AddNode
		D.AddNode = s.AddNode
		
		return D
	end
	
	return V
end

function PANEL:Think()
	if (self.Delta > 0.01 or self.Delta < -0.01 or self.Smooth > 0.01 or self.Smooth < -0.01) then
		self.Delta = self.Delta - self.Delta/8
		self.Smooth = self.Smooth + (self.Delta-self.Smooth)/32
		self:AddVScroll(-self.Smooth/2)
	end
end

function PANEL:Paint()
end

vgui.Register( "MBTree", PANEL , "DTree" )