//#define HIGHLIGHT_BORDER		WINDOW_BORDER_RAISED
//#define HIGHLIGHT_SHADER		"white"
#define MENU_FONT_SIZE			TEXTSIZE_DEFAULT
#define MENU_FONT_COLOR			1 1 1 0.65
#define MENU_LOCKED_COLOR		0.3 0.3 0.3 1
#define HIGHLIGHT_X				248
#define HIGHLIGHT_Y				20
#define HIGHLIGHT_SIZE			(-(HIGHLIGHT_X)) HIGHLIGHT_Y
//#define A_BUTTON_SIZE			0.27
//#define HIGHLIGHT_COLOR			0.2 0.25 0.35 0.25
//#define A_BUTTON_COLOR			1 1 1 1
//#define HIGHLIGHT_BORDER_COLOR	0.8 0.95 1 0.4

//-------------------------------------
#define ORIGIN_MENU_TREE		54 64
#define ORIGIN_MENU_TITLE		248 64
#define ORIGIN_MENU_TITLE2		248 64
#define ORIGIN_MENU_TITLE3		246 64
#define TREE_COLOR				1 1 1 0.5

#define ORIGIN_BUTTON_BACK		52 438
#define ORIGIN_BUTTON_CONTINUE	508 438

//--------------------------------
#define ORIGIN_CHOICE_X		80
#define ORIGIN_CHOICE1		ORIGIN_CHOICE_X 130
#define ORIGIN_CHOICE2		ORIGIN_CHOICE_X 150
#define ORIGIN_CHOICE3		ORIGIN_CHOICE_X 170
#define ORIGIN_CHOICE4		ORIGIN_CHOICE_X 190
#define ORIGIN_CHOICE5		ORIGIN_CHOICE_X 210
#define ORIGIN_CHOICE6		ORIGIN_CHOICE_X 270
#define ORIGIN_CHOICE7		ORIGIN_CHOICE_X 290
#define ORIGIN_CHOICE8		ORIGIN_CHOICE_X 310
#define ORIGIN_CHOICE9		ORIGIN_CHOICE_X 330

#define ORIGIN_SETTING_X	240
#define ORIGIN_SETTING1		ORIGIN_SETTING_X 130
#define ORIGIN_SETTING2		ORIGIN_SETTING_X 150
#define ORIGIN_SETTING3		ORIGIN_SETTING_X 170
#define ORIGIN_SETTING4		ORIGIN_SETTING_X 190
#define ORIGIN_SETTING5		ORIGIN_SETTING_X 210
#define ORIGIN_SETTING6		ORIGIN_SETTING_X 270
#define ORIGIN_SETTING7		ORIGIN_SETTING_X 290
#define ORIGIN_SETTING8		ORIGIN_SETTING_X 310
#define ORIGIN_SETTING9		ORIGIN_SETTING_X 330

#define ORIGIN_CHOICE_HL_X	54
#define ORIGIN_CHOICE1_HL	ORIGIN_CHOICE_HL_X 128
#define ORIGIN_CHOICE2_HL	ORIGIN_CHOICE_HL_X 148
#define ORIGIN_CHOICE3_HL	ORIGIN_CHOICE_HL_X 168
#define ORIGIN_CHOICE4_HL	ORIGIN_CHOICE_HL_X 188
#define ORIGIN_CHOICE5_HL	ORIGIN_CHOICE_HL_X 208
#define ORIGIN_CHOICE6_HL	ORIGIN_CHOICE_HL_X 268
#define ORIGIN_CHOICE7_HL	ORIGIN_CHOICE_HL_X 288
#define ORIGIN_CHOICE8_HL	ORIGIN_CHOICE_HL_X 308
#define ORIGIN_CHOICE9_HL	ORIGIN_CHOICE_HL_X 328

