Single Player Tutorial Part II

In Part II we will examine the non-ingame main, credits, quit and play menus to see any special features they may contain. Note that all of the menus in the non-ingame system, except the pop up menus, are set to be fullscreen using the fullScreen MENU_TRUE command. See here for the explaination of why this is required.

In all the 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 main Menu

In the main menu the onOpen command in the Overall Menu Information section contains script commands that are unique to a single player game.

      onOpen 
{
playlooped "music/sonic1.wav" ;
setcvar "ui_q3model" 1 ;
setcvar "model" starman ;
setcvar "headmodel" starman ;
uiScript UpdateModel ;
}

Since the scripted menus were meant to be used with both Team Arena and Quake 3, a cvar was provide to switch between TA player models and Quake 3 player models. This cvar, ui_q3model, must be set to 1 in a single player game in order to use a Quake 3 model for your player. The cvars model and headmodel must also be set to the desired player model since you normally can not select the player model in a single player game. Here they are set to the starman model of The Dark Conjunction. We then have to run the uiScript UpdateModel command to make sure the changes have taken place.

With the player model information set, the next thing done only in this menu is to preload the model. This avoids a loading delay the first time the player model is drawn.

      itemDef
{
name modelselection
ownerdraw UI_PLAYERMODEL
rect 0 0 0 0
decoration
visible MENU_TRUE
}

This is special case of the ownerdraw UI_PLAYERMODEL command. If the item window area is set using rect 0 0 0 0 then the model will be loaded but not drawn. The accomplishes the model preload we wanted. This item should be included in the main menu of any scripted menu system that will display the player model at some point.

The credits Menu

Like all the menus except for main, the credits menu has a title placed under the header line and top row of buttons. This title, drawn using the credits_title item, uses a shader to create a blue glow and places text over top of that. The text is centered in the window and is the default white in color.

The actual credits box is the creditbackground item. This draws the Quake 3 logo with a border around it. The credits text is drawn using all the items named idcredit. They place centered text in various places over top of the credits box (since they are defined after the creditbackground item) using the default white color.

 

The quit Menu

The quit menu is made to appear over top of other menus and allow only its items to recieve the focus. To achieve this the popup command is added to the Overall Menu Information section. It is not set to be a fullscreen menu, since there will be a fullscreen menu underneath it, so it uses the rect command to define its window area.

The background item uses a shader to make the background for the window area and it has a border around it. Text is written overtop of the background by the quit_title item, defined after background so the text will be on top.

There are two buttons in this menu, YES and NO, each with a glow background. The buttons are created using the methods shown here. The action command for the YES button executes the uiScript quit command to completely exit the program. The action command for the NO button simply closes the quit menu. One unfortunate side effect of closing a popup menu, and not specifically opening another menu, is that all menus will be closed and the main menu opened. This not generally a problem, since you can normally only quit the program from the main menu, but in the menu style we are using here you can quit from any menu. It just has to be lived with is all.

 

The play Menu

This menu is much more complex than the previous ones we've looked at, and it starts in the onOpen command in the Overall Menu Information section. The first thing here is the uiScript LoadSave command. Later on in this menu we will be looking at the saved games avalible to us so we must load them into the appropriate List Box feeder when the menu opens. This command does that for us. Next is the following :

        hide singleControls ;
hide loadControls ;
show playControls ;

In this menu we have placed our items into three different groups, using the group command. The playControls group consists of the buttons NEW GAME, LOAD GAME, PLAY DEMO and PLAY MOD. The singleControls group contains the buttons used to start a single player game, while the loadControls group has those items needed to select a saved game to play. These three groups are drawn in the same area of the menu so we must make it so only one group is visible at any one time. Since we use the playControls group to select the other groups (and other menus) we show it when the menu opens and hide the other groups. We then end up with this :

 

The playControls group items all have the command group playControls in them. This includes the play_title item, which draws a title under the header line and top row of buttons. The buttons are standard items and each has a glow item associated with it. It is in the action command script that the differences are made. We'll look at each button's action command in turn to see these differences.

NEW GAME

The NEW GAME button is defined by the singlebutton item and is used to activate the items needed to start a new single player game. It's action command script looks like the following :

          hide singlebutton_glow ;
hide singletext
hide playControls ;
show singleControls ;
show easybutton_glow ;
hide mediumbutton_glow ;
hide hardbutton_glow ;
hide veryhardbutton_glow ;
setitemcolor easybutton forecolor 1 1 1 1 ;
setitemcolor mediumbutton forecolor 0.65 0.65 1 1 ;
setitemcolor hardbutton forecolor 0.65 0.65 1 1 ;
setitemcolor veryhardbutton forecolor 0.65 0.65 1 1 ;
setcvar "g_spSkill" 1 ;

Complex looking but actually quite simple. The first two lines make sure the button glow and mouseover text are not visible. This is required because these items are not part of any group and are made visible only when the mouse is over the button. When the action script is run these items will always be visible so we must explicitly turn them off.

Next we hide the playControls group with the hide playControls command. This makes the buttons dissappear so we can fill the area with other items. These other items are the singleControls group, which we make visible with the show singleControls command. So to this point, we have hidden the playControls group and shown the singleControls group.

 

The singleControls group items all have the command group singleControls in them. This group includes the single_title item which replaces the play_title item to display a title for this group, the EASY, MEDIUM, HARD and VERY HARD buttons and the BACK and BEGIN buttons. All the buttons have a glow item associated with them.

