#include "ui/menudef.h"
#include "ui_mp/main.inc"
#include "ui_mp/logo.inc"

#define MENU_NAME					"main_text"
#define MENU_MUSIC					"music_mainmenu_mp"
#define MENU_TITLE					"IW4x"

#undef CHOICE_GROUP
#define CHOICE_GROUP				MENU_NAME

#undef TEXTSIZE_TITLE
#define TEXTSIZE_TITLE				FONTSCALE_BIG

#define ON_MENU_OPEN \
	exec							"selectStringTableEntryInDvar mp/didyouknow.csv 0 didyouknow"; \
	uiScript						"checkFirstLaunch"; \
	setLocalVarString				ui_hint_text "";

#define CHECK_FOR_UPDATE_ACTION \
	exec							"checkforupdate"; \
	open							"auconfirm";

#define CREATE_GAME_ACTION \
	exec							"xrequirelivesignin"; \
	setDvar							"systemlink" 0; \
	setDvar							"splitscreen" 0; \
	setDvar							"onlinegame" 1; \
	exec							"exec default_xboxlive.cfg"; \
	setDvar							"party_maxplayers" 18; \
	setDvar							"xblive_privateserver" 0; \
	setDvar							"xblive_rankedmatch" 0; \
	exec							"xstartprivateparty"; \
	setDvar							"ui_mptype" 0; \
	exec							"xcheckezpatch"; \
	exec							"exec default_xboxlive.cfg" \
	setDvar							"xblive_rankedmatch" 0; \
	exec							"ui_enumeratesaved"; \
	setDvar							"xblive_privateserver" 1; \
	exec							"xstartprivatematch"; \
	open							"menu_xboxlive_privatelobby";

#define CHOICE_Y(i)					(88 + (i * 20))
#define CHOICE_ORIGIN(i)			-64 CHOICE_Y(i)
#define CHOICE_RECT(i)				CHOICE_ORIGIN(i) 336 20 HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_TOP

#define HR_ORIGIN(i)				0 (CHOICE_Y(i) - 0.5)
#define HR_RECT(i)					HR_ORIGIN(i) 216 1 HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_TOP

