#include "ui/menudef.h"
#include "ui/menumacros.h"

// Defines //
#define WINDOW_X		16
#define WINDOW_Y		16
#define WINDOW_WIDTH	__WINDOW_WIDTH-32
#define WINDOW_HEIGHT	448
#define MENU_WIDTH		128
#define MENU_HEIGHT		248
#define GROUP_NAME		"grpMain"

// Opener //
menuDef {
	name		"main_opener"
	visible		0
	fullscreen	0
	rect		WINDOW_X WINDOW_Y MENU_WIDTH MENU_HEIGHT

	onOpen {
		open fadebox_black ;
		open background_1 ;
		setmenuitemcolor fadebox_black fadebox backcolor 0 0 0 1 ;
		fadeoutmenu fadebox_black ;
		open main ;
		clearcvar ui_profile_create_error ;
		close main_opener
	}
}

// Main Menu //
menuDef {
	name		"main"
	visible		0
	fullscreen	0
	rect		WINDOW_X WINDOW_Y $evalint(WINDOW_WIDTH) WINDOW_HEIGHT
	style		WINDOW_STYLE_FILLED

	onOpen {
		exec "set cl_noprint 1; exec etlegacy.cfg; set cl_noprint 0"

		conditionalscript cl_profile 1
			( "clearFocus" )
			( "close main ; open profile_create_initial_opener" )	// do we want an abort here?

		conditionalscript ROldModeCheck 2
			( "clearFocus ; open vid_confirm" )
			( "clearFocus" )
	}

	onEsc {
		clearFocus ;
		open quit
	}

// Background Logo //
	itemDef {
		name		"etl_logo"
		rect		$evalint(__WINDOW_WIDTH/2-100-16) 124 200 200		// 16, 16 offset!!
		style		WINDOW_STYLE_SHADER
		background	"ui/assets/etl_logo_huge"
		visible		1
		decoration
	}

// Company Logos //
	itemDef {
		name		"sd_logo"
		rect		0 394 54 54		// 16, 16 offset!!
		style		WINDOW_STYLE_SHADER
		background	"ui/assets/logo_sd_dark"
		forecolor	1 1 1 1
		visible		1
		decoration
	}

	itemDef {
		name		"atvi_logo"
		rect		$evalint(__WINDOW_WIDTH-(2*WINDOW_X)-48-4-108) 421 108 27		// 16, 16 offset!! (note offset to left a little as well)
		style		WINDOW_STYLE_SHADER
		background	"ui/assets/logo_atvi_dark"
		forecolor	1 1 1 1
		visible		1
		decoration
	}

	itemDef {
		name		"id_logo"
		rect		$evalint(__WINDOW_WIDTH-(2*WINDOW_X)-48) 400 48 48		// 16, 16 offset!!
		style		WINDOW_STYLE_SHADER
		background	"ui/assets/logo_id_dark"
		forecolor	1 1 1 1
		visible		1
		decoration
	}


// Window //
	//WINDOW( _("MENU"), 50 ) // FIXME: script error with WINDOW_HEIGHT
	SUBWINDOW( 0, 0, MENU_WIDTH, MENU_HEIGHT, _("WELCOME") )
	execKey "c" { close main ; open main_quickconnect }

// Active profile
	CVARLABEL( 6+((MENU_WIDTH-12)/2), 18, MENU_WIDTH-12, 10, "cl_profile", .2, ITEM_ALIGN_CENTER, 0, 8 )

// Buttons //
	BUTTON( 6, 32, MENU_WIDTH-12, 18, _("PLAY ONLINE"), .3, 14, close main ; /*close backgroundmusic ; open backgroundmusic_server ;*/ uiScript UpdateFilter ; uiScript ServerSort 2 ; open playonline )
	BUTTON( 6, 56, MENU_WIDTH-12, 18, _("HOST GAME"), .3, 14, close main ; /*close backgroundmusic ; open backgroundmusic_server ;*/ uiScript loadArenas ; uiScript initHostGameFeatures ; open hostgame )
	BUTTON( 6, 80, MENU_WIDTH-12, 18, _("REPLAYS"), .3, 14, close main ; open viewreplay )
	BUTTON( 6, 104, MENU_WIDTH-12, 18, _("OPTIONS"), .3, 14, close main ; open options )
	BUTTON( 6, 128, MENU_WIDTH-12, 18, _("PROFILE"), .3, 14, close main ; open profile )
	BUTTON( 6, 152, MENU_WIDTH-12, 18, _("MODS"), .3, 14, close main ; open mods )
	BUTTON( 6, 176, MENU_WIDTH-12, 18, _("CREDITS"), .3, 14, close main ; open credits_etlegacy )
	BUTTON( 6, 200, MENU_WIDTH-12, 18, _("WEBSITE"), .3, 14, clearFocus ; open website_etlegacy )
	BUTTON( 6, 224, MENU_WIDTH-12, 18, _("EXIT GAME"), .3, 14, clearFocus ; open quit )

// Vanilla client warning //
#ifndef LEGACY
#define SECURITY_WIDTH	200
	LABEL( __WINDOW_WIDTH/2-100-16, 368, SECURITY_WIDTH, 18, _("^1SECURITY INFORMATION"), .3, ITEM_ALIGN_CENTER, .5*SECURITY_WIDTH, 8 )
	LABELWHITE( __WINDOW_WIDTH/2-100-16, 384, SECURITY_WIDTH, 9, _("You are running old software"), .2, ITEM_ALIGN_CENTER, .5*SECURITY_WIDTH, 8 )
	LABEL( __WINDOW_WIDTH/2-100-16, 398, SECURITY_WIDTH, 9, _("We do recommend to\nupgrade your ET client"), .2, ITEM_ALIGN_CENTER, .5*SECURITY_WIDTH, 8 )
	BUTTON( __WINDOW_WIDTH/2-100-16+6, 428, SECURITY_WIDTH-12, 18, _("UPGRADE NOW"), .3, 14, clearFocus ; uiScript validate_openURL )
#endif

// Version //
LABEL( 2, 450, 114, 10, "^1"ETLEGACY_VERSION, .2, ITEM_ALIGN_LEFT, 0, 8 )

// message of the day?
//	SUBWINDOW( MENU_WIDTH+6, 0, __WINDOW_WIDTH-MENU_WIDTH-6-32, 28, _("MESSAGE OF THE DAY") )
//	itemDef {
//		name			"messageOfTheDay"
//		group			GROUP_NAME
//		rect			0 340 640 10
//		ownerDraw		UI_SERVERMOTD
//		textfont		UI_FONT_COURBD_21
//		textstyle		ITEM_TEXTSTYLE_SHADOWED
//		textscale		.2
//		textalignx		4
//		textaligny		8
//		forecolor		.6 .6 .6 1
//		visible			1
//		decoration
//	}
}
