#include "ui/menudef.h"
#include "ui_mp/common_macro.inc"
#include "ui/framestyle.inc"
#include "ui_mp/newframe.inc"
#include "ui_mp/serverbrowser.inc";
#include "ui_mp/menustyle.inc"
#include "ui/choices_setup_common.menu"
#include "ui_mp/item_animate.inc"

#define SERVER_BROWSER_HEIGHT	420
#define SERVER_BROWSER_WIDTH	TABLE_WIDTH

#define SERVER_BROWSER_BODY_X_START		( -SERVER_BROWSER_WIDTH / 2 + 15 )
#define	SERVER_BROWSER_BODY_Y_START		( -SERVER_BROWSER_HEIGHT / 2 + 15 + NEW_FRAME_HEADER_HEIGHT )


#undef	CHOICE_HORIZONTAL_ALIGN 
#define CHOICE_HORIZONTAL_ALIGN		HORIZONTAL_ALIGN_CENTER 

#undef  CHOICE_VERTICAL_ALIGN
#define CHOICE_VERTICAL_ALIGN		VERTICAL_ALIGN_CENTER

#define FLYOUT_NONE				0
#define	FLYOUT_BROWSER			3

#undef	CHOICE_TEXTSTYLE
#define CHOICE_TEXTSTYLE		ITEM_TEXTSTYLE_NORMAL

#define TAB_OPEN( menuName ) \
		execNow closemenuImmediate (dvarstring("ui_serverBrowserMenu")); \
		execNow openMenuImmediate (menuName); \

#undef 	ORIGIN_TITLE
#define ORIGIN_TITLE		10 0

#define CHOICE_TAB_TEXTSIZE			TEXTSIZE_DEFAULT
#define TAB_1_TEXT					( locString( "@MENU_JOIN_SERVER_RANKED_CAPS" ) )
#define TAB_2_TEXT					( locString( "@MENU_JOIN_SERVER_UNRANKED_CAPS" ) )
#define TAB_3_TEXT					( locString( "@MENU_JOIN_SERVER_WAGER_CAPS" ) )
#define TAB_4_TEXT					( locString( "@MENU_JOIN_SERVER_FRIENDS_CAPS" ) )
#define TAB_5_TEXT					( locString( "@MENU_JOIN_SERVER_FAVORITES_CAPS" ) )
#define TAB_6_TEXT					( locString( "@MENU_JOIN_SERVER_HISTORY_CAPS" ) )

#define TAB_BG_PAD					5
#define TAB_1_WIDTH					( getTextWidth( TAB_1_TEXT, CHOICE_TEXTFONT, TEXTSIZE_SMALL ) + (TAB_BG_PAD*2) )
#define TAB_2_WIDTH					( getTextWidth( TAB_2_TEXT, CHOICE_TEXTFONT, TEXTSIZE_SMALL ) + (TAB_BG_PAD*2) )
#define TAB_3_WIDTH					( getTextWidth( TAB_3_TEXT, CHOICE_TEXTFONT, TEXTSIZE_SMALL ) + (TAB_BG_PAD*2) )
#define TAB_4_WIDTH					( getTextWidth( TAB_4_TEXT, CHOICE_TEXTFONT, TEXTSIZE_SMALL ) + (TAB_BG_PAD*2) )
#define TAB_5_WIDTH					( getTextWidth( TAB_5_TEXT, CHOICE_TEXTFONT, TEXTSIZE_SMALL ) + (TAB_BG_PAD*2) )
#define TAB_6_WIDTH					( getTextWidth( TAB_6_TEXT, CHOICE_TEXTFONT, TEXTSIZE_SMALL ) + (TAB_BG_PAD*2) )
#define TAB_HEIGHT				15

#define SERVER_BROWSER_TAB_1_X	9
#define SERVER_BROWSER_TAB_2_X	( SERVER_BROWSER_TAB_1_X + TAB_1_WIDTH )
#define SERVER_BROWSER_TAB_3_X	( SERVER_BROWSER_TAB_2_X + TAB_2_WIDTH )
#define SERVER_BROWSER_TAB_4_X	( SERVER_BROWSER_TAB_3_X + TAB_3_WIDTH )
#define SERVER_BROWSER_TAB_5_X	( SERVER_BROWSER_TAB_4_X + TAB_4_WIDTH )
#define SERVER_BROWSER_TAB_6_X	( SERVER_BROWSER_TAB_5_X + TAB_5_WIDTH )

#define SERVER_BROWSER_TAB_Y			( ( -SERVER_BROWSER_HEIGHT / 2 ) + NEW_FRAME_HEADER_HEIGHT - TAB_HEIGHT + 1 )


