Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: [CoD2] create functions in .menu-files!

  1. #1
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts

    [CoD2] create functions in .menu-files!

    Sanibonani =)

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

    PHP Code:
    #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

  2. The Following 4 Users Say Thank You to serthy For This Useful Post:

    kung foo man (9th January 2013),Mitch (12th August 2014),Ni3ls (9th January 2013),ysniper (25th March 2016)

  3. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    They are called Macros.

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


    One more example:

    Code:
    		#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.
    timescale 0.01

  4. #3
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    *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

  5. The Following User Says Thank You to serthy For This Useful Post:

    kung foo man (10th January 2013)

  6. #4
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    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:

    PHP Code:
    // 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:

    PHP Code:
    {
        
    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 00 0 640 480 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN1 1 1 .9"gradient")
            
            
    #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_TOPORIGIN_TITLE1 1 1 1"@Assault Class"1UI_FONT_NORMALGLOBAL_HEADER_SIZE00ITEM_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"1RECTANGLEORIGIN_CHOICE1GLOBAL_UNFOCUSED_COLOR"@MPUI_1_GREASEGUN"UI_FONT_NORMALGLOBAL_TEXT_SIZEITEM_TEXTSTYLE_SHADOWED20"ui_allow_greasegun""1""greasegun_mp"thompson_infoshotgun_info""greasegun_infoweapon_propertiestext )    
            
    CHOICE_DIS_BUTTON"button_greasegun_disabled"1RECTANGLEORIGIN_CHOICE1"@MPUI_1_GREASEGUN"UI_FONT_NORMALGLOBAL_TEXT_SIZEITEM_TEXTSTYLE_SHADOWED20"ui_allow_greasegun""1"thompson_infoshotgun_infogreasegun_infoweapon_propertiestextfragtabungastabungas_replacedisabled_info )
            
            
    //--- THOMPSON ----
            
            
    CHOICE_BUTTON"button_thompson"1RECTANGLEORIGIN_CHOICE2GLOBAL_UNFOCUSED_COLOR"@2. Thompson"UI_FONT_NORMALGLOBAL_TEXT_SIZEITEM_TEXTSTYLE_SHADOWED20"ui_allow_thompson""1""thompson_mp"greasegun_infoshotgun_info""thompson_infoweapon_propertiestext )
            
    CHOICE_DIS_BUTTON"button_thompson_disabled"1RECTANGLEORIGIN_CHOICE2"@2. Thompson"UI_FONT_NORMALGLOBAL_TEXT_SIZEITEM_TEXTSTYLE_SHADOWED20"ui_allow_thompson""1"thompson_infoshotgun_infogreasegun_infoweapon_propertiestextfragtabungastabungas_replacedisabled_info )
            
            
    //--- SHOTGUN ----
            
            
    CHOICE_BUTTON"button_shotgun"1RECTANGLEORIGIN_CHOICE3GLOBAL_UNFOCUSED_COLOR"@3. M1897 Trench Gun"UI_FONT_NORMALGLOBAL_TEXT_SIZEITEM_TEXTSTYLE_SHADOWED20"ui_allow_shotgun""1""shotgun_mp"greasegun_infothompson_info""shotgun_infoweapon_propertiestext )
            
    CHOICE_DIS_BUTTON"button_shotgun_disabled"1RECTANGLEORIGIN_CHOICE3"@3. M1897 Trench Gun"UI_FONT_NORMALGLOBAL_TEXT_SIZEITEM_TEXTSTYLE_SHADOWED20"ui_allow_shotgun""1"thompson_infoshotgun_infogreasegun_infoweapon_propertiestextfragtabungastabungas_replacedisabled_info )
            
            
            
    //*************** PERK ICONS *********************

            //--- TABUN GAS ---
            
    DRAWSHADER"tabungas_perk"ORIGN_PERK_1PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER.7 .7 .7 .7"specialty_weapon_tabungas""scr_demon_allow_tabungas""1")
            
    HIDESHADER"null"ORIGN_PERK_1PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER.7 .7 .7 .7"specialty_null""scr_demon_allow_tabungas""1")
            
            
    //--- STOPPING POWER ---
            
    DRAWSHADER"stopping_power"ORIGN_PERK_2PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER.7 .7 .7 .7"specialty_bulletdamage""scr_demon_allow_bulletdamage""1")
            
    HIDESHADER"null"ORIGN_PERK_2PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER.7 .7 .7 .7"specialty_null""scr_demon_allow_bulletdamage""1")
            
            
    //--- MARTYRDOM ---
            
    DRAWSHADER"martyrdom"ORIGN_PERK_3PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER.7 .7 .7 .7"specialty_grenadepulldeath""scr_demon_allow_martyrdom""1")
            
    HIDESHADER"null"ORIGN_PERK_3PERK_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER.7 .7 .7 .7"specialty_null""scr_demon_allow_martyrdom""1")

            
    //*************** PERK TEXT ***********************
            
            //--- TABUN GAS ---
            
    DRAWTEXT"tabungas_perk"DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTERPERK_DES_11 1 1 1"@Tabun Gas""scr_demon_allow_tabungas""1"1UI_FONT_NORMAL.1877ITEM_TEXTSTYLE_SHADOWED )
            
    HIDETEXT"tabungas_perk"DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTERPERK_DES_11 1 1 1"@DISABLED""scr_demon_allow_tabungas""1"1UI_FONT_NORMAL.1877ITEM_TEXTSTYLE_SHADOWED )
            
            
    //--- STOPPING POWER ---
            
    DRAWTEXT"stopping_power"DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTERPERK_DES_21 1 1 1"@Stopping Power""scr_demon_allow_bulletdamage""1"1UI_FONT_NORMAL.1870ITEM_TEXTSTYLE_SHADOWED )
            
    HIDETEXT"stopping_power"DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTERPERK_DES_21 1 1 1"@DISABLED""scr_demon_allow_bulletdamage""1"1UI_FONT_NORMAL.1877ITEM_TEXTSTYLE_SHADOWED )
            
            
    //--- MARTYRDOM ---
            
    DRAWTEXT"martyrdom"DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTERPERK_DES_31 1 1 1"@Martyrdom""scr_demon_allow_martyrdom""1"1UI_FONT_NORMAL.1877ITEM_TEXTSTYLE_SHADOWED )
            
    HIDETEXT"martyrdom"DESCRIP_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTERPERK_DES_31 1 1 1"@DISABLED""scr_demon_allow_martyrdom""1"1UI_FONT_NORMAL.1877ITEM_TEXTSTYLE_SHADOWED )
        

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

            //--- GREASEGUN ----
            
    DRAWSHADER_NODVAR"greasegun_info"ORIGIN_WEAPONIMAGE_1WEAPONIMAGE_SIZE HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_TOP1 1 1 1"weapon_greasegun")
            
            
    //--- THOMPSON ---
            
    DRAWSHADER_NODVAR"thompson_info"ORIGIN_WEAPONIMAGE_1WEAPONIMAGE_SIZE HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_TOP1 1 1 1"weapon_thompson")
            
            
    //--- SHOTGUN ----
            
    DRAWSHADER_NODVAR"shotgun_info"ORIGIN_WEAPONIMAGE_1WEAPONIMAGE_SIZE HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_TOP1 1 1 1"weapon_shotgun")

            
    //*************** WEAPON PROPERTIES ***************
            
            
    DRAWTEXT_NODVAR"weapon_propertiestext"0 0 20 50 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTERORIGIN_WEAPONPROPERTIESTEXT_11 1 1 1"@MPUI_ACCURACY_DAMAGE_MOBILITY"0UI_FONT_NORMALGLOBAL_TEXT_SIZE00ITEM_TEXTSTYLE_SHADOWED )

            
    //--- GREASEGUN ----

            
    DRAWSHADER_NODVAR"greasegun_info"ORIGIN_WEAPONACCURACY_10 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 .125"white")
            
    DRAWSHADER_NODVAR"greasegun_info"ORIGIN_WEAPONACCURACY_10 0 70 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 1"white")
            
            
    DRAWSHADER_NODVAR"greasegun_info"ORIGIN_WEAPONDAMAGE_10 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 .125"white")
            
    DRAWSHADER_NODVAR"greasegun_info"ORIGIN_WEAPONDAMAGE_10 0 75 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 1"white")
            
            
    DRAWSHADER_NODVAR"greasegun_info"ORIGIN_WEAPONMOBILITY_10 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 .125"white")
            
    DRAWSHADER_NODVAR"greasegun_info"ORIGIN_WEAPONMOBILITY_10 0 96 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 1"white")
            
            
    //--- THOMPSON ---

            
    DRAWSHADER_NODVAR"thompson_info"ORIGIN_WEAPONACCURACY_10 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 .125"white")
            
    DRAWSHADER_NODVAR"thompson_info"ORIGIN_WEAPONACCURACY_10 0 56 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 1"white")
            
            
    DRAWSHADER_NODVAR"thompson_info"ORIGIN_WEAPONDAMAGE_10 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 .125"white")
            
    DRAWSHADER_NODVAR"thompson_info"ORIGIN_WEAPONDAMAGE_10 0 83 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 1"white")
            
            
    DRAWSHADER_NODVAR"thompson_info"ORIGIN_WEAPONMOBILITY_10 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 .125"white")
            
    DRAWSHADER_NODVAR"thompson_info"ORIGIN_WEAPONMOBILITY_10 0 96 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 1"white")
            
            
    //---- SHOTGUN ----
            
            
    DRAWSHADER_NODVAR"shotgun_info"ORIGIN_WEAPONACCURACY_10 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 .125"white")
            
    DRAWSHADER_NODVAR"shotgun_info"ORIGIN_WEAPONACCURACY_10 0 35 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 1"white")
            
            
    DRAWSHADER_NODVAR"shotgun_info"ORIGIN_WEAPONDAMAGE_10 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 .125"white")
            
    DRAWSHADER_NODVAR"shotgun_info"ORIGIN_WEAPONDAMAGE_10 0 100 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 1"white")
            
            
    DRAWSHADER_NODVAR"shotgun_info"ORIGIN_WEAPONMOBILITY_10 0 128 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 .125"white")
            
    DRAWSHADER_NODVAR"shotgun_info"ORIGIN_WEAPONMOBILITY_10 0 80 10 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER1 1 1 1"white")
            
            
            
    //******************** SIDEARM ************************
            
            
    DRAWSHADER"colt"ORIGIN_PISTOLPISTOL_IMAGE_SIZE HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER1 1 1 1"weapon_colt45""ui_sidearm_colt""1")
            
            
    DRAWSHADER"magnum"ORIGIN_PISTOL0 4 75 75 HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER1 1 1 1"weapon_magnum""ui_sidearm_magnum""1")
            
            
    DRAWSHADER"knife"ORIGIN_PISTOL0 0 95 95 HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTER1 1 1 1"weapon_knife""ui_sidearm_knife""1")

            
    /////////////////// EDIT BUTTON /////////////////////////////
            
            
    EDIT_BUTTON"edit_sidearm"1PISTOL_RECT HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_CENTERSIDEARM_EDIT_ORGEDIT_COLOR.18150"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:

    PHP Code:
    #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:

    Last edited by Tally; 2nd June 2013 at 19:15.

  7. The Following 4 Users Say Thank You to Tally For This Useful Post:

    kung foo man (2nd June 2013),Ni3ls (3rd June 2013),serthy (2nd June 2013),ysniper (25th March 2016)

  8. #5
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    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:

    Code:
    #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?
    Last edited by serthy; 2nd June 2013 at 18:42.

  9. The Following 4 Users Say Thank You to serthy For This Useful Post:

    kung foo man (2nd June 2013),Ni3ls (3rd June 2013),RobsoN (4th July 2013),Tally (2nd June 2013)

  10. #6
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    @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.

  11. #7
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    [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
    timescale 0.01

  12. #8
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by kung foo man View Post
    [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!
    Last edited by Tally; 8th August 2013 at 12:37.

  13. #9
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    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!

    PHP Code:
    #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
        


  14. The Following 3 Users Say Thank You to serthy For This Useful Post:

    kung foo man (14th September 2013),Lonsofore (20th March 2017),Ni3ls (14th September 2013)

  15. #10
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    preprocessor directives (## and #) only work in macros
    Code:
    #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
        }
    }
    Code:
    #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?
    Last edited by serthy; 15th September 2013 at 09:36.

  16. The Following User Says Thank You to serthy For This Useful Post:

    Lonsofore (22nd May 2017)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •