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

// Defines //
#define WINDOW_X		0
#define WINDOW_Y		0
#define WINDOW_WIDTH	__WINDOW_WIDTH
#define WINDOW_HEIGHT	480
#define GROUP_NAME		"grpProfileCreate"

// Create Profile Menu //
#define DEFAULT_SETTINGS	setcvar ui_cl_lang en ;					\
                            setcvar ui_glCustom 1 ;					\
							setcvar ui_rate 25000 ;					\
							setcvar ui_sensitivity 5 ;				\
							setcvar ui_profile_mousePitch 0 ;		\
							setcvar ui_handedness 0 ;				\
							uiScript update "ui_glCustom"			\

menuDef {
	name		"profile_create"
	visible		0
	fullscreen	0
	rect		WINDOW_X WINDOW_Y WINDOW_WIDTH WINDOW_HEIGHT
	style		WINDOW_STYLE_FILLED
	popup

	fadeClamp	0.5
	fadeAmount  0.075

	onOpen {
		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:" ;
		uiScript systemCvarsGet ;
		setcvar ui_rate "0" ;
		clearcvar ui_profile ;
		uiScript profileCvarsGet ;
		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"
	}

	onESC {
		close profile_create ;
		open profile ;
		uiScript systemCvarsReset ;
		uiScript profileCvarsReset
	}

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

// Subwindows //
#define SUBWINDOW_WIDTH		354
#define SUBWINDOW_HEIGHT	294
#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 Enemy Territory: Legacy, 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") )

	// TODO: use FEEDER_LANGUAGES to automatically show available localizations
#ifdef LEGACY
	COMBO( SUBWINDOW_X+4, SUBWINDOW_Y+112, (SUBWINDOW_WIDTH)-8, 10, _("Language:"), .2, 8, "ui_cl_lang", LEGACY_LANGUAGES, none, _("Set your desired language") )
#else
	MULTI( SUBWINDOW_X+4, SUBWINDOW_Y+112, (SUBWINDOW_WIDTH)-8, 10, _("Language:"), .2, 8, "ui_cl_lang", LEGACY_LANGUAGES, _("Set your desired language") )
#endif
	MULTIACTION( SUBWINDOW_X+4, SUBWINDOW_Y+136, (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") )

#ifdef LEGACY
	COMBO( SUBWINDOW_X+4, SUBWINDOW_Y+150, (SUBWINDOW_WIDTH)-8, 10, _("Resolution:"), .2, 8, "ui_r_mode", LEGACY_RESOLUTIONS, uiScript glCustom, _("Choose your preferred video resolution, if unsure leave it as the default") )
	COMBO( SUBWINDOW_X+4, SUBWINDOW_Y+164, (SUBWINDOW_WIDTH)-8, 10, _("Window mode:"), .2, 8, "ui_r_windowmode", LEGACY_WINDOWMODES, uiScript glCustom, _("Toggle fullscreen") )
#endif

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

	MULTI( SUBWINDOW_X+4, SUBWINDOW_Y+224, (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+238, 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" )

	BUTTON( SUBWINDOW_X+6, SUBWINDOW_Y+SUBWINDOW_HEIGHT-24, .5*(SUBWINDOW_WIDTH-18), 18, _("BACK"), .3, 14, close profile_create ; open profile )
	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 ;
			uiScript createProfile ;
			uiScript vidSave ;
			uiScript clearPID ;
			uiScript applyProfile ;
			execwolfconfig 1 ;
			uiScript systemCvarsApply ;
			uiScript profileCvarsApply ;
			setcvar ui_showtooltips 1 ;
			uiScript loadCachedServers ;
			exec vid_restart ; )
}
