DModelSelect - Find Out If Someone Clicked A Model

Hey,

I’ve been messing around with DERMA’s DModelSelect panel and I’ve been looking to see if there is a way to check if a player clicks on a model but can’t find anything.

Is it possible?

Thanks.

-snip-

Nvm, for a different element. Sorry.

If you enable mouse input ( http://wiki.garrysmod.com/page/Panel/SetMouseInputEnabled ) then you can use the following functions: http://wiki.garrysmod.com/page/PANEL/OnMousePressed
http://wiki.garrysmod.com/page/PANEL/OnMouseReleased
http://wiki.garrysmod.com/page/PANEL/OnMouseWheeled
http://wiki.garrysmod.com/page/Panel/DragMousePress
http://wiki.garrysmod.com/page/Panel/DragMouseRelease
http://wiki.garrysmod.com/page/Panel/MouseCapture


local _panel = vgui.Create( "DModelPanel" ); -- DAdjustableModelPanel?
-- ... other set up

// Key Codes: http://wiki.garrysmod.com/page/Enums/MOUSE
function _panel:OnMousePressed( _key )
	-- ... // action when mouse button is pressed on element
end

function _panel:OnMouseReleased( _key )
	-- ... // action when mouse button is released
end


-snip-

Confused DModelSelect with DModelPanel.

I don’t think you guys have paid attention to what element OP is requesting help with. DModelSelect populates itself with several SpawnIcons and OP wants to know what icon was clicked.

DModelSelect inherits from DPanelSelect, which when populated using SetModelList or AddPanel will take care of adding a DoClick function on the newly added panel. That click function will call DPanelSelect:SelectPanel which will finally call DPanelSelect:OnActivePanelChanged which is where you can deal with the clicked icon.


yourDModelSelector.OnActivePanelChanged = function(self,oldIcon,newIcon)
    --newIcon should be instance of SpawnIcon if you are using the default method of populating DModelSelect
    print("Clicked on",newIcon:GetModelName())
end