Single Player Tutorial Part IV

In Part IV we will examine the non-ingame controls menu to see any special features it may contain.

As in all the previously examined menus, the first part of the file contains the itemDefs for the background, the main buttons and their associated glow and mouseover text. It is only after the section looking like the following that menu specific items are defined.

/*********************************************************************/
//
// Start of menu Specific Items
//
/*********************************************************************/

The controls Menu

This menu is very complex looking and contains many items. However, it is not as complicated as it seems if we break it down into its different sections. The first section is the onOpen command in the Overall Menu Information section.

      onOpen 
{
playlooped "music/sonic1.wav" ;
uiScript "loadControls" ;
setcvar "ui_q3model" 1 ;
setcvar "model" starman ;
setcvar "headmodel" starman ;
uiScript UpdateModel ;
show lookControls ;
hide moveControls ;
hide shootControls ;
hide weaponControls ;
hide miscControls ;
setitemcolor lookbutton forecolor 1 1 1 1 ;
setitemcolor movebutton forecolor 0.64 0.65 1 1 ;
setitemcolor shootbutton forecolor 0.64 0.65 1 1 ;
setitemcolor miscbutton forecolor 0.64 0.65 1 1 ;
setitemcolor weaponbutton forecolor 0.64 0.65 1 1 ;
}

Since this menu deals with binding keys to game actions we must load those binds into the program before we do anything else. This is done with the uiScript "loadControls" command. Without this command our binds would not be loaded from the q3config.cfg file. The next four lines deal with the player model. Back in the onOpen command of the main menu we set these three cvars and updated the model but we will do it again here just to make sure that the model is correct.

The controls menu contains five buttons we can click to select a group of actions to bind to keys. These buttons, LOOK, MOVE, SHOOT, WEAPON and MISC, will make their group of binds visible and make all the other groups invisible when we click on them. When the menu first opens we want the LOOK group of binds visible and the others invisible so we show lookControls and hide the other groups. We also set the foreground color of the LOOK button (the text color) to white and make all the other buttons have off white text to highlight the fact that the LOOK controls are visible.

onClose

The onClose command in the Overall Menu Information section also plays a major role in this menu. This command is executed when the menu closes and it runs the uiScript "saveControls" command. This saves the binds to the q3config.cfg file. Without this, any changes to the binds would not be saved and would be lost when the program ends.

Player Model

If you look in the first section of this menu that defines the background for the menu you'll notice that the rotating model (item model) is missing. Instead it has been replaced by the modelselection item, which draws the player model. We do this so we can show many of the actions we are binding on the player model itself. Since we are working with the player model in this menu we have added the #include "ui/animdef.h" line at the top of the file.

Group Buttons

The five buttons are next and are standard items with a background glow. The differences between them are in their action script and even there they are very similar. We'll look at the MOVE button's action script to see what happens there.

        action
{
hide lookControls ;
show moveControls ;
hide shootControls ;
hide weaponControls ;
hide miscControls ;
setitemcolor movebutton forecolor 1 1 1 1 ;
setitemcolor lookbutton forecolor 0.64 0.65 1 1 ;
setitemcolor shootbutton forecolor 0.64 0.65 1 1 ;
setitemcolor miscbutton forecolor 0.64 0.65 1 1 ;
setitemcolor weaponbutton forecolor 0.64 0.65 1 1 ;
}

This script is very similar to what happened in the onOpen script in the Overall Menu Information section. The first five lines show the group of binds associated with the button (in this case the moveControls group) and hide all the other groups. It then sets the foreground (text) color of itself to white and the text color of the other buttons to off white to show which group is visible. All the buttons do the same thing so you see only the binds associated with that particular button. We must place our binds into groups and show only one group at a time because there are too many binds to show on the screen all at once and we can not use a scrolling list like some games do.

Background, Highlights and Messages

The next section of items is the background and highlights for the binds. The bind_background item draws a background in the area where the binds will be shown. The items highlight1 through highlight12 are the glow that will appear behind each bind shown in the bind_background area. The highlight items are set to be invisible (visible MENU_FALSE) when the menu opens and are made visible only when the mouse is over the bind item on top of them. By doing it this way, we can use the same background glow for binds in different groups.

Another part of this section is the keyBindStatus item. This is an ownerdraw item that tells us the status of our binding. See here for details. It places its text below the bind_background item and is set to be invisible when the menu opens. It will only be made visible when we are actually doing something with a bind.

Also in this section is the yesno_message item. Since some of the things we are dealing with in this menu are yes or no (ie. Always Run? requires a yes or no answer) we have to have a message telling the user that clicking on the item will change the yes or no value. This item places that message in the same area as the text from the keyBindStatus item and is normally invisible. It will be made visible only when the mouse is over a Yes/No item.

The lookControls

This group of items all contain the group lookControls command and are used to bind keys to actions pertaining to looking. The actions in this group are :

  1. Look Up - item lookup
  2. Look Down - item lookdown
  3. Mouse Look - item mlook
  4. CenterView - item center
  5. ZoomView - item zoom
  6. Free Look - item free

All of these items are of type ITEM_TYPE_BIND and contain text that is aligned to the right. This ensures that the key descriptions are all nicely lined up. Each item is located so it is on top of one of the glow item highlights highlight1 through highlight12. The mouseEnter and mouseExit scripts are where things happen in these items.

When the mouse moves over each item there are several things that must be done. First, the appropriate highlight must be made visible by use of the show command. For item lookup this would be show highlight1 since it is located over top of that item. Second, since this is a key bind item, we want to show the status of the binding. To do this we use the show keyBindStatus command to make the keyBindStatus item visible. This displays the bind status text at the bottom of the screen. And lastly, for certain items, we modify the player model (which is displayed on the screen) so we can see what the action does. For the lookup item this entails changing the ui_PlayerViewAnglePitch cvar and then updating the player model with uiScript UpdateModel. Without the update command the change to the cvar will not be shown.

When the mouse leaves the item we have to set things back to the way they were. This means we hide the highlight we made visible earlier and hide the keyBindStatus item as well. If we made changes to the player model then those cvars must be set back to their default values and the uiScript UpdateModel command run to make the changes show. See here for more information on the cvars that can be modified and their default values.


The moveControls

This group of items all contain the group moveControls command and are used to bind keys to actions pertaining to moving. The actions in this group are :

  1. Run/Walk - item runwalk
  2. Always Run - item alwaysrun
  3. Forward - item forward
  4. Backpedal - item backward
  5. Move Left - item moveleft
  6. Move Right - item moveright
  7. Jump - item jump
  8. Crouch - item crouch
  9. Turn Left - item turnleft
  10. Turn Right - item turnright
  11. Strafe - item strafe

All but one of these items is of type ITEM_TYPE_BIND and contain text that is aligned to the right. This ensures that the key descriptions are all nicely lined up. Each item is located so it is on top of one of the glow item highlights highlight1 through highlight12. The item alwaysrun is of type ITEM_TYPE_YESNO. Again, the mouseEnter and mouseExit scripts are where things happen in these items.

When the mouse moves over each item there are several things that must be done. First, the appropriate highlight must be made visible by use of the show command. For item runwalk this would be show highlight1 since it is located over top of that item. Second, since this is a key bind item, we want to show the status of the binding. To do this we use the show keyBindStatus command to make the keyBindStatus item visible. This displays the bind status text at the bottom of the screen. For the alwaysrun item, instead of making the keyBindStatus item visible, we make the yesno_message item visible, since this is a Yes/No item. And lastly, for certain items, we modify the player model (which is displayed on the screen) so we can see what the action does. For the alwaysrun item this entails changing the ui_LowerAnim cvar to LEGS_RUN and then updating the player model with uiScript UpdateModel. Without the update command the change to the cvar will not be shown.

When the mouse leaves the item we have to set things back to the way they were. This means we hide the highlight we made visible earlier and hide the keyBindStatus item (or yesno_message item for alwaysrun) as well. If we made changes to the player model then those cvars must be set back to their default values and the uiScript UpdateModel command run to make the changes show. See here for more information on the cvars that can be modified and their default values.


The shootControls