#define TAB( x, tabWidth, textArg, menuName, selected ) \
		PREPROC_TEXT_DRAW_ADV_VIS_EX(	( -SERVER_BROWSER_WIDTH / 2 + x ),														\
										SERVER_BROWSER_TAB_Y,																	\
										tabWidth,																				\
										TAB_HEIGHT,																				\
										HORIZONTAL_ALIGN_CENTER, VERTICAL_ALIGN_CENTER,											\
										textArg, TEXTSIZE_SMALL, 0, 0, ITEM_ALIGN_MIDDLE_CENTER,								\
										NEW_FRAME_GRAY_TEXT_COLOR,  when( !selected ), TAB_MOUSEOVER_HIGHLIGHT; )				\
		PREPROC_TEXT_DRAW_ADV_VIS_EX(	( -SERVER_BROWSER_WIDTH / 2 + x ),														\
										SERVER_BROWSER_TAB_Y,																	\
										tabWidth,																				\
										TAB_HEIGHT,																				\
										HORIZONTAL_ALIGN_CENTER, VERTICAL_ALIGN_CENTER,											\
										textArg, TEXTSIZE_SMALL, 0, 0, ITEM_ALIGN_MIDDLE_CENTER,								\
										NEW_FRAME_ORANGE_RGB 1, when( selected ), ; )											\
		TAB_ACTION_BUTTON_ADV(	( -SERVER_BROWSER_WIDTH / 2 + x ),																\
								( -SERVER_BROWSER_HEIGHT / 2 + NEW_FRAME_HEADER_HEIGHT - TAB_HEIGHT ),							\
								tabWidth,																						\
								TAB_HEIGHT,																						\
								HORIZONTAL_ALIGN_CENTER, VERTICAL_ALIGN_CENTER,													\
								TAB_OPEN( menuName ), 1, ; )																	\


#define SERVER_BROWSER_TAB_BG( px, tabWidth, selected ) \
	itemDef																									\
	{																										\
		style			WINDOW_STYLE_SHADER																	\
		frame           16 0.2 FRAME_OPEN_BOTTOM															\
		rect            0 SERVER_BROWSER_TAB_Y 0 TAB_HEIGHT HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER	\
		exp				rect X( ( -SERVER_BROWSER_WIDTH / 2 + px ) )										\
		exp				rect W(	tabWidth )																	\
		background      "menu_mp_tab_frame_inner"															\
		forecolor       0.5 0.5 0.5 0.5																		\
		visible			when( selected )																	\
		decoration																							\
	}																										\
	itemDef																									\
	{																										\
		style			WINDOW_STYLE_SHADER																	\
		frame           16 0.2 FRAME_OPEN_BOTTOM															\
		rect            0 SERVER_BROWSER_TAB_Y 0 TAB_HEIGHT HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER	\
		exp				rect X( ( -SERVER_BROWSER_WIDTH / 2 + px ) )										\
		exp				rect W(	tabWidth )																	\
		background      "menu_mp_tab_frame_inner"															\
		forecolor       1 1 1 1																				\
		visible			when( !selected )																	\
		decoration																							\
	} 

#define ON_ESC \
	if( menuisopen( filter_window ) )	\
	{ \
		close filter_window; \
	} \
	else \
	{ \
		close self; \
	}

#define SERVER_BROWSER_MENU_TEMPLATE( menuName, onOpenArg, onCloseArg ) \
		name					menuName \
		rect					0 0 640 480 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN  \
		focuscolor				COLOR_FOCUSED \
		style					WINDOW_STYLE_FILLED \
		priority				MENU_PRI_DEFAULT \
		soundloop 				MENU_MUSIC \
		openSlideSpeed			DEFAULT_SLIDE_IN_SPEED \
		closeSlideSpeed			DEFAULT_SLIDE_OUT_SPEED \
		openSlideDirection		MENU_SLIDE_DIRECTION_TOP_TO_BOTTOM \
		closeSlideDirection		MENU_SLIDE_DIRECTION_TOP_TO_BOTTOM \
		onFocus {  \
					setDvar ui_flyoutHasFocus FLYOUT_BROWSER; \
				} \		
		onOpen  {	\
					activateBlur; \
					play uin_navigation_menu_lg_open; \
					setdvar ui_serverBrowserMenu menuName; \
					onOpenArg; \
					uiScript PopulateServers; \					
				} \
		onClose { \
					execNow ui_animate menuName Browser "Maximized" DEFAULT_SLIDE_OUT_SPEED; \
					deactivateBlur; \
					onCloseArg; \
					setDvar ui_flyoutHasFocus FLYOUT_NONE; \
					execNow closemenuImmediate (filter_window); \
				} \
		onEsc	{ \
					ON_ESC \
				} \
		execKeyInt 171	{ \
							uiScript RefreshServers; \
						} \
						
						
