PDA

View Full Version : [CoD2] create functions in .menu-files!



serthy
9th January 2013, 09:57
Sanibonani =)

I just discovered that you are able to define simple functions in CoD2-menus!


#include "ui_mp/menudef.h"


#define TEXT_DRAW( t_rect , t_text ) \
itemDef \
{ \
rect t_rect \
text t_text \
visible 1 \
}

{
menuDef
{
name "testmenu"
rect 0 0 640 480 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN
focuscolor GLOBAL_FOCUSED_COLOR
style WINDOW_STYLE_EMPTY
blurWorld 5.0

TEXT_DRAW( 0 0 0 0 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER , "Text on the center of your screen!" )
}
}

- you have to add after every line of your function a "\", except for the last closing bracket!
- just call the function as in the example without a semicolon! >>> FUNCTION( parameter )
- I guess your FUNCTION-pointer needs to be defined and called in UPPERCASE!

feel free to find other possible ones and please post them here!

cheers serthy

kung foo man
9th January 2013, 19:55
They are called Macros. :D

.menu-files are basically preprocessed like .h-files in C.


One more example:



#define DVAR_CHECK(name, value) \
dvartest name \
showDvar { value/*, ("12")*/ } /*wow,very dynamic,that works*/

#define RECT(_rect_) \
rect _rect_ HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN

#define BUTTON_WEAPON(_name, _rect, _origin, _forecolor, _text, _scriptMenuResponse, _dvartest, _showdvar) \
itemDef \
{ \
name _name \
visible 1 \
RECT(_rect) \
origin _origin \
forecolor _forecolor \
type ITEM_TYPE_BUTTON \
text _text \
textfont UI_FONT_NORMAL \
textscale GLOBAL_TEXT_SIZE \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textaligny 20 \
DVAR_CHECK(_dvartest, _showdvar) \
action \
{ \
play "mouse_click"; \
scriptMenuResponse _scriptMenuResponse; \
} \
onFocus \
{ \
play "mouse_over"; \
} \
}

//BUTTON_WEAPON(
// /*name*/ "button_springfield",
// /*rect*/ 0 0 128 24,
// /*origin*/ ORIGIN_CHOICE4,
// /*forecolor*/ GLOBAL_UNFOCUSED_COLOR,
// /*text*/ "@MPUI_4_SPRINGFIELD",
// /*scriptMenuResponse*/ "springfield_mp",
// /*dvartest and showdvar*/ "ui_allow_springfield", ("1","5", "6", "8"))

/*
itemDef
{
name "button_springfield"
visible 1
rect 0 0 128 24
origin ORIGIN_CHOICE4
forecolor GLOBAL_DISABLED_COLOR
type ITEM_TYPE_BUTTON
text "@MPUI_4_SPRINGFIELD"
textfont UI_FONT_NORMAL
textscale GLOBAL_TEXT_SIZE
textstyle ITEM_TEXTSTYLE_SHADOWED
textaligny 20
dvartest "ui_allow_springfield"
showDvar { "2" }
onFocus
{
hide greasegun_info;
hide m1carbine_info;
hide m1garand_info;
hide thompson_info;
hide bar_info;
hide shotgun_info;
play "mouse_over";
show springfield_info;
show weapon_propertiestext;
}
}
*/


//BUTTON_WEAPON(
// /*name*/ "button_springfield",
// /*rect*/ 0 0 128 24,
// /*origin*/ ORIGIN_CHOICE4,
// /*forecolor*/ GLOBAL_DISABLED_COLOR,
// /*text*/ "@MPUI_4_SPRINGFIELD",
// /*scriptMenuResponse*/ "springfield_mp",
// /*dvartest and showdvar*/ "ui_allow_springfield", ("2")
//)




#define BUTTON(_origin, _dvar, _scriptMenuResponse, _dvartest, _showdvar) \
itemDef \
{ \
name _dvar \
visible 1 \
RECT(0 0 128 24) \
origin _origin \
forecolor GLOBAL_UNFOCUSED_COLOR \
type ITEM_TYPE_BUTTON \
textfont UI_FONT_NORMAL \
textscale GLOBAL_TEXT_SIZE \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textaligny 20 \
DVAR_CHECK(_dvartest, _showdvar) \
dvar _dvar \
action \
{ \
play "mouse_click"; \
scriptMenuResponse _scriptMenuResponse; \
} \
onFocus \
{ \
play "mouse_over"; \
} \
}



BUTTON(80 80, "ui_weapon_0", "weapon 0", "ui_weapon_0_show", "1")
BUTTON(80 100, "ui_weapon_1", "weapon 1", "ui_weapon_1_show", "1")
BUTTON(80 120, "ui_weapon_2", "weapon 2", "ui_weapon_2_show", "1")
BUTTON(80 140, "ui_weapon_3", "weapon 3", "ui_weapon_3_show", "1")


Very good to shorten .menu-files.

serthy
10th January 2013, 00:19
*macros yeah, sorry