#define ORIGIN_CHOICE_A_X	60
#define ORIGIN_CHOICE1_A	ORIGIN_CHOICE_A_X 144
#define ORIGIN_CHOICE2_A	ORIGIN_CHOICE_A_X 164
#define ORIGIN_CHOICE3_A	ORIGIN_CHOICE_A_X 184
#define ORIGIN_CHOICE4_A	ORIGIN_CHOICE_A_X 204
#define ORIGIN_CHOICE5_A	ORIGIN_CHOICE_A_X 224
#define ORIGIN_CHOICE6_A	ORIGIN_CHOICE_A_X 284
#define ORIGIN_CHOICE7_A	ORIGIN_CHOICE_A_X 304
#define ORIGIN_CHOICE8_A	ORIGIN_CHOICE_A_X 324
#define ORIGIN_CHOICE9_A	ORIGIN_CHOICE_A_X 344

// ------
#define ORIGIN_CHOICE_X2	360
#define ORIGIN_CHOICE11		ORIGIN_CHOICE_X2 130
#define ORIGIN_CHOICE12		ORIGIN_CHOICE_X2 150
#define ORIGIN_CHOICE13		ORIGIN_CHOICE_X2 170
#define ORIGIN_CHOICE14		ORIGIN_CHOICE_X2 190
#define ORIGIN_CHOICE15		ORIGIN_CHOICE_X2 210
#define ORIGIN_CHOICE16		ORIGIN_CHOICE_X2 270
#define ORIGIN_CHOICE17		ORIGIN_CHOICE_X2 290
#define ORIGIN_CHOICE18		ORIGIN_CHOICE_X2 310
#define ORIGIN_CHOICE19		ORIGIN_CHOICE_X2 330

#define ORIGIN_SETTING_X2	520
#define ORIGIN_SETTING11	ORIGIN_SETTING_X2 130
#define ORIGIN_SETTING12	ORIGIN_SETTING_X2 150
#define ORIGIN_SETTING13	ORIGIN_SETTING_X2 170
#define ORIGIN_SETTING14	ORIGIN_SETTING_X2 190
#define ORIGIN_SETTING15	ORIGIN_SETTING_X2 210
#define ORIGIN_SETTING16	ORIGIN_SETTING_X2 270
#define ORIGIN_SETTING17	ORIGIN_SETTING_X2 290
#define ORIGIN_SETTING18	ORIGIN_SETTING_X2 310
#define ORIGIN_SETTING19	ORIGIN_SETTING_X2 330

#define ORIGIN_CHOICE_HL_X2	334
#define ORIGIN_CHOICE11_HL	ORIGIN_CHOICE_HL_X2 128
#define ORIGIN_CHOICE12_HL	ORIGIN_CHOICE_HL_X2 148
#define ORIGIN_CHOICE13_HL	ORIGIN_CHOICE_HL_X2 168
#define ORIGIN_CHOICE14_HL	ORIGIN_CHOICE_HL_X2 188
#define ORIGIN_CHOICE15_HL	ORIGIN_CHOICE_HL_X2 208
#define ORIGIN_CHOICE16_HL	ORIGIN_CHOICE_HL_X2 268
#define ORIGIN_CHOICE17_HL	ORIGIN_CHOICE_HL_X2 288
#define ORIGIN_CHOICE18_HL	ORIGIN_CHOICE_HL_X2 308
#define ORIGIN_CHOICE19_HL	ORIGIN_CHOICE_HL_X2 328

#define ORIGIN_CHOICE_A_X2	340
#define ORIGIN_CHOICE11_A	ORIGIN_CHOICE_A_X2 144
#define ORIGIN_CHOICE12_A	ORIGIN_CHOICE_A_X2 164
#define ORIGIN_CHOICE13_A	ORIGIN_CHOICE_A_X2 184
#define ORIGIN_CHOICE14_A	ORIGIN_CHOICE_A_X2 204
#define ORIGIN_CHOICE15_A	ORIGIN_CHOICE_A_X2 224
#define ORIGIN_CHOICE16_A	ORIGIN_CHOICE_A_X2 284
#define ORIGIN_CHOICE17_A	ORIGIN_CHOICE_A_X2 304
#define ORIGIN_CHOICE18_A	ORIGIN_CHOICE_A_X2 324
#define ORIGIN_CHOICE19_A	ORIGIN_CHOICE_A_X2 344