{
	menuDef
	{
		name						MENU_NAME
		fullscreen					1
		rect						0 0 640 480
		foreColor					CHOICE_TEXTCOLOR
		focusColor					CHOICE_TEXTCOLOR
		soundLoop					MENU_MUSIC
		fadeCycle					1
		fadeClamp					1
		fadeAmount					0.1
		
		MENU_ON_OPEN(ON_MENU_OPEN)
		MENU_ON_ESC(open "quit_popmenu";)
		
		#define BACKGROUND_IW4
		#include "ui_mp/bg.inc"

		LOGO_GAME

		ITEM_NEWSTICKER_VIS("", 1, NEWSTICKER_SPEED)
		
		MENU_CHOICE_TITLE_VIS(MENU_TITLE, 78, when(!dvarBool(cl_updateavailable)))
		MENU_CHOICE_TITLE_VIS(MENU_TITLE, 58, when(dvarBool(cl_updateavailable)))

		// update buttons
		MENU_CHOICE_BUTTON_VIS(0, button_0, "@MENU_CHECK_FOR_UPDATES_CAPS", CHECK_FOR_UPDATE_ACTION, "@MPUI_DESC_CHECK_FOR_UPDATES", when(dvarBool(cl_updateavailable)))
		MENU_CHOICE_NEWICON_VIS(0, when(dvarBool(cl_updateavailable)))
		MENU_CHOICE_HORIZONTAL_LINE_VIS(1, when(dvarBool(cl_updateavailable)))

		// general menu buttons
		MENU_CHOICE_BUTTON_VIS(1, button_1, "@MENU_JOIN_GAME_CAPS", exec "xrequirelivesignin"; open pc_join_unranked;, "@MPUI_DESC_JOIN_GAME", 1)
		MENU_CHOICE_BUTTON_VIS(2, button_2, "@MENU_CREATE_GAME_CAPS", CREATE_GAME_ACTION, "@MPUI_DESC_CREATE_GAME", 1)
		MENU_CHOICE_HORIZONTAL_LINE_VIS(3, 1)
		MENU_CHOICE_DBUTTON_VIS(3, button_3, "@MENU_CREATE_A_CLASS_CAPS", "@PERKS_UNLOCKED_BY_CHALLENGE", when(!isItemUnlocked("cac")))
		MENU_CHOICE_BUTTON_VIS(3, button_3, "@MENU_CREATE_A_CLASS_CAPS", open cac_popup;, "@MPUI_DESC_CREATE_A_CLASS", when(isItemUnlocked("cac")))
		MENU_CHOICE_NEWICON_VIS(3, when( ( isItemUnlocked("cac") && ( getPlayerDataAnyBoolTrue( "weaponNew" ) || getPlayerDataAnyBoolTrue( "camoNew" ) || getPlayerDataAnyBoolTrue( "attachmentNew" ) ) || getPlayerDataAnyBoolTrue( "perkNew" ) || ( ( getPlayerData( "perkNew" , "frag_grenade_mp" ) || getPlayerData( "perkNew" , tablelookup( "mp/perkTable.csv" , 1 , "frag_grenade_mp" , 8 ) ) ) || ( getPlayerData( "perkNew" , "semtex_mp" ) || getPlayerData( "perkNew" , tablelookup( "mp/perkTable.csv" , 1 , "semtex_mp" , 8 ) ) ) || ( getPlayerData( "perkNew" , "c4_mp" ) || getPlayerData( "perkNew" , tablelookup( "mp/perkTable.csv" , 1 , "c4_mp" , 8 ) ) ) || ( getPlayerData( "perkNew" , "claymore_mp" ) || getPlayerData( "perkNew" , tablelookup( "mp/perkTable.csv" , 1 , "claymore_mp" , 8 ) ) ) || ( getPlayerData( "perkNew" , "throwingknife_mp" ) || getPlayerData( "perkNew" , tablelookup( "mp/perkTable.csv" , 1 , "throwingknife_mp" , 8 ) ) ) || ( getPlayerData( "perkNew" , "specialty_tacticalinsertion" ) || getPlayerData( "perkNew" , tablelookup( "mp/perkTable.csv" , 1 , "specialty_tacticalinsertion" , 8 ) ) ) || ( getPlayerData( "perkNew" , "specialty_blastshield" ) || getPlayerData( "perkNew" , tablelookup( "mp/perkTable.csv" , 1 , "specialty_blastshield" , 8 ) ) ) || weaponClassNew( "weapon_grenade" ) || weaponClassNew( "weapon_equipment" ) ) || getPlayerData( "featureNew" , "cac" ) ) ) )
		MENU_CHOICE_DBUTTON_VIS(4, button_4, "@MENU_PLAYERCARD_CAPS", "@PERKS_UNLOCKED_BY_CHALLENGE", when(!isItemUnlocked("cac")))
		MENU_CHOICE_BUTTON_VIS(4, button_4, "@MENU_PLAYERCARD_CAPS", open popup_callsign;, "@MPUI_DESC_PLAYERCARD", when(isItemUnlocked("cac")))
		MENU_CHOICE_NEWICON_VIS(4, when( ( getPlayerData( "featureNew" , "cas" ) || getPlayerData( "featureNew" , "token_1" ) || getPlayerData( "featureNew" , "token_2" ) || getPlayerData( "featureNew" , "token_3" ) || getPlayerData( "featureNew" , "token_4" ) || getPlayerData( "featureNew" , "token_5" ) || getPlayerData( "featureNew" , "token_6" ) || getPlayerData( "featureNew" , "token_7" ) || getPlayerData( "featureNew" , "token_8" ) || getPlayerData( "featureNew" , "token_9" ) || getPlayerData( "featureNew" , "token_10" ) || getPlayerData( "featureNew" , "token_11" ) || getPlayerData( "featureNew" , "token_12" ) ) || getPlayerData( "featureNew" , "clantag" ) || ( getPlayerDataAnyBoolTrue( "iconNew" ) || getPlayerData( "featureNew" , "playercard_icon" ) ) || ( getPlayerDataAnyBoolTrue( "titleNew" ) || getPlayerData( "featureNew" , "playercard_title" ) ) ))
		MENU_CHOICE_HORIZONTAL_LINE_VIS(5, 1)
		MENU_CHOICE_BUTTON_VIS(5, button_5, "@MENU_BARRACKS_CAPS", open menu_online_barracks;, "@PATCH_DESC_BARRACKS", 1)
		MENU_CHOICE_NEWICON_VIS(5, when( ( ( getPlayerDataAnyBoolTrue( "challengeTierNew" ) || getPlayerData( "featureNew" , "challenges" ) ) || getPlayerData( "featureNew" , "challenges" ) || getPlayerData( "featureNew" , "prestige" ) ) ) )
		MENU_CHOICE_BUTTON_VIS(6, button_6, "@MENU_THEATER_CAPS", open pc_theater_menu;, "@MPUI_DESC_THEATER", 1)
		MENU_CHOICE_HORIZONTAL_LINE_VIS(7, 1)
		MENU_CHOICE_BUTTON_VIS(7, button_7, "@MENU_MODS_CAPS", open mods_menu;, "@MPUI_DESC_MODS", 1)
		MENU_CHOICE_BUTTON_VIS(8, button_8, "@MENU_STORE_CAPS", open pc_store, "@MPUI_DESC_STORE", 1)
		MENU_CHOICE_NEWICON_VIS(8, when(!dvarBool(isDlcInstalled_All)))
		MENU_CHOICE_HORIZONTAL_LINE_VIS(8, 1)
		MENU_CHOICE_BUTTON_VIS(9, button_9, "@MENU_OPTIONS_CAPS", open pc_options_video;, "@MPUI_DESC_OPTIONS", 1)
		MENU_CHOICE_HORIZONTAL_LINE_VIS(9, 1)
		MENU_CHOICE_BUTTON_VIS(10, button_10, "@MENU_SP_CREDITS_CAPS", open iw4x_credits;, "@NULL_EMPTY", 1)
		MENU_CHOICE_HORIZONTAL_LINE_VIS(10, 1)
		MENU_CHOICE_BUTTON_VIS(11, button_11, "@MENU_QUIT_CAPS", open quit_popmenu;, "@MPUI_DESC_QUIT", 1)

		ITEM_BUTTON_FRIENDS(-250)

		itemDef
		{
			name						"button_changelog"
			rect						-120 -4 120 20 HORIZONTAL_ALIGN_RIGHT VERTICAL_ALIGN_BOTTOM
			foreColor					CHOICE_TEXTCOLOR
			style						WINDOW_STYLE_FILLED
			type						ITEM_TYPE_BUTTON
			textAlign					ITEM_ALIGN_CENTER
			textAlignY					16
			textScale					MENU_BUTTON_TEXTSIZE
			textfont					9
			visible						1
			text						"@MENU_CHANGELOG_CAPS"
			onFocus
			{
				play					CHOICE_FOCUS_SOUND;
				setItemColor			self backcolor 0 0 0 1;
				setLocalVarBool			ui_menuAButton 1;
				setLocalVarFloat		ui_popupYPos 0;
				setLocalVarString		ui_hint_text "@MPUI_DESC_CHANGELOG";
			}
			leaveFocus
			{
				setItemColor			self backcolor 0 0 0 0;
				setLocalVarBool			ui_menuAButton 1;
				setLocalVarString		ui_hint_text "@NULL_EMPTY";
			}
			action
			{
				play				CHOICE_CLICK_SOUND;
				open				"changelog";
			}
		}
		
		// hint text
		itemDef
		{
			name					"hint_area"
			rect					0 340 215 18 HORIZONTAL_ALIGN_LEFT VERTICAL_ALIGN_TOP
			foreColor				1 1 1 0.65
			textAlign				6
			textScale				CHOICE_TEXTSIZE
			textFont				UI_FONT_SMALL
			decoration
			autoWrapped
			visible					1
			exp						text ( localvarstring( "ui_hint_text" )  )
		}
	}
}
