#include "ui/menudef.h"
#include "ui/controls_common.h"
#include "ui/tabs.h"

////////////////////////////////////
//
// CONSTANTS
//
//


#define OPTION_COLOR 0 0 .1 1
#define Tab_Color1 0 0 0 1
#define Tab_Color2 0 0 .5 1
#define VSPACE 16
#define VSIZE 16
#define ICON_ALPHA 0.5
#define LINE_ALPHA 0.2
#define FADEIN_TIME 125
#define HINT_COLOR .25 .25 .25
#define HINT_FADE_TIME 125
#define LINE_WIDTH			240


////////////////////////////////////
//
// MENU DEFINITION
//
//

{
    menuDef {
	name "system_menu"
	visible MENU_FALSE				// Visible on open
	//fullScreen MENU_FALSE
	focusColor RQ3_MAIN_FOCUSCOLOR			// Menu focus color for text and items
	rect 112 88 300 348
	anglevectors 4 -86
	style WINDOW_STYLE_EMPTY
	popup
	
	onOOBClick { close _self }
	onOpen { play "sound/ui/whoosh3.wav" ; uiScript initSystemSettings ;
		setitemcolor hints forecolor HINT_COLOR 1 ; hide hints ;
		ACTIVATE_TAB(1) ;
	}
	onClose { uiScript saveControls ; open _prev }
	onEsc { close _self }

	onOpenSpecial {
		//normal items
		setItemColor "fade_alpha" forecolor 5 5 5 0 ;
		timeFade "fade_alpha" forecolor 5 5 5 1 0 FADEIN_TIME ;

		//icon - special alpha
		setItemColor "icon" forecolor 5 5 5 0 ;
		timeFade "icon" forecolor 5 5 5 ICON_ALPHA 0 FADEIN_TIME ;

		//line - special alpha; using backcolor
		setItemColor "line" backcolor 5 5 5 0 ;
		timeFade "line" backcolor 5 5 5 LINE_ALPHA 0 FADEIN_TIME ;
	}



	itemDef {
	renderpoint
	name "paper,fade_alpha"
	style WINDOW_STYLE_SHADER
	background UI_ASSETS"/paper_1"
	forecolor MENUCOLOR_SYSTEM 1
	rect 0 -20 320 420
	anglevectors 4 -86
	visible 1
	menuAnchor
	decoration
    }

	itemdef {
	renderpoint
	name "title,fade_alpha"
	text "System:"
	forecolor .6 .0 .0 1
	style WINDOW_STYLE_EMPTY
	textalign ITEM_ALIGN_LEFT
	textalignx 4
	textaligny 24
	textscale RQ3_MAIN_TEXTSIZE
	alignrect paper ITEM_ALIGN_LEFT 32 40 240 36 
	visible 1
	autowrapped
	decoration
    }

	//Line

    itemDef {
	name "line,fade_alpha"
	style WINDOW_STYLE_FILLED
	backcolor .25 .25 .25 LINE_ALPHA
	alignrect "title" ITEM_ALIGN_LEFT 0 48 LINE_WIDTH 2
	visible 1
	decoration
	}

    ///////////////////////////////////////////////////////////
    //
    // Sub-options
    //
    //

	// Graphics

	ADD_TAB(
		"^_G^_raphics.",
		"G", 1, "group2,group3,group4",
		alignrect "title" ITEM_ALIGN_LEFT 2 28 52 16
	)
	ADD_HINT("hint_tab1", "Change rendering options", "group2,group3,group4")

//---------------------------------------------------------

	// Driver info

	ADD_TAB(
		"^_D^_river info.",
		"D", 2, "group1,group3,group4",
		alignrect "tab1" ITEM_ALIGN_RIGHT -56 0 60 16
	)
    ADD_HINT("hint_tab2", "View OpenGL driver info", "group1,group3,group4")

//---------------------------------------------------------

	// Misc - Display/Sound/Net

	ADD_TAB(
		"^_M^_isc.",
		"M", 3, "group1,group2,group4",
		alignrect "tab2" ITEM_ALIGN_RIGHT -30 0 32 16
	)
    ADD_HINT("hint_tab3", "Change display/sound/network options", "group1,group2,group4")

//---------------------------------------------------------

	// VoIP

	ADD_TAB(
		"^_V^_oIP.",
		"V", 4, ",group1,group2,group3",
		alignrect "tab3" ITEM_ALIGN_RIGHT -28 0 32 16
	)
    ADD_HINT("hint_tab4", "Change VoIP settings", "group1,group2,group3")




/*
==========================================================

Group # 1 - Graphics

==========================================================
*/

	//Icon

	ADD_TITLE_ICON(UI_ASSETS"/icons/rq3-system-graphics", "group1")

	// Pre-defined settings //

	BEGIN_OPTION("Quality", "ui_glCustom", ITEM_TYPE_MULTI, 1, 1)
		alignrect "line" ITEM_ALIGN_CENTER 56 32 112 VSIZE
		cvarFloatList {
			"Crappiest"		2
			"Crappy"		3
			"Normal"		1
			"High"			4
			"Highest"		5
			"Custom"		0
		}
		action { uiScript update "ui_glCustom" }
		ASSIGN_HINT("hint_predef")
	END_OPTION
	ADD_HINT("hint_predef", "Choose pre-defined graphics settings", "group1")


	// GL Driver //
	// ioq3 doesn't recognize this cvar
	/*
	BEGIN_OPTION("GL Driver", "r_glDriver", ITEM_TYPE_EDITFIELD, 2, 1)
		OPTION_BELOW("gr1_ctrl1")		
		ASSIGN_HINT("hint_gldriver")
	END_OPTION
	ADD_HINT("hint_gldriver", "Choose OpenGL driver (default: opengl32)", "group1")
	*/

	// GL Extensions //
	// required for the new renderer
	/*
	BEGIN_OPTION("GL Extensions", "r_allowExtensions", ITEM_TYPE_YESNO, 2, 1)
		OPTION_BELOW("gr1_ctrl1")
		action { uiScript glCustom }
		ASSIGN_HINT("hint_glext")
	END_OPTION
	ADD_HINT("hint_glext", "Enable OpenGL extensions", "group1")
	*/

	// Resolution //

	BEGIN_SIMPLE_OPTION(2, 1)
		OPTION_BELOW("gr1_ctrl1")
		text "Resolution:"
		ownerDraw UI_RESOLUTION
		ASSIGN_HINT("hint_res")
	END_OPTION
	ADD_HINT("hint_res", "Choose rendering resolution", "group1")


	// Color depth //
	/*
	BEGIN_OPTION("Color Depth", "r_colorbits", ITEM_TYPE_MULTI, 3, 1)
		cvarFloatList { "Desktop Default" 0 "16-bit" 16 "32-bit" 32 }
		OPTION_BELOW("gr1_ctrl2")
		action { uiScript glCustom ; uiScript update "r_colorbits" }
		ASSIGN_HINT("hint_depth")
	END_OPTION
	ADD_HINT("hint_depth", "Choose rendering color depth", "group1")
	*/

	// Fullscreen //

	BEGIN_OPTION("Fullscreen", "ui_RQ3_fullscreen", ITEM_TYPE_YESNO, 3, 1)
		OPTION_BELOW("gr1_ctrl2")
		ASSIGN_HINT("hint_fullscreen")
	END_OPTION
	ADD_HINT("hint_fullscreen", "Render in full-screen or windowed mode", "group1")


	// Anti-Aliasing Mode //

	BEGIN_OPTION("Anti-Aliasing", "r_ext_framebuffer_multisample", ITEM_TYPE_MULTI, 4, 1)
		cvarFloatList {
			"Off"		0
			"2x MSAA"	2
			"4x MSAA"	4
		}
		OPTION_BELOW("gr1_ctrl3")
		action { uiScript glCustom ; }
		ASSIGN_HINT("hint_aa")
	END_OPTION
    ADD_HINT("hint_aa", "Use anti-aliasing to reduce jaggedness", "group1")


    // Texture filtering mode //

	BEGIN_OPTION("Filtering Mode", "ui_filteringMode", ITEM_TYPE_MULTI, 5, 1)
		cvarFloatList {
			"Bilinear"				0
			"Trilinear"				1
			"2x Anisotropic"		2
			"4x Anisotropic"		3
			"8x Anisotropic"		4
			"16x Anisotropic"		5
		}
		OPTION_BELOW("gr1_ctrl4")
		action { uiScript glCustom ; uiScript update "ui_filteringMode" }
		ASSIGN_HINT("hint_texfilter")
    END_OPTION
    ADD_HINT("hint_texfilter", "Choose texture filtering mode", "group1")


    // Per-pixel lighting //

	BEGIN_OPTION("Per-pixel Lighting", "ui_shaderLevel", ITEM_TYPE_YESNO, 6, 1)
		OPTION_BELOW("gr1_ctrl5")
		action { uiScript glCustom ; uiScript update "ui_shaderLevel" }
		ASSIGN_HINT("hint_shader")
    END_OPTION
    ADD_HINT("hint_shader", "Enable normal mapping and specular reflectivity", "group1")


    // Cascaded Shadow Maps //

	BEGIN_OPTION("Cascaded Shadow Maps", "ui_shadowMaps", ITEM_TYPE_MULTI, 7, 1)
		cvarFloatList {
			"Off"					0
			"Low"					1
			"Medium"				2
			"High"					3
		}
		OPTION_BELOW("gr1_ctrl6")
		action { uiScript glCustom ; uiScript update "ui_shadowMaps" }
		ASSIGN_HINT("hint_csm")
    END_OPTION
    ADD_HINT("hint_csm", "Enable sunlight and cascaded shadow maps", "group1")


	// Lightmap/vertex //

	/*
	BEGIN_OPTION("Lighting", "r_vertexlight", ITEM_TYPE_MULTI, 9, 1)
		cvarFloatList { "Light Map (high)" 0 "Vertex (low)" 1  }
		OPTION_BELOW("gr1_ctrl8")
		action { uiScript glCustom ; }
		ASSIGN_HINT("hint_lightmap")
	END_OPTION
	ADD_HINT("hint_lightmap", "Choose map light rendering mode", "group1")
	*/


	// Geometric detail //

	BEGIN_OPTION("Geometric Detail", "r_lodbias", ITEM_TYPE_MULTI, 8, 1)
		cvarFloatList {
			"Low"		2
			"Medium"	1
			"High"		0
		}
		OPTION_BELOW("gr1_ctrl7")
		action { uiScript glCustom ; uiScript update "r_lodbias" }
		ASSIGN_HINT("hint_geodetail")
	END_OPTION
	ADD_HINT("hint_geodetail", "Choose geometric detail level", "group1")


	// Texture detail //

	BEGIN_OPTION("Texture Detail", "r_picmip", ITEM_TYPE_MULTI, 9, 1)
		cvarFloatList {
			"Very Low"	3
			"Low"		2
			"Medium"	1
			"High"		0
		}
		OPTION_BELOW("gr1_ctrl8")
		action { uiScript glCustom ; }
		ASSIGN_HINT("hint_texdetail")
	END_OPTION
	ADD_HINT("hint_texdetail", "Choose texture detail level", "group1")


	// Texture quality //
	/*
	BEGIN_OPTION("Texture Quality", "r_texturebits", ITEM_TYPE_MULTI, 8, 1)
		cvarFloatList {
			"Default"	0
			"16 bit"	16
			"32 bit"	32
		}
		OPTION_BELOW("gr1_ctrl7")
		action { uiScript glCustom ; }
		ASSIGN_HINT("hint_texquality")
	END_OPTION
	ADD_HINT("hint_texquality", "Choose texture quality", "group1")
	*/

	// Compressed textures //

	BEGIN_OPTION("Compress Textures", "r_ext_compressed_textures", ITEM_TYPE_YESNO, 10, 1)
		OPTION_BELOW("gr1_ctrl9")
		action { uiScript glCustom ; }
		ASSIGN_HINT("hint_compress")
	END_OPTION
	ADD_HINT("hint_compress", "Enable texture compression", "group1")


	// APPLY //

	itemdef {
	name "btn_apply,fade_alpha,allgroups,group1"
	style WINDOW_STYLE_EMPTY
	alignrect "gr1_ctrl10" ITEM_ALIGN_RIGHT 0 24 80 VSIZE
	type ITEM_TYPE_BUTTON
	text "^_A^_pply >"
	shortcutKey "A"
	textscale .225
	textstyle ITEM_TEXTSTYLE_NORMAL
	textalign ITEM_ALIGN_RIGHT
	textalignx 64
	textaligny 14
	forecolor 0 0 0 1
	action { uiScript applysystemSettings ; }
	ASSIGN_HINT("hint_apply")
	anglevectors 4 -83
	visible 1
	}

	ADD_HINT("hint_apply", "Apply graphics changes and return to main menu", "group1")

/*
==========================================================

Group # 2 - Driver info

==========================================================
*/

    //Icon

	ADD_TITLE_ICON(UI_ASSETS"/icons/rq3-system-driverinfo", "group2")

    // DRIVER INFO //

    itemdef {
	name "allgroups,group2,fade_alpha,driver_info"
	ownerdraw UI_GLINFO
	alignrect "line" ITEM_ALIGN_LEFT 0 24 220 64
	style WINDOW_STYLE_EMPTY
	textalign ITEM_ALIGN_LEFT
	textalignx 8
	textaligny 12
	textscale .15
	forecolor OPTION_COLOR
	visible 0
	decoration
    }

    itemdef {
	name "allgroups,group2,gr2_ctrl1,fade_alpha,extension_list"
	type ITEM_TYPE_LISTBOX
	alignRect driver_info ITEM_ALIGN_LEFT 0 64 232 140
	forcetextcolor
	LISTBOX_STYLE(.175, 4)
	feeder FEEDER_GLDRIVER_INFO
	columns 1 4 200 0
	visible 1
	onFocus { show list_hint ; timeFade list_hint forecolor .9 .9 .9 1 0 250 }
	leaveFocus { timeFade list_hint forecolor .9 .9 .9 0 0 250 }
    }

	itemdef {
	name "allgroups,group2,fade_alpha,col1_title"
	text "Supported OpenGL Extensions:"
	forecolor .25 .25 .25 1
	style WINDOW_STYLE_EMPTY
	textalign ITEM_ALIGN_LEFT
	textscale .175
	textalignx 4
	textaligny 14
	alignRect extension_list ITEM_ALIGN_LEFT 4 -16 80 16
	visible 1
	decoration
    }

/*
==========================================================

Group # 3 - Misc

==========================================================
*/

	//Icon

	ADD_TITLE_ICON(UI_ASSETS"/icons/rq3-menu-setup", "group3")

	//Icon

	itemdef {
		name "icon,allgroups,group3"
		background UI_ASSETS"/icons/rq3-system-display"
		forecolor 1 1 1 ICON_ALPHA
		alignrect "line" ITEM_ALIGN_LEFT 0 36 24 24
		style WINDOW_STYLE_SHADER
		visible 1
		decoration
	}


    // Brightness //

	BEGIN_SLIDER("Brightness", "r_gamma", 1, .5, 1.7, 1, 3)
		alignrect "line" ITEM_ALIGN_CENTER 56 40 112 VSIZE
		ASSIGN_HINT("hint_gamma")
	END_OPTION
	ADD_HINT("hint_gamma", "Change image brightness", "group3")


	// Screen size //

	/*
	BEGIN_SLIDER("Screen Size", "cg_viewsize", 100, 30, 100, 2, 3)
		OPTION_BELOW("gr3_ctrl1")
		ASSIGN_HINT("hint_screensize")
	END_OPTION
	ADD_HINT("hint_screensize", "Change rendering window size", "group3")
	*/


	// Overbrightbits //

	BEGIN_OPTION("Overbright Bits", "r_overbrightbits", ITEM_TYPE_YESNO, 2, 3)
		OPTION_BELOW("gr3_ctrl1")
		ASSIGN_HINT("hint_overbits")
	END_OPTION
	ADD_HINT("hint_overbits", "Enable overbright bits (greater color range at the expense of precision)", "group3")


	// V-SYNC //

	BEGIN_OPTION("Sync Every Frame", "r_finish", ITEM_TYPE_YESNO, 3, 3)
		//kind YESNO_ICON_RIGHT
		OPTION_BELOW("gr3_ctrl2")
		ASSIGN_HINT("hint_vsync")
	END_OPTION
    ADD_HINT("hint_vsync", "Wait for vertical sync (recommended off)", "group3")


    // Sound //

    //Icon

    itemdef {
	name "icon,allgroups,group3"
	background UI_ASSETS"/icons/rq3-system-sound"
	forecolor 1 1 1 ICON_ALPHA
	alignrect "line" ITEM_ALIGN_LEFT 0 120 24 24
	style WINDOW_STYLE_SHADER
	visible 1
	decoration
	}


	// OpenAL //

	BEGIN_OPTION("OpenAL", "s_useOpenAL", ITEM_TYPE_YESNO, 5, 3)
		alignrect "line" ITEM_ALIGN_CENTER 56 120 112 VSIZE
		ASSIGN_HINT("hint_openal")
	END_OPTION
	ADD_HINT("hint_openal", "Enable OpenAL sound rendering", "group3")

	// Sound volume //

	BEGIN_SLIDER("Sound Volume", "s_volume", 0.7, 0, 1, 6, 3)
		OPTION_BELOW("gr3_ctrl5")
		ASSIGN_HINT("hint_sndvol")
	END_OPTION
	ADD_HINT("hint_sndvol", "Change sound effects volume", "group3")


	// Music volume //

	BEGIN_SLIDER("Music Volume", "s_musicvolume", 0.25, 0, 1, 7, 3)
		OPTION_BELOW("gr3_ctrl6")
		ASSIGN_HINT("hint_musicvol")
	END_OPTION
	ADD_HINT("hint_musicvol", "Change background music volume", "group3")


	// Sound quality //

	BEGIN_OPTION("Sound Quality", "s_khz", ITEM_TYPE_MULTI, 8, 3)
		cvarFloatList {
			"22 khz (high)"		22
			"11 khz (low)"		11
		}
		OPTION_BELOW("gr3_ctrl7")
		ASSIGN_HINT("hint_sndquality")
	END_OPTION
	ADD_HINT("hint_sndquality", "Choose sound quality", "group3")


	// Doppler effect //

	BEGIN_OPTION("Doppler Effect", "s_doppler", ITEM_TYPE_YESNO, 9, 3)
		OPTION_BELOW("gr3_ctrl8")
		ASSIGN_HINT("hint_doppler")
	END_OPTION
	ADD_HINT("hint_doppler", "Enable Doppler effect", "group3")


	// Net //

	//Icon

	itemdef {
	name "icon,allgroups,group3"
	background UI_ASSETS"/icons/rq3-system-network"
	forecolor 1 1 1 ICON_ALPHA
	alignrect "line" ITEM_ALIGN_LEFT 0 216 24 24
	style WINDOW_STYLE_SHADER
	visible 1
	decoration
	}


	// Net rate //

	BEGIN_OPTION("Net Rate", "rate", ITEM_TYPE_MULTI, 10, 3)
		alignrect "line" ITEM_ALIGN_CENTER 56 216 112 VSIZE
		cvarFloatList {
			"<=28.8k"			2500
			"33.6k"				3000
			"56k"				4000
			"ISDN"				5000
			"LAN/CABLE/xDSL"	25000
		}
		ASSIGN_HINT("hint_netrate")
	END_OPTION
	ADD_HINT("hint_netrate", "Choose network speed", "group3")


/*
==========================================================

Group # 4 - VoIP

==========================================================
*/

	// Hints
	__CONTROLS_HINTS__

	//Icon

	ADD_TITLE_ICON(UI_ASSETS"/icons/rq3-system-voip", "group4")

	BEGIN_OPTION("VoIP", "cl_voip", ITEM_TYPE_YESNO, 1, 4)
		alignrect "line" ITEM_ALIGN_CENTER 56 44 112 VSIZE
		ASSIGN_HINT("hint_voip")
	END_OPTION
	ADD_HINT("hint_voip", "Enable client-side VoIP support", "group4")

	BEGIN_OPTION("OpenAL Capture", "s_alCapture", ITEM_TYPE_YESNO, 2, 4)
		OPTION_BELOW("gr4_ctrl1")
		ASSIGN_HINT("hint_alcapture")
	END_OPTION
	ADD_HINT("hint_alcapture", "Disabling this means that you won't transmit, but you can still hear other people", "group4")

	BEGIN_OPTION("Voice Level Meter", "cl_voipShowMeter", ITEM_TYPE_YESNO, 3, 4)
		OPTION_BELOW("gr4_ctrl2")
		ASSIGN_HINT("hint_voipmeter")
	END_OPTION
	ADD_HINT("hint_voipmeter", "Enable a volume meter that shows how well the game can hear your voice", "group4")

	BEGIN_SLIDER("Gain", "cl_voipGainDuringCapture", 0.2, 0, 1, 4, 4)
		OPTION_BELOW("gr4_ctrl3")
		ASSIGN_HINT("hint_gain")
	END_OPTION
	ADD_HINT("hint_gain", "The volume of audio coming out of your speakers while you are recording sound for transmission.", "group4")

	BEGIN_OPTION("Transmit Mode", "cl_voipUseVAD", ITEM_TYPE_MULTI, 5, 4)
		OPTION_BELOW("gr4_ctrl4")
		cvarFloatList {
			"Push-to-talk"		0
			"Automatic"			1
		}
		ASSIGN_HINT("hint_usevad")
	END_OPTION
	ADD_HINT("hint_usevad", "Select between holding down a key (the default) and automatic transmitting", "group4")

	BEGIN_SLIDER("Threshold", "cl_voipVADThreshold", 0.25, 0, 1, 6, 4)
		OPTION_BELOW("gr4_ctrl5")
		ASSIGN_HINT("hint_thresh")
		cvarTest "cl_voipUseVAD"
		showCvar { "1" }
	END_OPTION
	ADD_HINT("hint_thresh", "Signifies the volume of recorded audio that the game considers to be speech", "group4")

	BEGIN_OPTION("Push-to-talk Key", "+voiprecord", ITEM_TYPE_BIND, 7, 4)
		OPTION_BELOW("gr4_ctrl5")
		ASSIGN_HINT("keyBindStatus")
		cvarTest "cl_voipUseVAD"
		showCvar { "0" }
	END_OPTION

}
}