I want to add tooltip to my game. It should be a brief text message when mouse is on some Control nodes, like texture rects or labels etc..
This tooltip should also work when mouse is on the game world elements
So something like this comes to my mind:
Check if mouse is hovering on any Control node
If yes, show control node tooltip
If no, show game world element tooltip
I thought maybe I can use mouse_entered and exited signals of Control, but it seems to be a tedious task. Also, it doesn’t work well if there is a round texture in the control, so the empty parts of the node still counted as on the node. And same logic, when using containers, and the size of the container cell is much bigger than the texture.
you don’t need to code tooltips or windows in godot like you would in unity.
godot has many built-in UI features, tooltips are one of them.
with a Control selected, you can go to the inspector and there will be a tooltip option where you can write text. this text will become the tooltip for the control.
if you want more advanced tooltips you do need to code, but not much. you need to override the _make_custom_tooltip function in the Control that will use a custom tooltip. you then need a Scene that will work as your custom tooltip. do this if you want to use a RichTextLabel or add additional stuff on the tooltip.
func _make_custom_tooltip(for_text : String) -> Object:
var tooltip : Control = AssetManager.BASIC_TOOLTIP.instantiate()#I'm using an autoload to obtain the PackedScene containing a custom tooltip scene
tooltip.get_child(0).text = for_text#set text on the first child
return tooltip
then the text in the tooltip field will be passed as the for_text parameter.
I don’t know of a good way to work with rounded buttons, that is a different problem that needs some testing, or maybe someone has done it and can offer a solution.
Thank you. I totally forgot about this feature. It may work well for some use-case, but I still need to keep track if mouse is on ui, because I also show tooltip about 2D nodes when mouse is not on ui.