Debian Codegraph @

code/q3_ui/ui_firstconnect.c

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 ===========================================================================
3 Copyright (C) 2009 Poul Sander
4
5 This file is part of the Open Arena source code.
6
7 Open 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 Open 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 Open 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 #include "ui_local.h"
24
25 /******************************************************************************
26 * This is the menu displayed the first time the player selects "Multiplayer" *
27 * It only has the must set or know about options! *
28 * Options: Name, Network Rate, Delag, Auto Download *
29 ******************************************************************************/
30
31 #define ART_BACK0 "menu/art_blueish/back_0"
32 #define ART_BACK1 "menu/art_blueish/back_1"
33 #define ART_FRAMEL "menu/art_blueish/frame2_l"
34 #define ART_FRAMER "menu/art_blueish/frame1_r"
35 #define ART_FIGHT0 "menu/art_blueish/accept_0"
36 #define ART_FIGHT1 "menu/art_blueish/accept_1"
37
38
39 #define ID_NAME 10
40 #define ID_RATE 11
41 #define ID_DELAGHITSCAN 12
42 #define ID_ALLOWDOWNLOAD 13
43
44 #define ID_GO 100
45 #define ID_BACK 101
46
47
48 #define MAX_NAMELENGTH 20
49
50 /*static const char *rate_items[] = {
51 "<= 28.8K",
52 "33.6K",
53 "56K",
54 "ISDN",
55 "LAN/Cable/xDSL",
56 NULL
57 };*/
58 extern const char *rate_items[];
59
60 static char* art_artlist[] =
61 {
62 ART_FRAMEL,
63 ART_FRAMER,
64 ART_BACK0,
65 ART_BACK1,
66 ART_FIGHT0,
67 ART_FIGHT1,
68 NULL
69 };
70
71 typedef struct
72 {
73 menuframework_s menu;
74 menutext_s banner;
75 menubitmap_s framel;
76 menubitmap_s framer;
77 menubitmap_s go;
78 menubitmap_s back;
79 menutext_s info;
80 menutext_s info2;
81
82 //Important options
83 menufield_s name;
84 menulist_s rate;
85
86 //Optional options
87 menuradiobutton_s delaghitscan;
88 menuradiobutton_s allowdownload;
89 } firstconnect_t;
90
91 static firstconnect_t s_firstconnect;
92
93 /*
94 =================
95 PlayerSettings_DrawName2
96 =================
97 */
98 static void PlayerSettings_DrawName2( void *self ) {
99 menufield_s *f;
100 qboolean focus;
101 int style;
102 char *txt;
103 char c;
104 float *color;
105 int n;
106 int basex, x, y;
107 char name[32];
108
109 f = (menufield_s*)self;
110 basex = f->generic.x;
111 y = f->generic.y;
112 focus = (f->generic.parent->cursor == f->generic.menuPosition);
113
114 style = UI_LEFT|UI_SMALLFONT;
115 color = text_color_normal;
116 if( focus ) {
117 style |= UI_PULSE;
118 color = text_color_highlight;
119 }
120
121 UI_DrawProportionalString( basex, y, "Name:", style, color );
122
123 // draw the actual name
124 basex += 64+10;
125 //y += PROP_HEIGHT;
126 y+= 4;
127 txt = f->field.buffer;
128 color = g_color_table[ColorIndex(COLOR_WHITE)];
129 x = basex;
130 while ( (c = *txt) != 0 ) {
131 if ( !focus && Q_IsColorString( txt ) ) {
132 n = ColorIndex( *(txt+1) );
133 if( n == 0 ) {
134 n = 7;
135 }
136 color = g_color_table[n];
137 txt += 2;
138 continue;
139 }
140 UI_DrawChar( x, y, c, style, color );
141 txt++;
142 x += SMALLCHAR_WIDTH;
143 }
144
145 // draw cursor if we have focus
146 if( focus ) {
147 if ( trap_Key_GetOverstrikeMode() ) {
148 c = 11;
149 } else {
150 c = 10;
151 }
152
153 style &= ~UI_PULSE;
154 style |= UI_BLINK;
155
156 UI_DrawChar( basex + f->field.cursor * SMALLCHAR_WIDTH, y, c, style, color_white );
157 }
158
159 // draw at bottom also using proportional font
160 Q_strncpyz( name, f->field.buffer, sizeof(name) );
161 Q_CleanStr( name );
162 }
163
164 /*
165 =================
166 FirstConnect_StatusBar_Name
167 =================
168 */
169 static void FirstConnect_StatusBar_Name( void* ptr ) {
170 UI_DrawString( 320, 440, "Your nickname", UI_CENTER|UI_SMALLFONT, colorWhite );
171 }
172
173 /*
174 =================
175 FirstConnect_StatusBar_Rate
176 =================
177 */
178 static void FirstConnect_StatusBar_Rate( void* ptr ) {
179 UI_DrawString( 320, 440, "Your connection speed", UI_CENTER|UI_SMALLFONT, colorWhite );
180 }
181
182 /*
183 =================
184 FirstConnect_StatusBar_Delag
185 =================
186 */
187 static void FirstConnect_StatusBar_Delag( void* ptr ) {
188 UI_DrawString( 320, 440, "Reliable Instanthit weapons", UI_CENTER|UI_SMALLFONT, colorWhite );
189 }
190
191 /*
192 =================
193 FirstConnect_StatusBar_Download
194 =================
195 */
196 static void FirstConnect_StatusBar_Download( void* ptr ) {
•197 UI_DrawString( 320, 440, "Security risk, see <http://deb.li/Q3DL>", UI_CENTER|UI_SMALLFONT, colorWhite );
198 }
199
200 static void AutoDownloadAction( qboolean result )
201 {
202 if (result) {
203 trap_Cvar_SetValue( "cl_allowDownload", 1 );
204 } else {
205 trap_Cvar_SetValue( "cl_allowDownload", 0 );
206 }
207 s_firstconnect.allowdownload.curvalue = result;
208 }
209
210 /*
211 =================
212 FirstConnect_SaveChanges
213 =================
214 */
215 static void FirstConnect_SaveChanges( void ) {
216 // name
217 trap_Cvar_Set( "name", s_firstconnect.name.field.buffer );
218 }
219
220 /*
221 =================
222 FirstConnect_Event
223 =================
224 */
225 static void FirstConnect_Event( void* ptr, int event )
226 {
227 switch (((menucommon_s*)ptr)->id)
228 {
229 case ID_GO:
230 if (event != QM_ACTIVATED)
231 break;
232 FirstConnect_SaveChanges();
233 UI_PopMenu();
234 trap_Cvar_SetValue( "ui_setupchecked", 1 );
235 UI_ArenaServersMenu();
236 break;
237
238 case ID_BACK:
239 if (event != QM_ACTIVATED)
240 break;
241
242 UI_PopMenu();
243 break;
244
245 case ID_RATE:
246 if( s_firstconnect.rate.curvalue == 0 ) {
247 trap_Cvar_SetValue( "rate", 2500 );
248 }
249 else if( s_firstconnect.rate.curvalue == 1 ) {
250 trap_Cvar_SetValue( "rate", 3000 );
251 }
252 else if( s_firstconnect.rate.curvalue == 2 ) {
253 trap_Cvar_SetValue( "rate", 4000 );
254 }
255 else if( s_firstconnect.rate.curvalue == 3 ) {
256 trap_Cvar_SetValue( "rate", 5000 );
257 }
258 else if( s_firstconnect.rate.curvalue == 4 ) {
259 trap_Cvar_SetValue( "rate", 25000 );
260 }
261 break;
262
263 case ID_ALLOWDOWNLOAD:
264 trap_Cvar_SetValue( "sv_allowDownload", s_firstconnect.allowdownload.curvalue );
•265 if ( s_firstconnect.allowdownload.curvalue )
266 UI_ConfirmAutoDownload( AutoDownloadAction );
267 else
268 trap_Cvar_SetValue( "cl_allowDownload", 0 );
269 break;
270
271 case ID_DELAGHITSCAN:
272 trap_Cvar_SetValue( "g_delagHitscan", s_firstconnect.delaghitscan.curvalue );
273 trap_Cvar_SetValue( "cg_delag", s_firstconnect.delaghitscan.curvalue );
274 break;
275 }
276 }
277
278 /*
279 =================
280 FirstConnect_SetMenuItems
281 =================
282 */
283 static void FirstConnect_SetMenuItems( void ) {
284 int rate;
285 // name
286 Q_strncpyz( s_firstconnect.name.field.buffer, UI_Cvar_VariableString("name"), sizeof(s_firstconnect.name.field.buffer) );
287
288 rate = trap_Cvar_VariableValue( "rate" );
289 if( rate <= 2500 ) {
290 s_firstconnect.rate.curvalue = 0;
291 }
292 else if( rate <= 3000 ) {
293 s_firstconnect.rate.curvalue = 1;
294 }
295 else if( rate <= 4000 ) {
296 s_firstconnect.rate.curvalue = 2;
297 }
298 else if( rate <= 5000 ) {
299 s_firstconnect.rate.curvalue = 3;
300 }
301 else {
302 s_firstconnect.rate.curvalue = 4;
303 }
304
305 s_firstconnect.allowdownload.curvalue = trap_Cvar_VariableValue( "cl_allowDownload" ) != 0;
306 s_firstconnect.delaghitscan.curvalue = trap_Cvar_VariableValue( "cg_delag" ) != 0;
307 }
308
309 /*
310 =================
311 FirstConnect_MenuInit
312 =================
313 */
314 void FirstConnect_MenuInit( void )
315 {
316 int y;
317 // zero set all our globals
318 memset( &s_firstconnect, 0 ,sizeof(firstconnect_t) );
319
320 FirstConnect_Cache();
321
322 s_firstconnect.menu.wrapAround = qtrue;
323 s_firstconnect.menu.fullscreen = qtrue;
324
325 s_firstconnect.banner.generic.type = MTYPE_BTEXT;
326 s_firstconnect.banner.generic.x = 320;
327 s_firstconnect.banner.generic.y = 16;
328 s_firstconnect.banner.string = "FIRST CONNECT";
329 s_firstconnect.banner.color = color_white;
330 s_firstconnect.banner.style = UI_CENTER;
331
332 s_firstconnect.framel.generic.type = MTYPE_BITMAP;
333 s_firstconnect.framel.generic.name = ART_FRAMEL;
334 s_firstconnect.framel.generic.flags = QMF_INACTIVE;
335 s_firstconnect.framel.generic.x = 0;
336 s_firstconnect.framel.generic.y = 78;
337 s_firstconnect.framel.width = 256;
338 s_firstconnect.framel.height = 329;
339
340 s_firstconnect.framer.generic.type = MTYPE_BITMAP;
341 s_firstconnect.framer.generic.name = ART_FRAMER;
342 s_firstconnect.framer.generic.flags = QMF_INACTIVE;
343 s_firstconnect.framer.generic.x = 376;
344 s_firstconnect.framer.generic.y = 76;
345 s_firstconnect.framer.width = 256;
346 s_firstconnect.framer.height = 334;
347
348 s_firstconnect.go.generic.type = MTYPE_BITMAP;
349 s_firstconnect.go.generic.name = ART_FIGHT0;
350 s_firstconnect.go.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
351 s_firstconnect.go.generic.callback = FirstConnect_Event;
352 s_firstconnect.go.generic.id = ID_GO;
353 s_firstconnect.go.generic.x = 640;
354 s_firstconnect.go.generic.y = 480-64;
355 s_firstconnect.go.width = 128;
356 s_firstconnect.go.height = 64;
357 s_firstconnect.go.focuspic = ART_FIGHT1;
358
359 s_firstconnect.back.generic.type = MTYPE_BITMAP;
360 s_firstconnect.back.generic.name = ART_BACK0;
361 s_firstconnect.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
362 s_firstconnect.back.generic.callback = FirstConnect_Event;
363 s_firstconnect.back.generic.id = ID_BACK;
364 s_firstconnect.back.generic.x = 0;
365 s_firstconnect.back.generic.y = 480-64;
366 s_firstconnect.back.width = 128;
367 s_firstconnect.back.height = 64;
368 s_firstconnect.back.focuspic = ART_BACK1;
369
370 y = 144;
371 s_firstconnect.name.generic.type = MTYPE_FIELD;
372 s_firstconnect.name.generic.flags = QMF_NODEFAULTINIT;
373 s_firstconnect.name.generic.ownerdraw = PlayerSettings_DrawName2;
374 s_firstconnect.name.field.widthInChars = MAX_NAMELENGTH;
375 s_firstconnect.name.field.maxchars = MAX_NAMELENGTH;
376 s_firstconnect.name.generic.x = 192;
377 s_firstconnect.name.generic.y = y;
378 s_firstconnect.name.generic.left = 192 - 8;
379 s_firstconnect.name.generic.top = y - 8;
380 s_firstconnect.name.generic.right = 192 + 200;
381 s_firstconnect.name.generic.bottom = y + 2 * PROP_HEIGHT;
382 s_firstconnect.name.generic.statusbar = FirstConnect_StatusBar_Name;
383
384 y+= 4*PROP_HEIGHT;
385 s_firstconnect.rate.generic.type = MTYPE_SPINCONTROL;
386 s_firstconnect.rate.generic.name = "Data Rate:";
387 s_firstconnect.rate.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
388 s_firstconnect.rate.generic.callback = FirstConnect_Event;
389 s_firstconnect.rate.generic.id = ID_RATE;
390 s_firstconnect.rate.generic.x = 320;
391 s_firstconnect.rate.generic.y = y;
392 s_firstconnect.rate.itemnames = rate_items;
393 s_firstconnect.rate.generic.statusbar = FirstConnect_StatusBar_Rate;
394
395 y += BIGCHAR_HEIGHT+2;
396 s_firstconnect.delaghitscan.generic.type = MTYPE_RADIOBUTTON;
397 s_firstconnect.delaghitscan.generic.name = "Compensate latency:";
398 s_firstconnect.delaghitscan.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
399 s_firstconnect.delaghitscan.generic.callback = FirstConnect_Event;
400 s_firstconnect.delaghitscan.generic.id = ID_DELAGHITSCAN;
401 s_firstconnect.delaghitscan.generic.x = 320;
402 s_firstconnect.delaghitscan.generic.y = y;
403 s_firstconnect.delaghitscan.generic.statusbar = FirstConnect_StatusBar_Delag;
404
405 y += BIGCHAR_HEIGHT+2;
406 s_firstconnect.allowdownload.generic.type = MTYPE_RADIOBUTTON;
407 s_firstconnect.allowdownload.generic.name = "Automatic Downloading:";
408 s_firstconnect.allowdownload.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
409 s_firstconnect.allowdownload.generic.callback = FirstConnect_Event;
410 s_firstconnect.allowdownload.generic.id = ID_ALLOWDOWNLOAD;
411 s_firstconnect.allowdownload.generic.x = 320;
412 s_firstconnect.allowdownload.generic.y = y;
413 s_firstconnect.allowdownload.generic.statusbar = FirstConnect_StatusBar_Download;
414
415 s_firstconnect.info.generic.type = MTYPE_TEXT;
416 s_firstconnect.info.generic.x = 320;
417 s_firstconnect.info.generic.y = 400;
418 s_firstconnect.info.color = color_white;
419 s_firstconnect.info.style = UI_CENTER|UI_SMALLFONT;
420 s_firstconnect.info.string = "Note: All settings can be changed later in SETUP";
421
422 s_firstconnect.info2.generic.type = MTYPE_TEXT;
423 s_firstconnect.info2.generic.x = 320;
424 s_firstconnect.info2.generic.y = 80;
425 s_firstconnect.info2.color = color_white;
426 s_firstconnect.info2.style = UI_CENTER|UI_SMALLFONT;
427 s_firstconnect.info2.string = "Please verify these settings";
428
429 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.banner );
430 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.framel );
431 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.framer );
432 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.go );
433 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.back );
434
435 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.name );
436 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.rate );
437
438 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.delaghitscan );
439 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.allowdownload );
440
441 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.info );
442 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.info2 );
443
444 FirstConnect_SetMenuItems();
445 }
446
447 /*
448 =================
449 FirstConnect_Cache
450 =================
451 */
452 void FirstConnect_Cache( void )
453 {
454 int i;
455
456 // touch all our pics
457 for (i=0; ;i++)
458 {
459 if (!art_artlist[i])
460 break;
461 trap_R_RegisterShaderNoMip(art_artlist[i]);
462 }
463 }
464
465 /*
466 =================
467 UI_FirstConnectMenu
468 =================
469 */
470 void UI_FirstConnectMenu( void )
471 {
472 FirstConnect_MenuInit();
473 UI_PushMenu( &s_firstconnect.menu );
474 }