#define GLOBAL_SERVER_COUNT \
	PREPROC_TEXT_DRAW( (SERVER_BROWSER_WIDTH/2-7) (-SERVER_BROWSER_HEIGHT/2+2) 1 1 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 0 0, ( locString( "@PLATFORM_PLAYERS_ONLINE", GetPlayersRegisteredOnline() ) ), TEXTSIZE_DEFAULT, 0, 1, ITEM_ALIGN_TOP_RIGHT, 1 1 1 1 ) \
	PREPROC_TEXT_DRAW( (SERVER_BROWSER_WIDTH/2-7) (-SERVER_BROWSER_HEIGHT/2+20) 1 1 HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER, 0 0, ( locString( "@PLATFORM_ALL_SERVERS", GetDedicatedServersRegisteredOnline() ) ), TEXTSIZE_DEFAULT, 0, 1, ITEM_ALIGN_TOP_RIGHT, 1 1 1 1 )
	
// Don't let keys fall through to the main menu.
#define MASSIVE_HACK_KEYCATCHER \	
	itemDef \
	{ \
		style           WINDOW_STYLE_EMPTY \
		rect			0 0 640 480 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN \
		forecolor       1 1 1 0 \
		visible         1 \
	}

#define SERVER_BROWSER_TAB_COMMON_ITEMS( selectedTabIndex ) \ 
		MASSIVE_HACK_KEYCATCHER \
		NEW_FRAME( SERVER_BROWSER_WIDTH, SERVER_BROWSER_HEIGHT ) \
		NEW_FRAME_TITLE( SERVER_BROWSER_WIDTH, SERVER_BROWSER_HEIGHT, "@MENU_SERVER_BROWSER_CAPS", 1 ) \
		SERVER_BROWSER_TAB_BG( SERVER_BROWSER_TAB_1_X, TAB_1_WIDTH, ( selectedTabIndex == 1 ) ) \
		SERVER_BROWSER_TAB_BG( SERVER_BROWSER_TAB_2_X, TAB_2_WIDTH, ( selectedTabIndex == 2 ) ) \
		SERVER_BROWSER_TAB_BG( SERVER_BROWSER_TAB_3_X, TAB_3_WIDTH, ( selectedTabIndex == 3 ) ) \
		SERVER_BROWSER_TAB_BG( SERVER_BROWSER_TAB_4_X, TAB_4_WIDTH, ( selectedTabIndex == 4 ) ) \
		SERVER_BROWSER_TAB_BG( SERVER_BROWSER_TAB_5_X, TAB_5_WIDTH, ( selectedTabIndex == 5 ) ) \
		SERVER_BROWSER_TAB_BG( SERVER_BROWSER_TAB_6_X, TAB_6_WIDTH, ( selectedTabIndex == 6 ) ) \
		TAB( SERVER_BROWSER_TAB_1_X, TAB_1_WIDTH, TAB_1_TEXT, server_browser_ranked, ( selectedTabIndex == 1 ) ) \
		TAB( SERVER_BROWSER_TAB_2_X, TAB_2_WIDTH, TAB_2_TEXT, server_browser_unranked, ( selectedTabIndex == 2 ) ) \
		TAB( SERVER_BROWSER_TAB_3_X, TAB_3_WIDTH, TAB_3_TEXT, server_browser_wager, ( selectedTabIndex == 3 ) ) \
		TAB( SERVER_BROWSER_TAB_4_X, TAB_4_WIDTH, TAB_4_TEXT, server_browser_friends, ( selectedTabIndex == 4 ) ) \
		TAB( SERVER_BROWSER_TAB_5_X, TAB_5_WIDTH, TAB_5_TEXT, server_browser_favorites, ( selectedTabIndex == 5 ) ) \
		TAB( SERVER_BROWSER_TAB_6_X, TAB_6_WIDTH, TAB_6_TEXT, server_browser_history, ( selectedTabIndex == 6 ) ) \
		GLOBAL_SERVER_COUNT

			
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
//	server_browser_main acts as a gateway to open the correct sub menu based upon dvar settings
	menuDef
	{
		name			server_browser_main
		fullScreen		0
		style			WINDOW_STYLE_EMPTY
		rect			0 0 640 480 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN

		onFocus
		{
			close self;	
			exec openmenu (dvarString( "ui_serverBrowserMenu" ));		
		}
	}

#define FILTER_ACTION \
	if( menuisopen( filter_window ) )	\
	{ \
		close filter_window; \
	} \
	else \
	{ \
		open filter_window; \
	}

