/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#include "ui_local.h"

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

QUIT MENU

=======================================================================
*/
static menuframework_s	s_quit_menu;

void YesFunc( void *unused )
{
	trap_CL_SetKeyDest ( key_console );
	trap_CL_Quit();
}

void M_QuitInit( void )
{
	int y = 0;
	int yoffset = 0;
	menucommon_t *menuitem;

	s_quit_menu.x = uis.vidWidth / 2;
	s_quit_menu.nitems = 0;

	menuitem = UI_InitMenuItem( "m_quit_sure" ,"Are you sure?", 0, y+yoffset, MTYPE_SEPARATOR, ALIGN_CENTER_TOP, uis.fontSystemBig, NULL );
	Menu_AddItem( &s_quit_menu, menuitem );
	yoffset+=2*trap_SCR_strHeight( menuitem->font );

	menuitem = UI_InitMenuItem( "m_quit_yes", "YES", 16, y+yoffset, MTYPE_ACTION, ALIGN_LEFT_TOP, uis.fontSystemBig, YesFunc );
	Menu_AddItem( &s_quit_menu, menuitem );

	menuitem = UI_InitMenuItem( "m_quit_back", "NO", -16, y+yoffset, MTYPE_ACTION, ALIGN_RIGHT_TOP, uis.fontSystemBig, M_genericBackFunc );
	Menu_AddItem( &s_quit_menu, menuitem );
	yoffset+=trap_SCR_strHeight( menuitem->font );

	Menu_Center( &s_quit_menu );

	Menu_Init( &s_quit_menu );
}

void M_Quit_Draw( void )
{
	Menu_AdjustCursor( &s_quit_menu, 1 );
	Menu_Draw( &s_quit_menu );
}

const char *M_Quit_Key( int key )
{
	return Default_MenuKey( &s_quit_menu, key );
}

const char *M_Quit_CharEvent( int key )
{
	switch (key)
	{
	case 'n':
	case 'N':
		M_PopMenu ();
		return NULL;

	case 'Y':
	case 'y':
		trap_CL_SetKeyDest( key_console );
		trap_CL_Quit();
		return NULL;

	default:
		break;
	}

	return Default_MenuCharEvent( &s_quit_menu, key );
}

void M_Menu_Quit_f( void )
{
	M_QuitInit();
	M_PushMenu( &s_quit_menu, M_Quit_Draw, M_Quit_Key, M_Quit_CharEvent );
}