This group of items all contain the group shootControls command and are used to bind keys to actions pertaining to shooting. The actions in this group are :

  1. Attack - item attack
  2. Prev Weapon - item prev
  3. Next Weapon - item next
  4. Autoswitch - item auto

All but one of these items is of type ITEM_TYPE_BIND and contain text that is aligned to the right. This ensures that the key descriptions are all nicely lined up. Each item is located so it is on top of one of the glow item highlights highlight1 through highlight12. The item auto is of type ITEM_TYPE_YESNO. Again, the mouseEnter and mouseExit scripts are where things happen in these items.

When the mouse moves over each item there are several things that must be done. First, the appropriate highlight must be made visible by use of the show command. For item attack this would be show highlight1 since it is located over top of that item. Second, since this is a key bind item, we want to show the status of the binding. To do this we use the show keyBindStatus command to make the keyBindStatus item visible. This displays the bind status text at the bottom of the screen. For the auto item, instead of making the keyBindStatus item visible, we make the yesno_message item visible, since this is a Yes/No item. And lastly, for certain items, we modify the player model (which is displayed on the screen) so we can see what the action does. For the attack item this entails changing the ui_UpperAnim cvar to TORSO_ATTACK and then updating the player model with uiScript UpdateModel. Without the update command the change to the cvar will not be shown.

When the mouse leaves the item we have to set things back to the way they were. This means we hide the highlight we made visible earlier and hide the keyBindStatus item (or yesno_message item for auto) as well. If we made changes to the player model then those cvars must be set back to their default values and the uiScript UpdateModel command run to make the changes show. See here for more information on the cvars that can be modified and their default values.

 

The weaponControls

This group of items all contain the group weaponControls command and are used to bind keys to actions pertaining to selecting weapons. The actions in this group are :

  1. Bone - item weapon1
  2. Pistol - item weapon2
  3. Shotgun - item weapon3
  4. Machine Gun - item weapon4

All of these items are of type ITEM_TYPE_BIND and contain text that is aligned to the right. This ensures that the key descriptions are all nicely lined up. Each item is located so it is on top of one of the glow item highlights highlight1 through highlight12. Again, the mouseEnter and mouseExit scripts are where things happen in these items.

When the mouse moves over each item there are several things that must be done. First, the appropriate highlight must be made visible by use of the show command. For item weapon1 this would be show highlight1 since it is located over top of that item. Second, since this is a key bind item, we want to show the status of the binding. To do this we use the show keyBindStatus command to make the keyBindStatus item visible. This displays the bind status text at the bottom of the screen. And lastly, for all items, we modify the player model (which is displayed on the screen) so we can see what the action does. For the weapon1 item this entails changing the ui_Weapon cvar to WP_GAUNTLET and then updating the player model with uiScript UpdateModel. Without the update command the change to the cvar will not be shown.

When the mouse leaves the item we have to set things back to the way they were. This means we hide the highlight we made visible earlier and hide the keyBindStatus item as well. If we made changes to the player model then those cvars must be set back to their default values and the uiScript UpdateModel command run to make the changes show. See here for more information on the cvars that can be modified and their default values.

 

The miscControls

This group of items all contain the group miscControls command and are used to bind keys to actions that don't fit any other group. The actions in this group are :

  1. Use Item - item useitem

All of these items is of type ITEM_TYPE_BIND and contain text that is aligned to the right. This ensures that the key descriptions are all nicely lined up. Each item is located so it is on top of one of the glow item highlights highlight1 through highlight12. Again, the mouseEnter and mouseExit scripts are where things happen in these items.

When the mouse moves over each item there are several things that must be done. First, the appropriate highlight must be made visible by use of the show command. For item useitem this would be show highlight1 since it is located over top of that item. Second, since this is a key bind item, we want to show the status of the binding. To do this we use the show keyBindStatus command to make the keyBindStatus item visible. This displays the bind status text at the bottom of the screen.

When the mouse leaves the item we have to set things back to the way they were. This means we hide the highlight we made visible earlier and hide the keyBindStatus item as well.

 

Part V : Setup Menu

 

[Part 1] [Part II] [Part III] [Part IV] [Part V] [Part VI] [Part VII]

 

Return to Home Page