Code Changes
Acknowledgement for this feature must go to the Tremulous mod, as much of the code was taken from their source and modified to fit my circumstances. The code changes required to implement the Scripted Loading Screen can be found on the Loading Screen Code page.
Scripting
Since the scripted HUD system is the only place in the CGame module that menus can be loaded, we must load our Loading Screen menu using it. This means we must include our menu file in hud.txt (or whatever file is specified by the cg_hudFiles cvar). If our menu is defined in the loading.menu file then we would add :
loadMenu { "ui/loading.menu" }
to the hud.txt file. Without doing this, our menu file will never be loaded.
The menu used for the Loading Screen must be named loading and nothing else. The program looks for a menu named this when it comes time to display the loading screen and, if it finds it, will run the menu script. Otherwise it will show the default Quake 3 loading screen. The menu must be made fullscreen with the fullscreen MENU_TRUE command and be invisible by default by including the visible MENU_FALSE command. Failure to do this will make a complete mess of both the loading screen and the Hud. The menuDef must look like :
menuDef
{
name "Loading"
fullScreen MENU_TRUE
visible MENU_FALSE
}
Since the menu is fullscreen you must use a background or have an item covers the entire screen with a graphic or fills it with color. Again. failure to do this will make a visual mess of the loading screen.
Warning : using shaders (as the background or in items) that require continuous animation will not work correctly in the loading screen. This screen is displayed when the client initialization starts and is only updated when a progess bar changes. It is not updated on a regular clock tick. Therefore, shaders that change over time will not work correctly.
That said, you are free to use most any item type and command in those items that you wish, as long as it is supported by the Hud scripting system.. The mouse is turned off for the duration of the loading screen so nothing will receive the focus. Any of the decorative item types that display a graphic or fill the window with color will work, as will any text display. Items can be made visible or invisible using the showCvar and hideCvar commands and the contents of a cvar can be displayed with an Editfield item type.
There are also a number of new ownerdraw commands specific to the loading screen. Some of these display information about the game itself and others display the progress bars and titles. In those ownerdraw items that display text there is one major difference from normal text items. Instead of using the textalign command to set the alignment point they use the align command. It is used as follows :
align ITEM_ALIGN_LEFT - set alignment point to left side of text
align ITEM_ALIGN_CENTER - set alignment point to center of text
align ITEM_ALIGN_RIGHT - set alignment point to right side of text
This is identical to the textalign command. The ownerdraw commands are as follows :
1. ownerdraw CG_LOAD_LEVELSHOT - this displays the levelshot graphic for the map being loaded in the item's window area.
itemDef
{
name "levelshot"
rect 300 20 320 240
visible MENU_TRUE
ownerdraw CG_LOAD_LEVELSHOT
}
This displays the levelshot graphic at a size of 320x240.
2. ownerdraw CG_LOAD_LEVELNAME - this displays the name of the map as text. It uses the text formatting commands to place the text in the item's window.
itemDef
{
name "levelname"
rect 20 20 260 20
visible MENU_TRUE
align ITEM_ALIGN_LEFT
textscale 0.4
textaligny 28
textalignx 0
ownerdraw CG_LOAD_LEVELNAME
}
3. ownerdraw CG_LOAD_HOSTNAME - display the name of the game's host as text. It uses the text formatting commands to place the text in the item's window.
itemDef
{
name "hostname"
rect 20 100 260 20
visible MENU_TRUE
align ITEM_ALIGN_LEFT
textscale 0.4
textaligny 28
textalignx 0
ownerdraw CG_LOAD_HOSTNAME
}
4. ownerdraw CG_LOAD_MOTD - dispaly the message of the day from the host as text. It uses the text formatting commands to place the text in the item's window.
itemDef
{
name "motd"
rect 20 180 260 20
visible 1
align ITEM_ALIGN_LEFT
textscale 0.4
textaligny 28
textalignx 0
ownerdraw CG_LOAD_MOTD
}
5. ownerdraw CG_LOAD_MEDIA_LABEL - this displays the text Overall in the item's window using the text formatting commands. This text is the label for the Media progress bar. While the progress bar is less than 100% the text is displayed in the default ( ITEM_TEXTSTYLE_NORMAL ) style and in the white color. When the progress bar reaches 100% the color is changed to the foreground color and the text style is changed to Neon, to indicate that the bar is finished.
itemDef
{
name "medialabel"
textscale 0.6
rect 420 380 200 40
align ITEM_ALIGN_RIGHT
textaligny 28
textalignx 0
forecolor 0.0 0.8 1 1
visible MENU_TRUE
ownerdraw CG_LOAD_MEDIA_LABEL
}
This displays the text in white until the Media progress bar is at 100%, then changes it to a bluish neon color.
6. ownerdraw CG_LOAD_SOUND_LABEL - this displays the text Sound in the item's window using the text formatting commands. This text is the label for the Sound progress bar. While the progress bar is less than 100% the text is displayed in the default ( ITEM_TEXTSTYLE_NORMAL ) style and in the white color. When the progress bar reaches 100% the color is changed to the foreground color and the text style is changed to Neon, to indicate that the bar is finished.
itemDef
{
name "soundlabel"
textscale 0.6
rect 420 300 200 40
align ITEM_ALIGN_RIGHT
textaligny 28
textalignx 0
forecolor 0.0 0.8 1 1
visible MENU_TRUE
ownerdraw CG_LOAD_SOUND_LABEL
}
This displays the text in white until the Sound progress bar is at 100%, then changes it to a bluish neon color.
7. ownerdraw CG_LOAD_GRAPHIC_LABEL - this displays the text Graphics in the item's window using the text formatting commands. This text is the label for the Graphic progress bar. While the progress bar is less than 100% the text is displayed in the default ( ITEM_TEXTSTYLE_NORMAL ) style and in the white color. When the progress bar reaches 100% the color is changed to the foreground color and the text style is changed to Neon, to indicate that the bar is finished.
itemDef
{
name "graphiclabel"
textscale 0.6
rect 420 340 200 40
align ITEM_ALIGN_RIGHT
textaligny 28
textalignx 0
forecolor 0.0 0.8 1 1
visible MENU_TRUE
ownerdraw CG_LOAD_GRAPHIC_LABEL
}
This displays the text in white until the Graphic progress bar is at 100%, then changes it to a bluish neon color.
The progress bars for sound, graphics and the overall media are identical in form and creation, with the exception of the ownerdraw command used. The bar consists of a foreground colored outline (filling the item's window) whose center is filled with the foreground color as the progress advances. The percentage of progress completed is displayed as text inside the bar. This text uses the textstyle, textscale and align commands to format the text. The text is always vertically centered and the align command determines where on the bar it is placed. It is colored using the foreground color. The special command is used to set the width of the bar's outline as follows :
special 1 - make the outline 1 pixel wide
special 4 - make the outline 4 pixels wide
If the align command is set to ITEM_ALIGN_RIGHT the percentage text is placed on the right side and the progress of the bar is shown as moving from right to left. Any other alignment has the progress moving from left to right.
The upper progress bar has the alignment set to ITEM_ALIGN_CENTER so the bar moves from left to right. The bottom bar has it's alignment set to ITEM_ALIGN_RIGHT and the bar moves from right to left. In both bars the textstyle is set to ITEM_TEXTSTYLE_NEON so the text is still visible when the bar covers it. Using other text styles will make the percentage text dissappear as the bar covers it.
8. ownerdraw CG_LOAD_MEDIA - display the Media progress bar which shows the overall progress in loading the game's media (sound and graphics).
itemDef
{
name "media"
rect 20 380 380 30
visible MENU_TRUE
forecolor 0.0 0.8 1 1
ownerdraw CG_LOAD_MEDIA
align ITEM_ALIGN_CENTER
textstyle ITEM_TEXTSTYLE_NEON
textscale 0.5
special 1.0
}
9. ownerdraw CG_LOAD_SOUND - display the Sound progress bar which shows the progress in loading the game's sound files.
itemDef
{
name "sound"
rect 20 300 380 30
visible MENU_TRUE
forecolor 0.0 0.8 1 1
ownerdraw CG_LOAD_SOUND
align ITEM_ALIGN_CENTER
textstyle ITEM_TEXTSTYLE_NEON
textscale 0.5
special 1.0
}
10. ownerdraw CG_LOAD_GRAPHIC - display the Graphic progress bar which shows the progress in loading the game's graphic and shader files.
itemDef
{
name "graphics"
rect 20 340 380 30
visible MENU_TRUE
forecolor 0.0 0.8 1 1
ownerdraw CG_LOAD_GRAPHIC
align ITEM_ALIGN_CENTER
textstyle ITEM_TEXTSTYLE_NEON
textscale 0.5
special 1.0
}
You can download a sample loading screen menu script and the latest version of the menudef.h file on the Downloads page.