-unfortunately mathematical operations like + - * / and % do NOT work on CoD2, also brackets () and such menu-events like 'exp', 'fadein', 'fadeout' and 'transition' do NOT work
-if you add them into your menu, it will NOT load ingame
-boolean operators like && and || do work in menu-actions like showDvar{ 1 || 2 || 3 }
-assetGlobalDef{} settings are like the name assumes, GLOBAL, but i failed to set other values for ex. fadeClamp or changing the connect/main/ingame etc menu name, also the shadowcolor stays the same

Tally
2nd June 2013, 14:25
I've been playing around with Macros all week now, converting Demon mod menus to macros. Here are a couple of "gottayas" I experienced:

1. ITEM RECTANGLES - you can no longer get away with defining just 4 parameters in an itemDef{} rectangle. It has to have 6 parameters. If you don't put 6 in, it wont parse the rest of your arguments. It will throw an error telling you it expected an integer or float but found something else - ignoring the comma which separates them. So, you need to use 2 more coordinates, and these are bitmask numbers which tell the engine where to align your rectangle.

COD2 doesn't give us access to menudefinitions.h (don't confuse this with menudef.h - it isn't the same), but as COD4 uses the same definitions, and as they gave us menudefinitons.h for COD4, here is a list of the menu bitmask definitions used by Infinity Ward:


// Edge relative placement values for rect->h_align and rect->v_align
#define HORIZONTAL_ALIGN_SUBLEFT 0 // left edge of a 4:3 screen (safe area not included)
#define HORIZONTAL_ALIGN_LEFT 1 // left viewable (safe area) edge
#define HORIZONTAL_ALIGN_CENTER 2 // center of the screen (reticle)
#define HORIZONTAL_ALIGN_RIGHT 3 // right viewable (safe area) edge
#define HORIZONTAL_ALIGN_FULLSCREEN 4 // disregards safe area
#define HORIZONTAL_ALIGN_NOSCALE 5 // uses exact parameters - neither adjusts for safe area nor scales for screen size
#define HORIZONTAL_ALIGN_TO640 6 // scales a real-screen resolution x down into the 0 - 640 range
#define HORIZONTAL_ALIGN_CENTER_SAFEAREA 7 // center of the safearea
#define HORIZONTAL_ALIGN_MAX HORIZONTAL_ALIGN_CENTER_SAFEAREA
#define HORIZONTAL_ALIGN_DEFAULT HORIZONTAL_ALIGN_SUBLEFT

#define VERTICAL_ALIGN_SUBTOP 0 // top edge of the 4:3 screen (safe area not included)
#define VERTICAL_ALIGN_TOP 1 // top viewable (safe area) edge
#define VERTICAL_ALIGN_CENTER 2 // center of the screen (reticle)
#define VERTICAL_ALIGN_BOTTOM 3 // bottom viewable (safe area) edge
#define VERTICAL_ALIGN_FULLSCREEN 4 // disregards safe area
#define VERTICAL_ALIGN_NOSCALE 5 // uses exact parameters - neither adjusts for safe area nor scales for screen size
#define VERTICAL_ALIGN_TO480 6 // scales a real-screen resolution y down into the 0 - 480 range
#define VERTICAL_ALIGN_CENTER_SAFEAREA 7 // center of the save area
#define VERTICAL_ALIGN_MAX VERTICAL_ALIGN_CENTER_SAFEAREA
#define VERTICAL_ALIGN_DEFAULT VERTICAL_ALIGN_SUBTOP


All of those work. You have to work your way through all of your itemDef{} rectangles and redefine them, as your originals wont work any longer.

2. Onfocus{} + "mouse_over" soundalias - this produces a horrible buzzing sound all over the menu. I could not get rid of it. So, I reverted to using mouseEnter{} to play "mouse_over".

3. You can only include your macros file once - otherwise it throws an error that the macros are already defined. The thing is, if you want to use the macros in another file included in your main menu file, it wont find them. And, as stated, if you try to include the macros file at the top of this include file, it will tell you the macros are already defined. So, it wont let you define them twice, but wont actually use the macro file in an include. Pretty much screwed with that one. Back to including all your items in one file.

4. A good tip when defining your rectangles is to use boarders so you can see where the actual size. Then use the Y co-ordinates to move either your text or your shader down.

So, here is an updated version of Demon mod's Assault Class menu:



{
menuDef
{
name "assault_american"
rect 0 0 640 480
focuscolor GLOBAL_FOCUSED_COLOR
style WINDOW_STYLE_EMPTY
blurWorld 5.0
onEsc
{
close assault_american;
}
onOpen
{
show greasegun_info;
show weapon_propertiestext;
show tabungas;
show tabungas_replace;
show frag;
}
onClose
{
hide greasegun_info;
hide thompson_info;
hide shotgun_info;
hide frag;
hide tabungas;
hide tabungas_replace;
}

#include "ui_mp/custom/templates.inc"

DRAWSHADER_NODVAR( "gradient", 0 0, 0 0 640 480 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, 1 1 1 .9, "gradient", 1 )

#include "ui/bars.menu"
#include "ui_mp/custom/teamicon_allies.inc"
#include "ui_mp/custom/menu_wireframe.inc"
// #include "ui_mp/custom/sidearm.inc"
#include "ui_mp/custom/allied_special_grenades.inc"

DRAWTEXT_NODVAR( "title", 0 0 50 50 HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_TOP, ORIGIN_TITLE, 1 1 1 1, "@Assault Class", 1, UI_FONT_NORMAL, GLOBAL_HEADER_SIZE, 0, 0, ITEM_TEXTSTYLE_SHADOWED )

//********* MENU CHOICES ****************

execKey "1" { play "mouse_click"; scriptMenuResponse "greasegun_mp"; }
execKey "2" { play "mouse_click"; scriptMenuResponse "thompson_mp"; }
execKey "3" { play "mouse_click"; scriptMenuResponse "shotgun_mp"; }

//--- GREASEGUN ----

CHOICE_BUTTON( "button_greasegun", 1, RECTANGLE, ORIGIN_CHOICE1, GLOBAL_UNFOCUSED_COLOR, "@MPUI_1_GREASEGUN", UI_FONT_NORMAL, GLOBAL_TEXT_SIZE, ITEM_TEXTSTYLE_SHADOWED, 20, "ui_allow_greasegun", "1", "greasegun_mp", thompson_info, shotgun_info, "", greasegun_info, weapon_propertiestext )
CHOICE_DIS_BUTTON( "button_greasegun_disabled", 1, RECTANGLE, ORIGIN_CHOICE1, "@MPUI_1_GREASEGUN", UI_FONT_NORMAL, GLOBAL_TEXT_SIZE, ITEM_TEXTSTYLE_SHADOWED, 20, "ui_allow_greasegun", "1", thompson_info, shotgun_info, greasegun_info, weapon_propertiestext, frag, tabungas, tabungas_replace, disabled_info )

//--- THOMPSON ----

CHOICE_BUTTON( "button_thompson", 1, RECTANGLE, ORIGIN_CHOICE2, GLOBAL_UNFOCUSED_COLOR, "@2. Thompson", UI_FONT_NORMAL, GLOBAL_TEXT_SIZE, ITEM_TEXTSTYLE_SHADOWED, 20, "ui_allow_thompson", "1", "thompson_mp", greasegun_info, shotgun_info, "", thompson_info, weapon_propertiestext )
CHOICE_DIS_BUTTON( "button_thompson_disabled", 1, RECTANGLE, ORIGIN_CHOICE2, "@2. Thompson", UI_FONT_NORMAL, GLOBAL_TEXT_SIZE, ITEM_TEXTSTYLE_SHADOWED, 20, "ui_allow_thompson", "1", thompson_info, shotgun_info, greasegun_info, weapon_propertiestext, frag, tabungas, tabungas_replace, disabled_info )

//--- SHOTGUN ----

CHOICE_BUTTON( "button_shotgun", 1, RECTANGLE, ORIGIN_CHOICE3, GLOBAL_UNFOCUSED_COLOR, "@3. M1897 Trench Gun", UI_FONT_NORMAL, GLOBAL_TEXT_SIZE, ITEM_TEXTSTYLE_SHADOWED, 20, "ui_allow_shotgun", "1", "shotgun_mp", greasegun_info, thompson_info, "", shotgun_info, weapon_propertiestext )
CHOICE_DIS_BUTTON( "button_shotgun_disabled", 1, RECTANGLE, ORIGIN_CHOICE3, "@3. M1897 Trench Gun", UI_FONT_NORMAL, GLOBAL_TEXT_SIZE, ITEM_TEXTSTYLE_SHADOWED, 20, "ui_allow_shotgun", "1", thompson_info, shotgun_info, greasegun_info, weapon_propertiestext, frag, tabungas, tabungas_replace, disabled_info )


//*************** PERK ICONS *********************

//--- TABUN GAS ---
DRAWSHADER( "tabungas_perk", ORIGN_PERK_1, PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, .7 .7 .7 .7, "specialty_weapon_tabungas", "scr_demon_allow_tabungas", "1", 1 )
HIDESHADER( "null", ORIGN_PERK_1, PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, .7 .7 .7 .7, "specialty_null", "scr_demon_allow_tabungas", "1", 1 )

//--- STOPPING POWER ---
DRAWSHADER( "stopping_power", ORIGN_PERK_2, PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, .7 .7 .7 .7, "specialty_bulletdamage", "scr_demon_allow_bulletdamage", "1", 1 )
HIDESHADER( "null", ORIGN_PERK_2, PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, .7 .7 .7 .7, "specialty_null", "scr_demon_allow_bulletdamage", "1", 1 )

//--- MARTYRDOM ---
DRAWSHADER( "martyrdom", ORIGN_PERK_3, PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, .7 .7 .7 .7, "specialty_grenadepulldeath", "scr_demon_allow_martyrdom", "1", 1 )
HIDESHADER( "null", ORIGN_PERK_3, PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, .7 .7 .7 .7, "specialty_null", "scr_demon_allow_martyrdom", "1", 1 )

//*************** PERK TEXT ***********************

//--- TABUN GAS ---
DRAWTEXT( "tabungas_perk", DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, PERK_DES_1, 1 1 1 1, "@Tabun Gas", "scr_demon_allow_tabungas", "1", 1, UI_FONT_NORMAL, .18, 7, 7, ITEM_TEXTSTYLE_SHADOWED )
HIDETEXT( "tabungas_perk", DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, PERK_DES_1, 1 1 1 1, "@DISABLED", "scr_demon_allow_tabungas", "1", 1, UI_FONT_NORMAL, .18, 7, 7, ITEM_TEXTSTYLE_SHADOWED )

//--- STOPPING POWER ---
DRAWTEXT( "stopping_power", DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, PERK_DES_2, 1 1 1 1, "@Stopping Power", "scr_demon_allow_bulletdamage", "1", 1, UI_FONT_NORMAL, .18, 7, 0, ITEM_TEXTSTYLE_SHADOWED )
HIDETEXT( "stopping_power", DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, PERK_DES_2, 1 1 1 1, "@DISABLED", "scr_demon_allow_bulletdamage", "1", 1, UI_FONT_NORMAL, .18, 7, 7, ITEM_TEXTSTYLE_SHADOWED )

//--- MARTYRDOM ---
DRAWTEXT( "martyrdom", DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, PERK_DES_3, 1 1 1 1, "@Martyrdom", "scr_demon_allow_martyrdom", "1", 1, UI_FONT_NORMAL, .18, 7, 7, ITEM_TEXTSTYLE_SHADOWED )
HIDETEXT( "martyrdom", DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, PERK_DES_3, 1 1 1 1, "@DISABLED", "scr_demon_allow_martyrdom", "1", 1, UI_FONT_NORMAL, .18, 7, 7, ITEM_TEXTSTYLE_SHADOWED )


//******************* WEAPON IMAGES ********************

//--- GREASEGUN ----
DRAWSHADER_NODVAR( "greasegun_info", ORIGIN_WEAPONIMAGE_1, WEAPONIMAGE_SIZE HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_TOP, 1 1 1 1, "weapon_greasegun", 0 )

//--- THOMPSON ---
DRAWSHADER_NODVAR( "thompson_info", ORIGIN_WEAPONIMAGE_1, WEAPONIMAGE_SIZE HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_TOP, 1 1 1 1, "weapon_thompson", 0 )

//--- SHOTGUN ----
DRAWSHADER_NODVAR( "shotgun_info", ORIGIN_WEAPONIMAGE_1, WEAPONIMAGE_SIZE HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_TOP, 1 1 1 1, "weapon_shotgun", 0 )

//*************** WEAPON PROPERTIES ***************

DRAWTEXT_NODVAR( "weapon_propertiestext", 0 0 20 50 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, ORIGIN_WEAPONPROPERTIESTEXT_1, 1 1 1 1, "@MPUI_ACCURACY_DAMAGE_MOBILITY", 0, UI_FONT_NORMAL, GLOBAL_TEXT_SIZE, 0, 0, ITEM_TEXTSTYLE_SHADOWED )

//--- GREASEGUN ----

DRAWSHADER_NODVAR( "greasegun_info", ORIGIN_WEAPONACCURACY_1, 0 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 .125, "white", 0 )
DRAWSHADER_NODVAR( "greasegun_info", ORIGIN_WEAPONACCURACY_1, 0 0 70 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 1, "white", 0 )

DRAWSHADER_NODVAR( "greasegun_info", ORIGIN_WEAPONDAMAGE_1, 0 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 .125, "white", 0 )
DRAWSHADER_NODVAR( "greasegun_info", ORIGIN_WEAPONDAMAGE_1, 0 0 75 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 1, "white", 0 )

DRAWSHADER_NODVAR( "greasegun_info", ORIGIN_WEAPONMOBILITY_1, 0 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 .125, "white", 0 )
DRAWSHADER_NODVAR( "greasegun_info", ORIGIN_WEAPONMOBILITY_1, 0 0 96 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 1, "white", 0 )

//--- THOMPSON ---

DRAWSHADER_NODVAR( "thompson_info", ORIGIN_WEAPONACCURACY_1, 0 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 .125, "white", 0 )
DRAWSHADER_NODVAR( "thompson_info", ORIGIN_WEAPONACCURACY_1, 0 0 56 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 1, "white", 0 )

DRAWSHADER_NODVAR( "thompson_info", ORIGIN_WEAPONDAMAGE_1, 0 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 .125, "white", 0 )
DRAWSHADER_NODVAR( "thompson_info", ORIGIN_WEAPONDAMAGE_1, 0 0 83 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 1, "white", 0 )

DRAWSHADER_NODVAR( "thompson_info", ORIGIN_WEAPONMOBILITY_1, 0 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 .125, "white", 0 )
DRAWSHADER_NODVAR( "thompson_info", ORIGIN_WEAPONMOBILITY_1, 0 0 96 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 1, "white", 0 )

//---- SHOTGUN ----

DRAWSHADER_NODVAR( "shotgun_info", ORIGIN_WEAPONACCURACY_1, 0 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 .125, "white", 0 )
DRAWSHADER_NODVAR( "shotgun_info", ORIGIN_WEAPONACCURACY_1, 0 0 35 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 1, "white", 0 )

DRAWSHADER_NODVAR( "shotgun_info", ORIGIN_WEAPONDAMAGE_1, 0 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 .125, "white", 0 )
DRAWSHADER_NODVAR( "shotgun_info", ORIGIN_WEAPONDAMAGE_1, 0 0 100 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 1, "white", 0 )

DRAWSHADER_NODVAR( "shotgun_info", ORIGIN_WEAPONMOBILITY_1, 0 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 .125, "white", 0 )
DRAWSHADER_NODVAR( "shotgun_info", ORIGIN_WEAPONMOBILITY_1, 0 0 80 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 1 1 1 1, "white", 0 )


//******************** SIDEARM ************************

DRAWSHADER( "colt", ORIGIN_PISTOL, PISTOL_IMAGE_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, 1 1 1 1, "weapon_colt45", "ui_sidearm_colt", "1", 1 )

DRAWSHADER( "magnum", ORIGIN_PISTOL, 0 4 75 75 HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, 1 1 1 1, "weapon_magnum", "ui_sidearm_magnum", "1", 1 )

DRAWSHADER( "knife", ORIGIN_PISTOL, 0 0 95 95 HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, 1 1 1 1, "weapon_knife", "ui_sidearm_knife", "1", 1 )

/////////////////// EDIT BUTTON /////////////////////////////

EDIT_BUTTON( "edit_sidearm", 1, PISTOL_RECT HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER, SIDEARM_EDIT_ORG, EDIT_COLOR, .18, 15, 0, "popup_sidearm" )


//************* MISC BUTTONS *************************

//BACK BUTTON
itemDef
{
#include "ui_mp/button_back.menu"

action
{
play "mouse_click";
close medic_american;
close gunner_american;
close assault_american;
close engineer_american;
close officer_american;
close sniper_american;

open class_allies;
}
mouseEnter
{
play "mouse_over";
}
}

// MAIN MENU
itemDef
{
#include "ui_mp/button_mainmenu.menu"

action
{
play "mouse_click";
close assault_american;
open main;
}
mouseEnter
{
play "mouse_over";
}
}

}
}


