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

// Defines //
#define WINDOW_X		16
#define WINDOW_Y		16
#define WINDOW_WIDTH	608
#define WINDOW_HEIGHT	448
#define GROUP_NAME		"grpOptionsSystem"

// Subwindows //
#define SUBWINDOW_WIDTH_L		.50*(WINDOW_WIDTH-18)
#define SUBWINDOW_WIDTH_R		.50*(WINDOW_WIDTH-18)

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
	}

	onESC {
		uiScript systemCvarsReset ;
		uiScript vidReset ;
		close options_system ;
		open options
	}

	WINDOW( _("SYSTEM"), 150 )

// Simple graphics //
#define GRAPHICS_Y 32
	SUBWINDOW( 6, GRAPHICS_Y, (SUBWINDOW_WIDTH_L), 160, _("GRAPHICS") )
#ifdef LEGACY
	COMBO( 8, GRAPHICS_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, _("Renderer:"), .2, 8, "cl_renderer", LEGACY_RENDERERS, exec vid_restart, _("Set your desired renderer (does a video restart)") )
	MULTIACTION( 8, GRAPHICS_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, _("Overall Quality:"), .2, 8, "ui_glCustom", cvarFloatList { "fastest" 3 "fast" 2 "normal" 1 "high" 0 }, uiScript update "ui_glCustom", _("Set overall video quality") )
	COMBO( 8, GRAPHICS_Y+40, (SUBWINDOW_WIDTH_L)-4, 10, _("Resolution:"), .2, 8, "ui_r_mode", LEGACY_RESOLUTIONS, uiScript glCustom, _("Set video resolution of the game") )
#else
	MULTI( 8, GRAPHICS_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, _("Renderer:"), .2, 8, "cl_renderer", cvarStrList { "Default"; "" }, _("Set your desired renderer (does a video restart)") )
	MULTIACTION( 8, GRAPHICS_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, _("Overall Quality:"), .2, 8, "ui_glCustom", cvarFloatList { "fastest" 3 "fast" 2 "normal" 1 "high" 0 }, uiScript update "ui_glCustom", _("Set overall video quality") )
	MULTI( 8, GRAPHICS_Y+40, (SUBWINDOW_WIDTH_L)-4, 10, _("Resolution:"), .2, 8, "ui_r_mode", VANILLA_RESOLUTIONS, _("Set video resolution of the game") )
#endif
	NUMERICFIELD( 8, GRAPHICS_Y+52, (SUBWINDOW_WIDTH_L)-4, 10, _("Custom Width:"), .2, 8, "r_customwidth", 5, _("Specifies custom resolution width (requires custom resolution set - *Use at your own risk*)") )
	NUMERICFIELD( 8, GRAPHICS_Y+64, (SUBWINDOW_WIDTH_L)-4, 10, _("Custom Height:"), .2, 8, "r_customheight", 5, _("Specifies custom resolution height (requires custom resolution set - *Use at your own risk*)") )
#ifdef LEGACY
	COMBO( 8, GRAPHICS_Y+76, (SUBWINDOW_WIDTH_L)-4, 10, _("Window mode:"), .2, 8, "ui_r_windowmode", LEGACY_WINDOWMODES, uiScript glCustom, _("Toggle fullscreen") )
#else
	MULTI( 8, GRAPHICS_Y+76, (SUBWINDOW_WIDTH_L)-4, 10, _("Window mode:"), .2, 8, "ui_r_windowmode", cvarStrList { "Default"; "" }, _("Toggle fullscreen") )