// ---
#define ORIGIN_OP1			176 122
#define ORIGIN_OP2			176 262
#define ORIGIN_OP3			456 122
#define ORIGIN_OP4			456 262

// ---
#define ORIGIN_QUAD1_HL		48 96
#define ORIGIN_QUAD2_HL		48 236
#define ORIGIN_QUAD3_HL		328 96
#define ORIGIN_QUAD4_HL		328 236
#define QUAD_SIZE_X			260
#define QUAD_SIZE_Y			140
#define QUAD_SIZE			QUAD_SIZE_X QUAD_SIZE_Y

// ===================== popup preproc =====================

#ifdef PC
	#define BACK_BUTTON_CLOSE \
		itemDef { \
			type			ITEM_TYPE_BUTTON \
			rect			-600 -800 2000 2000 0 0 \
			text			"" \
			textfont		UI_FONT_NORMAL \
			visible			1 \
			action{ close self; } \
		}
#else
	#define BACK_BUTTON_CLOSE \
		PREPROC_SHADER_DRAW( 0 0 0 0, 0 0, "white", 0 0 0 0, 0, 0, 0 0 0 0 )
#endif

#define PREPROC_POPUP_CHOICE( pp_update, pp_popupname, pp_offset, pp_height, pp_origin, pp_string, pp_setdvar, pp_show ) \
itemDef { \
	textscale 		TEXTSIZE_SMALL \
	textstyle 		ITEM_TEXTSTYLE_SHADOWED \
	rect 			pp_offset 110 pp_height 0 0 \
	origin			pp_origin \
	text 			pp_string \
	forecolor		MENU_FONT_COLOR \
	textalign		ITEM_ALIGN_RIGHT \
	textalignx		-101 \
	textaligny		-21 \
	visible 		pp_show; \
	leaveFocus { \
		play "mouse_submenu_over"; \
	}\
	action { \
		exec pp_setdvar; \
		play "mouse_click"; \
		pp_update \
		close GAME_OPTIONS_MENU_NAME"_"pp_popupname; \
	} \
}


#define PREPROC_POPUP( pp_update, pp_name, pp_origin, pp_height, pp_string1, pp_string2, pp_string3, pp_string4, pp_string5, pp_string6, pp_setdvar1, pp_setdvar2, pp_setdvar3, pp_setdvar4, pp_setdvar5, pp_setdvar6, show1, show2, show3, show4, show5, show6 ) \
menuDef	{ \
	name			GAME_OPTIONS_MENU_NAME"_"pp_name \
	visible			1 \
	fullscreen		0 \
	rect			0 0 640 480 0 0 \
	focusColor		COLOR_FOCUSED \
	style			WINDOW_STYLE_FILLED popup \
	onESC { \
		play "mouse_click"; \
		close GAME_OPTIONS_MENU_NAME"_"pp_name; \
	} \
	BACK_BUTTON_CLOSE\
	PREPROC_SHADER_DRAW( pp_origin 110 pp_height, -50 -4, "white", 0.2 0.2 0.22 1, 1, 2, 0.4 0.4 0.42 1 ) \
	PREPROC_POPUP_CHOICE( pp_update, pp_name, pp_origin, pp_height, 32 37, pp_string1, pp_setdvar1, show1 ) \
	PREPROC_POPUP_CHOICE( pp_update, pp_name, pp_origin, pp_height, 32 52, pp_string2, pp_setdvar2, show2 ) \
	PREPROC_POPUP_CHOICE( pp_update, pp_name, pp_origin, pp_height, 32 67, pp_string3, pp_setdvar3, show3 ) \
	PREPROC_POPUP_CHOICE( pp_update, pp_name, pp_origin, pp_height, 32 82, pp_string4, pp_setdvar4, show4 ) \
	PREPROC_POPUP_CHOICE( pp_update, pp_name, pp_origin, pp_height, 32 97, pp_string5, pp_setdvar5, show5 ) \
	PREPROC_POPUP_CHOICE( pp_update, pp_name, pp_origin, pp_height, 32 112, pp_string6, pp_setdvar6, show6 ) \
}