#define BUTTON_SPACING 20
#define FILTER_BUTTON_OFFSET		( getTextWidth( locString( "@PLATFORM_BACK" ), CHOICE_TEXTFONT, TEXTSIZE_DEFAULT ) + 8 + BUTTON_SPACING )
#define SERVER_INFO_BUTTON_OFFSET	( FILTER_BUTTON_OFFSET + getTextWidth( locString( "@MENU_FILTER_SERVERS" ), CHOICE_TEXTFONT, TEXTSIZE_DEFAULT ) + 8 + BUTTON_SPACING )
#define JOIN_BUTTON_OFFSET			( 0 )
#define REFRESH_BUTTON_OFFSET		( -JOIN_BUTTON_OFFSET - getTextWidth( locString( "@MENU_JOIN_SERVER" ), CHOICE_TEXTFONT, TEXTSIZE_DEFAULT ) - 8 - BUTTON_SPACING )

#define SERVER_BROWSER_BOTTOM_BUTTONS \
	NEW_FRAME_BUTTON_PC_LEFT_OFFSET( SERVER_BROWSER_WIDTH, SERVER_BROWSER_HEIGHT, FILTER_BUTTON_OFFSET, "@MENU_FILTER_SERVERS", FILTER_ACTION, 1 ) \
	NEW_FRAME_BUTTON_PC_LEFT_OFFSET( SERVER_BROWSER_WIDTH, SERVER_BROWSER_HEIGHT, SERVER_INFO_BUTTON_OFFSET, "@MENU_SERVER_INFO", open newframeserverinfo;, 1 ) \
	NEW_FRAME_BUTTON_PC_RIGHT_OFFSET( SERVER_BROWSER_WIDTH, SERVER_BROWSER_HEIGHT, REFRESH_BUTTON_OFFSET, "@MENU_REFRESH_LIST", uiScript RefreshServers;, 1 ) \
	NEW_FRAME_BUTTON_PC_RIGHT_OFFSET( SERVER_BROWSER_WIDTH, SERVER_BROWSER_HEIGHT, JOIN_BUTTON_OFFSET, "@MENU_JOIN_SERVER", JOIN_SERVER_ACTION;, 1 ) \
	NEW_FRAME_BACK_BUTTON_ACTION( SERVER_BROWSER_WIDTH, SERVER_BROWSER_HEIGHT, ON_ESC )

	menuDef
	{
		SERVER_BROWSER_MENU_TEMPLATE( server_browser_ranked, uiscript UpdateNetSource AS_RANKED;, ; )
		PC_TAB_SWITCH_ACTIONS( server_browser_ranked, server_browser_history, server_browser_unranked )
		SERVER_BROWSER_TAB_COMMON_ITEMS( 1 );
		
		// buttons
		SERVER_BROWSER_BOTTOM_BUTTONS
		
		// browser
		SERVER_BROWSER( browser, FEEDER_SERVERS, 1)		
	}
	
	menuDef
	{
		SERVER_BROWSER_MENU_TEMPLATE( server_browser_unranked, uiscript UpdateNetSource  AS_UNRANKED;, ; )
		PC_TAB_SWITCH_ACTIONS( server_browser_unranked, server_browser_ranked, server_browser_wager )
		SERVER_BROWSER_TAB_COMMON_ITEMS( 2 )
		
		// buttons
		SERVER_BROWSER_BOTTOM_BUTTONS
		
		// browser listbox with background
		SERVER_BROWSER( browser, FEEDER_SERVERS, 1)
	}

	menuDef
	{
		SERVER_BROWSER_MENU_TEMPLATE( server_browser_wager, uiscript UpdateNetSource AS_WAGER;, ; )
		PC_TAB_SWITCH_ACTIONS( server_browser_wager, server_browser_unranked, server_browser_friends )
		SERVER_BROWSER_TAB_COMMON_ITEMS( 3 )
		
		// buttons
		SERVER_BROWSER_BOTTOM_BUTTONS
		
		// browser listbox with background
		SERVER_BROWSER( browser, FEEDER_SERVERS, 1)
	}
	
	menuDef
	{
		SERVER_BROWSER_MENU_TEMPLATE( server_browser_friends, uiscript UpdateNetSource AS_FRIENDS;, ; )
		PC_TAB_SWITCH_ACTIONS( server_browser_friends, server_browser_wager, server_browser_favorites )
		SERVER_BROWSER_TAB_COMMON_ITEMS( 4 )
		
		// buttons
		SERVER_BROWSER_BOTTOM_BUTTONS
		
		// browser listbox with background
		SERVER_BROWSER( browser, FEEDER_SERVERS, 1)
	}
	
	menuDef
	{
		SERVER_BROWSER_MENU_TEMPLATE( server_browser_favorites, uiscript UpdateNetSource AS_FAVORITES;, ; )
		PC_TAB_SWITCH_ACTIONS( server_browser_favorites, server_browser_friends, server_browser_history )
		SERVER_BROWSER_TAB_COMMON_ITEMS( 5 )
		
		// buttons
		SERVER_BROWSER_BOTTOM_BUTTONS
		
		// browser listbox with background
		SERVER_BROWSER( browser, FEEDER_SERVERS, 1)
	}
	
	menuDef
	{
		SERVER_BROWSER_MENU_TEMPLATE( server_browser_history, uiscript UpdateNetSource AS_HISTORY;, ; )
		PC_TAB_SWITCH_ACTIONS( server_browser_history, server_browser_favorites, server_browser_ranked )
		SERVER_BROWSER_TAB_COMMON_ITEMS( 6 )
		
		// buttons
		SERVER_BROWSER_BOTTOM_BUTTONS
		
		// browser listbox with background
		SERVER_BROWSER( browser, FEEDER_SERVERS, 1)
	}