#endif
	CVARFLOATLABEL( 8, GRAPHICS_Y+88, (SUBWINDOW_WIDTH_L)-6, 10, "r_gamma", .2, ITEM_ALIGN_RIGHT, $evalfloat((SUBWINDOW_WIDTH_L)-6), 8 )
	SLIDER( 8, GRAPHICS_Y+88, (SUBWINDOW_WIDTH_L)-4, 10, _("Brightness:"), .2, 8, "r_gamma" 1.3 1 3, _("Set the brightness of the game") )
	MULTIACTION( 8, GRAPHICS_Y+100, (SUBWINDOW_WIDTH_L)-4, 10, _("Intensity:"), .2, 8, "ui_r_intensity", cvarFloatList { "1.0" 1.0 "1.1" 1.1 "1.2" 1.2 "1.3" 1.3 "1.4" 1.4 "1.5" 1.5 }, uiScript update "ui_glCustom", _("The intensity of textures (requires vid_restart)") )
	MULTIACTION( 8, GRAPHICS_Y+112, (SUBWINDOW_WIDTH_L)-4, 10, _("Map overbright bits:"), .2, 8, "ui_r_mapoverbrightbits", cvarFloatList { "0" 0 "1" 1 "2" 2 "3" 3 }, uiScript update "ui_glCustom", _("The world gets brighter, but paler (requires vid_restart)") )
	YESNOACTION( 8, GRAPHICS_Y+124, (SUBWINDOW_WIDTH_L)-4, 10, _("Overbright Bits:"), .2, 8, "ui_r_overBrightBits", uiScript update "ui_glCustom", _("Map shines brighter (requires vid_restart)") )
	MULTIACTION( 8, GRAPHICS_Y+136, (SUBWINDOW_WIDTH_L)-4, 10, _("Max. Frames Per Second:"), .2, 8, "com_maxfps", cvarFloatList { "Very Low (43 FPS)" 43 "Low (76 FPS)" 76 "Medium (85 FPS)" 85 "High (125 FPS)" 125 "Very High (250 FPS)" 250 }, uiScript update "ui_glCustom", _("Sets the frames per second limit for a stable render rate") )
	YESNOACTION( 8, GRAPHICS_Y+148, (SUBWINDOW_WIDTH_L)-4, 10, _("High Quality Video:"), .2, 8, "r_highQualityVideo", uiScript update "ui_glCustom", _("Sets high quality video") )

