/
derma_menus.lua
59 lines (34 loc) · 1.01 KB
/
derma_menus.lua
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
local tblOpenMenus = {}
function RegisterDermaMenuForClose( dmenu )
table.insert( tblOpenMenus, dmenu )
end
function DermaMenu( parentmenu, parent )
if ( !parentmenu ) then CloseDermaMenus() end
local dmenu = vgui.Create( "DMenu", parent )
return dmenu
end
function CloseDermaMenus()
for k, dmenu in pairs( tblOpenMenus ) do
if ( IsValid( dmenu ) ) then
dmenu:SetVisible( false )
if ( dmenu:GetDeleteSelf() ) then
dmenu:Remove()
end
end
end
tblOpenMenus = {}
hook.Run( "CloseDermaMenus" )
end
--
-- Here we detect when the mouse is pressed on another panel
-- This allows us to close the menus.
--
local function DermaDetectMenuFocus( panel, mousecode )
if ( IsValid( panel ) ) then
if ( panel.m_bIsMenuComponent ) then return end
-- Is the parent a menu?
return DermaDetectMenuFocus( panel:GetParent(), mousecode )
end
CloseDermaMenus()
end
hook.Add( "VGUIMousePressed", "DermaDetectMenuFocus", DermaDetectMenuFocus )