AddMenuItem

Category: Objects / Menu
Since engine version: 4.6.5.0 CP (extended in 4.9.5.0 CE)

Description

Adds a menu entry.

Syntax

int AddMenuItem (string szCaption, string szCommand, id idItem, object pMenuObject, int iCount, int iParameter, string szInfoCaption, int iExtra, any XPar1, any XPar2);

Parameters

szCaption:
Text of the new menu entry
szCommand:
Script to be executed. Can be a function name or other statement. If a function name is specified, it will be called in pCommandObject specified with CreateMenu.
idItem:
The ID is used as a picture for the menu entry. The name of the definition can be used in szCaption via %s. Furthermore the ID is passed as first argument to the function specified in szCommand, if it is a function name.
pMenuObject:
Object holding the menu to which to add the entry. Can be 0 in local calls.
iCount:
Numeric value to be displayed next to the menu entry (such as counts and amounts).
iParameter:
Second parameter to the function specified in szCommand (see remark).
szInfoCaption:
Description text of the new menu entry
iExtra:
[opt] Additional parameter determining the behavior of the menu entry.
Lower 7 bits (0-127): Menu entry icon. Can't be combined.
0: Normal
C4MN_Add_ImgRank = 1; Rank icon. With a specified idItem the Rank.png of the definition will be used if applicable. iCount determines the rank level.
C4MN_Add_ImgIndexed = 2; The picture facet XPar1 times the picture width shifted to the right will be used. This may be used to store multiple icons in a single definition.
C4MN_Add_ImgObjRank = 3: XPar1 is an object of which the picture including its rank will be used as icon. If the object doesn't have any info section (thus also no rank) in context menus a space for the rank symbol will be left out anyway. Since CE.
C4MN_Add_ImgObject = 4: XPar1 is an object of which the picture is used as icon. Since CE.
C4MN_Add_ImgTextSpec = 5: The symbol is defined in szCaption and can be either a normal ID, a portrait specification of the format "Portrait:CLNK::00ff00::1" or one of the following icons:
Name Description
Ico:Locked Password icon
Ico:League League icon
Ico:GameRunning Game running icon
Ico:Lobby Lobby icon
Ico:RuntimeJoin Runtime join allowed icon
Ico:FairCrew Fair crew icon
Ico:Settlement Settlement score icon

C4MN_Add_ImgColor = 6: The owner color area of the icon will be colorized with the color specified in XPar1.
C4MN_Add_ImgIndexedColor = 7: The picture facet XPar1 times the picture width shifted to the right will be used. The owner color area of the icon will be colorized with the color specified in XPar2. Can not be combined with C4MN_Add_PassValue.

Additional flags (can be combined with those mentioned before):
C4MN_Add_PassValue = 128: XPar2 is used as value and overrides the default value found (in the definition idItem). See also iExtra of CreateMenu.
C4MN_Add_ForceCount = 256: If this flag is specified, also an iCount of 0 will be shown (like it is the case in the buying menu, for example).
It should also be mentioned that internally the value C4MN_Item_NoCount = 12345678 is used if this flag isn't specified but iCount is 0. This means that in the special case where iCount is passed as 12345678 the count won't be shown.
C4MN_Add_ForceNoDesc = 512: If this flag is specified the description (set with szInfoCaption and shown as a tooltip) of the menu entry is suppressed completely, whereas in contrast passing 0 as szInfoCaption will show the description of idItem.
XPar1:
[opt] First additional parameter for iExtra.
XPar2:
[opt] Second additional parameter for iExtra.

Remarks

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

Examples

/* Wird bei Doppelklick auf Graben aufgerufen */
func Activate()
{
	// Lokales Menü mit lokalen Kommandos erzeugen
	CreateMenu(GetID());
	// Menüeinträge erzeugen
	AddMenuItem("Hallo sagen", "SayHello", 0);
	AddMenuItem("Zaubern", "DoMagic", 0);
	AddMenuItem("Objekt erzeugen: %s", "CreateItem", ROCK);
	AddMenuItem("Objekt erzeugen: %s", "CreateItem", FLNT);
}

/* Diese Kommados werden vom Menü aufgerufen */
func SayHello()
{
	Message("Hallo",this());
}

func DoMagic()
{
	Sound("Magic*");
	ObjectCall(CreateObject(MLGT,0,0),"Activate",this());
}

func CreateItem(id item)
{
	Sound("Magic*");
	CreateContents(item);
}
Menu for a special clonk.
func Activate(object clonk)
{
	// Menü im Clonk mit lokalen Kommandos erzeugen
	CreateMenu(GetID(), clonk, this());
	// Menüeinträge erzeugen
	AddMenuItem(Format("%s Schrumpfen", GetName(clonk)), Format("DoCon(-10,Object(%d))", ObjectNumber(%d)), 0, this(), 0, 0, "Eine Art Jungbrunnen.", 4, clonk);
}
Menu for a shrinking object.
See also: CloseMenu, CreateMenu, SelectMenuItem, SetMenuDecoration, SetMenuTextProgress
jwk, April 2002