// Advanced graphics //
#define GRAPHICSADVANCED_Y 196
	SUBWINDOW( 6, GRAPHICSADVANCED_Y, (SUBWINDOW_WIDTH_L), 220, _("ADVANCED GRAPHICS") )
	YESNO( 8, GRAPHICSADVANCED_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, _("Low Quality Sky:"), .2, 8, "r_fastsky", _("Toggles wether the detailed skybox is drawn or just a basic sky") )
	// FIXME: fix cg_shadows >= 2
	MULTIACTION( 8, GRAPHICSADVANCED_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, _("Shadow Detail:"), .2, 8, "ui_cg_shadows", cvarFloatList { "None" 0 "Blob" 1 /*"Stencil shadows" 2 "Projection shadows" 3 "Polygon shadows" 4 */}, uiScript glCustom, _("Set shadow details") )
	MULTIACTION( 8, GRAPHICSADVANCED_Y+40, (SUBWINDOW_WIDTH_L)-4, 10, _("Texture Detail:"), .2, 8, "ui_r_picmip", cvarFloatList { "Low" 2 "Medium" 1 "High" 0 }, uiScript glCustom, _("Set texture details") )
	// add options 0 - disabled, 1 - single path, 2 - path
	YESNOACTION( 8, GRAPHICSADVANCED_Y+52, (SUBWINDOW_WIDTH_L)-4, 10, _("Dynamic Lights:"), .2, 8, "ui_r_dynamiclight", uiScript glCustom; uiScript update "r_dynamicLight", _("Toggles use of dynamic lighting effects") )
	// check this if ET supports same way
	MULTIACTION( 8, GRAPHICSADVANCED_Y+64, (SUBWINDOW_WIDTH_L)-4, 10, _("Geometric Detail:"), .2, 8, "ui_r_lodbias", cvarFloatList { "Low" 2 "Medium" 1 "High" 0 }, uiScript glCustom; uiScript update "r_lodbias", _("Set level of details bias") )
	MULTIACTION( 8, GRAPHICSADVANCED_Y+76, (SUBWINDOW_WIDTH_L)-4, 10, _("Texture Quality:"), .2, 8, "ui_r_texturebits", cvarFloatList { "Default" 0 "16-bit" 16 "32-bit" 32 }, uiScript glCustom, _("Set the number of bits for textures") )
	// "GL_NEAREST" "GL_LINEAR" "GL_NEAREST_MIPMAP_NEAREST" "GL_LINEAR_MIPMAP_NEAREST" "GL_NEAREST_MIPMAP_LINEAR" "GL_LINEAR_MIPMAP_LINEAR"
	MULTIACTION( 8, GRAPHICSADVANCED_Y+88, (SUBWINDOW_WIDTH_L)-4, 10, _("Texture Filter:"), .2, 8, "ui_r_texturemode", cvarStrList { "Bilinear"; "GL_LINEAR_MIPMAP_NEAREST"; "Trilinear"; "GL_LINEAR_MIPMAP_LINEAR" }, uiScript glCustom, _("Set the GL texture mode") )
	MULTIACTION( 8, GRAPHICSADVANCED_Y+100, (SUBWINDOW_WIDTH_L)-4, 10, _("Anisotropic Filter:"), .2, 8, "ui_r_ext_texture_filter_anisotropic", cvarFloatList { "Disabled" 0 "Medium" 4 "High" 8 }, uiScript glCustom, _("Set anisotropic filtering") )
	MULTIACTION( 8, GRAPHICSADVANCED_Y+112, (SUBWINDOW_WIDTH_L)-4, 10, _("Anti-Aliasing:"), .2, 8, "ui_r_ext_multisample", cvarFloatList { "Off" 0 "x2" 2 "x4" 4 }, uiScript glCustom, _("Set Anti-Aliasing") )
	MULTIACTION( 8, GRAPHICSADVANCED_Y+124, (SUBWINDOW_WIDTH_L)-4, 10, _("Color Depth:"), .2, 8, "ui_r_colorbits", cvarFloatList { "Desktop Default" 0 "16-bit" 16 "32-bit" 32 }, uiScript glCustom, _("Set color depth") )
	YESNOACTION( 8, GRAPHICSADVANCED_Y+136, (SUBWINDOW_WIDTH_L)-4, 10, _("Detail Textures:"), .2, 8, "ui_r_detailtextures", uiScript glCustom, _("Toogles usage of high detail textures") )
	MULTIACTION( 8, GRAPHICSADVANCED_Y+148, (SUBWINDOW_WIDTH_L)-4, 10, _("Depth Buffer:"), .2, 8, "ui_r_depthbits", cvarFloatList { "Default" 0 "16-bit" 16 "24-bit" 24 }, uiScript glCustom, _("Set the number of desired depth bits") )
	YESNOACTION( 8, GRAPHICSADVANCED_Y+160, (SUBWINDOW_WIDTH_L)-4, 10, _("Compress Textures:"), .2, 8, "ui_r_ext_compressed_textures", uiScript glCustom, _("Toggles the compression of textures") )
	YESNOACTION( 8, GRAPHICSADVANCED_Y+172, (SUBWINDOW_WIDTH_L)-4, 10, _("Sync Every Frame:"), .2, 8, "ui_r_finish", uiScript glCustom, _("Prevent screen tearing") )
	MULTIACTION( 8, GRAPHICSADVANCED_Y+184, (SUBWINDOW_WIDTH_L)-4, 10, _("GL Extensions:"), .2, 8, "ui_r_allowExtensions", cvarFloatList { "Enabled" 1 "Disabled" 0 }, uiScript glCustom, _("Enables or disables usage of OpenGL extensions"))

	BUTTON( 8+.5*((SUBWINDOW_WIDTH_L)-196), GRAPHICSADVANCED_Y+198, 196, 14, _("SET RECOMMENDED"), .24, 11, uiScript vidReset ; uiScript systemCvarsReset ; open rec_restart )

// LANGUAGE //
#define LANGUAGE_Y 32
	SUBWINDOW( 6+(SUBWINDOW_WIDTH_L)+6, LANGUAGE_Y, (SUBWINDOW_WIDTH_R), 28, _("LANGUAGE") )
	// TODO: use FEEDER_LANGUAGES to automatically show available localizations
	//MULTI( 6+(SUBWINDOW_WIDTH_L)+6+2, LANGUAGE_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, _("Language:"), .2, 8, "ui_cl_lang", LEGACY_LANGUAGES, _("Set your desired language") )
	COMBO( 6+(SUBWINDOW_WIDTH_L)+6+2, LANGUAGE_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, _("Language:"), .2, 8, "ui_cl_lang", LEGACY_LANGUAGES, none, _("Set your desired language") )