#undef MENUDEF_NAME
#define MENUDEF_NAME filter_window

#undef CHOICE_BUTTON_NAME
#define CHOICE_BUTTON_NAME		"filter_"

#define	FILTER_WIDTH		TABLE_WIDTH		
#define	FILTER_HEIGHT		FILTER_MENU_HEIGHT
#define FILTER_X			(TABLE_X - 10)
#define FILTER_Y			( TABLE_Y + (TABLE_HEIGHT - FILTER_HEIGHT) - 2 )

#undef	CHOICE_TEXT_COLOR_NO_HL
#undef	CHOICE_TEXT_COLOR_HL
#undef	CHOICE_CAPTION_TEXT_COLOR_NO_HL
#undef	CHOICE_CAPTION_TEXT_COLOR_HL

#define	CHOICE_TEXT_COLOR_NO_HL			CHOICE_TEXTCOLOR
#define	CHOICE_TEXT_COLOR_HL			1 1 1 1
#define	CHOICE_CAPTION_TEXT_COLOR_NO_HL	CHOICE_TEXTCOLOR
#define	CHOICE_CAPTION_TEXT_COLOR_HL	0 0 0 1


#undef	CHOICE_SIZE_X			
#define CHOICE_SIZE_X		120
#undef	CHOICE_Y_START
#define CHOICE_Y_START		0
#undef	CHOICE_X_START
#define CHOICE_X_START		0

#undef CHOICE_TEXTSIZE
#define CHOICE_TEXTSIZE TEXTSIZE_SMALL

