Close all frames

Hello.



local function showmenu()
InvFrameOn = false
if input.IsKeyDown(KEY_F2) and InvFrameOn == false then
	InvFrameOn = true
	-- Lua generated by DermaDesigner
	local DFrame1

	DFrame1 = vgui.Create('DFrame')
	DFrame1:SetSize(449, 326)
	DFrame1:Center()
	DFrame1:SetTitle('Inventory')
	DFrame1:SetSizable(false)
	DFrame1:MakePopup()
	
	-- End DD lua
	
	local sheet = vgui.Create("DPropertySheet")
	sheet:SetParent(DFrame1)
	sheet:SetPos(5,25)
	sheet:SetSize(439, 296)
	
	-- ITEMS --
	
	local list1 = vgui.Create("DPanelList")
	list1:SetSize(439, 296)
	list1:SetSpacing( 5 )
	list1:EnableHorizontal( false )
	list1:EnableVerticalScrollbar( true )
	
	for k,v in pairs(cl_inv) do
		local DPanel1 = vgui.Create('DPanel')
		DPanel1:SetSize(419, 74)
		
		local info = items[k] -- should be faster...
		
		local icon = vgui.Create("SpawnIcon", DPanel1)
		icon:SetModel(info.model)
		icon:SetPos(5,5)
		icon:SetMouseInputEnabled(false)
		
		local name = vgui.Create("DLabel", DPanel1)
		name:SetText(info.name)
		name:SizeToContents()
		name:SetPos(89, 5)
		
		local desc = vgui.Create("DLabel", DPanel1)
		desc:SetText(info.desc)
		desc:SizeToContents()
		desc:SetPos(89, 20)
		
		local amt = vgui.Create("DLabel", DPanel1)
		amt:SetText("Amount: " .. v)
		amt:SizeToContents()
		amt:SetPos(89, 54)
		
		local drop = vgui.Create("DButton", DPanel1)
		drop:SetSize(45, 15)
		drop:SetPos(310, 54)
		drop:SetText("Drop")
		drop.DoClick = function()
			RunConsoleCommand("drp_dropitem", k)
			DFrame1:Remove()
		end
		
		if info.useable then
			local use = vgui.Create("DButton", DPanel1)
			use:SetSize(45, 15)
			use:SetPos(360, 54)
			use:SetText("Use")
			use.DoClick = function()
				RunConsoleCommand("drp_useitem", k)
				DFrame1:Remove()
			end
		end
		
		list1:AddItem(DPanel1)
	end
	
	-- SWEPS --
	
	local list2 = vgui.Create("DPanelList")
	list2:SetSize(439, 296)
	list2:SetSpacing( 5 )
	list2:EnableHorizontal( false )
	list2:EnableVerticalScrollbar( true )
	
	for k,v in pairs(cl_sweps) do
		local DPanel1 = vgui.Create('DPanel')
		DPanel1:SetSize(419, 74)
		
		local info = weps[v.class] -- should be faster...
		
		local icon = vgui.Create("SpawnIcon", DPanel1)
		icon:SetModel(v.model)
		icon:SetPos(5,5)
		icon:SetMouseInputEnabled(false)
		
		local name = vgui.Create("DLabel", DPanel1)
		name:SetText(info.name)
		name:SizeToContents()
		name:SetPos(89, 5)
		
		local desc = vgui.Create("DLabel", DPanel1)
		desc:SetText(info.desc)
		desc:SizeToContents()
		desc:SetPos(89, 20)
		
		local drop = vgui.Create("DButton", DPanel1)
		drop:SetSize(45, 15)
		drop:SetPos(310, 54)
		drop:SetText("Drop")
		drop.DoClick = function()
			RunConsoleCommand("drp_dropswep", k)
			DFrame1:Remove()
		end
		
		local use = vgui.Create("DButton", DPanel1)
		use:SetSize(45, 15)
		use:SetPos(360, 54)
		use:SetText("Pickup")
		use.DoClick = function()
			RunConsoleCommand("drp_useswep", k)
			DFrame1:Remove()
		end
		
		list2:AddItem(DPanel1)
	end
	
	-- FOODS --
	
	local list3 = vgui.Create("DPanelList")
	list3:SetSize(439, 296)
	list3:SetSpacing( 5 )
	list3:EnableHorizontal( false )
	list3:EnableVerticalScrollbar( true )
	
	for k,v in pairs(cl_foods) do
		local DPanel1 = vgui.Create('DPanel')
		DPanel1:SetSize(419, 74)
		
		local info = foodies[v.model] -- should be faster...
		
		local icon = vgui.Create("SpawnIcon", DPanel1)
		icon:SetModel(v.model)
		icon:SetPos(5,5)
		icon:SetMouseInputEnabled(false)
		
		local name = vgui.Create("DLabel", DPanel1)
		name:SetText(info.name)
		name:SizeToContents()
		name:SetPos(89, 5)
		
		local desc = vgui.Create("DLabel", DPanel1)
		desc:SetText(info.desc)
		desc:SizeToContents()
		desc:SetPos(89, 20)
		
		local amt = vgui.Create("DLabel", DPanel1)
		amt:SetText("Fills " .. v.amount .. " hunger.")
		amt:SizeToContents()
		amt:SetPos(89, 35)
		
		local drop = vgui.Create("DButton", DPanel1)
		drop:SetSize(45, 15)
		drop:SetPos(310, 54)
		drop:SetText("Drop")
		drop.DoClick = function()
			RunConsoleCommand("drp_dropfood", k)
			DFrame1:Remove()
		end
		
		local use = vgui.Create("DButton", DPanel1)
		use:SetSize(45, 15)
		use:SetPos(360, 54)
		use:SetText("Eat")
		use.DoClick = function()
			RunConsoleCommand("drp_usefood", k)
			DFrame1:Remove()
		end
		
		list3:AddItem(DPanel1)
	end
	
	-- SHIPS --
	
	local list4 = vgui.Create("DPanelList")
	list4:SetSize(439, 296)
	list4:SetSpacing( 5 )
	list4:EnableHorizontal( false )
	list4:EnableVerticalScrollbar( true )
	
	for k,v in pairs(cl_ships) do
		local DPanel1 = vgui.Create('DPanel')
		DPanel1:SetSize(419, 74)
		
		local info = CustomShipments[v.cont]
		if not info then info = {name="N/A"} end
		
		local icon = vgui.Create("SpawnIcon", DPanel1)
		icon:SetModel("models/Items/item_item_crate.mdl")
		icon:SetPos(5,5)
		icon:SetMouseInputEnabled(false)
		
		local name = vgui.Create("DLabel", DPanel1)
		name:SetText(info.name)
		name:SizeToContents()
		name:SetPos(89, 5)
		
		local desc = vgui.Create("DLabel", DPanel1)
		desc:SetText("A shipment with " .. v.count .. " left.")
		desc:SizeToContents()
		desc:SetPos(89, 20)
		
		local drop = vgui.Create("DButton", DPanel1)
		drop:SetSize(45, 15)
		drop:SetPos(310, 54)
		drop:SetText("Drop")
		drop.DoClick = function()
			RunConsoleCommand("drp_dropship", k)
			DFrame1:Remove()
		end
		
		list4:AddItem(DPanel1)
	end
	
	sheet:AddSheet( "Items", list1, "VGUI/null", false, false, "General Items" )
	sheet:AddSheet( "Weapons", list2, "VGUI/null", false, false, "Things that go \"pew\"" )
	sheet:AddSheet( "Food", list3, "VGUI/null", false, false, "Delicious Edibles" )
	sheet:AddSheet( "Shipments", list4, "VGUI/null", false, false, "Various Packages" )
end
if input.IsKeyDown(KEY_F2) and InvFrameOn == true then
InvFrameOn = false
     end
end
concommand.Add("drp_showinv", showmenu)
hook.Add("Think","BM - Clients - Key", showmenu)


How make this close by Pressing Key, if it’s opened?
I try to do it:



if input.IsKeyDown(KEY_F2) and InvFrameOn == true then
InvFrameOn = false
DFrame1:SetVisible(false)
end


but doesn’t work.

First off, don’t use derma designer, you’re not learning anything.

Second, make the Panel that everything is parented to, a global variable.

Lastly, this can be used to toggle the frame that you want to be toggled.
[lua]
MyFrame:SetVisible(!MyFrame:IsVisible())
[/lua]

I talk about command which just shut(close) the window? (Simulate clicking the close button)

up

UP

What can you really learn by doing derma by hand? It’s repetitive as balls and it’s much quicker/easier to just use a tool

If you’re creating a derma menu for much more complicated, practical uses it takes a lot more thinking through. Trust me, it’s good practice.

It will be helpful later on when you have to create custom panels that don’t exist and with the practice you’ve had with creating panels manually, you can then apply it to those panels.