Custom tooltip for a single element (e.g. a button) only?

Hi. I’m trying to create a custom tooltip style that can be used on selected elements only. For example, a button can access the function “SetTooltip()”. I’d like to add my own tooltip method and call it “SetCustomTooltip()” but keep the original function as well. Here is my approach:

Interesting lua files:
garrysmod/lua/vgui/**dtooltip.lua **: https://github.com/garrynewman/garrysmod/blob/e3a696421bfc6bfbaac88a29788c30962e2b9a4f/garrysmod/lua/vgui/dtooltip.lua
Line 180: derma.DefineControl( “DTooltip”, “”, PANEL, “DLabel” )
garrysmod/lua/includes/util/tooltips.lua: https://github.com/garrynewman/garrysmod/blob/3d193fcbc4490009901aad31d742ea93998cf613/garrysmod/lua/includes/util/tooltips.lua
Line 52: Tooltip = vgui.Create( “DTooltip” )

If I just duplicate **dtooltip.lua ** and override some functions then it affects all tooltips.

After duplicating it, I could rename the control to: derma.DefineControl( “CustomTooltip”, “”, PANEL, “DLabel” ) - but I don’t know where this control needs to be called - and how to implement a “SetCustomTooltip()” method.

Hopefully it’s not too much to ask how to solve this, or is it even possible?

To make the :SetCustomTooltip() method you’re going to want to find the “Panel” metatable and just do:

[lua]
function PanelMeta:SetCustomTooltip()
code here
end
[/lua]

You can pretty much just copy your Garry’s function “SetTooltip”, you can find it in “lua\includes\extensions\client” and make sure it creates your tooltip instead of “DTooltip”.

Thank you this helped me alot. :slight_smile:

No problem, you should mark your thread as solved if you think that answer was sufficient though.