#undef CHOICE_DVAR_EXTRA_WIDTH
#define CHOICE_DVAR_EXTRA_WIDTH 60

	menuDef																													
	{																														
		name			filter_window
		rect			FILTER_X FILTER_Y FILTER_WIDTH FILTER_HEIGHT CHOICE_HORIZONTAL_ALIGN CHOICE_VERTICAL_ALIGN				
		focuscolor				COLOR_FOCUSED
		style					WINDOW_STYLE_FILLED
		priority				MENU_PRI_ONTOP
		openSlideSpeed			DEFAULT_SLIDE_IN_SPEED
		closeSlideSpeed			(DEFAULT_SLIDE_OUT_SPEED*2)
		openSlideDirection		MENU_SLIDE_DIRECTION_BOTTOM_TO_TOP
		closeSlideDirection		MENU_SLIDE_DIRECTION_TOP_TO_BOTTOM
		visible			1

		onOpen
		{
			play uin_navigation_menu_lg_open;
			execNow ui_animate (dvarString( "ui_serverBrowserMenu" )) Browser "Reduced" DEFAULT_SLIDE_IN_SPEED;
		}
		onClose
		{
			execNow ui_animate (dvarString( "ui_serverBrowserMenu" )) Browser "Maximized" DEFAULT_SLIDE_OUT_SPEED;
		}
		onEsc
		{
			close self;
		}
		leaveFocus
		{
			close self;
		}

		itemDef
		{	
			style           WINDOW_STYLE_SHADER_FRAMED
			rect            -10 -10 ( FILTER_WIDTH + 20 ) ( FILTER_HEIGHT + 20 ) HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER
			background      "menu_mp_lobby_frame_outer"
			forecolor       1 1 1 1					
			visible         when( 1 );
			decoration														
			frame           26 0.1 FRAME_SIDE_ALL							
		}																	
		itemDef																
		{																	
			style           WINDOW_STYLE_SHADER_FRAMED						
			rect            0 0 FILTER_WIDTH FILTER_HEIGHT HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER
			background      "menu_mp_lobby_frame_inner"																																					
			forecolor       1 1 1 1																																										
			visible         when( 1 );																															
			decoration																																													
			frame           26 0.1 FRAME_OPEN_TOP																																						
		}
		
		// View empty.
		FRAME_CHOICE_DVARFLOATLIST( 1, "@MENU_VIEW_EMPTY", ui_browserShowEmpty, { "@MENU_NO" 0 "@MENU_YES" 1 }, uiScript RefreshFilter; )
					
		// View full.
		FRAME_CHOICE_DVARFLOATLIST( 2, "@MENU_VIEW_FULL", ui_browserShowFull, { "@MENU_NO" 0 "@MENU_YES" 1 }, uiScript RefreshFilter; )

		// With password.
  		FRAME_CHOICE_DVARFLOATLIST( 3, "@MENU_VIEW_PASSWORD", ui_browserShowPassword, { "@MENU_ALL" -1 "@MENU_NO" 0 "@MENU_YES" 1 }, uiScript RefreshFilter; )

		// mods
		FRAME_CHOICE_DVARLIST_VIS( 4, "@MENU_MODS", "", ITEM_TYPE_OD_TEXT_BUTTON, ownerdraw UI_JOINMOD, uiScript RefreshFilter;, 1 )
  		
  		
  		#undef CHOICE_X_START
  		#define CHOICE_X_START 180
  		
  		#undef CHOICE_Y_START
  		#define CHOICE_Y_START -76
		
		// Voice chat.
  		FRAME_CHOICE_DVARFLOATLIST( 5, "@MENU_VOICECHAT", ui_browserVoiceChat, { "@MENU_ALL" -1 "@MENU_NO" 0 "@MENU_YES" 1 }, uiScript RefreshFilter; )
			
		// Hardcore.
  		FRAME_CHOICE_DVARFLOATLIST( 6, "@MPUI_HARDCORE_PRE", ui_browserHardcore, { "@MENU_ALL" -1 "@MENU_NO" 0 "@MENU_YES" 1 }, uiScript RefreshFilter; )
  		
  		// Friendly fire.
  		FRAME_CHOICE_DVARFLOATLIST( 7, "@MENU_VIEW_FRIENDLY_FIRE", ui_browserFriendlyfire, { "@MENU_ALL" -1 "@MENU_OFF" 0 "@MENU_ON" 1 "@MENU_REFLECT" 2 "@MENU_SHARED" 3 }, uiScript RefreshFilter; )
  		
  		
  		#undef CHOICE_X_START
  		#define CHOICE_X_START 360
  		
  		#undef CHOICE_Y_START
  		#define CHOICE_Y_START -152
  		
// Map
		FRAME_CHOICE_DVARENUMLIST_VIS( 9, "@MPUI_CHANGE_MAP_LOWER", ui_browserMap, ui_browserMap, uiScript RefreshFilter;, 1 )
  		
  		// Game Mode
  		#define MODE_LIST { "@MENU_ALL"; 0; "@MPUI_TDM_SHORT_CAPS"; "tdm"; "@MPUI_DM_SHORT_CAPS"; "dm"; "@MPUI_SD_SHORT_CAPS"; "sd"; "@MPUI_DOM_SHORT_CAPS"; "dom"; "@MPUI_KOTH_SHORT_CAPS"; "koth"; "@MPUI_DEM_SHORT_CAPS"; "dem"; "@MPUI_CTF_SHORT_CAPS"; "ctf"; "@MPUI_SAB_SHORT_CAPS"; "sab"; }
  		FRAME_CHOICE_DVARSTRINGLIST( 10, "@MENU_GAME_MODE_PRE", ui_browserGameMode, MODE_LIST;, uiScript RefreshFilter;)

		// Hide Dlc.
  		FRAME_CHOICE_DVARFLOATLIST( 11, "@MPUI_DLC_CONTENT", ui_browserHideDlc, { "@MENU_ALL" 0 "@MPUI_PURCHASED" 1 }, uiScript RefreshFilter; )

		#undef CHOICE_SIZE_X
		#define CHOICE_SIZE_X		98
			
		#undef CHOICE_X_START
  		#define CHOICE_X_START 480

#undef	CHOICE_TEXT_COLOR_NO_HL
#undef	CHOICE_TEXT_COLOR_HL
#undef	CHOICE_CAPTION_TEXT_COLOR_NO_HL
#undef	CHOICE_CAPTION_TEXT_COLOR_HL

#define	CHOICE_TEXT_COLOR_NO_HL			CHOICE_TEXTCOLOR
#define	CHOICE_TEXT_COLOR_HL			0 0 0 1
#define	CHOICE_CAPTION_TEXT_COLOR_NO_HL	CHOICE_TEXTCOLOR
#define	CHOICE_CAPTION_TEXT_COLOR_HL	0 0 0 1

		// Reset
		FRAME_CHOICE_BUTTON( 12, "@MENU_RESET", exec "exec default_filter.cfg"; )
  		
  		// Apply
		//FRAME_CHOICE_BUTTON( 14, "@MENU_APPLY", uiScript RefreshFilter; )
	} 
}