#define PREPROC_DVAR_POPUP_CHOICE( pp_action, pp_origin, pp_string, pp_show ) \
itemDef { \
	text 			pp_string \
	textscale 		TEXTSIZE_SMALL \
	textstyle 		ITEM_TEXTSTYLE_SHADOWED \
	rect 			pp_origin 110 POPUP_ITEM_HEIGHT CHOICE_HORIZONTAL_ALIGN CHOICE_VERTICAL_ALIGN \
	origin			0 4 \
	forecolor		MENU_FONT_COLOR \
	textalign		ITEM_ALIGN_MIDDLE_CENTER \
	textalignx		0 \
	textaligny		0 \
	visible 		pp_show; \
	leaveFocus { \
		play "mouse_submenu_over"; \
	}\
	action { \
		pp_action \
		play "mouse_click"; \
		close self; \
	} \
}


#define PREPROC_DVAR_POPUP_CHOICE_EX( pp_action, pp_origin, pp_string, pp_show, pp_extra ) \
itemDef { \
	text 			pp_string \
	textscale 		TEXTSIZE_SMALL \
	textstyle 		ITEM_TEXTSTYLE_SHADOWED \
	rect 			pp_origin 110 POPUP_ITEM_HEIGHT CHOICE_HORIZONTAL_ALIGN CHOICE_VERTICAL_ALIGN \
	origin			0 4 \
	forecolor		MENU_FONT_COLOR \
	textalign		ITEM_ALIGN_MIDDLE_CENTER \
	textalignx		0 \
	textaligny		0 \
	visible 		pp_show; \
	pp_extra \
	leaveFocus { \
		play "mouse_submenu_over"; \
	}\
	action { \
		pp_action \
		play "mouse_click"; \
		close self; \
	} \
}

