Game Development Reference
In-Depth Information
ing a callback function that gets called when the button is clicked. Right now, the
menu system does not support keyboard navigation because it was designed for a
PC with a mouse, though it's certainly a feature that could be added.
Although the UIScreen system isn't that complicated, the tooltip system ended
up being much more complex. There were a few reasons it ended up that way.
First of all, by default, text rendering in XNA cannot wrap to a specific width. You
give it a string and it'll simply draw that string until the text ends. For a tooltip,
it's important that it wraps around nicely to a specific maximum width. Second, I
wanted to be able to arbitrarily change the font and color in the middle of a text
string to help certain information pop out on the tooltips. This is also something
that XNA does not provide by default. To solve these two problems, I ended
up using the extremely useful MarkupTextEngine , which was released by
“astroboid” under the Microsoft Permissive License ( http://astroboid.com/2011/
06/markup-text-rendering-in-xna.html ) . It worked marvelously to solve those two
problems, though the code for it might be a bit difficult to understand.
That wasn't the end of the tooltip complexity, though. I also wanted to be able to
dynamically change the text inside of tooltips. I didn't want the tooltip text to just
befixed(asin“Thiscosts$500”)becausethenwheneveranyvalueswerechanged
in Balance.cs, the tooltip text would have to change also. Instead, I wanted to be
able to replace placeholders in the tooltips with actual values. So instead of “This
costs $500,” the tooltip string would be “This costs ${0},” with the {0} getting
replaced with the correct value. And to even make it more complex, I wanted to
be able to colorize things depending on the situation. So if a building costs $500,
but you don't have $500, I wanted the text to be red so it pops out that there isn't
enough money to purchase the building. The end result of the tooltip system is
shown in Figure 14.4 .
Search WWH ::




Custom Search