#undef CHOICE_TEXTSIZE
#define CHOICE_TEXTSIZE TEXTSIZE_DEFAULT

#include "ui_mp/popupstyle.inc"
#include "ui/choices_setup_popmenu.menu"
#include "ui_mp/popup_player_info.inc"

#undef CHOICE_FOCUS_SOUND
#define CHOICE_FOCUS_SOUND		"uin_navigation_over"
	
	// Redefinitions for MEDIUM_POPUP_SETUP popups
	#undef	POPUP_WIDTH
	#define	POPUP_WIDTH								MEDIUM_POPUP_WIDTH		
	#undef	POPUP_HEIGHT
	#define	POPUP_HEIGHT							MEDIUM_POPUP_HEIGHT
	#undef	CHOICE_SIZE_X			
	#define CHOICE_SIZE_X							CONFIRM_PURCHASE_SIZE_X
	#undef	CHOICE_Y_START
	#define CHOICE_Y_START							POPUP_Y_START_TOP
	#undef	PLAYER_INFO_ALIGN
	#define PLAYER_INFO_ALIGN						// Purposely set to nothing. The popup setup macro sets the alignment. If items within it set their own aligment, they end up offset incorrectly.
	#undef	PLAYER_INFO_X_START
	#define	PLAYER_INFO_X_START( frameWidth )		( frameWidth - PLAYER_INFO_WIDTH - PLAYER_INFO_PAD )
	#undef	PLAYER_INFO_Y_START
	#define	PLAYER_INFO_Y_START( frameHeight )		( PLAYER_INFO_PAD * 2 )
	#undef	BG_BACKCOLOR
	#define BG_BACKCOLOR							POPUP_BACKCOLOR

	#define PURCHASE_CONFIRMATION_RIGHT_X			( MEDIUM_POPUP_WIDTH / 2 )
	#define PURCHASE_INFO_WIDTH						( ( MEDIUM_POPUP_WIDTH / 2 ) - POPUP_SIDE_PAD )

	#define PURCHASE_CONFIRMATION_ITEM_INFO( itemName, itemCost )	\
			CONFIRMATION_ITEM_INFO_VIS( itemName, itemCost, "@MPUI_BALANCE_AFTER_PURCHASE",	locString( "@MENU_POINTS", GetStatByName( "CODPOINTS" ) - itemCost ), 1 )	

	#define CONFIRMATION_ITEM_INFO_VIS( itemName, itemCost, balanceHeader, balanceAfter, visArg )																																																	\
			PREPROC_TEXT_DRAW_VIS_EX( (PURCHASE_CONFIRMATION_RIGHT_X)	CHOICE_Y( 1 )	PURCHASE_INFO_WIDTH CHOICE_SIZE_Y,	0 0, locString( itemName, itemCost ),						TEXTSIZE_LARGE,		0, 0, ITEM_ALIGN_MIDDLE_LEFT,	NEW_FRAME_GREEN_RGB 1,	visArg, ;				)	\	/* Name								*/
			PREPROC_TEXT_DRAW_VIS_EX( (PURCHASE_CONFIRMATION_RIGHT_X)	CHOICE_Y( 7 )	PURCHASE_INFO_WIDTH CHOICE_SIZE_Y,	0 0, "@MPUI_YOUR_BANK",											TEXTSIZE_DEFAULT,	0, 0, ITEM_ALIGN_TOP_LEFT,		MEDIUM_POPUP_GRAY,		visArg, ;				)	\	/* Currency Available Header		*/
			PREPROC_TEXT_DRAW_VIS_EX( (MEDIUM_POPUP_WIDTH-75)			CHOICE_Y( 7 )	PURCHASE_INFO_WIDTH CHOICE_SIZE_Y,	0 0, locString( "@MENU_POINTS", GetStatByName( "CODPOINTS" ) ),	TEXTSIZE_DEFAULT,	0, 0, ITEM_ALIGN_TOP_LEFT,		1 1 1 1,				visArg, ;				)	\	/* Currency Available				*/
			PREPROC_TEXT_DRAW_VIS_EX( (PURCHASE_CONFIRMATION_RIGHT_X)	CHOICE_Y( 8 )	PURCHASE_INFO_WIDTH CHOICE_SIZE_Y,	0 0, balanceHeader,												TEXTSIZE_DEFAULT,	0, 0, ITEM_ALIGN_TOP_LEFT,		MEDIUM_POPUP_GRAY,		visArg, ;				)	\	/* Balance After Purchase Header	*/
			PREPROC_TEXT_DRAW_VIS_EX( (MEDIUM_POPUP_WIDTH-75)			CHOICE_Y( 8 )	PURCHASE_INFO_WIDTH CHOICE_SIZE_Y,	0 0, balanceAfter,												TEXTSIZE_DEFAULT,	0, 0, ITEM_ALIGN_TOP_LEFT,		1 1 1 1,				visArg, ;				)		/* Balance After Purchase			*/
		
		#define WAGER_ONFOCUS \
				; 
		
		#define WAGER_ONESC \
				setDvar ui_joiningwagerfrominvite "0"; \
				close self;
				
		#define WAGER_ACTION \
				play CHOICE_FOCUS_SOUND; \
				uiScript JoinServer; \
				WAGER_ONESC
