1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4 
5 This file is part of Quake III Arena source code.
6 
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11 
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 ===========================================================================
21 */
22 /*
23 =======================================================================
24 
25 RESET MENU
26 
27 =======================================================================
28 */
29 
30 #include "ui_local.h"
31 
32 
33 #define ART_FRAME					"menu/art/cut_frame"
34 
35 #define ID_NO		100
36 #define ID_YES		101
37 
38 typedef struct
39 {
40 	menuframework_s menu;
41 	menutext_s		no;
42 	menutext_s		yes;
43 	int				slashX;
44 } resetMenu_t;
45 
46 static resetMenu_t	s_reset;
47 
48 
49 /*
50 =================
51 Reset_MenuEvent
52 =================
53 */
Reset_MenuEvent(void * ptr,int event)54 void Reset_MenuEvent(void* ptr, int event) {
55 	if( event != QM_ACTIVATED ) {
56 		return;
57 	}
58 
59 	UI_PopMenu();
60 
61 	if( ((menucommon_s*)ptr)->id == ID_NO ) {
62 		return;
63 	}
64 
65 	// reset the game, pop the level menu and restart it so it updates
66 	UI_NewGame();
67 	trap_Cvar_SetValue( "ui_spSelection", 0 );
68 	UI_PopMenu();
69 	UI_SPLevelMenu();
70 }
71 
72 
73 /*
74 =================
75 Reset_MenuKey
76 =================
77 */
Reset_MenuKey(int key)78 static sfxHandle_t Reset_MenuKey( int key ) {
79 	switch ( key ) {
80 	case K_KP_LEFTARROW:
81 	case K_LEFTARROW:
82 	case K_KP_RIGHTARROW:
83 	case K_RIGHTARROW:
84 		key = K_TAB;
85 		break;
86 
87 	case 'n':
88 	case 'N':
89 		Reset_MenuEvent( &s_reset.no, QM_ACTIVATED );
90 		break;
91 
92 	case 'y':
93 	case 'Y':
94 		Reset_MenuEvent( &s_reset.yes, QM_ACTIVATED );
95 		break;
96 	}
97 
98 	return Menu_DefaultKey( &s_reset.menu, key );
99 }
100 
101 
102 /*
103 =================
104 Reset_MenuDraw
105 =================
106 */
Reset_MenuDraw(void)107 static void Reset_MenuDraw( void ) {
108 	UI_DrawNamedPic( 142, 118, 359, 256, ART_FRAME );
109 	UI_DrawProportionalString( 320, 194 + 10, "RESET GAME?", UI_CENTER|UI_INVERSE, color_red );
110 	UI_DrawProportionalString( s_reset.slashX, 265, "/", UI_LEFT|UI_INVERSE, color_red );
111 	Menu_Draw( &s_reset.menu );
112 
113 	UI_DrawProportionalString( SCREEN_WIDTH/2, 356 + PROP_HEIGHT * 0, "WARNING: This resets all of the", UI_CENTER|UI_SMALLFONT, color_yellow );
114 	UI_DrawProportionalString( SCREEN_WIDTH/2, 356 + PROP_HEIGHT * 1, "single player game variables.", UI_CENTER|UI_SMALLFONT, color_yellow );
115 	UI_DrawProportionalString( SCREEN_WIDTH/2, 356 + PROP_HEIGHT * 2, "Do this only if you want to", UI_CENTER|UI_SMALLFONT, color_yellow );
116 	UI_DrawProportionalString( SCREEN_WIDTH/2, 356 + PROP_HEIGHT * 3, "start over from the beginning.", UI_CENTER|UI_SMALLFONT, color_yellow );
117 }
118 
119 
120 /*
121 =================
122 Reset_Cache
123 =================
124 */
Reset_Cache(void)125 void Reset_Cache( void ) {
126 	trap_R_RegisterShaderNoMip( ART_FRAME );
127 }
128 
129 
130 /*
131 =================
132 UI_ResetMenu
133 =================
134 */
UI_ResetMenu(void)135 void UI_ResetMenu(void) {
136 	uiClientState_t	cstate;
137 	int	n1, n2, n3;
138 	int	l1, l2, l3;
139 
140 	// zero set all our globals
141 	memset( &s_reset, 0, sizeof(s_reset) );
142 
143 	Reset_Cache();
144 
145 	n1 = UI_ProportionalStringWidth( "YES/NO" );
146 	n2 = UI_ProportionalStringWidth( "YES" ) + PROP_GAP_WIDTH;
147 	n3 = UI_ProportionalStringWidth( "/" )  + PROP_GAP_WIDTH;
148 	l1 = 320 - ( n1 / 2 );
149 	l2 = l1 + n2;
150 	l3 = l2 + n3;
151 	s_reset.slashX = l2;
152 
153 	s_reset.menu.draw       = Reset_MenuDraw;
154 	s_reset.menu.key        = Reset_MenuKey;
155 	s_reset.menu.wrapAround = qtrue;
156 
157 	trap_GetClientState( &cstate );
158 
159 	if ( cstate.connState >= CA_CONNECTED ) {
160 		// float on top of running game
161 		s_reset.menu.fullscreen = qfalse;
162 	}
163 	else {
164 		// game not running
165 		s_reset.menu.fullscreen = qtrue;
166 	}
167 
168 	s_reset.yes.generic.type		= MTYPE_PTEXT;
169 	s_reset.yes.generic.flags		= QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
170 	s_reset.yes.generic.callback	= Reset_MenuEvent;
171 	s_reset.yes.generic.id			= ID_YES;
172 	s_reset.yes.generic.x			= l1;
173 	s_reset.yes.generic.y			= 264;
174 	s_reset.yes.string				= "YES";
175 	s_reset.yes.color				= color_red;
176 	s_reset.yes.style				= UI_LEFT;
177 
178 	s_reset.no.generic.type			= MTYPE_PTEXT;
179 	s_reset.no.generic.flags		= QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
180 	s_reset.no.generic.callback		= Reset_MenuEvent;
181 	s_reset.no.generic.id			= ID_NO;
182 	s_reset.no.generic.x		    = l3;
183 	s_reset.no.generic.y		    = 264;
184 	s_reset.no.string				= "NO";
185 	s_reset.no.color			    = color_red;
186 	s_reset.no.style			    = UI_LEFT;
187 
188 	Menu_AddItem( &s_reset.menu,	&s_reset.yes );
189 	Menu_AddItem( &s_reset.menu,	&s_reset.no );
190 
191 	UI_PushMenu( &s_reset.menu );
192 
193 	Menu_SetCursorToItem( &s_reset.menu, &s_reset.no );
194 }
195