PDA

View Full Version : Strange things in menus



Lonsofore
13th June 2017, 06:12
It's again me. I'm making menu of weapons and I found a problem. This code works perfect:


#ifndef DRAW_WEAPON_ITEM
#define DRAW_WEAPON_ITEM(_key, _name) \
itemDef \
{ \
name "button_" ## #_name \
visible 1 \
rect ORIGIN_CHOICE ## _key 128 24 \
forecolor GLOBAL_UNFOCUSED_COLOR \
dvar "ui_weapon_" ## #_name \
textfont UI_FONT_NORMAL \
textscale .25 \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textalignx 10 \
textaligny 20 \
action \
{ \
play "mouse_click"; \
scriptMenuResponse "" ## #_name; \
} \
onFocus \
{ \
play "mouse_over"; \
show _name ## _info; \
show weapon_propertiestext; \
} \
}
#endif
DRAW_WEAPON_ITEM(A, m1carbine_mp)


But this doesn't work:


#ifndef DRAW_WEAPON_ITEM
#define DRAW_WEAPON_ITEM(_key, _name) \
itemDef \
{ \
name "button_" ## #_name \
visible 1 \
rect ORIGIN_CHOICE ## _key 128 24 \
forecolor GLOBAL_UNFOCUSED_COLOR \
dvar "ui_weapon_" ## #_name \
textfont UI_FONT_NORMAL \
textscale .25 \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textalignx 10 \
textaligny 20 \
action \
{ \
play "mouse_click"; \
scriptMenuResponse "" ## #_name; \
} \
onFocus \
{ \
play "mouse_over"; \
show _name ## _info; \
show weapon_propertiestext; \
} \
}
#endif

#ifndef DRAW_WEAPON
#define DRAW_WEAPON(_key, _name) \
DRAW_WEAPON_ITEM(_key, _name) \
#endif

DRAW_WEAPON(A, m1carbine_mp)


Any ideas, why?

kung foo man
13th June 2017, 08:22
#ifndef DRAW_WEAPON
#define DRAW_WEAPON(_key, _name) \
DRAW_WEAPON_ITEM(_key, _name) \
#endif


Last \ drags in the #endif and probably causes whatever kind of syntax error, which must be in your console somewhere (shift+tilde in menu)

Lonsofore
13th June 2017, 11:27
#ifndef DRAW_WEAPON
#define DRAW_WEAPON(_key, _name) \
DRAW_WEAPON_ITEM(_key, _name) \
#endif


Last \ drags in the #endif and probably causes whatever kind of syntax error, which must be in your console somewhere (shift+tilde in menu)

Doesn't work with these both cases:

#ifndef DRAW_WEAPON
#define DRAW_WEAPON(_key, _name) \
DRAW_WEAPON_ITEM(_key, _name)
#endif

#ifndef DRAW_WEAPON
#define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(_key, _name)
#endif

Offtop: where are you? haven't seen you in IRC for a long time

kung foo man
13th June 2017, 11:55
Probably need to stringify right away then:



#define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(#_key, #_name)

Lonsofore
13th June 2017, 12:19
Probably need to stringify right away then:



#define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(#_key, #_name)


Doesn't work aswell :(

Starting to think that we can't use variables in macroses in macroses, because this code works:

#ifndef DRAW_LINES_MAIN
#define DRAW_LINES_MAIN() \
DRAW_LINE(102 100, 0 0 446 1, COLOR_LINE_DARK) \
DRAW_LINE(270 101, 0 0 1 268, COLOR_LINE_DARK) \
#endif

serthy
13th June 2017, 15:32
I recogn this bug, but forgot the details

but you actually can have variables in macros as kung did it here (DVAR_CHECK): https://killtube.org/showthread.php?1082-CoD2-create-functions-in-menu-files!&p=3524&viewfull=1#post3524

kung foo man
13th June 2017, 16:41
I guess single values like 100 might be transferable through multiple macros, but stuff like 100 200 for colors e.g. fails (dunno what A in your example is). So just try to split the values into non-spaced strings, that might work. And/or post the error messages you get from the parser, should give some clues

Lonsofore
14th June 2017, 10:49
Ok, I found that the problem with rect string - working nice without it. And here I found the main problem.

This code works perfect:

#ifndef DRAW_WEAPON_ITEM
#define DRAW_WEAPON_ITEM(_key, _name) \
itemDef \
{ \
name "button_" ## #_name \
visible 1 \
rect _key 128 24 \
forecolor GLOBAL_UNFOCUSED_COLOR \
dvar "ui_weapon_" ## #_name \
textfont UI_FONT_NORMAL \
textscale .25 \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textalignx 10 \
textaligny 20 \
}
#endif

DRAW_WEAPON_ITEM(ORIGIN_CHOICEA, m1carbine_mp)

And this code doesn't:

#ifndef DRAW_WEAPON_ITEM
#define DRAW_WEAPON_ITEM(_key, _name) \
itemDef \
{ \
name "button_" ## #_name \
visible 1 \
rect _key 128 24 \
forecolor GLOBAL_UNFOCUSED_COLOR \
dvar "ui_weapon_" ## #_name \
textfont UI_FONT_NORMAL \
textscale .25 \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textalignx 10 \
textaligny 20 \
}
#endif

