Now is the time to start giving the player more options and more information. We've almost got a playable racing game at this point, though we don't have the weapons yet. If we add in a Graphical User Interface, we'll be that much closer to our goal of a complete game.
The GUI components we'll need to create are:
To create these elements, we'll be using Panda3D's DirectGUI
system. This system includes all the tools we'll need to make our GUI and get it running.
Rather than creating menus individually, it would be wiser to create a system that will allow us to make all the menus we need. We can do this if we rely on the handy feature of Python that allows us to pass functions and methods between objects.
We'll create a menu system that takes functions or methods as arguments and executes them when menu options are selected. We'll also need to take in the arguments for those functions and methods.
The DirectGUI
system in Panda3D is a series of tools for constructing a graphical user interface. Among the objects in DirectGUI
we can find DirectFrames
to act as the backgrounds of menus, DirectLabels
that will put text on the menus, DirectButtons
that will serve for the menu buttons, and more.
All of the DirectGUI
objects inherit from DirectGUIBase
, so they share many of their features. The typical method for creating a DirectGUI
object is to fill the constructor with keyword/value pairs, like the following:
myDirectGuiObject = DirectGUIObject(keyword = value, keyword = value, keyword = value)
For that reason, it's a good idea to know what the keywords that are shared by most, if not all, of the DirectGUI
objects. Here's a list of those keywords for reference. It's taken from the Panda3D manual on the Panda3D website, with a couple of updates.
Keyword |
Description |
Value |
---|---|---|
|
Text to be displayed on the object |
string |
|
Background color of text on the object |
(R,G,B,A) |
|
Color of the text |
(R,G,B,A) |
|
Position of the displayed text |
(x,y,z) |
|
Rotation of the displayed text |
number |
|
Scale of the displayed text |
(sx,sy,sz) |
|
Parameters to control the appearance of the text |
Any keyword parameter appropriate to |
|
Size of the object |
(left, right, bottom, top) |
|
Size of the object |
(Left,Right,Bottom,Top) |
|
Relative scale of the visible frame to its clickable bounds. Useful for creating things such as the paging region of a slider, which is visibly smaller than the acceptable click region |
(hscale, vscale) |
|
Color of the object's frame |
(R,G,B,A) |
|
Relief appearance of the frame |
SUNKEN, RAISED, GROOVE, RIDGE, FLAT, or None |
|
If true, switches the meaning of SUNKEN and RAISED |
0 or 1 |
|
If relief is SUNKEN, RAISED, GROOVE, or RIDGE, changes the size of the bevel |
(Width,Height) |
|
An image to be displayed on the object |
image filename or |
|
Position of the displayed image |
(x,y,z) |
|
Rotation of the displayed image |
(h,p,r) |
|
Scale of the displayed image |
(sx,sy,sz) |
|
A |
|
|
Position of the displayed |
(x,y,z) |
|
Rotation of the displayed |
(h,p,r) |
|
Scale of the displayed |
(sx,sy,sz) |
|
Position of the object |
(X,Y,Z) |
|
Orientation of the object |
(H,P,R) |
|
Scale of the object |
(sx, sy, sz) |
|
When |
(Width,Height) |
|
The initial state of the object |
NORMAL or DISABLED |
|
|
image filename or |