// SCREENSHOTS //
#define SCREENSHOTS_Y 64
	SUBWINDOW( 6+(SUBWINDOW_WIDTH_L)+6, SCREENSHOTS_Y, (SUBWINDOW_WIDTH_R), 42, _("SCREENSHOTS") )
	MULTI( 6+(SUBWINDOW_WIDTH_L)+6+2, SCREENSHOTS_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, _("Format:"), .2, 8, "r_screenshotFormat", cvarFloatList { "TGA (lossless)" 0 "JPEG (lossy)" 1 "PNG (lossless)" 2 }, _("Set your preferred screenshot format") )
	CVARFLOATLABEL( 6+(SUBWINDOW_WIDTH_L)+6+2, SCREENSHOTS_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, "r_screenshotJpegQuality", .2, ITEM_ALIGN_RIGHT, $evalfloat((SUBWINDOW_WIDTH_L)-6), 8 )
	SLIDER( 6+(SUBWINDOW_WIDTH_L)+6+2, SCREENSHOTS_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, _("JPEG Quality:"), .2, 8, "r_screenshotJpegQuality" 90 50 100, _("Set the JPEG quality") )

// Audio //
#define AUDIO_Y 110
	SUBWINDOW( 6+(SUBWINDOW_WIDTH_L)+6, AUDIO_Y, (SUBWINDOW_WIDTH_R), 102, _("AUDIO") )
	CVARFLOATLABEL( 6+(SUBWINDOW_WIDTH_L)+6+2, AUDIO_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, "s_volume", .2, ITEM_ALIGN_RIGHT, $evalfloat((SUBWINDOW_WIDTH_L)-6), 8 )
	SLIDER( 6+(SUBWINDOW_WIDTH_L)+6+2, AUDIO_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, _("Effects Volume:"), .2, 8, "s_volume" .7 0 1, _("Set the effects volume") )
	CVARFLOATLABEL( 6+(SUBWINDOW_WIDTH_L)+6+2, AUDIO_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, "s_musicvolume", .2, ITEM_ALIGN_RIGHT, $evalfloat((SUBWINDOW_WIDTH_L)-6), 8 )
	SLIDER( 6+(SUBWINDOW_WIDTH_L)+6+2, AUDIO_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, _("Music Volume:"), .2, 8, "s_musicvolume" .25 0 1, _("Set the music volume") )
	MULTI( 6+(SUBWINDOW_WIDTH_L)+6+2, AUDIO_Y+40, (SUBWINDOW_WIDTH_L)-4, 10, _("Sound Quality:"), .2, 8, "ui_s_khz", cvarFloatList { "11 khz (low)" 11 "22 khz (high)" 22 "44 khz (ultra high)" 44 }, _("Set the sound quality") )
	YESNO( 6+(SUBWINDOW_WIDTH_L)+6+2, AUDIO_Y+52, (SUBWINDOW_WIDTH_L)-4, 10, _("Doppler FX:"), .2, 8, "s_doppler", _("Enables or disables the doppler effect") )
	YESNO( 6+(SUBWINDOW_WIDTH_L)+6+2, AUDIO_Y+64, (SUBWINDOW_WIDTH_L)-4, 10, _("Mute When Minimized:"), .2, 8, "s_muteWhenMinimized", _("Enables or disables sound when window is minimized") )
	YESNO( 6+(SUBWINDOW_WIDTH_L)+6+2, AUDIO_Y+76, (SUBWINDOW_WIDTH_L)-4, 10, _("Mute When Unfocused:"), .2, 8, "s_muteWhenUnfocused", _("Enables or disables sound when window is unfocused") )
	MULTIACTION( 6+(SUBWINDOW_WIDTH_L)+6+2, AUDIO_Y+88, (SUBWINDOW_WIDTH_L)-4, 10, _("System Sound Control:"), .2, 8, "ui_s_initsound", cvarFloatList { "SDL2" 1 "OpenAL" 2 }, uiScript update "ui_s_initsound", _("Set the system sound control") )