#define PREPROC_DVAR_POPUP2( pp_itemIndex, pp_name, pp_items, pp_dvar, pp_string1, pp_string2, pp_string3, pp_string4, pp_string5, pp_string6, pp_setdvar1, pp_setdvar2, pp_setdvar3, pp_setdvar4, pp_setdvar5, pp_setdvar6, pp_xOffset ) \
menuDef	{ \
	name			GAME_OPTIONS_MENU_NAME"_"pp_name \
	visible			1 \
	fullscreen		0 \
	rect			0 0 640 480 0 0 \
	focusColor		COLOR_FOCUSED \
	style			WINDOW_STYLE_FILLED popup \
	onOpen { \
		focusFirst; \
		setfocusbydvar pp_dvar; \
	} \
	onESC { \
		play "mouse_click"; \
		close GAME_OPTIONS_MENU_NAME"_"pp_name; \
	} \
	BACK_BUTTON_CLOSE \
	itemDef { \
		style			WINDOW_STYLE_SHADER \
		rect			(CHOICE_X(pp_itemIndex)+pp_xOffset) (CHOICE_Y(pp_itemIndex)-2) 110 (10+(POPUP_ITEM_HEIGHT*pp_items)) CHOICE_HORIZONTAL_ALIGN CHOICE_VERTICAL_ALIGN \
		forecolor		0.2 0.2 0.22 1 \
		exp				material( "white" ); \
		border			1 \
		bordersize		2 \
		bordercolor		0.4 0.4 0.42 1 \
		visible			1 decoration \
	}	\
	PREPROC_DVAR_POPUP_CHOICE_EX( setdvar pp_dvar pp_setdvar1, (CHOICE_X( pp_itemIndex )+pp_xOffset) (CHOICE_Y( pp_itemIndex )+(POPUP_ITEM_HEIGHT*0)), pp_string1, when( pp_string1 != "" ), dvartest pp_dvar focusdvar { pp_setdvar1 } ) \
	PREPROC_DVAR_POPUP_CHOICE_EX( setdvar pp_dvar pp_setdvar2, (CHOICE_X( pp_itemIndex )+pp_xOffset) (CHOICE_Y( pp_itemIndex )+(POPUP_ITEM_HEIGHT*1)), pp_string2, when( pp_string2 != "" ), dvartest pp_dvar focusdvar { pp_setdvar2 } ) \
	PREPROC_DVAR_POPUP_CHOICE_EX( setdvar pp_dvar pp_setdvar3, (CHOICE_X( pp_itemIndex )+pp_xOffset) (CHOICE_Y( pp_itemIndex )+(POPUP_ITEM_HEIGHT*2)), pp_string3, when( pp_string3 != "" ), dvartest pp_dvar focusdvar { pp_setdvar3 } ) \
	PREPROC_DVAR_POPUP_CHOICE_EX( setdvar pp_dvar pp_setdvar4, (CHOICE_X( pp_itemIndex )+pp_xOffset) (CHOICE_Y( pp_itemIndex )+(POPUP_ITEM_HEIGHT*3)), pp_string4, when( pp_string4 != "" ), dvartest pp_dvar focusdvar { pp_setdvar4 } ) \
	PREPROC_DVAR_POPUP_CHOICE_EX( setdvar pp_dvar pp_setdvar5, (CHOICE_X( pp_itemIndex )+pp_xOffset) (CHOICE_Y( pp_itemIndex )+(POPUP_ITEM_HEIGHT*4)), pp_string5, when( pp_string5 != "" ), dvartest pp_dvar focusdvar { pp_setdvar5 } ) \
	PREPROC_DVAR_POPUP_CHOICE_EX( setdvar pp_dvar pp_setdvar6, (CHOICE_X( pp_itemIndex )+pp_xOffset) (CHOICE_Y( pp_itemIndex )+(POPUP_ITEM_HEIGHT*5)), pp_string6, when( pp_string6 != "" ), dvartest pp_dvar focusdvar { pp_setdvar6 } ) \
}
// ================ preprocessing definitions ==================

#define LOCAL_HIDE( pnum ) hide "highlight_choice"pnum; hide "a_button_choice"pnum;
#define LOCAL_HIDEALL \
	LOCAL_HIDE("1") LOCAL_HIDE("2") LOCAL_HIDE("3") LOCAL_HIDE("4") LOCAL_HIDE("5") LOCAL_HIDE("6") \
	LOCAL_HIDE("7") LOCAL_HIDE("8") LOCAL_HIDE("9") LOCAL_HIDE("10") LOCAL_HIDE("11") LOCAL_HIDE("12") \
	LOCAL_HIDE("13") LOCAL_HIDE("14") LOCAL_HIDE("15") LOCAL_HIDE("16") LOCAL_HIDE("17") LOCAL_HIDE("18") \
	LOCAL_HIDE("19")

#define PREPROC_HIGHLIGHT( pname, porigin ) \
itemDef { \
	name			pname \
	style			WINDOW_STYLE_SHADER \
	rect			porigin HIGHLIGHT_SIZE 0 0 \
	origin			5 0 \
	background		HIGHLIGHT_SHADER \
	forecolor		HIGHLIGHT_COLOR \
	border			HIGHLIGHT_BORDER \
	bordersize		1 \
	bordercolor		HIGHLIGHT_BORDER_COLOR \
	visible			1 decoration }\
	UI_EDGE_REVERSE( porigin, 0 0, 0, 0, HIGHLIGHT_COLOR name pname )

#define PREPROC_A_BUTTON( pname, porigin ) \
itemDef { \
	name			pname \
	style			WINDOW_STYLE_SHADER \
	rect			porigin 18 18 0 0 \
	origin			-1 -15 \
	background		ALTERNATE_HINT_SHADER \
	forecolor		ALTERNATE_HINT_COLOR \
	visible			1 decoration }

