Ownerdraw Item Examples

The Ownerdraw item allows a menu access to much game specific information. It will draw the information in the menu, be it text, graphics, models or cinematics, and, in some cases, allow you to change the value of the information. This changed information can be used in the game to alter gameplay.

There are different catagories of Ownerdraw items and each requires a different set of commands to be defined in the item in order for them to work. We will look at examples of each catagory to see what makes them tick.

Note : In many cases you can change the value of the information shown by an Ownerdraw item by clicking on it. Changing the information can also cause a change in the information contained in other cvars. The program updates any associated cvars when you change Ownerdraw information. For example, changing the game type displayed by UI_GAMETYPE will change the value of the "ui_q3model" cvar, which determines which player model group (Team Arena or Quake 3) is displayed.

Text

Text Ownerdraw items are like any other text items in that they need to have all the usual text commands present in order to draw properly. These items usually draw the contents of a specific cvar and, in many cases, allow you to alter the cvar contents by clicking on the item.

    itemDef 
{
name handicapfield
text "Handicap:"
ownerdraw UI_HANDICAP
textstyle ITEM_TEXTSTYLE_SHADOWEDMORE
rect 0 105 215 32
textalign ITEM_ALIGN_LEFT
textalignx 20
textaligny 21
textscale .333
forecolor 1 1 1 1
visible 1
}

This draws the contents of the "handicap" cvar. The horizontal alignment is applied only to the text string you define with the text command. Therefore, if you use a centered alignment only the text string will be centered, not the text string and the handicap value. The handicap value will be drawn 8 pixels to the right of the end of the text string. The vertical alignment applies to the handicap value, as does the scale and foreground color. The text and the handicap value will be tinted with the focus color and pulse when the item receives the focus.

This Ownerdraw item is one of those that allow you to click on the item and change the value of the cvar. Like all changable Ownerdraw items, the change per click is fixed in the code. In this case, the change is 5 per click, with left click increasing and right click decreasing. The minimum and maximum values of 5 and 100 are also fixed in the code.

In the above example, the contents of the cvar were displayed as a numeric value. The Ownerdraw item automatically chooses the way the contents will be displayed to fit the type of information. If the information is best shown as a text string then it will displayed that way. The following example shows the cvar contents being displayed as a string rather than a value.

    itemDef 
{
name handicapfield
text ""
ownerdraw UI_NETFILTER
textstyle ITEM_TEXTSTYLE_SHADOWEDMORE
rect 0 105 215 32
textalign ITEM_ALIGN_LEFT
textalignx 20
textaligny 21
textscale .333
forecolor 1 1 1 1
visible 1
}

You'll notice that we haven't defined any text in the text command. This is because this Ownerdraw item includes the text "Filter :", followed by the name of the server type. Clicking on the item will change the name of the server type shown.

The above examples are of the type that allows clicking on the item to change the value. Some of the Ownerdraw items don't allow that and are for display purposes only. These items must be set to decoration so they don't gain the focus.

    itemDef 
    {
name driver
rect 10 70 400 300
ownerdraw UI_GLINFO
textalign ITEM_ALIGN_LEFT
textalignx 0
textaligny 23
textscale .25
forecolor 1 1 1 1
visible MENU_TRUE
decoration
}

This Ownerdraw item displays a large amount of information about the OpenGl driver so we give it a large window area and a small text size. It doesn't support any changes by clicking on it so we use the decoration command to stop it ever gaining the focus, which would tint the text the focus color.

Graphics

Some Ownerdraw item display a graphic rather than text, although you can include text in the item definition. Some of these items also allow you to click on them and change the graphic being displayed. Like the text Ownerdraw items, the change is fixed by the program and you are limited to what the program will display.

All of these items except one draw the graphic the same size as the window area so including text in the item tends to make a mess of the display. The UI_EFFECTS item draws the player effects slider in a fixed (128x8) size but places it 14 pixels above the vertical text alignment point. If you include text in the item it can look a little funny unless the text size is just right.. It is normally better to define the text in another item so it can be aligned properly with the graphic.

    itemDef 
    {
name effectfield
ownerdraw UI_EFFECTS
rect 0 205 256 22
visible MENU_TRUE
}

This will draw the effects slider but since no text alignment points are present it will be placed above the item window. Not what we wanted - you have to click on the item window below the slider to change the effect color. To correct this problem we need to use the textaligny command. The effects slider will be placed 14 pixels above the vertical alignment point, so adding :

textaligny 14

will move the slider back into the item's window area. To center the slider you'd need to use :

textaligny 21

since we want 7 pixels above the slider (22-8 = 14 / 2 = 7) and 14 more are needed just to put the slider at the top of the window.

    itemDef 
    {
name effectfield
ownerdraw UI_EFFECTS
rect 0 205 256 22 textaligny 21
visible MENU_TRUE
}

The textalign and textalignx commands can be used (without a text command) to move the left side of the slider in the window.

    itemDef 
    {
name effectfield
ownerdraw UI_EFFECTS
rect 0 205 256 22 textalign ITEM_ALIGN_LEFT textalignx 128 textaligny 21
visible MENU_TRUE
}

This will move the slider over in the window 128 pixels to the right. The effects slider is not really a slider, since you don't click on the thumb and move it. Instead, every time you left click on the item window the effect color moves up one color. A right click on the window moves it down one color.

The Ownerdraw item that draws the crosshair (UI_CROSSHAIR) also places it funny on the screen. The crosshair graphic is drawn the size of the item window but it is drawn so it is completely above the window. You need to use the textaligny command to move it down into the item's window.

    itemDef 
    {
name effectfield
ownerdraw UI_CROSSHAIR
rect 0 205 22 22 textaligny 22
visible MENU_TRUE
}

This will draw the crosshair to fit a window of 22x22 and the textaligny command will move it down 22 pixels to place it inside the window. By left clicking on the item you will advance the crosshair graphic to the next one in the list. Right clicking will move it to the pervious one in the list.

The other graphic Ownerdraw items all draw the graphic to the size of the item window and place in inside the window area. No other formatting is needed to correctly align the graphic. None of these items will respond to clicking and should include the decoration command to avoid giving them the focus.

Models

The model Ownerdraw items are used to display a player model, either the player's model or the opponent's model. The size of the model is determined by the width of the item window. If the height of the window is smaller than the width then not all the model will be displayed. It is best to make the width and height the same size. The model will be centered in the window.

    itemDef 
    {
      name modelselection
      ownerdraw UI_PLAYERMODEL
      rect 424 80 260 260
      decoration 
      visible MENU_TRUE
    }

This draws the player's player model so it fits into a 260x260 window. Since this item doesn't allow clicking on it, it includes the decoration command to avoid giving it the focus. Because this is the player's model there are a number of cvars avalible to customize the animation and weapon shown. To make the customization easier there is a file that contains the defines for the player model. To make these defines avalible to the script you place the following line at the start of your script file, right after the #include "ui/menudef.h" line .

#include "ui/animdef.h"

This line needs to be present only in the script files where player model customization takes place.

First of all is the "ui_Q3Model" cvar. If its value is 0 then it displays the Team Arena player model and if it is 1 then it displays the Quake 3 player model. This cvar is important since to controls what models are avalible to the user for selection. The Team Arena models are loaded from the info in the teaminfo.txt file, while Quake 3 models are found by searching the models/players directory. If the model you expected is not showing up then the value of this cvar is probably incorrect.

Next is the model's animation. The animations are controlled by the value of two cvars, "ui_LowerAnim" and "ui_UpperAnim". Changing the value of these cvars will change the animation of the displayed model. By default the model's leg animation is LEGS_IDLE and the torso animation is TORSO_STAND. You must use other items to change the cvar values since the UI_PLAYERMODEL Ownerdraw item can do nothing except display the model.

    itemDef 
    {
      name leganim
      type ITEM_TYPE_MULTI
      text "Lower Animation:"
      cvar "ui_LowerAnim"
      cvarFloatList { "Idle" LEGS_IDLE "Walk" LEGS_WALK "Run" LEGS_RUN}
      rect 99 150 256 20
      textalign ITEM_ALIGN_CENTER
      textalignx 128
      textaligny 20
      textscale .333        
      forecolor 1 1 1 1
      visible MENU_TRUE 
      action { uiScript UpdateModel }
    }

Here we have a Multi item that changes the value of "ui_LowerAnim". It gives us a choice of three leg animations (Idle, Walk and Run) and sets the cvar to the actual value required. The important line in this item is the action command. When we click on item to change the animation this command is executed. This runs the uiScript UpdateModel action command which updates the player model to reflect the animation change. Without this command the changes to the animation won't show up on the displayed model.

The weapon displayed with the model can also be changed. The weapon shown by default is the machinegun but this can be changed by changing the value of the "ui_Weapon" cvar. Like the animation, this value must be changed by another item and the model updated afterward.

    itemDef 
    {
      name weapon
      type ITEM_TYPE_MULTI
      text "Weapon:"
      cvar "ui_Weapon"
      cvarFloatList { "Machinegun" WP_MACHINEGUN "Shotgun" WP_SHOTGUN "Railgun" WP_RAILGUN}
      rect 99 180 256 20
      textalign ITEM_ALIGN_CENTER
      textalignx 128
      textaligny 20
      textscale .333        
      forecolor 1 1 1 1
      visible MENU_TRUE 
      action { uiScript UpdateModel }
    }

This item allows us a choice of three weapons and updates the model after every change.

The model's view angle is the direction that the model is looking, in relation to us. A yaw angle of 180 has the player looking right at us, face on, while an angle of 0 has him facing the otherway, back to us. By default the yaw angle is 165, so the model is turned slightly to his right. The pitch angle determines the up and down direction the model is looking. An angle of 0 is straight ahead, less than 0 is looking up and larger than 0 is down. By default the pitch angle is 10, looking slightly down. The view angle is controled by the two cvars, "ui_PlayerViewAngleYaw" and "ui_PlayerViewAnglePitch". Again, these values must be changed in another item and the model updated afterward.

    itemDef 
    {
      name viewpitch
      type ITEM_TYPE_MULTI
      text "View Pitch:"
      cvar "ui_PlayerViewAnglePitch"
      cvarFloatList { "Straight" 10 "Up" -30 "Down" 40}
      rect 99 210 256 20
      textalign ITEM_ALIGN_CENTER
      textalignx 128
      textaligny 20
      textscale .333        
      forecolor 1 1 1 1
      visible MENU_TRUE 
      action { uiScript UpdateModel }
    }

With this item we can choose between three directions and have the player model updated after every change.

The model's move angle is the direction the model is moving in relation to the direction it is looking. Only the yaw angle affects the model. An angle of 180 moves the model ahead, while lesser values move it to the right and greater values to the left. The yaw angle is controlled by the "ui_PlayerMoveAngleYaw" cvar and is 165 by default. Once again, this value must be changed in another item and the model updated afterward.

Later, when we look at key binding, we will see other examples of displaying the player model and altering its parameters from other items.

If the model to be displayed is the opponent's model then there is no customization avaible. The model will be shown holding the machinegun and standing at idle.

    itemDef 
    {
      name modelselection
      ownerdraw UI_OPPONENTMODEL
      rect 424 80 260 260
      decoration 
      visible MENU_TRUE
    }

The opponent model is drawn to fit the 260x260 window area and is standing at the default viewing angles.

Cinematics

Cinematic Ownerdraw items are used to display a Roq movie in the item window. The actual movie used is determined by other items which set various cvar values related to maps, teams or listboxes.

    itemDef 
    {
name mappreview
ownerdraw UI_MAPCINEMATIC
rect 320 170 320 192
backcolor 1 1 1 .25
decoration
visible MENU_TRUE
}

This plays the the movie associated with the currently selected map and fits it into a window 320x192 in size. The item is set to decoration to avoid giving it the focus. The background color is not used to tint the movie but it is used if no movie is avalible and a levelshot graphic is used in its place. The graphic is tinted with the background color.

 

Return to Home Page