// Networking //
#define NETWORK_Y 216
	SUBWINDOW( 6+(SUBWINDOW_WIDTH_L)+6, NETWORK_Y, (SUBWINDOW_WIDTH_R), 42, _("NETWORK") )
	MULTIACTION( 6+(SUBWINDOW_WIDTH_L)+6+2, NETWORK_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, _("Max Packets:"), .2, 8, "ui_cl_maxpackets", cvarFloatList { "Very Low (15)" 15 "Low (30)" 30 "Medium (60)" 60 "High (100)" 100 "Very High (125)" 125 }, uiScript update "ui_cl_maxpackets", _("Cap for upstream data packet transmissions") )
	MULTIACTION( 6+(SUBWINDOW_WIDTH_L)+6+2, NETWORK_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, _("Packet Duplication:"), .2, 8, "ui_cl_packetdup", cvarFloatList { "No" 0 "x1" 1 "x2" 2 }, uiScript update "ui_cl_packetdup", _("Number of duplicates for every data packet sent upstream, minimized packetloss") )

// Downloads //
#define DOWNLOADS_Y 262
	SUBWINDOW( 6+(SUBWINDOW_WIDTH_L)+6, DOWNLOADS_Y, (SUBWINDOW_WIDTH_R), 42, _("DOWNLOADS") )
	MULTI( 6+(SUBWINDOW_WIDTH_L)+6+2, DOWNLOADS_Y+16, (SUBWINDOW_WIDTH_L)-4, 10, _("Get Missing Files:"), .2, 8, "cl_allowDownload", cvarFloatList { "Disabled" 0 "Enabled" 1 "Enabled & no sound" 2 }, _("Download missing files when available") )	
	YESNO( 6+(SUBWINDOW_WIDTH_L)+6+2, DOWNLOADS_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, _("Use HTTP/FTP Downloads:"), .2, 8, "cl_wwwDownload", _("Enables or disables http/ftp downloads") )

// IRC //
#define IRC_Y 308
	SUBWINDOW( 6+(SUBWINDOW_WIDTH_L)+6, IRC_Y, (SUBWINDOW_WIDTH_R), 102, _("IRC CLIENT") )
	MULTI( 6+(SUBWINDOW_WIDTH_L)+6+2, IRC_Y+16, (SUBWINDOW_WIDTH_R)-4, 10, _("Mode:"), .2, 8, "irc_mode", cvarFloatList { "Disabled" 0 "Direct connect" 1 "Override nickname" 2 "Mute channel" 4 "Direct + Override" 3 "Direct + Mute" 5 "Override + Mute" 6 "Direct + Over. + Mute" 7 }, _("Specifies IRC client behavior") )
	EDITFIELD( 6+(SUBWINDOW_WIDTH_L)+6+2, IRC_Y+28, (SUBWINDOW_WIDTH_L)-4, 10, _("Server:"), .2, 8, "irc_server", 25, 18, _("Name of IRC server") )
	EDITFIELD( 6+(SUBWINDOW_WIDTH_L)+6+2, IRC_Y+40, (SUBWINDOW_WIDTH_L)-4, 10, _("Channel #:"), .2, 8, "irc_channel", 25, 18, _("Name of IRC channel - no '#' required") )
	NUMERICFIELD( 6+(SUBWINDOW_WIDTH_L)+6+2, IRC_Y+52, (SUBWINDOW_WIDTH_L)-4, 10, _("Port:"), .2, 8, "irc_port", 5, _("Port of IRC server") )
	EDITFIELD( 6+(SUBWINDOW_WIDTH_L)+6+2, IRC_Y+64, (SUBWINDOW_WIDTH_L)-4, 10, _("Nickname:"), .2, 8, "irc_nickname", 25, 18, _("IRC nickame in channel") )
	NUMERICFIELD( 6+(SUBWINDOW_WIDTH_L)+6+2, IRC_Y+76, (SUBWINDOW_WIDTH_L)-4, 10, _("Kick rejoin time ms:"), .2, 8, "irc_kick_rejoin", 5, _("Auto rejoin time after kick") )
	NUMERICFIELD( 6+(SUBWINDOW_WIDTH_L)+6+2, IRC_Y+88, (SUBWINDOW_WIDTH_L)-4, 10, _("Reconnect time ms:"), .2, 8, "irc_reconnect_delay", 5, _("Reconnect time in ms") )

// 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 systemCvarsApply ; close options_system ; open options" ) )
}