And here are the Macros it uses:



#define EDIT_BUTTON( nameArg, visArg, rectArg, originArg, colorArg, scaleArg, alignYArg, alignXArg, menuArg ) \
itemDef \
{ \
name nameArg \
type ITEM_TYPE_BUTTON \
visible visArg \
rect rectArg \
origin originArg \
forecolor colorArg \
text "@[ CLICK TO EDIT ]" \
textfont UI_FONT_NORMAL \
textscale scaleArg \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textaligny alignYArg \
textalignx alignXArg \
action \
{ \
play "mouse_click"; \
open menuArg; \
} \
mouseEnter \
{ \
play "mouse_over"; \
} \
}\

#define CHOICE_BUTTON( nameArg, visArg, rectArg, originArg, colorArg, textArg, fontArg, scaleArg, styleArg, alignYArg, dvarArg, valueArg, responseArg, hideArg1, hideArg2, hideArg3, showArg1, showArg2 ) \
itemDef \
{ \
name nameArg \
type ITEM_TYPE_BUTTON \
visible visArg \
rect rectArg \
origin originArg \
forecolor colorArg \
text textArg \
textfont fontArg \
textscale scaleArg \
textstyle styleArg \
textaligny alignYArg \
dvartest dvarArg \
showDvar { valueArg } \
action \
{ \
play "mouse_click"; \
scriptMenuResponse responseArg; \
} \
onFocus \
{ \
hide hideArg1; \
hide hideArg2; \
hide hideArg3; \
show showArg1; \
show showArg2; \
} \
mouseEnter \
{ \
play "mouse_over"; \
} \
}

