#include "ui/menudef.h"
#include "ui_mp/main.inc"
#include "ui_mp/pc_options.inc"

#define MENU_NAME									"pc_options_audio"
#define MENU_TITLE									"@MENU_AUDIO"

#undef CHOICE_GROUP
#define CHOICE_GROUP								MENU_NAME

#define CLOSE_MENUS \
	close "controls_multi"; \
	close "main_controls"; \
	close "main_options"; \
	close "options_control_defaults"; \
	close "options_graphics"; \
	close "options_graphics_defaults"; \
	close "options_graphics_texture"; \
	close "options_multi"; \
	close "options_voice"; \
	close "pc_options_advanced_video"; \
	close "pc_options_controls"; \
	close "pc_options_game"; \
	close "pc_options_movement"; \
	close "pc_options_multi"; \
	close "pc_options_video"; \
	close "pc_options_voice";

#define ON_MENU_OPEN \
	CLOSE_MENUS										\
	setLocalVarString								ui_hint_text "@NULL_EMPTY"; \
	if (!localvarint("ui_showAudioApply")) \
	{ \
		exec										"setfromdvar ui_snd_khz snd_khz"; \
		exec										"setfromdvar ui_snd_enableEq snd_enableEq"; \
		exec										"setfromdvar ui_outputConfig snd_outputConfiguration"; \
	} \
	execnow											"profile_menuDvarsSetup; resetViewport"; \
	setFocus										"buttonAudio";

#define ON_MENU_ESC \
	close self; \
	if (!(menuisopen("pc_options_advanced_video") || menuisopen("pc_options_video") || menuisopen("pc_options_Audio") || menuisopen("pc_options_controls") || menuisopen("pc_options_voice") ) && localvarbool("ui_showPicApply") && !localvarbool("ui_showApply") && !localvarbool("ui_showAudioApply")) \
	{ \
		execnow										"setfromdvar r_picmip ui_r_picmip"; \
		execnow										"setfromdvar r_picmip_bump ui_r_picmip_bump"; \
		execnow										"setfromdvar r_picmip_spec ui_r_picmip_spec"; \
		execnow										"setfromdvar r_picmip_manual ui_r_picmip_manual"; \
		exec										"wait; wait; r_applyPicmip"; \
		setLocalVarBool								"ui_showPicApply" (0); \
	} \
	if (!(menuisopen("pc_options_advanced_video") || menuisopen("pc_options_video") || menuisopen("pc_options_Audio") || menuisopen("pc_options_controls") || menuisopen("pc_options_voice") ) && localvarbool("ui_showApply") || localvarbool("ui_showAudioApply")) \
	{ \
		open "all_restart_popmenu"; \
	} \
	execnow											"profile_menuDvarsFinish; resetViewport"; \
	setLocalVarString								ui_hint_text "@NULL_EMPTY";

menuDef
{
	name											MENU_NAME
	rect											0 0 640 480
	foreColor										CHOICE_TEXTCOLOR
	focusColor										CHOICE_TEXTCOLOR
	blurWorld										7

	MENU_ON_OPEN(ON_MENU_OPEN)
	MENU_ON_ESC(ON_MENU_ESC)

	#define BACKGROUND_PC_OPTIONS
	#define BACKGROUND_IW4
	#define SIDEBAR_RIGHT
	#include "ui_mp/bg.inc"

	#include "ui_mp/leftside_options.inc"

	PC_OPTIONS_SECTION_TITLE(MENU_TITLE)

	PC_OPTIONS_DVARSLIDER_RAW(0, "@MENU_MASTER_VOLUME", "snd_volume", 0, 1, 0, ;, ;, ;, when(0), 1, 1)
	PC_OPTIONS_STRLIST_RAW(1, "@MENU_SPEAKER_CONFIG", "ui_outputConfig", {"@MENU_WINDOWS_DEFAULT"; "Windows default"; "@MENU_MONO"; "Mono"; "@MENU_STEREO"; "Stereo"; "@MENU_FOUR_SPEAKERS"; "4 speakers"; "@MENU_FIVE_ONE_SPEAKERS"; "5.1 speakers"}, setLocalVarBool "ui_showAudioApply" (1);, ;, when((dvarBool("cl_ingame") || dvarBool("sv_running") || inlobby())), 1)
}