#define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(_key, _name)

DRAW_WEAPON(ORIGIN_CHOICEA, m1carbine_mp)

But as we know (from old kung's message) we can use macroses with variables in macroses. So, I think, the problem with ORIGIN_CHOICEA. In second case something is wrong with it. And I guess that ORIGIN_CHOICEA in DRAW_WEAPON is setting to real variables. In first case we set just in DRAW_WEAPON_ITEM directly.

Well, trying to find, how to fix it.

IzNoGoD
14th June 2017, 12:40
Most rects in macros need a 5th and a 6th argument iirc.

Lonsofore
14th June 2017, 15:00
Most rects in macros need a 5th and a 6th argument iirc.

And you're right, it works. But I can't see the button with all these cases:

rect _key 128 24 HORIZONTAL_ALIGN_DEFAULT VERTICAL_ALIGN_DEFAULT\

rect _key 128 24 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN \

rect 0 0 128 24 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN \
origin _key \

Something strange with coordinates now
Full code:


#ifndef DRAW_WEAPON_ITEM
#define DRAW_WEAPON_ITEM(_key, _name) \
itemDef \
{ \
name "button_" ## #_name \
visible 1 \
rect 0 0 128 24 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN \
origin _key \
forecolor GLOBAL_UNFOCUSED_COLOR \
dvar "ui_weapon_" ## #_name \
textfont UI_FONT_NORMAL \
textscale .25 \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textalignx 10 \
textaligny 20 \
}
#endif

#define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(_key, _name)

DRAW_WEAPON(ORIGIN_CHOICEA, m1carbine_mp)

Lonsofore
17th June 2017, 10:21
Ok, so I've got this problem. I tried this case:

#ifndef DRAW_WEAPON_ITEM
#define DRAW_WEAPON_ITEM(_key, _name) \
itemDef \
{ \
name "button_" ## _name \
visible 1 \
rect 0 0 128 24 HORIZONTAL_ALIGN_DEFAULT VERTICAL_ALIGN_DEFAULT \
origin _key \
forecolor GLOBAL_UNFOCUSED_COLOR \
type ITEM_TYPE_BUTTON \
text "test " ## _name \
textfont UI_FONT_NORMAL \
textscale .25 \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textalignx 10 \
textaligny 20 \
}
#endif

#define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(_key, _name)

DRAW_WEAPON(ORIGIN_CHOICEA, m1carbine_mp)

And the button name here was "test _name". So, my variable wasn't used. I tried this one then (with #):

#ifndef DRAW_WEAPON_ITEM
#define DRAW_WEAPON_ITEM(_key, _name) \
itemDef \
{ \
name "button_" ## #_name \
visible 1 \
rect 0 0 128 24 HORIZONTAL_ALIGN_DEFAULT VERTICAL_ALIGN_DEFAULT \
origin _key \
forecolor GLOBAL_UNFOCUSED_COLOR \
type ITEM_TYPE_BUTTON \
text "test " ## #_name \
textfont UI_FONT_NORMAL \
textscale .25 \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textalignx 10 \
textaligny 20 \
}
#endif

#define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(_key, #_name)

DRAW_WEAPON(ORIGIN_CHOICEA, m1carbine_mp)

And here I've got this name: "test #_name". So, as I see, we can't send our variables. And that's strange, because in kung used it... By the way, with define ORIGIN_CHOICEA it works, so I'll try to use defines only.

Lonsofore
17th June 2017, 10:58
Ok, and here I found why kung could use it and why I couldn't. That's all because we can't use concatenation here. Removed concatenation and now it's ok:

#ifndef DRAW_WEAPON_ITEM
#define DRAW_WEAPON_ITEM(_key, _name) \
itemDef \
{ \
name _name \
visible 1 \
rect 0 0 128 24 HORIZONTAL_ALIGN_DEFAULT VERTICAL_ALIGN_DEFAULT \
origin _key \
forecolor GLOBAL_UNFOCUSED_COLOR \
type ITEM_TYPE_BUTTON \
text _name \
textfont UI_FONT_NORMAL \
textscale .25 \
textstyle ITEM_TEXTSTYLE_SHADOWED \
textalignx 10 \
textaligny 20 \
}
#endif

#define DRAW_WEAPON(_key, _name) DRAW_WEAPON_ITEM(_key, _name)

DRAW_WEAPON(ORIGIN_CHOICEA, "m1carbine_mp")

Or maybe somebody knows how to use it?

Lonsofore
17th June 2017, 11:43
By the way. in this message (https://killtube.org/showthread.php?1082-CoD2-create-functions-in-menu-files!&p=7075&viewfull=1#post7075) serthy showed concatenation outside the macros:

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

But can we do the same with non-string text (without quotes)? Because this cases don't work (TEST is variable here):

FUNC( "test" , test TEST blaa )

FUNC( "test" , test ## TEST ## blaa )

P.S. and sorry for 3 messages in a row

kung foo man
17th June 2017, 14:52
By the time of now you could already have written a Python/PHP/Perl/whatever script which easily produces way more complex menus than what macro fu ever could :p