Editfield items are used to allow the user to type information and have it placed in a cvar for use by other menus and the game. These are text items and require the usual text commands in order to display properly. Numeric Editfield items differ from ordinary Editfield items in that they will only allow numeric input, rather than any text.
itemDef
{
name namefield
type ITEM_TYPE_EDITFIELD
text "Name:"
cvar "ui_Name"
textstyle ITEM_TEXTSTYLE_SHADOWEDMORE
rect 0 70 215 32
textalign ITEM_ALIGN_LEFT
textalignx 20
textaligny 21
textscale .333
forecolor 1 1 1 1
visible MENU_TRUE
}
This item allows us to enter a string of text and have it placed in the "ui_Name" cvar. This cvar is used by the program to hold the name of the player. 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 entered text. The entered text will be drawn 8 pixels to the right of the end of the text string. The vertical alignment applies to the entered text, as does the scale and foreground color. The text and the entered text will be tinted with the focus color and pulse when the item receives the focus.
It can be useful to limit the number of characters that can be entered into the Editfield item and to limit the number of characters that will be displayed. If too many characters are entered into the cvar an overflow can occur with unforeseen results. Displaying more characters than can fit in the item window can lead to problems with other items.
itemDef
{
name namefield
type ITEM_TYPE_EDITFIELD
text "Name:"
cvar "ui_Name"
textstyle ITEM_TEXTSTYLE_SHADOWEDMORE
rect 0 70 215 32
textalign ITEM_ALIGN_LEFT
textalignx 20
textaligny 21
textscale .333
maxChars 32
maxPaintChars 20
forecolor 1 1 1 1
visible MENU_TRUE
}
We set the maximum number of characters that can be entered to 32 with the maxChars command. The maxPaintChars command makes it so only 20 characters will be shown. You can scroll the entered text to see all of it if there is more than 20 characters entered.
As with other text items you can have a colored or graphic background and have borders if desired.
itemDef
{
name namefield
type ITEM_TYPE_EDITFIELD
text "Name:"
cvar "ui_Name"
textstyle ITEM_TEXTSTYLE_SHADOWEDMORE
rect 0 70 215 32
textalign ITEM_ALIGN_LEFT
textalignx 20
textaligny 21
textscale .333
maxChars 32
maxPaintChars 20
forecolor 1 1 1 1
backcolor 0 0 .75 .25
border WINDOW_BORDER_KCGRADIENT
bordercolor 0.5 0.5 0.5 1
bordersize 1
visible MENU_TRUE
}
This fills the background with a light blue and places a border top and bottom.
Sometimes you want to display the contents of a cvar but don't want the user to be able to change it. The Editfield item can be used for this by the addition of the decoration command.
itemDef
{
name frag
type ITEM_TYPE_NUMERICFIELD
text "Frag limit:"
cvar "ui_fraglimit"
rect 120 200 128 12
textalign ITEM_ALIGN_LEFT
textalignx 0
textaligny 12
textscale .25
forecolor 1 1 1 1
visible MENU_TRUE
decoration
}
This item displays the contents of the "ui_fraglimit" cvar as a number, since the item type is ITEM_TYPE_NUMERICFIELD. The decoration command ensures that the value can not be changed since the item can never receive the focus. If we were displaying a cvar that contains text, like the "ui_Name" cvar, then we'd change the item type to ITEM_TYPE_EDITFIELD.