menuDef
{
	MEDIUM_POPUP_SETUP_VIS( "WagerConfirmation", setfocus "WagerConfirmation_2";, ;, POPUP_GLOW_GREEN, 1, 1 )
	MEDIUM_POPUP_TITLE_VIS( "@PLATFORM_CONFIRM_WAGER_CAPS", 1 )
	PLAYER_INFO_VIS( MEDIUM_POPUP_WIDTH, MEDIUM_POPUP_HEIGHT, 1 )
	PURCHASE_CONFIRMATION_ITEM_INFO( "@PLATFORM_WAGER_BET", dvarInt("ui_wagerbet") )
	

	FRAME_CHOICE_BUTTON_VIS_EX( 1, "@MENU_JOIN_GAME_CAPS",				WAGER_ACTION,				1, ;							)
	FRAME_CHOICE_BUTTON_VIS_EX( 2, "@MENU_CANCEL_CAPS",	WAGER_ONESC,				1, name WagerConfirmation_2	) 
}

#define WAGER_ACTION2 \
		play CHOICE_FOCUS_SOUND; \
		execNow quickmatchconnect; \
		WAGER_ONESC
menuDef
{
	MEDIUM_POPUP_SETUP_VIS( "QuickWagerConfirmation", setfocus "QuickWagerConfirmation_2";, ;, POPUP_GLOW_GREEN, 1, 1 )
	MEDIUM_POPUP_TITLE_VIS( "@PLATFORM_CONFIRM_WAGER_CAPS", 1 )
	PLAYER_INFO_VIS( MEDIUM_POPUP_WIDTH, MEDIUM_POPUP_HEIGHT, 1 )
	PURCHASE_CONFIRMATION_ITEM_INFO( "@PLATFORM_WAGER_BET", dvarInt("ui_wagerbet") )
	

	FRAME_CHOICE_BUTTON_VIS_EX( 1, "@MENU_JOIN_GAME_CAPS",				WAGER_ACTION2,				1, ;							)
	FRAME_CHOICE_BUTTON_VIS_EX( 2, "@MENU_CANCEL_CAPS",	close self,				1, name QuickWagerConfirmation_2	) 
}

	#undef	CHOICE_Y_START
	#define CHOICE_Y_START							POPUP_Y_START_CENTER

	#undef	POPUP_BUTTON_COUNT
	#define	POPUP_BUTTON_COUNT		1
menuDef
{			
		SYSTEM_POPUP_SETUP_VIS( WagerDeadBeat, WAGER_ONFOCUS, WAGER_ONESC, 1 )
		SYSTEM_POPUP_TITLE_VIS( "@PLATFORM_WAGER_DEADBEAT_TITLE", 1 )

		SYSTEM_POPUP_SUBTITLE_VIS( locString( "@PLATFORM_WAGER_DEADBEAT_DESC", dvarInt( "ui_wagerbet" ) ), 1 )
		FRAME_CHOICE_BUTTON_VIS_EX( 1, "@MENU_OK", WAGER_ONESC, 1, ; )
}

menuDef
{			
		SYSTEM_POPUP_SETUP_VIS( WagerPlaylistIsOld, WAGER_ONFOCUS, WAGER_ONESC, 1 )
		SYSTEM_POPUP_TITLE_VIS( "@MENU_ERROR_CAPS", 1 )

		SYSTEM_POPUP_SUBTITLE_VIS( locString( "@PATCH_PLAYLISTISOLD" ), 1 )
		FRAME_CHOICE_BUTTON_VIS_EX( 1, "@MENU_OK", WAGER_ONESC, 1, ; )
}

menuDef
{			
		SYSTEM_POPUP_SETUP_VIS( WagerPlaylistIsNew, WAGER_ONFOCUS, WAGER_ONESC, 1 )
		SYSTEM_POPUP_TITLE_VIS( "@MENU_ERROR_CAPS", 1 )

		SYSTEM_POPUP_SUBTITLE_VIS( locString( "@PATCH_PLAYLISTISNEW" ), 1 )
		FRAME_CHOICE_BUTTON_VIS_EX( 1, "@MENU_OK", WAGER_ONESC, 1, ; )
}