#define PREPROC_ITEM( pname, porigin, ptext, pshow, pvisible, phighlight, pabutton, pitem, porigin2, ptext2, pleft, pright, pup, pdown, paction ) \
itemDef {\
	name			pname \
	type			ITEM_TYPE_BUTTON \
	textstyle		ITEM_TEXTSTYLE_SHADOWED \
	origin			porigin \
	textfont		UI_FONT_NORMAL \
	text			ptext \
	textscale		TEXTSIZE_SMALL \
	textaligny		16 \
	forecolor		MENU_FONT_COLOR \
	backcolor		0 0 0 0 \
	visible			when( pvisible == 1 ) \
	onFocus	{ \
		setItemColor pitem forecolor COLOR_FOCUSED \
		play "mouse_over"; \
		LOCAL_HIDEALL \
		show phighlight; \
		show pabutton; \
		pshow } \
	leaveFocus { \
		setItemColor pitem forecolor MENU_FONT_COLOR \
		hide phighlight; \
		hide pabutton; } \
	execKeyInt DPAD_RIGHT { \
		pright; \
		play "mouse_click"; } \
	execKeyInt DPAD_LEFT { \
		pleft; \
		play "mouse_click"; } \
	execKeyInt APAD_RIGHT { \
		pright; \
		play "mouse_click"; } \
	execKeyInt APAD_LEFT { \
		pleft; \
		play "mouse_click"; } \
	pup pdown paction } \
itemDef {\
	type			ITEM_TYPE_BUTTON \
	textstyle		ITEM_TEXTSTYLE_SHADOWED \
	origin			porigin \
	textfont		UI_FONT_NORMAL \
	text			ptext \
	textscale		TEXTSIZE_SMALL \
	textaligny		16 \
	forecolor		MENU_LOCKED_COLOR \
	backcolor		0 0 0 0 \
	visible			when( pvisible == 0 ) \
	decoration } \
itemDef { \
	name			pitem \
	type	 		ITEM_TYPE_TEXT \
	rect			32 0 1 16 0 0 \
	origin			porigin2 \
	textfont		UI_FONT_NORMAL \
	dvar			ptext2 \
	textscale		TEXTSIZE_SMALL \
	textaligny		16 \
	textalign		ITEM_ALIGN_RIGHT \
	textstyle		ITEM_TEXTSTYLE_SHADOWED \
	forecolor		MENU_FONT_COLOR \
	backcolor		0 0 0 0 \
	visible			pvisible decoration } 

#define PREPROC_ITEM_TITLE( porigin, ptext, pcolor ) \
		PREPROC_TEXT_DRAW( porigin 260 20, -130 0, text ptext, TEXTSIZE_DEFAULT, 0, 0, ITEM_ALIGN_CENTER, MENU_FONT_COLOR )

// pc only drop down custom option
#define CHOICE_BUTTON_DROPDOWN( itemNum, itemName, itemUnit, itemAction, itemDvar, nav )\
	CHOICE_BUTTON_EX( itemNum, itemName, itemAction, nav )\
	itemDef {\
		type			ITEM_TYPE_BUTTON \
		textstyle		ITEM_TEXTSTYLE_SHADOWED \
		rect			CHOICE_ORIGIN( itemNum ) (CHOICE_SIZE_X+CHOICE_DVAR_WIDTH_OFFSET) CHOICE_SIZE_Y CHOICE_HORIZONTAL_ALIGN CHOICE_VERTICAL_ALIGN \
		textfont		UI_FONT_NORMAL \
		exp				text( locString(itemUnit, dvarInt( ) \
		textscale		TEXTSIZE_SMALL \
		textalign		CHOICE_DVAR_TEXTALIGN \
		textalignx		CHOICE_DVAR_OFFSET_X \
		forecolor		MENU_FONT_COLOR \
		backcolor		0 0 0 0 \
		visible			1 \
		decoration }