AddMenuItem

Category: Objects / Menu
Since engine version: 1.0 OC

Description

Adds a menu entry.

Syntax

int AddMenuItem(string caption, string command, id symbol, int count, any parameter, string info_caption, int extra, any XPar1, any XPar2);

Parameters

caption:
Text of the new menu entry
command:
Command to be executed when the menu item is selected. This can be either a function name or a statement. If a function name is given then the function will be called in the object which was given as command_object to CreateMenu.
symbol:
The ID is used as a picture for the menu item. The name of the definition can be used in caption using %s. Also the ID is passed as the first parameter to the call to command in case it is a function name.
count:
Numeric value to be displayed next to the menu entry (such as counts and amounts).
parameter:
Second parameter to the function specified in command (see remark).
info_caption:
Description text of the new menu entry.
extra:
[opt] Extra parameter for special behaviour of the menu entry.
Lower 7 bits (0-127): menu symbol.
0: normal
1: rank symbol. With symbol specified, the Rank.png component of that definition will be used. count indicates the rank
2: picture facet, shifted to the right by XPar1 times the facet width. This is used to include multiple menu symbols in a single definition.
3: XPar1 specifies an object to be drawn with the rank symbol. If the object has no info section (and thus no rank), there will be an empty entry in context menus.
4: XPar1 specifies an object to be drawn.
7: XPar1 is a prop list that contains parameters for the menu symbol drawing. See picture parameter of CustomMessage for possible members. Bit 8 (128): XPar2 is used as object value and overrides the normal object value. Also see extra in CreateMenu
XPar1:
[opt] First additional parameter for extra.
XPar2:
[opt] Second additional parameter for extra.

Remarks

Custom menu symbols should best have square aspect ratio.
If a function name is specified for command, the following parameters are passed: symbol, parameter, bRight[, value] with bRight indicating whether the menu entry was selected with [Special2] or the right mouse button. value is passed only if bit 8 is set in extra and specifies the displayed (overridden) object value of the menu entry.

Example

func ControlUse()
{
	// Create local menu with local commandos
	CreateMenu(GetID());
	// Create menu items
	AddMenuItem("Say hello", "SayHello");
	AddMenuItem("Do magic", "DoMagic");
	AddMenuItem("Create an object: %s", "CreateItem", Rock);
	AddMenuItem("Create another object: %s", "CreateItem", Firestone);
}

func SayHello()
{
	Message("Hello",this);
}

func DoMagic()
{
	Sound("Magic*");
}

func CreateItem(id item)
{
	CreateContents(item);
}
Menu for a special item.
See also: CloseMenu, CreateMenu, SelectMenuItem
jwk, 2002-04