DragnDrop

The wiki contains no documentation on how to use this library and I can’t find any examples. The only place I saw it used was once in the spawnmenu, and it wasn’t that useful of information. I was wondering if anyone would be able to help out with some sort of guidance on how to use this library.

I don’t think you’re actually supposed to use the dragndrop library itself, it’s more of an internal set of functions for the Panel library. You have to do panel:SetDraggable(true) to make it dragable. You can use the dragndrop functions like IsDragging to check if someone is dragging on mouse release to handle custom vgui dragging and dropping, I guess.

PS: If you ever can’t find documentation on a lua function, try the github, like so: https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/includes/extensions/client/panel/dragdrop.lua

I used the drag/drop functionality.

I found it to be a bit glitchy.
I can provide some info on it if you really need it, but instead I suggest this code:

It’s taken from Luabee and simply put it allows you to move things around by clicking and dragging them.

I have documented this here:
http://wiki.garrysmod.com/page/Panel/Receiver - Apply to the panel that drag’n’drop panels must be dropped onto.
http://wiki.garrysmod.com/page/Panel/Droppable - Apply to the panel that must be drag’n’dropped

Receiver and Droppable must have the same id to work. More explanation on the wiki pages.
It works just like this and is working glitch-less.

He was talking about the actual Dragndrop Library not being documented: http://wiki.garrysmod.com/page/Libraries/dragndrop

You don’t need to use the library.

I’m trying to use the Droppable/Reciever and I can’t get the receiver function to work.


function Menu()
	LeftSideMenu = vgui.Create("DFrame")
	LeftSideMenu:SetSize(300, 600)
	LeftSideMenu:SetPos(0,0)
	LeftSideMenu:SetVisible( true )
	LeftSideMenu:MakePopup()
	LeftSideMenu:SetTitle("Left Side Menu")

	LeftSidePanel = vgui.Create("DPanelList",  LeftSideMenu)
	LeftSidePanel:EnableHorizontal(false)
	LeftSidePanel:EnableVerticalScrollbar(true)
	LeftSidePanel:StretchToParent(5, 30, 5, 5);
	LeftSidePanel:SetPadding(5);
	LeftSidePanel:SetSpacing(5);

	JobsPanel = vgui.Create( "DPanel")
	JobsPanel:SetSize( 490, 67 )
	JobsPanel:Droppable("LeftPanel")
	LeftSidePanel:AddItem(JobsPanel)

	RightSideMenu = vgui.Create("DFrame")
	RightSideMenu:SetSize(300, 600)
	RightSideMenu:SetPos(1300,0)
	RightSideMenu:SetVisible( true )
	RightSideMenu:MakePopup()
	RightSideMenu:SetTitle("Right Side Menu")
	
	RightSidePanel = vgui.Create("DPanelList", RightSideMenu)
	RightSidePanel:EnableHorizontal(false)
	RightSidePanel:EnableVerticalScrollbar(true)
	RightSidePanel:StretchToParent(5, 30, 5, 5);
	RightSidePanel:SetPadding(5);
	RightSidePanel:SetSpacing(5);

	RightSidePanel:Receiver("LeftPanel", 
	function() 
		LeftSidePanel:RemoveItem(table)
		RightSidePanel:AddItem(table)
	end)

end

concommand.Add("test_menu", Menu)

I’ve created a little test menu to drag the panel from one PanelList to the other and can’t seem to get it to actually drop onto it. The reciever function should remove the item from the previous list and add to the new one but it doesn’t. I’ve tried changing the :Receiver() to the DFrame and still nothing happened so.

You don’t do that. It moves & parents the panel automatically.

Here’s what my functions look like:


slot1:Receiver( slot, function( pnl, tbl, dropped, menu, x, y )
        pnl.PHovered = true

        if ( !dropped ) then return end

        RunConsoleCommand( "pointshop_equip", tbl[1].Item.__itemID )
    end )

    Inventory:Receiver( slot, function( pnl, tbl, dropped, menu, x, y )
        if ( !dropped ) then return end
            
        RunConsoleCommand( "pointshop_equip", tbl[1].Item.__itemID, 1 )
    end )

Inventory is DPanelSelect and slot1 is DPanel.

[editline]20th September 2013[/editline]

Also your variable “table” is not even defined.

I’ve fixed up the reciever hooks and when I drag it onto the other panellist, it doesn’t “drop” onto it and like add it to it. I tried using the :AddItem() part of the DPanelList but that didn’t do much. I’m not sure how I’m supposed to get the panel to goto the other panellist.


function Menu()

	// Inventory
	InventoryFrame = vgui.Create("DFrame")
	InventoryFrame:SetSize(300, 600)
	InventoryFrame:SetPos(0,0)
	InventoryFrame:SetVisible( true )
	InventoryFrame:MakePopup()
	InventoryFrame:SetTitle("Left Side Menu")

	Inventory = vgui.Create("DPanelSelect", InventoryFrame)
	Inventory:SetPos(5,25)
	Inventory:SetSize(300,600)
	
	// Add inventory slots
	function addslot() 
		Slot = vgui.Create("DPanel")
		Slot:SetSize(64,64)
		Slot:Droppable("slot")
		Inventory:AddItem(Slot)
	end
	for i=1,10 do 
		addslot()
	end 


	Inventory:Receiver( "slot", function( pnl, tbl, dropped, menu, x, y )
    	if ( !dropped ) then return end
    end )

    Slot:Receiver( "slot", function( pnl, tbl, dropped, menu, x, y )
    	if ( !dropped ) then return end
    end )



    // Equipment
	EquipmentFrame = vgui.Create("DFrame")
	EquipmentFrame:SetSize(300, 600)
	EquipmentFrame:SetPos(1300,0)
	EquipmentFrame:SetVisible( true )
	EquipmentFrame:MakePopup()
	EquipmentFrame:SetTitle("Right Side Menu")

	Equipment = vgui.Create("DPanelSelect", EquipmentFrame)
	Equipment:SetPos(5,25)
	Equipment:SetSize(300,600)

	Equipment:Receiver( "slot", function( pnl, tbl, dropped, menu, x, y )
    	if ( !dropped ) then return end
    	Equipment:AddItem(table.Panel)
    end )

end

concommand.Add("test_menu", Menu)

I actually was wrong, here’s working example:


function Menu()

	local InventoryFrame = vgui.Create("DFrame")
	InventoryFrame:SetSize(600, 300)
	InventoryFrame:SetPos(0,0)
	InventoryFrame:MakePopup()
	InventoryFrame:SetTitle("Left Side Menu")

	local Inventory = vgui.Create("DPanelSelect", InventoryFrame)
	Inventory:SetPos(5,25)
	Inventory:SetSize(280,280)
	
	Inventory2 = vgui.Create("DPanelSelect", InventoryFrame)
	Inventory2:SetPos(285,25)
	Inventory2:SetSize(280,280)
	
	// Add inventory slots
	for i=1,10 do 
		Slot = vgui.Create("DPanel")
		Slot:SetSize(64,64)
		Slot:Droppable("slot")
		Inventory2:AddItem(Slot)
	end 

	Inventory:Receiver( "slot", function( pnl, tbl, dropped, menu, x, y )
    	if ( !dropped ) then return end
		
		pnl:AddItem(tbl[1])
    end )

	Inventory2:Receiver( "slot", function( pnl, tbl, dropped, menu, x, y )
    	if ( !dropped ) then return end
		
		pnl:AddItem(tbl[1])
    end )

end

concommand.Add("test_menu", Menu)