#include "ui/menudef.h"

// Defines //

#define WINDOW_X		0
#define WINDOW_Y		0
#define WINDOW_WIDTH	640
#define WINDOW_HEIGHT	480
#define GROUP_NAME		"grpProfileCreateInitial"

// Macros //

#include "ui/menumacros.h"
		
// Create Profile Menu //

#define INITIAL_PROFILEDEFAULT_SETTINGS		uiScript systemCvarsGet ;				\
											uiScript profileCvarsGet ;				\
											setcvar ui_glCustom 1 ;					\
											setcvar ui_r_gamma 1.3 ;				\
											setcvar ui_sensitivity 5 ;				\
											setcvar ui_profile_mousePitch 0 ;		\
											setcvar ui_handedness 0 ;				\
											setcvar ui_rate 0 ;						\
											uiScript update ui_glCustom				\

// Opener //

menuDef {
	name		"profile_create_initial_opener"
	visible		0
	fullscreen	0
	rect		WINDOW_X WINDOW_Y WINDOW_WIDTH WINDOW_HEIGHT
	
	onOpen {
		INITIAL_PROFILEDEFAULT_SETTINGS ;

		open profile_create_initial ;
		close profile_create_initial_opener	;
		
		conditionalscript com_recommendedSet 0
			( "clearfocus" )
			( "abort" )

		conditionalscript com_recommended 3
			( "setcvar ui_glCustom 1 ; uiScript update ui_glCustom" )
			( "copycvar com_recommended ui_glCustom ; uiScript update ui_glCustom" ) "-1"
	}
}