#define CHOICE_DIS_BUTTON( nameArg, visArg, rectArg, originArg, textArg, fontArg, scaleArg, styleArg, alignYArg, dvarArg, valueArg, hideArg1, hideArg2, hideArg3, hideArg4, hideArg5, hideArg6, hideArg7, showArg ) \
itemDef \
{ \
name nameArg \
type ITEM_TYPE_BUTTON \
visible visArg \
rect rectArg \
origin originArg \
forecolor GLOBAL_DISABLED_COLOR \
text textArg \
textfont fontArg \
textscale scaleArg \
textstyle styleArg \
textaligny alignYArg \
dvartest dvarArg \
hideDvar { valueArg } \
decoration \
mouseEnter \
{ \
hide hideArg1; \
hide hideArg2; \
hide hideArg3; \
hide hideArg4; \
hide hideArg5; \
hide hideArg6; \
hide hideArg7; \
hide hideArg8; \
show showArg; \
} \
mouseExit \
{ \
hide showArg; \
show hideArg5; \
show hideArg6; \
show hideArg7; \
} \
}

#define DRAWSHADER( nameArg, originArg, rectArg, colorArg, shaderArg, dvarArg, valueArg, visArg ) \
itemDef \
{ \
name nameArg \
style WINDOW_STYLE_SHADER \
visible visArg \
rect rectArg \
origin originArg \
forecolor colorArg \
background shaderArg \
dvartest dvarArg \
showDvar { valueArg } \
}

