
Originally Posted by
Cyaegha
Then post what you're trying to do.
Make is so that when you click insert the menu opens and then you drag the menu to a certain position on your screen and then you press insert to close the menu and when you click insert again to open it the menu would be in the same place you dragged it to.
Code:
local menuframe, menudown
local ToggleMenu = function()
if (menuframe) then
menuframe:SetVisible(false)
menuframe = nil
return
end
local dframe = vgui.Create("DFrame")
dframe:SetSize(800, 400)
dframe:Center()
dframe:MakePopup(true)
dframe:SetVisible(true)
local oThink = dframe.Think
dframe.Think = function(self)
local mousex = math.Clamp( gui.MouseX(), 1, ScrW() - 1 )
local mousey = math.Clamp( gui.MouseY(), 1, ScrH() - 1 )
if ( self.Dragging ) then
local x = mousex - self.Dragging[1]
local y = mousey - self.Dragging[2]
if ( self:GetScreenLock() ) then
x = math.Clamp( x, 0, ScrW() - self:GetWide() )
y = math.Clamp( y, 0, ScrH() - self:GetTall() )
end
self:SetPos( x, y )
end
if ( self.Hovered && self:GetDraggable() && mousey < ( self.y + 24 ) ) then
self:SetCursor( "arrow" )
return
end
self:SetCursor( "arrow" )
if ( self.y < 0 ) then
self:SetPos( self.x, 0 )
end
return oThink(self)
end
menuframe = dframe
end
hook.Add("Think", "you really should put an identifier here", function()
local down = input.IsButtonDown(KEY_INSERT)
if (down and !menudown) then
ToggleMenu()
end
menudown = down
end)