menuDef {
	name		"profile_create_initial"
	visible		0
	fullscreen	0
	rect		WINDOW_X WINDOW_Y WINDOW_WIDTH WINDOW_HEIGHT
	style		WINDOW_STYLE_FILLED
	popup
	
	fadeClamp	0.5
	
	onOpen {
		setEditFocus "efleftProfile Name:" ;
	
		conditionalscript ui_profile_create_error 1 
			( "clearcvar ui_profile_create_error ; abort" )
			( "clearfocus" )

		setitemcolor background backcolor 0 0 0 0 ;
		fadein background ;
		setEditFocus "efleftProfile Name:" ;
//		DEFAULT_SETTINGS

		conditionalScript cl_punkbuster 0
			( "hide bttn_pbenable" )
			( "show bttn_pbenable" )

		/*conditionalscript com_recommendedSet 0
			( "clearfocus" )
			( "abort" )

		conditionalscript com_recommended 3
			( "setcvar ui_glCustom 1 ; uiScript update ui_glCustom" )
			( "copycvar com_recommended ui_glCustom ; uiScript update ui_glCustom" ) "-1"*/
	}
	
	/*onESC {
		close profile_create ;
		open profile ;
		uiScript systemCvarsReset ;
		uiScript profileCvarsReset
	}*/
	
// Background //

	/*itemDef {
		name		"background"
		rect		0 0 640 480
		style		WINDOW_STYLE_FILLED
		background	"ui/assets/fadebox.tga"
		backcolor	0 0 0 0
		visible		1
		decoration
	}*/

// Subwindows //

#define SUBWINDOW_WIDTH		350
#define SUBWINDOW_HEIGHT	362
#define SUBWINDOW_X			.5*(WINDOW_WIDTH-SUBWINDOW_WIDTH)
#define SUBWINDOW_Y			.5*(WINDOW_HEIGHT-SUBWINDOW_HEIGHT)

	SUBWINDOWBLACK( SUBWINDOW_X, SUBWINDOW_Y, SUBWINDOW_WIDTH, SUBWINDOW_HEIGHT, "CREATE PROFILE" )

	LABEL( SUBWINDOW_X+4, SUBWINDOW_Y+16, (SUBWINDOW_WIDTH)-8, 10, "Please choose your initial settings below. You can change these at any time and access more advanced options by visiting the Options Menu. Should more than one person wish to play Wolfenstein: Enemy Territory, you can create additional profiles by visiting the Profiles Menu.", .2, ITEM_ALIGN_LEFT, 0, 8 )

	itemDef {
		name		"efleftbackPlayer Alias:"
		group		GROUP_NAME
		rect		$evalfloat((SUBWINDOW_X+4+32)+80+6) $evalfloat(SUBWINDOW_Y+88) $evalfloat((SUBWINDOW_WIDTH)-8-64-80-6) $evalfloat(10)
		style		WINDOW_STYLE_FILLED
		backcolor	.5 .5 .5 .2
		visible		1
		decoration
	}
	EDITFIELDLEFT( SUBWINDOW_X+4+32, SUBWINDOW_Y+88, (SUBWINDOW_WIDTH)-8-64, 10, "Player Alias:", .2, 8, "ui_profile", 36, 23, "Enter the alias here that you would like displayed to others on servers" )

	MULTIACTION( SUBWINDOW_X+4, SUBWINDOW_Y+112, (SUBWINDOW_WIDTH)-8, 10, "Video Quality:", .2, 8, "ui_glCustom", cvarFloatList { "Fastest" 3 "Fast" 2 "Normal" 1 "High" 0 }, uiScript update "ui_glCustom", "Select your initial video settings, these can be changed later via the options menu" )
	MULTIACTION( SUBWINDOW_X+4, SUBWINDOW_Y+124, (SUBWINDOW_WIDTH)-8, 10, "Resolution:", .2, 8, "ui_r_mode", cvarFloatList { "640*480" 3 "800*600" 4 "960*720" 5 "1024*768" 6 "1152*864" 7 "1280*1024" 8 "1600*1200" 9 "2048*1536" 10 "856*480 Wide Screen" 11 }, uiScript glCustom, "Choose your preferred video resolution - if you're unsure what this means, leave it as the default" )
	SLIDER( SUBWINDOW_X+4, SUBWINDOW_Y+136, (SUBWINDOW_WIDTH)-8, 10, "Brightness:", .2, 8, "ui_r_gamma" 1 0.5 2, "Set the brightness of the game" )
	CVARFLOATLABEL( SUBWINDOW_X+4, SUBWINDOW_Y+136, (SUBWINDOW_WIDTH)-8, 10, "ui_r_gamma", .2, ITEM_ALIGN_RIGHT, $evalfloat((SUBWINDOW_WIDTH)-8), 8 )

	MULTIACTION( SUBWINDOW_X+4, SUBWINDOW_Y+160, (SUBWINDOW_WIDTH)-8, 10, "Connection:", .2, 8, "ui_rate", cvarFloatList { "Modem" 4000 "ISDN" 5000 "LAN/CABLE/xDSL" 25000 } cvarListUndefined "Unselected", uiScript update "ui_setRate", "Select your connection type, if unsure select Modem" )

	SLIDER( SUBWINDOW_X+4, SUBWINDOW_Y+184, (SUBWINDOW_WIDTH)-8, 10, "Mouse Sensitivity:", .2, 8, "ui_sensitivity" 5 1 30, "Use this slider to set your mouse sensitivity" )
	CVARFLOATLABEL( SUBWINDOW_X+4, SUBWINDOW_Y+184, (SUBWINDOW_WIDTH)-8, 10, "ui_sensitivity", .2, ITEM_ALIGN_RIGHT, $evalfloat((SUBWINDOW_WIDTH)-8), 8 )
	YESNO( SUBWINDOW_X+4, SUBWINDOW_Y+196, (SUBWINDOW_WIDTH)-8, 10, "Invert Mouse:", .2, 8, "ui_profile_mousePitch", "Choose invert mouse if you prefer flight-simulator style mouse pitch controls" )

	MULTI( SUBWINDOW_X+4, SUBWINDOW_Y+220, (SUBWINDOW_WIDTH)-8, 10, "Handedness:", .2, 8, "ui_handedness", cvarFloatList { "Right" 0 "Left" 1 }, "Left or Right Handed? This sets your default controls\nwhich you can modify later via the options menu" )
	
	BUTTON( (SUBWINDOW_X+4)+.5*((SUBWINDOW_WIDTH)-164), SUBWINDOW_Y+234, 164, 14, "DEFAULT SETTINGS", .24, 11, DEFAULT_SETTINGS ;
																												conditionalscript com_recommendedSet 0
																													( "clearfocus" )
																													( "abort" )

																												conditionalscript com_recommended 3
																													( "setcvar ui_glCustom 1 ; uiScript update ui_glCustom" )
																													( "copycvar com_recommended ui_glCustom ; uiScript update ui_glCustom" ) "-1" )
	
	LABEL( SUBWINDOW_X+4, SUBWINDOW_Y+264, (SUBWINDOW_WIDTH)-8-4, 10, "PunkBuster is a powerful cheat protection technology that prevents dishonest players from gaining an unfair advantage. Many games servers will not allow you to join unless PunkBuster is enabled.", .2, ITEM_ALIGN_LEFT, 0, 8 )
	NAMEDBUTTON( "bttn_pbenable", (SUBWINDOW_X+4)+.5*((SUBWINDOW_WIDTH)-164), SUBWINDOW_Y+312, 164, 14, "ENABLE PUNKBUSTER", .24, 11, clearFocus ; open playonline_enablepb )

	BUTTON( SUBWINDOW_X+6, SUBWINDOW_Y+SUBWINDOW_HEIGHT-24, .5*(SUBWINDOW_WIDTH-18), 18, "QUIT", .3, 14, close profile_create_initial ; close main ; open credits_quit )
	BUTTON( SUBWINDOW_X+6+.5*(SUBWINDOW_WIDTH-18)+6, SUBWINDOW_Y+SUBWINDOW_HEIGHT-24, .5*(SUBWINDOW_WIDTH-18), 18, "CREATE", .3, 14, conditionalscript UIProfileValidName 2
																																		( "clearFocus" )
																																		( "setcvar ui_profile_create_error \\\"Can't create profile. Please enter a valid player alias.\\\" ; open profile_create_error ; abort" )
																																	 conditionalscript ui_rate 0
																																		( "clearFocus" )
																																		( "setcvar ui_profile_create_error \\\"Can't create profile. Please select your connection type. If you are unsure what to select, choose Modem.\\\" ; open profile_create_error ; abort" )
																																	 conditionalscript UIProfileAlreadyExists 2
																																		( "setcvar ui_profile_create_error \\\"Can't create profile. A profile with the same name already exists.\\\" ; open profile_create_error ; abort" )
																																		( "clearFocus" )
																																		
																																	close profile_create_initial ;
																																	uiscript createProfile ;
																																	uiScript vidSave ;
																																	uiscript setDefaultProfile ;
																																	uiscript applyProfile ;
																																	execwolfconfig 1 ;
																																	uiscript systemCvarsApply ;
																																	uiscript profileCvarsApply ;
																																	setcvar ui_showtooltips 1 ;
																																	uiscript loadCachedServers ;
																																	exec vid_restart ; )
}