#define HIDESHADER( nameArg, originArg, rectArg, colorArg, shaderArg, dvarArg, valueArg, visArg ) \
itemDef \
{ \
name nameArg \
style WINDOW_STYLE_SHADER \
visible visArg \
rect rectArg \
origin originArg \
forecolor colorArg \
background shaderArg \
dvartest dvarArg \
hideDvar { valueArg } \
}

#define DRAWSHADER_NODVAR( nameArg, originArg, rectArg, colorArg, shaderArg, visArg ) \
itemDef \
{ \
name nameArg \
style WINDOW_STYLE_SHADER \
visible visArg \
rect rectArg \
origin originArg \
forecolor colorArg \
background shaderArg \
}

#define DRAWTEXT( nameArg, rectArg, originArg, colorArg, textArg, dvarArg, valueArg, visArg, fontArg, scaleArg, alignYArg, alignXArg, fontStyleArg ) \
itemDef \
{ \
name nameArg \
type ITEM_TYPE_TEXT \
visible visArg \
rect rectArg \
origin originArg \
forecolor colorArg \
text textArg \
textfont fontArg \
textscale scaleArg \
textstyle fontStyleArg \
textaligny alignYArg \
textalignx alignXArg \
dvartest dvarArg \
showDvar { valueArg } \
}

#define HIDETEXT( nameArg, rectArg, originArg, colorArg, textArg, dvarArg, valueArg, visArg, fontArg, scaleArg, alignYArg, alignXArg, fontStyleArg ) \
itemDef \
{ \
name nameArg \
type ITEM_TYPE_TEXT \
visible visArg \
rect rectArg \
origin originArg \
forecolor colorArg \
text textArg \
textfont fontArg \
textscale scaleArg \
textstyle fontStyleArg \
textaligny alignYArg \
textalignx alignXArg \
dvartest dvarArg \
hideDvar { valueArg } \
}

#define DRAWTEXT_NODVAR( nameArg, rectArg, originArg, colorArg, textArg, visArg, fontArg, scaleArg, alignYArg, alignXArg, fontStyleArg ) \
itemDef \
{ \
name nameArg \
type ITEM_TYPE_TEXT \
visible visArg \
rect rectArg \
origin originArg \
forecolor colorArg \
text textArg \
textfont fontArg \
textscale scaleArg \
textstyle fontStyleArg \
textaligny alignYArg \
textalignx alignXArg \
}


