Debian Codegraph @

code/q3_ui/ui_menu.c

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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
26 MAIN MENU
27
28 =======================================================================
29 */
30
31
32 #include "ui_local.h"
33
34
35 #define ID_SINGLEPLAYER 10
36 #define ID_MULTIPLAYER 11
37 #define ID_SETUP 12
38 #define ID_DEMOS 13
39 //#define ID_CINEMATICS 14
40 #define ID_CHALLENGES 14
41 #define ID_TEAMARENA 15
42 #define ID_MODS 16
43 #define ID_EXIT 17
44
45 #define MAIN_BANNER_MODEL "models/mapobjects/banner/banner5.md3"
46 #define MAIN_MENU_VERTICAL_SPACING 34
47
48
49 typedef struct {
50 menuframework_s menu;
51
52 menutext_s singleplayer;
53 menutext_s multiplayer;
54 menutext_s setup;
55 menutext_s demos;
56 //menutext_s cinematics;
57 menutext_s challenges;
58 menutext_s teamArena;
59 menutext_s mods;
60 menutext_s exit;
61
62 qhandle_t bannerModel;
63 } mainmenu_t;
64
65
66 static mainmenu_t s_main;
67
68 typedef struct {
69 menuframework_s menu;
70 char errorMessage[4096];
71 } errorMessage_t;
72
73 static errorMessage_t s_errorMessage;
74
75 /*
76 =================
77 MainMenu_ExitAction
78 =================
79 */
80 /*static void MainMenu_ExitAction( qboolean result ) {
81 if( !result ) {
82 return;
83 }
84 UI_PopMenu();
85 //UI_CreditMenu();
86 trap_Cmd_ExecuteText( EXEC_APPEND, "quit\n" );
87 }*/
88
89
90
91 /*
92 =================
93 Main_MenuEvent
94 =================
95 */
96 void Main_MenuEvent (void* ptr, int event) {
97 if( event != QM_ACTIVATED ) {
98 return;
99 }
100
101 switch( ((menucommon_s*)ptr)->id ) {
102 case ID_SINGLEPLAYER:
103 UI_SPLevelMenu();
104 break;
105
106 case ID_MULTIPLAYER:
107 if(ui_setupchecked.integer)
108 UI_ArenaServersMenu();
109 else
110 UI_FirstConnectMenu();
111 break;
112
113 case ID_SETUP:
114 UI_SetupMenu();
115 break;
116
117 case ID_DEMOS:
118 UI_DemosMenu();
119 break;
120
121 /*case ID_CINEMATICS:
122 UI_CinematicsMenu();
123 break;*/
124
125 case ID_CHALLENGES:
126 UI_Challenges();
127 break;
128
129 case ID_MODS:
130 UI_ModsMenu();
131 break;
132
133 case ID_TEAMARENA:
134 trap_Cvar_Set( "fs_game", "missionpack");
135 trap_Cmd_ExecuteText( EXEC_APPEND, "vid_restart;" );
136 break;
137
138 case ID_EXIT:
139 //UI_ConfirmMenu( "EXIT GAME?", 0, MainMenu_ExitAction );
140 UI_CreditMenu();
141 break;
142 }
143 }
144
145
146 /*
147 ===============
148 MainMenu_Cache
149 ===============
150 */
151 void MainMenu_Cache( void ) {
152 s_main.bannerModel = trap_R_RegisterModel( MAIN_BANNER_MODEL );
153 }
154
155 sfxHandle_t ErrorMessage_Key(int key)
156 {
157 trap_Cvar_Set( "com_errorMessage", "" );
158 UI_MainMenu();
159 return (menu_null_sound);
160 }
161
162 /*
163 ===============
164 Main_MenuDraw
165 TTimo: this function is common to the main menu and errorMessage menu
166 ===============
167 */
168
169 static void Main_MenuDraw( void ) {
170 refdef_t refdef;
171 refEntity_t ent;
172 vec3_t origin;
173 vec3_t angles;
174 float adjust;
175 float x, y, w, h;
176 vec4_t color = {0.2, 0.2, 1.0, 1};
177
178 // setup the refdef
179
180 memset( &refdef, 0, sizeof( refdef ) );
181
182 refdef.rdflags = RDF_NOWORLDMODEL;
183
184 AxisClear( refdef.viewaxis );
185
186 x = 0;
187 y = 0;
188 w = 640;
189 h = 120;
190 UI_AdjustFrom640( &x, &y, &w, &h );
191 refdef.x = x;
192 refdef.y = y;
193 refdef.width = w;
194 refdef.height = h;
195
196 adjust = 0; // JDC: Kenneth asked me to stop this 1.0 * sin( (float)uis.realtime / 1000 );
197 refdef.fov_x = 60 + adjust;
198 refdef.fov_y = 19.6875 + adjust;
199
200 refdef.time = uis.realtime;
201
202 origin[0] = 300;
203 origin[1] = 0;
204 origin[2] = -32;
205
206 trap_R_ClearScene();
207
208 // add the model
209
210 memset( &ent, 0, sizeof(ent) );
211
212 adjust = 5.0 * sin( (float)uis.realtime / 5000 );
213 VectorSet( angles, 0, 180 + adjust, 0 );
214 AnglesToAxis( angles, ent.axis );
215 ent.hModel = s_main.bannerModel;
216 VectorCopy( origin, ent.origin );
217 VectorCopy( origin, ent.lightingOrigin );
218 ent.renderfx = RF_LIGHTING_ORIGIN | RF_NOSHADOW;
219 VectorCopy( ent.origin, ent.oldorigin );
220
221 trap_R_AddRefEntityToScene( &ent );
222
223 trap_R_RenderScene( &refdef );
224
225 if (strlen(s_errorMessage.errorMessage))
226 {
227 UI_DrawProportionalString_AutoWrapped( 320, 192, 600, 20, s_errorMessage.errorMessage, UI_CENTER|UI_SMALLFONT|UI_DROPSHADOW, menu_text_color );
228 }
229 else
230 {
231 // standard menu drawing
232 Menu_Draw( &s_main.menu );
233 }
234
235 UI_DrawProportionalString( 320, 372, "", UI_CENTER|UI_SMALLFONT, color );
236 UI_DrawString( 320, 400, "OpenArena(c) 2005-2012 OpenArena Team", UI_CENTER|UI_SMALLFONT, color );
237 UI_DrawString( 320, 414, "OpenArena comes with ABSOLUTELY NO WARRANTY; this is free software", UI_CENTER|UI_SMALLFONT, color );
238 UI_DrawString( 320, 428, "and you are welcome to redistribute it under certain conditions;", UI_CENTER|UI_SMALLFONT, color );
239 UI_DrawString( 320, 444, "read COPYING for details.", UI_CENTER|UI_SMALLFONT, color );
240
241 //Draw version.
242 UI_DrawString( 640-40, 480-14, "^70.8.8", UI_SMALLFONT, color );
243 if((int)trap_Cvar_VariableValue("protocol")!=71)
244 UI_DrawString( 0, 480-14, va("^7Protocol: %i",(int)trap_Cvar_VariableValue("protocol")), UI_SMALLFONT, color);
245 }
246
247
248 /*
249 ===============
250 UI_TeamArenaExists
251 ===============
252 */
253 static qboolean UI_TeamArenaExists( void ) {
254 int numdirs;
255 char dirlist[2048];
256 char *dirptr;
257 char *descptr;
258 int i;
259 int dirlen;
260
261 numdirs = trap_FS_GetFileList( "$modlist", "", dirlist, sizeof(dirlist) );
262 dirptr = dirlist;
263 for( i = 0; i < numdirs; i++ ) {
264 dirlen = strlen( dirptr ) + 1;
265 descptr = dirptr + dirlen;
266 if (Q_stricmp(dirptr, "missionpack") == 0) {
267 return qtrue;
268 }
269 dirptr += dirlen + strlen(descptr) + 1;
270 }
271 return qfalse;
272 }
273
274
275 /*
276 ===============
277 UI_MainMenu
278
279 The main menu only comes up when not in a game,
280 so make sure that the attract loop server is down
281 and that local cinematics are killed
282 ===============
283 */
284 void UI_MainMenu( void ) {
285 int y;
286 qboolean teamArena = qfalse;
287 int style = UI_CENTER | UI_DROPSHADOW;
288
289 trap_Cvar_Set( "sv_killserver", "1" );
290 trap_Cvar_SetValue( "handicap", 100 ); //Reset handicap during server change, it must be ser per game
291
292 memset( &s_main, 0 ,sizeof(mainmenu_t) );
293 memset( &s_errorMessage, 0 ,sizeof(errorMessage_t) );
294
295 // com_errorMessage would need that too
296 MainMenu_Cache();
297
298 trap_Cvar_VariableStringBuffer( "com_errorMessage", s_errorMessage.errorMessage, sizeof(s_errorMessage.errorMessage) );
299 if (strlen(s_errorMessage.errorMessage))
300 {
301 s_errorMessage.menu.draw = Main_MenuDraw;
302 s_errorMessage.menu.key = ErrorMessage_Key;
303 s_errorMessage.menu.fullscreen = qtrue;
304 s_errorMessage.menu.wrapAround = qtrue;
305 s_errorMessage.menu.showlogo = qtrue;
306
307 trap_Key_SetCatcher( KEYCATCH_UI );
308 uis.menusp = 0;
309 UI_PushMenu ( &s_errorMessage.menu );
310
311 return;
312 }
313
314 s_main.menu.draw = Main_MenuDraw;
315 s_main.menu.fullscreen = qtrue;
316 s_main.menu.wrapAround = qtrue;
317 s_main.menu.showlogo = qtrue;
318
319 y = 134;
320 s_main.singleplayer.generic.type = MTYPE_PTEXT;
321 s_main.singleplayer.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
322 s_main.singleplayer.generic.x = 320;
323 s_main.singleplayer.generic.y = y;
324 s_main.singleplayer.generic.id = ID_SINGLEPLAYER;
325 s_main.singleplayer.generic.callback = Main_MenuEvent;
326 s_main.singleplayer.string = "SINGLE PLAYER";
327 s_main.singleplayer.color = color_red;
328 s_main.singleplayer.style = style;
329
330 y += MAIN_MENU_VERTICAL_SPACING;
331 s_main.multiplayer.generic.type = MTYPE_PTEXT;
332 s_main.multiplayer.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
333 s_main.multiplayer.generic.x = 320;
334 s_main.multiplayer.generic.y = y;
335 s_main.multiplayer.generic.id = ID_MULTIPLAYER;
336 s_main.multiplayer.generic.callback = Main_MenuEvent;
337 s_main.multiplayer.string = "MULTIPLAYER";
338 s_main.multiplayer.color = color_red;
339 s_main.multiplayer.style = style;
340
341 y += MAIN_MENU_VERTICAL_SPACING;
342 s_main.setup.generic.type = MTYPE_PTEXT;
343 s_main.setup.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
344 s_main.setup.generic.x = 320;
345 s_main.setup.generic.y = y;
346 s_main.setup.generic.id = ID_SETUP;
347 s_main.setup.generic.callback = Main_MenuEvent;
348 s_main.setup.string = "SETUP";
349 s_main.setup.color = color_red;
350 s_main.setup.style = style;
351
352 y += MAIN_MENU_VERTICAL_SPACING;
353 s_main.demos.generic.type = MTYPE_PTEXT;
354 s_main.demos.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
355 s_main.demos.generic.x = 320;
356 s_main.demos.generic.y = y;
357 s_main.demos.generic.id = ID_DEMOS;
358 s_main.demos.generic.callback = Main_MenuEvent;
359 s_main.demos.string = "DEMOS";
360 s_main.demos.color = color_red;
361 s_main.demos.style = style;
362
363 /*y += MAIN_MENU_VERTICAL_SPACING;
364 s_main.cinematics.generic.type = MTYPE_PTEXT;
365 s_main.cinematics.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
366 s_main.cinematics.generic.x = 320;
367 s_main.cinematics.generic.y = y;
368 s_main.cinematics.generic.id = ID_CINEMATICS;
369 s_main.cinematics.generic.callback = Main_MenuEvent;
370 s_main.cinematics.string = "CINEMATICS";
371 s_main.cinematics.color = color_red;
372 s_main.cinematics.style = style;*/
373
374 y += MAIN_MENU_VERTICAL_SPACING;
375 s_main.challenges.generic.type = MTYPE_PTEXT;
376 s_main.challenges.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
377 s_main.challenges.generic.x = 320;
378 s_main.challenges.generic.y = y;
379 s_main.challenges.generic.id = ID_CHALLENGES;
380 s_main.challenges.generic.callback = Main_MenuEvent;
381 s_main.challenges.string = "STATISTICS";
382 s_main.challenges.color = color_red;
383 s_main.challenges.style = style;
384
385 if (UI_TeamArenaExists()) {
386 teamArena = qtrue;
387 y += MAIN_MENU_VERTICAL_SPACING;
388 s_main.teamArena.generic.type = MTYPE_PTEXT;
389 s_main.teamArena.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
390 s_main.teamArena.generic.x = 320;
391 s_main.teamArena.generic.y = y;
392 s_main.teamArena.generic.id = ID_TEAMARENA;
393 s_main.teamArena.generic.callback = Main_MenuEvent;
394 s_main.teamArena.string = "MISSION PACK";
395 s_main.teamArena.color = color_red;
396 s_main.teamArena.style = style;
397 }
398
399 y += MAIN_MENU_VERTICAL_SPACING;
400 s_main.mods.generic.type = MTYPE_PTEXT;
401 s_main.mods.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
402 s_main.mods.generic.x = 320;
403 s_main.mods.generic.y = y;
404 s_main.mods.generic.id = ID_MODS;
405 s_main.mods.generic.callback = Main_MenuEvent;
406 s_main.mods.string = "MODS";
407 s_main.mods.color = color_red;
408 s_main.mods.style = style;
409
410 y += MAIN_MENU_VERTICAL_SPACING;
411 s_main.exit.generic.type = MTYPE_PTEXT;
412 s_main.exit.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
413 s_main.exit.generic.x = 320;
414 s_main.exit.generic.y = y;
415 s_main.exit.generic.id = ID_EXIT;
416 s_main.exit.generic.callback = Main_MenuEvent;
417 s_main.exit.string = "EXIT";
418 s_main.exit.color = color_red;
419 s_main.exit.style = style;
420
421 Menu_AddItem( &s_main.menu, &s_main.singleplayer );
422 Menu_AddItem( &s_main.menu, &s_main.multiplayer );
423 Menu_AddItem( &s_main.menu, &s_main.setup );
424 Menu_AddItem( &s_main.menu, &s_main.demos );
425 //Menu_AddItem( &s_main.menu, &s_main.cinematics );
426 Menu_AddItem( &s_main.menu, &s_main.challenges );
427 if (teamArena) {
428 Menu_AddItem( &s_main.menu, &s_main.teamArena );
429 }
430 Menu_AddItem( &s_main.menu, &s_main.mods );
431 Menu_AddItem( &s_main.menu, &s_main.exit );
432
433 trap_Key_SetCatcher( KEYCATCH_UI );
434 uis.menusp = 0;
435 UI_PushMenu ( &s_main.menu );
436
437 }