Card Tooltip UI

Godot Version

4.2.1

Question

I’ve still been following this tutorial series: https://www.youtube.com/playlist?list=PL6SABXRSlpH8CD71L7zye311cp9R4JazJ

Recently I went back to the tooltips tutorial (I originally skipped that part because I decided to have the card text on the cards rather than in a tooltip, and to have the tooltip show just the ‘keywords’ on a given card.

So far I’ve created a card_tooltip scene, which is just a richtext label with this script attached:

I’ve also added an export group called ‘keywords’ to my Card resource script:

image

As an example:

I’ve also added a vboxcontainer called TooltipContainer to the card ui, with my original intention being to instantiate the relevant tooltips based on the card the mouse is hovering over. My question, really, is where do I go from this point? I’ve been thinking it over and I’m not sure I have the experience or knowledge to know how to implement this properly. Possibly create a new set of resources called keywords just to hold the text for each one? Is that overkill? Is there a much simpler solution I’m not thinking of?

Thanks for any help in advance, I’ve found this forum very helpful so far and I’ve learned a lot, I hope I can learn even more from all of you.

If the tooltips only consist of these 7 keywords, you might as well do only one scene and when the mouse hovers over a card you get the information of that card and apply it to the tooltip scene and show the tooltip-scene on the card you are currently hovering

It’ll likely be more keywords than this by the end of the project, but I don’t imagine too many more. So in the card_tooltip scene, just have all the tooltips in a vboxcontainer(?) as the root node, have them hidden by default and then only make the ones that match the card’s export group show when hovering?

Yes. Thats one way of doing it. This reduces the amount of neccessary scenes to 1.

So if I do something like this:

And then call the show_tooltip() function on mouseover, that should work? This seems like the easiest solution for me to wrap my head around at the moment honestly.

You probably have to set the position accordingly, but this sounds logical to me

Okay, it seems like this will work, but I’m getting an issue here. It’s giving me ‘Invalid get index ‘card’ (on base: ‘null instance’)’. I’ve had a look but I’m not really sure why this is happening.

So I emit the card_tooltip_requested signal in the card_base_state script, as I only want the tooltip to display when the card is in its base state in your hand:

image

I tried changing the function by saying show_tooltip(card: Card), and the emit to Events.card_tooltip_requested.emit(card), but I think I’m not understanding something here.

Edit: I updated them with show_tooltip(card_ui: CardUI) and emit(card_ui) instead, that gets rid of the error, but now it shows the tooltip for every card in the hand, and shows the tooltip underneath the other cards, and only shows the tooltip one time. If I stop hovering it disappears, but then won’t appear again afterward.

To help fix this i would need to see the code. Just note i have to go for now. Ill be back this evening

I’ll put what I think is all the relevant code here, but I’ll continue working on it and if I make any progress I’ll edit this post:






Edit: I’ve gotten it to show above the other cards correctly by changing the card tooltip scene’s Z Index to 1. I don’t know if this is the ideal solution, but it works for now. I’m still struggling to understand while it’s only showing the one time though, and why it’s showing on all cards in hand; I’ll keep looking into it.

1 Like

Can you make a screenshot of this showing on every card? I find it hard to understand really, since its only one scene? How can it be on every card?

So when I hover over the block card, it will display the block tooltip next to every card, rather than just the block card. But then if I had hovered over one of the other cards there would be nothing since they don’t have any keywords.

But how are there more then one? Where do you instantiate the tooltip?

I have the card tooltip scene:

Screenshot 2024-08-17 184608

And that’s instantiated in the card_ui scene:

Thats not the way i meant it. My idea was to only have one in the whole game and then put it to the position when its called:

func show_tooltip(card_ui: CardUI) -> void:
    global_position = card_ui.global_position # + offset_vector if needed
    ...

This would also fix your problem

Ah, I definitely misunderstood that! I’ve instantiated in a canvas layer called Tooltip Layer in the run scene, and then I can use this canvas layer for other tooltips I might include later. This has solved the issue of it showing on all cards, and does make a lot more sense to me. Unfortunately it will still show only the first time I mouse over a card, so I imagine something is wrong with the hide tooltip function?

So I emit the signal here in the base state script:

image

And this is the hide tooltip script:

Screenshot 2024-08-18 131221

I assume I’m missing something here but I’m not sure what, I’m just going to play with it a little more for now.

1 Like

i think the problem is that you dont call show() when show_tooltip is called

1 Like

I don’t know how I missed that :neutral_face:

Thanks so much for your help again, I learned alot!

1 Like

Although now I have another issue. Should this work:

image

Now what I get is the individual tooltips will stay visible when the tooltip is called again. So for example:

When I mouser over block it will just show block, as expected. However:

Then when I mouse over the next card, it still shows block along with the new keywords. Then:

When I hover over block again it will still show the other keywords too.

I’m trying some different things but it doesn’t seem to be helping. Something to do with the order? Or is my hide tooltip function just incorrect?

Yeah you want to hide all children as well so they dont automatically appear the next time the tooltip is requested

Yeah, I just tried this:

image

and it works, it just doesn’t feel like the most elegant solution. But then as long as I make sure to change the show and hide tooltip functions if I make any new keywords, I guess it’s fine?

Thanks again!

1 Like