Which produces the rather beautiful (if I don't say so myself) Assault Class menu:

http://imageshack.us/a/img827/1926/assaultclass.png

serthy
2nd June 2013, 19:35
good to see that macros come in handy even in cod2
you can find the menudefinitions.h in the ui-folder (iw7.iwd)

i'd advice everyone to use the ##-operator to combineyour variables much more easily:



#define DRAW_BUTTON( _name , _pos , _menu ) \

itemDef \
{ \
name "button" ## _name \
visible 1 \
rect _pos 50 50 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER \
origin 10 10 \
forecolor GLOBAL_UNFOCUSED_COLOR \
type ITEM_TYPE_BUTTON \
text _name \
textscale 0.23 \
textstyle ITEM_TEXTSTYLE_SHADOWEDMORE \
textalign ITEM_ALIGN_CENTER \
textalignx 25 \
textaligny 25 \
wrapped \
action \
{ \
play "click_2"; \
scriptMenuResponse _name; \
open _menu; \
} \
mouseEnter \
{ \
play "hover_2"; \
setItemColor "hover" ## _name forecolor 1 1 0 1; \
setItemColor "hover" ## _name backcolor 1 1 0 1; \
} \
mouseExit \
{ \
setItemColor "hover" ## _name forecolor BG_COLOR; \
setItemColor "hover" ## _name backcolor BG_COLOR; \
} \
}

## works like a '+'
in the preprocessor your variables will be combined before cod2 accesses the rest of your .menu
so with a _name of "test" setItemColor "hover" ## _name forecolor BG_COLOR; becomes setItemColor "hovertest" forecolor BG_COLOR;
also you should know:
you can show/hide/manipulate whatever all itemDef's with a given name
the same principle is available for the 'group'-attribute
you can show/hide/manipulate itemDef's with different names but the same group

ive made these menus with macros:

http://www.xfire.com/videos/5f6119

the best reference site i have found is this: http://rfactory.org/
read it and you will understand maybe abit more.
ive tested almost every feature on this side (transient, fog etc) but its not available in cod2

@Tally
how did you managed that cod2 will throw you error-messages on menu-files?

Tally
2nd June 2013, 20:22
@Tally
how did you managed that cod2 will throw you error-messages on menu-files?

I'm not 100% sure I understand the question, but here goes: I read console_mp.log file. Any error in a menu will show there. Even if everything looks fine when testing the menu, check console_mp.log. It will spit out errors for badly parsed menus.

kung foo man
4th August 2013, 16:00
[16:44] IzNoGoD: cause @ tally
[16:44] IzNoGoD:

3. You can only include your macros file once - otherwise it throws an error that the macros are already defined. The thing is, if you want to use the macros in another file included in your main menu file, it wont find them. And, as stated, if you try to include the macros file at the top of this include file, it will tell you the macros are already defined. So, it wont let you define them twice, but wont actually use the macro file in an include. Pretty much screwed with that one. Back to including all your items in one file.
[16:44] IzNoGoD: that might be solved by ifndef
[16:45] kung foo man: yea
[16:45] kung foo man: typical code is:
[16:45] kung foo man:
#ifndef _YOUR_FILE_NAME_H
#define _YOUR_FILE_NAME_H

your stuff here

#endif

Tally
8th August 2013, 13:34
[16:44] IzNoGoD: cause @ tally
[16:44] IzNoGoD:

3. You can only include your macros file once - otherwise it throws an error that the macros are already defined. The thing is, if you want to use the macros in another file included in your main menu file, it wont find them. And, as stated, if you try to include the macros file at the top of this include file, it will tell you the macros are already defined. So, it wont let you define them twice, but wont actually use the macro file in an include. Pretty much screwed with that one. Back to including all your items in one file.
[16:44] IzNoGoD: that might be solved by ifndef
[16:45] kung foo man: yea
[16:45] kung foo man: typical code is:
[16:45] kung foo man:
#ifndef _YOUR_FILE_NAME_H
#define _YOUR_FILE_NAME_H

your stuff here

#endif

Ah! That's good to hear. The use of ifndef and endif is used extensively in COD4, and I've used it a lot already for my COD4 mods, but I didn't think it would be active in COD2, so I didn't even experiment with it in COD2 because I assumed it would just throw an error. Thanks for the heads-up!

Now, if only COD2 supported COD4's visible = when(); in an ItemDef{}. Now, that really would improve COD2 menu modding!

serthy
14th September 2013, 12:50
Usage hint for ## and # in macros: only use ## on the same types!
There are 3 different types in menu-scripting:
- numbers: 1 2 3 4 5... (integer types only for ##)
- strings: "hello 123" (embraced in "")
- elements: element_123_test (can be treatened as strings, but neer contain spaces)

you cannot combine each with eachother, you have to keep the correct type!
you can combine elements and numbers, but you have to stringify them with the #-operator before you combine them with strings!


#define ORIGIN_1 0 0

#define TEST( _string , _number , _element ) \
itemDef \
{ \
name name_ ## _string \ //BAD
group "grp_" ## _number \ //BAD
origin ORIGIN_ ## _string \ //BAD: this does never work
} \
itemDef \
{ \
name #name_ ## _string \ //OK
group "grp_" ## #_number \ //OK
origin ORIGIN_ ## _number \ //OK
}

serthy
15th September 2013, 10:32
preprocessor directives (## and #) only work in macros

#define TEST test1234

#define BAD( _name , _arg ) \
itemDef \
{ \
name "button" ## #sw_name \
_arg \
}

BAD( "test" , text "test " ## #TEST ## " blaa" )

#define MENUNAME testmenu
{
menuDef
{
name #MENUNAME
}
}


#define TEST "test1234"

#define GOOD( _name , _arg ) \
itemDef \
{ \
name "button" ## #sw_name \
_arg \
}

GOOD( "test" , "test " TEST " blaa" )

#define MENUNAME "testmenu"
{
menuDef
{
name MENUNAME
}
}


Edit: kung, are you able to extend the edit-time?

kung foo man
17th January 2014, 20:41
Does somebody spot the error? I'm trying around for some time, but I just can't find it:



#define ITEM(_rect, _dvar) \
itemDef \
{ \
name "window" \
group ingamebox \
visible 1 \
rect _rect \
origin ORIGIN_QUICKMESSAGEWINDOW \
forecolor 1 1 1 1 \
textfont UI_FONT_NORMAL \
textscale .24 \
textaligny 8 \
dvar _dvar \
decoration \
}

ITEM(16 20 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_1")
ITEM(16 36 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_2")
ITEM(16 52 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_3")
ITEM(16 68 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_4")
ITEM(16 84 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_5")
ITEM(16 100 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_6")
ITEM(16 116 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_7")
ITEM(16 132 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_8")
ITEM(16 148 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_9")
ITEM(16 164 0 0 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN, "menu_0")


(when I unpack the macro everything looks fine)

It's supposed to generate a quickmenu, but the font becomes messed up:

RobsoN
17th January 2014, 21:13
Did you try with normal spaces between numbers in (first) rect argument?

Tally
17th January 2014, 21:15
It looks like ORIGIN_QUICKMESSAGEWINDOW is not defined. Try putting in the raw coordinates instead of a definition.

IzNoGoD
17th January 2014, 21:25
I think it is defined, but I also think its not fullscreen align, but rather a center_safearea thingy.

It should align correctly on 4:3 aspect ratio though, but try center_safearea first (or dig through cod2 source to find possible values)

kung foo man
17th January 2014, 21:58
Thanks for all the answers, I was already kinda giving up on this :D

IzNoGods fullscreen align thought and the search through ui/menudefinition.h got me the answer, now it's nice and clean :)



#define RECT4(_rect_) \
rect _rect_ HORIZONTAL_ALIGN_DEFAULT VERTICAL_ALIGN_DEFAULT

#define ITEM(_rect, _dvar) \
itemDef \
{ \
name "window" \
group ingamebox \
visible 1 \
RECT4(_rect) \
origin ORIGIN_QUICKMESSAGEWINDOW \
forecolor 1 1 1 1 \
textfont UI_FONT_NORMAL \
textscale .24 \
textaligny 8 \
dvar _dvar \
decoration \
}

ITEM(16 20 0 0, "menu_1")
ITEM(16 36 0 0, "menu_2")
ITEM(16 52 0 0, "menu_3")
ITEM(16 68 0 0, "menu_4")
ITEM(16 84 0 0, "menu_5")
ITEM(16 100 0 0, "menu_6")
ITEM(16 116 0 0, "menu_7")
ITEM(16 132 0 0, "menu_8")
ITEM(16 148 0 0, "menu_9")
ITEM(16 164 0 0, "menu_0")


So basically just replaced:
HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN
with:
HORIZONTAL_ALIGN_DEFAULT VERTICAL_ALIGN_DEFAULT

Here are the other definitions, they may help somebody out later:



// Edge relative placement values for rect->h_align and rect->v_align
#define HORIZONTAL_ALIGN_SUBLEFT 0 // left edge of a 4:3 screen (safe area not included)
#define HORIZONTAL_ALIGN_LEFT 1 // left viewable (safe area) edge
#define HORIZONTAL_ALIGN_CENTER 2 // center of the screen (reticle)
#define HORIZONTAL_ALIGN_RIGHT 3 // right viewable (safe area) edge
#define HORIZONTAL_ALIGN_FULLSCREEN 4 // disregards safe area
#define HORIZONTAL_ALIGN_NOSCALE 5 // uses exact parameters - neither adjusts for safe area nor scales for screen size
#define HORIZONTAL_ALIGN_TO640 6 // scales a real-screen resolution x down into the 0 - 640 range
#define HORIZONTAL_ALIGN_CENTER_SAFEAREA 7 // center of the safearea
#define HORIZONTAL_ALIGN_MAX HORIZONTAL_ALIGN_CENTER_SAFEAREA
#define HORIZONTAL_ALIGN_DEFAULT HORIZONTAL_ALIGN_SUBLEFT

#define VERTICAL_ALIGN_SUBTOP 0 // top edge of the 4:3 screen (safe area not included)
#define VERTICAL_ALIGN_TOP 1 // top viewable (safe area) edge
#define VERTICAL_ALIGN_CENTER 2 // center of the screen (reticle)
#define VERTICAL_ALIGN_BOTTOM 3 // bottom viewable (safe area) edge
#define VERTICAL_ALIGN_FULLSCREEN 4 // disregards safe area
#define VERTICAL_ALIGN_NOSCALE 5 // uses exact parameters - neither adjusts for safe area nor scales for screen size
#define VERTICAL_ALIGN_TO480 6 // scales a real-screen resolution y down into the 0 - 480 range
#define VERTICAL_ALIGN_CENTER_SAFEAREA 7 // center of the save area
#define VERTICAL_ALIGN_MAX VERTICAL_ALIGN_CENTER_SAFEAREA
#define VERTICAL_ALIGN_DEFAULT VERTICAL_ALIGN_SUBTOP

IzNoGoD
21st May 2015, 19:18
Basically created a simple && for menus (logical AND, in case if(a && b) set c 100)
code:



execnow "set first_ok 0";
execnow "set second_ok 0";
execnowondvarintvalue first_check 100 "set first_ok 1";
execnowondvarintvalue second_check 200 "setfromdvar second_ok first_ok";
execnowondvarintvalue second_ok 1 "set result 10";
execnowondvarintvalue second_ok 0 "set result -10";


which basically does this:


first_ok = false;
second_ok = false;
if(first_check == 100)
first_ok = true;
if(second_check == 200)
second_ok = first_ok;
if(second_ok)
result = 10;
else
result = -10;


It is however not very possible that you can use this for a double &&, as the amount of execnow's and execnowondvarint's is limited per action. You'll need a second menu then.