The next four lines of the action script show the glow behind the EASY button and hide the glow behind the MEDIUM, HARD and VERY HARD buttons. The following four lines set the foreground color of the buttons themselves. This affects the color of the button's text, with the EASY button having white text and the others an off white text. The whole pupose of these eight script lines is to highlight the EASY button when we switch to the singleControls group.

The last line of the script sets the g_spSkill cvar to 1. This cvar is used in the game to determine the skill level of the player. A value of 1 means the skill level is EASY, which matches the button we have highlighted.

LOAD GAME

The LOAD GAME button is defined by the loadbutton item and is used to activate the items needed to load a saved game. It's action command script looks like the following :

          hide loadbutton_glow ;
hide loadtext
hide playControls ;
show loadControls ;

Not as complex as the NEW GAME button. The first two lines make sure the button glow and mouseover text are not visible. This is required because these items are not part of any group and are made visible only when the mouse is over the button. When the action script is run these items will always be visible so we must explicitly turn them off.

Next we hide the playControls group with the hide playControls command. This makes the buttons dissappear so we can fill the area with other items. These other items are the loadControls group, which we make visible with the show loadControls command.

PLAY DEMO and PLAY MOD

These buttons are defined by the demobutton and the modbutton item, respectively. Both of these button's action command script simply closes the play menu and opens another menu, demo for the demobutton item and mod for the modbutton.

SINGLECONTROLS GROUP

The four skill level buttons in this group differ only in their action command scripts and, even there, they are very similar. When you click on one of these buttons it first removes the background glow from all the other buttons and adds the glow behind itself. Then it changes the foreground color for all the other buttons to off white and makes its own white. Lastly, it sets the g_spSkill cvar to the correct value for that skill level. For example, the MEDIUM button's action script looks like :

 
          hide easybutton_glow ;
show mediumbutton_glow ;
hide hardbutton_glow ;
hide veryhardbutton_glow ;
setitemcolor mediumbutton forecolor 1 1 1 1 ;
setitemcolor easybutton forecolor 0.65 0.65 1 1 ;
setitemcolor hardbutton forecolor 0.65 0.65 1 1 ;
setitemcolor veryhardbutton forecolor 0.65 0.65 1 1 ;
setcvar "g_spSkill" 2 ;

You can see the first four lines hide the other buttons' glow and show its own, the second four lines sets its foreground color to white and the others to off white and the last line sets the skill level to 2.

The BACK button's action command script may seem complicated but, again, it is fairly simple.

          hide sbackbutton_glow ;
hide easybutton_glow ;
hide mediumbutton_glow ;
hide hardbutton_glow ;
hide veryhardbutton_glow ;
hide singleControls;
show playControls

First it hides the glow behind itself, since that will always be visible and is not part of any group. Next it hides the glow behind all the skill level buttons. Since it doesn't know which one is actually visible it hides all of them to be safe. It then hides the singleControls group with the hide singleControls command and shows the playControls group with the show playControls command. This then gives us a menu showing only the playControl items so we can select another choice.

The BEGIN button's action command script is very interesting. It is here that we setup to run the actual game. Some of the things shown in this script are unique to The Dark Conjunction mod but the technique will be the same for all single player games.

          hide sbeginbutton_glow ;
setcvar "ui_LoadGame" aircrash ;
exec "spmap aircrash" ;

First we hide the glow behind the button. This is not strictly necessary since the whole menu system will be closed out when the game is started but we do it just for completeness. Next the ui_LoadGame cvar is set to aircrash, the name of the first level in the game. Then we use the exec command to execute spmap aircrash as a console command. The end result of this is that the spmap command loads the map named aircrash and starts to run it. At this point, The Dark Conjunction mod checks the contents of the ui_LoadGame cvar to see if it should load a saved game instead of running the aircrash level. If ui_LoadGame contains aircrash then that level is run as the start of the game. If ui_LoadGame contains another name then that saved game is loaded and run.

While this method of loading and running a game is part of The Dark Conjunction mod, it can be extended to any single player mod. The spmap command must have the name of a valid map when it runs or nothing will happen, so supplying it with the name of the first level and using the ui_LoadGame cvar to see what saved game (if any) should be run works very well.

LOADCONTROLS GROUP

The loadControls group contains a list box containing the saved games avalible and two buttons. Let's look at the list box first. The feeder for the list box is the FEEDER_SAVE feeder. We primed this feeder back in the onOpen script of this menu with the uiScript LoadSave command. It is a standard text list box with a shader background and a border. It contains the doubleClick script command which is run when you double click on any of the saved games listed in the box.

     uiScript LoadGame ;
exec "spmap aircrash" ;

The uiScript LoadGame command transfers the selected list box entry into the ui_LoadGame cvar so we can use it when The Dark Conjunction mod checks to see if a saved game should be loaded. Then we use the exec command to execute spmap aircrash as a console command. When the spmap command goes to run the aircrash level it checks the ui_LoadGame cvar and, since it contains a saved game name, the saved game is loaded.

The BACK button's action script is quite simple.

      hide lbackbutton_glow ;
hide loadControls;
show playControls

First, as usual, we hide the glow behind the button so it won't hang around when we don't want it to. Then we hide all of the loadControls group and show the playControls group. This gives us a menu showing only the playControl items so we can select another choice.

The BEGIN button's action script is a duplicate of the doubleClick script from the list box, since it does the exact same thing.


Part III : Demo, Mod, Connect and DriverInfo Menus

 

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

 

Return to Home Page