In Game Tooltips...

Started by
7 comments, last by Assassian360 16 years, 11 months ago
I'm starting work on an RTS game and I want to add in game tooltips that show up when you hover over certain elements, and I'm moderatly new to programming complex games like this, so i'm wondering if someone can either point me in the right direction for how to develop the tooltips or even give me a good idea of how to go about the implementation. Thanks in advance.
Advertisement
Are you talking about like when you hover over the [x] in windows, it says "close"? Implementing that seems relatively easy. You just have to check to see when the mouse is relatively motionless, and then figure out what element it is hovering over. Then figure out which image/text you want displayed, and make display it as a sprite or equivalent at the cursor's posisition. When you detect motion, text goes bye-bye.

Of course, this would probably differ or be done better depending on your implementation. Becuase I have no clue concerning what language/library you are using, I hoep this helps you out.
What I want to do is a little more complex than just showing a word like close when you hover over a close button etc.

I'm using C++ with directX9 for those wanting to know what language im using.

I want to be able to have tooltips sort of like in Warcraft 3 for example when you hover over a unit or builing that you may want to build and information about how much the building costs and what the item is etc show in the little tool tip next to the mouse.

So, I also want to be able to support multiple colours of text and also if it were possible to have icons/images shown in the tooltips.

If you need more information about specifics to be able to help suggest how I would do this please just ask and I will put the required information up.

Thanks.
Quote:Original post by Assassian360
What I want to do is a little more complex than just showing a word like close when you hover over a close button etc.

I'm using C++ with directX9 for those wanting to know what language im using.

I want to be able to have tooltips sort of like in Warcraft 3 for example when you hover over a unit or builing that you may want to build and information about how much the building costs and what the item is etc show in the little tool tip next to the mouse.

So, I also want to be able to support multiple colours of text and also if it were possible to have icons/images shown in the tooltips.

If you need more information about specifics to be able to help suggest how I would do this please just ask and I will put the required information up.

Thanks.
It seems to me that the 'tool tips' you mentioned would be no more difficult to implement than any other feature of an RTS. In other words, if you have the skills to program an RTS, implementing tool tips as you describe should be no problem.

Nevertheless, here's what comes to mind:

1. As the mouse moves, pick against the scene periodically (say, a few times a second), and record which (if any) entities fall under the mouse cursor. (If you're developing an RTS, then you already have a picking system set up, I assume.)

2. One option would be to (as suggested previously) only perform the picking operation when the mouse had been stationary for some period of time, or was moving slowly.

3. If it's determined that the cursor is over an entity, compute the screen space position or bounding volume for that entity. Then compute an appropriate position for the tool tip (e.g. a fixed amount up and to the right of the bounding volume).

4. The details of rendering 2d images and/or text to the screen (and applying different colors) are largely dependent on the API being used (DirectX in your case). Again, since you're developing an RTS, I assume you already have code in place for rendering text and UI elements to the screen.

5. As for figuring out which tool tip to display for a given entity, that's a programming detail - there are any number of ways you could implement this. Presumably though, each entity type would have its own 'tool tip template', and each entity would supply its own data with which to fill in the template ('printf'-style, as it were).

If you don't yet have a framework in place that supports picking, rendering of text and 2d images, and so on, then I would focus on implementing those features before worrying about tool tips or what have you.
I have not been programming all that long myself, but i'm using the book programming an RTS with direct3d as the basis for my game. The functions for detecting where the mouse is etc are there, but it is just the displaying of the tooltip that I need help with. It would be simple enough to just have the writing appear, but I don't know how to have a background, and im not sure if I want the background to be a 2d texture or a plain colour, so I would find it most useful to find out both ways.

Because the background is wanted, I will have a fixed width for the tooltip, but the height will need to vary depending upon content.

Any help with this would be great.

Thanks for the tips so far...
I'm currently developing an RTS game myself(Having some minor issues with a vertexbuffer, but that's a whole different story).

I currently seperate my game elements from the UI elements. Each frame, I update the WindowManager, who's responsible for managing all the UI elements and pass them their events. When the WindowManager updates, it walks over all it's top-level windows, and if there's no mouse over any of these windows, the control is passed to the normal game code.

What I am going to do is this: When the mouse is idle for 2 seconds over a specific game element, I create a new window(Tooltip) and register it with the ui manager. When it receives clicks or movement events, I destroy the tooltip and pass the event on to the normal game code.

If you don't have a seperate ui manager, you could always create a tooltip object, set a flag somewhere in your code that a tooltip is being shown, and when your mouse moves again, you check the flag, and destroy the tooltip.

Toolmaker

Quote:Original post by Assassian360
...
but I don't know how to have a background, and im not sure if I want the background to be a 2d texture or a plain colour, so I would find it most useful to find out both ways.

Because the background is wanted, I will have a fixed width for the tooltip, but the height will need to vary depending upon content.
...


What you need seems very simple to do. I am not very familiar with the directx api, but I know that it has some sort of 2d sprites. Simply load a picture from resources, and draw it onto your "tooltip" sprite. Then add text/pictures/whatever you want directly on top of your background. If it turns out to be too long, dynamically resize your sprite, and just redraw your background.

I dont want to judge, because I know very little about you, but it may be that you are over your head in tackling such a large project. I have been programming for four years now, and I only recently believe that I have the management skills necessary to deal with a project of such scope. Nonetheless, good luck in this endeavor.
If you already have buttons which work, then much of the code you need to determine where/when to display a tooltip is already there.

Since you plan on having quite a few tooltip features, you could create a tooltip class, then declare a variable of type tooltip in your button class (and all other classes that need to show a tooltip). The tooltip class would contain a list of tipobjects (images, strings, etc). Tipobjects could also be classes themselves and derived from a base class.

You can take it two directions from here:

A) Your render procedure would iterate through these tipobjects and draw them one after another like inline text. But first, it should draw a semi-transparent quad so you have the backround for the tooltip.

B) As you add or remove tipobjects from the list, the remaining tipobjects would be rendered to a texture and saved in a variable in the tooltip class. Then, you just render the texture to a quad when the tooltip needs to be shown. A transparent backround should be trivial, just draw a transparent color to the texture before drawing the tipobjects.

--

These are just simple ideas off the top of my head and are admittedly not very well thought out. I wouldn't be surprised if this system turned out to be a lemon/pita/other food connotating disapproval.
______________________________Perry Butler aka iosysiosys Website | iosys Music | iosys Engine
Well, im starting to get an idea about how I can do it now.

All I don't really know how to do now I recon is how to resize the background during runtime. Using directX how do I resize the sprite with only changing its height and not its width?

Thanks for all the help.

This topic is closed to new replies.

Advertisement