#include "ui/menudef.h"

// Defines //

//#define WINDOW_X		32
//#define WINDOW_Y		32
//#define WINDOW_WIDTH	576
//#define WINDOW_HEIGHT	416
#define WINDOW_X		16
#define WINDOW_Y		16
#define WINDOW_WIDTH	400
#define WINDOW_HEIGHT	374
#define GROUP_NAME		"grpOptionsSystem"

// Macros //

#include "ui/menumacros.h"
		
// System Menu //
	
menuDef {
	name		"options_system"
	visible		0
	fullscreen	0
	rect		WINDOW_X WINDOW_Y WINDOW_WIDTH WINDOW_HEIGHT
	style		WINDOW_STYLE_FILLED
	
	onOpen
	{
		uiScript systemCvarsGet ;
		uiScript vidSave ;
		uiScript glCustom	// really should find something better here
	}
	
	onESC {
		uiScript systemCvarsReset ;
		uiScript vidReset ;
		close options_system ;
		open options
	}

// Window //

	WINDOW( "SYSTEM", 90 )
	
// Subwindows //

//#define SUBWINDOW_WIDTH		.5*(WINDOW_WIDTH-18)
#define SUBWINDOW_WIDTH		WINDOW_WIDTH-12
	
// Audio //

	SUBWINDOW( 6, 32, (SUBWINDOW_WIDTH), 52, "AUDIO" )
	SLIDER( 8, 48, (SUBWINDOW_WIDTH)-4, 10, "Effects Volume:", .2, 8, "s_volume" .7 0 1, "" )
	SLIDER( 8, 60, (SUBWINDOW_WIDTH)-4, 10, "Music Volume:", .2, 8, "s_musicvolume" .25 0 1, "" )
	MULTI( 8, 72, (SUBWINDOW_WIDTH)-4, 10, "Sound Quality:", .2, 8, "ui_s_khz", cvarFloatList { "11 khz (low)" 11 "22 khz (high)" 22 "44 khz (ultra high)" 44 }, "" )

// Video //

	//SUBWINDOW( 6, 90, (SUBWINDOW_WIDTH), 196, "VIDEO" )
	SUBWINDOW( 6, 90, (SUBWINDOW_WIDTH), 220, "VIDEO" )
	MULTIACTION( 8, 106, (SUBWINDOW_WIDTH)-4, 10, "Video Quality:", .2, 8, "ui_glCustom", cvarFloatList { "Fastest" 3 "Fast" 2 "Normal" 1 "High" 0 }, uiScript update "ui_glCustom", "" )
	MULTIACTION( 8, 118, (SUBWINDOW_WIDTH)-4, 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, "" )
	MULTIACTION( 8, 130, (SUBWINDOW_WIDTH)-4, 10, "Color Depth:", .2, 8, "ui_r_colorbits", cvarFloatList { "Desktop Default" 0 "16-bit" 16 "32-bit" 32 }, uiScript glCustom, "" )
	YESNOACTION( 8, 142, (SUBWINDOW_WIDTH)-4, 10, "Fullscreen:", .2, 8, "ui_r_fullscreen", uiScript glCustom, "" )
	MULTIACTION( 8, 154, (SUBWINDOW_WIDTH)-4, 10, "Geometric Detail:", .2, 8, "ui_r_lodbias", cvarFloatList { "Low" 2 "Medium" 1 "High" 0 }, uiScript glCustom ; uiScript update "r_lodbias", "" )
	MULTIACTION( 8, 166, (SUBWINDOW_WIDTH)-4, 10, "Texture Detail:", .2, 8, "ui_r_picmip", cvarFloatList { "Low" 2 "Medium" 1 "High" 0 }, uiScript glCustom, "" )
	MULTIACTION( 8, 178, (SUBWINDOW_WIDTH)-4, 10, "Texture Quality:", .2, 8, "ui_r_texturebits", cvarFloatList { "Default" 0 "16-bit" 16 "32-bit" 32 }, uiScript glCustom, "" )
	MULTIACTION( 8, 190, (SUBWINDOW_WIDTH)-4, 10, "Texture Filter:", .2, 8, "ui_r_texturemode", cvarStrList { "Bilinear"; "GL_LINEAR_MIPMAP_NEAREST"; "Trilinear"; "GL_LINEAR_MIPMAP_LINEAR" }, uiScript glCustom, "" )
	YESNOACTION( 8, 202, (SUBWINDOW_WIDTH)-4, 10, "Detail Textures:", .2, 8, "ui_r_detailtextures", uiScript glCustom, "" )
	MULTIACTION( 8, 214, (SUBWINDOW_WIDTH)-4, 10, "Depth Buffer:", .2, 8, "ui_r_depthbits", cvarFloatList { "Default" 0 "16-bit" 16 "24-bit" 24 }, uiScript glCustom, "" )
	YESNOACTION( 8, 226, (SUBWINDOW_WIDTH)-4, 10, "Compress Textures:", .2, 8, "ui_r_ext_compressed_textures", uiScript glCustom, "" )
	YESNOACTION( 8, 238, (SUBWINDOW_WIDTH)-4, 10, "Sync Every Frame:", .2, 8, "ui_r_finish", uiScript glCustom, "" )
	MULTIACTION( 8, 250, (SUBWINDOW_WIDTH)-4, 10, "Dynamic Lights:", .2, 8, "ui_r_dynamiclight", cvarFloatList { "Disabled" 0 "Enabled (Single Pass)" 1 "Enabled (Multipass)" 2 }, uiScript glCustom, "" )
	MULTIACTION( 8, 262, (SUBWINDOW_WIDTH)-4, 10, "GL Extensions:", .2, 8, "ui_r_allowExtensions", cvarFloatList { "Enabled" 1 "Disabled" 0 }, uiScript glCustom , "")


	BUTTON( 8+.5*((SUBWINDOW_WIDTH)-196), 276, 196, 14, "CALIBRATE BRIGHTNESS", .24, 11, uiScript vidReset ;
																					uiScript systemCvarsReset ;
																					close options_system ;
																					open background_black ;
																					setmenuitemcolor background_black background backcolor 0 0 0 0 ;
																					fadeinmenu background_black ;
																					open options_system_gamma )
																					
	BUTTON( 8+.5*((SUBWINDOW_WIDTH)-196), 292, 196, 14, "SET RECOMMENDED", .24, 11, uiScript vidReset ;
																					uiScript systemCvarsReset ;
																					open rec_restart )

// Networking //

	SUBWINDOW( 6, 316, (SUBWINDOW_WIDTH), 28, "NETWORKING" )
	MULTIACTION( 8, 332, (SUBWINDOW_WIDTH)-4, 10, "Connection:", .2, 8, "ui_rate", cvarFloatList { "Modem" 4000 "ISDN" 5000 "LAN/CABLE/xDSL" 25000 } cvarListUndefined "Unselected", uiScript update "ui_setRate", "" )

// Buttons //
	
	BUTTON( 6, WINDOW_HEIGHT-24, .5*(WINDOW_WIDTH-18), 18, "BACK", .3, 14,
		uiScript vidReset ; close options_system ; open options )
	BUTTON( 6+.5*(WINDOW_WIDTH-18)+6, WINDOW_HEIGHT-24, .5*(WINDOW_WIDTH-18), 18, "APPLY", .3, 14,
		conditionalScript vidrestartIsRequired 2
		( "open vid_restart" )
		( "uiScript vidReset ; uiScript systemCvarsApply ; close options_system ; open options" ) )
}
