Debian Codegraph @

code/q3_ui/ui_firstconnect.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) 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, "Auto download missing maps and mods", UI_CENTER|UI_SMALLFONT, colorWhite );
198 }
199
200 /*
201 =================
202 FirstConnect_SaveChanges
203 =================
204 */
205 static void FirstConnect_SaveChanges( void ) {
206 // name
207 trap_Cvar_Set( "name", s_firstconnect.name.field.buffer );
208 }
209
210 /*
211 =================
212 FirstConnect_Event
213 =================
214 */
215 static void FirstConnect_Event( void* ptr, int event )
216 {
217 switch (((menucommon_s*)ptr)->id)
218 {
219 case ID_GO:
220 if (event != QM_ACTIVATED)
221 break;
222 FirstConnect_SaveChanges();
223 UI_PopMenu();
224 trap_Cvar_SetValue( "ui_setupchecked", 1 );
225 UI_ArenaServersMenu();
226 break;
227
228 case ID_BACK:
229 if (event != QM_ACTIVATED)
230 break;
231
232 UI_PopMenu();
233 break;
234
235 case ID_RATE:
236 if( s_firstconnect.rate.curvalue == 0 ) {
237 trap_Cvar_SetValue( "rate", 2500 );
238 }
239 else if( s_firstconnect.rate.curvalue == 1 ) {
240 trap_Cvar_SetValue( "rate", 3000 );
241 }
242 else if( s_firstconnect.rate.curvalue == 2 ) {
243 trap_Cvar_SetValue( "rate", 4000 );
244 }
245 else if( s_firstconnect.rate.curvalue == 3 ) {
246 trap_Cvar_SetValue( "rate", 5000 );
247 }
248 else if( s_firstconnect.rate.curvalue == 4 ) {
249 trap_Cvar_SetValue( "rate", 25000 );
250 }
251 break;
252
253 case ID_ALLOWDOWNLOAD:
254 trap_Cvar_SetValue( "cl_allowDownload", s_firstconnect.allowdownload.curvalue );
255 trap_Cvar_SetValue( "sv_allowDownload", s_firstconnect.allowdownload.curvalue );
256 break;
257
258 case ID_DELAGHITSCAN:
259 trap_Cvar_SetValue( "g_delagHitscan", s_firstconnect.delaghitscan.curvalue );
260 trap_Cvar_SetValue( "cg_delag", s_firstconnect.delaghitscan.curvalue );
261 break;
262 }
263 }
264
265 /*
266 =================
267 FirstConnect_SetMenuItems
268 =================
269 */
270 static void FirstConnect_SetMenuItems( void ) {
271 int rate;
272 // name
273 Q_strncpyz( s_firstconnect.name.field.buffer, UI_Cvar_VariableString("name"), sizeof(s_firstconnect.name.field.buffer) );
274
275 rate = trap_Cvar_VariableValue( "rate" );
276 if( rate <= 2500 ) {
277 s_firstconnect.rate.curvalue = 0;
278 }
279 else if( rate <= 3000 ) {
280 s_firstconnect.rate.curvalue = 1;
281 }
282 else if( rate <= 4000 ) {
283 s_firstconnect.rate.curvalue = 2;
284 }
285 else if( rate <= 5000 ) {
286 s_firstconnect.rate.curvalue = 3;
287 }
288 else {
289 s_firstconnect.rate.curvalue = 4;
290 }
291
292 s_firstconnect.allowdownload.curvalue = trap_Cvar_VariableValue( "cl_allowDownload" ) != 0;
293 s_firstconnect.delaghitscan.curvalue = trap_Cvar_VariableValue( "cg_delag" ) != 0;
294 }
295
296 /*
297 =================
298 FirstConnect_MenuInit
299 =================
300 */
301 void FirstConnect_MenuInit( void )
302 {
303 int y;
304 // zero set all our globals
305 memset( &s_firstconnect, 0 ,sizeof(firstconnect_t) );
306
307 FirstConnect_Cache();
308
309 s_firstconnect.menu.wrapAround = qtrue;
310 s_firstconnect.menu.fullscreen = qtrue;
311
312 s_firstconnect.banner.generic.type = MTYPE_BTEXT;
313 s_firstconnect.banner.generic.x = 320;
314 s_firstconnect.banner.generic.y = 16;
315 s_firstconnect.banner.string = "FIRST CONNECT";
316 s_firstconnect.banner.color = color_white;
317 s_firstconnect.banner.style = UI_CENTER;
318
319 s_firstconnect.framel.generic.type = MTYPE_BITMAP;
320 s_firstconnect.framel.generic.name = ART_FRAMEL;
321 s_firstconnect.framel.generic.flags = QMF_INACTIVE;
322 s_firstconnect.framel.generic.x = 0;
323 s_firstconnect.framel.generic.y = 78;
324 s_firstconnect.framel.width = 256;
325 s_firstconnect.framel.height = 329;
326
327 s_firstconnect.framer.generic.type = MTYPE_BITMAP;
328 s_firstconnect.framer.generic.name = ART_FRAMER;
329 s_firstconnect.framer.generic.flags = QMF_INACTIVE;
330 s_firstconnect.framer.generic.x = 376;
331 s_firstconnect.framer.generic.y = 76;
332 s_firstconnect.framer.width = 256;
333 s_firstconnect.framer.height = 334;
334
335 s_firstconnect.go.generic.type = MTYPE_BITMAP;
336 s_firstconnect.go.generic.name = ART_FIGHT0;
337 s_firstconnect.go.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
338 s_firstconnect.go.generic.callback = FirstConnect_Event;
339 s_firstconnect.go.generic.id = ID_GO;
340 s_firstconnect.go.generic.x = 640;
341 s_firstconnect.go.generic.y = 480-64;
342 s_firstconnect.go.width = 128;
343 s_firstconnect.go.height = 64;
344 s_firstconnect.go.focuspic = ART_FIGHT1;
345
346 s_firstconnect.back.generic.type = MTYPE_BITMAP;
347 s_firstconnect.back.generic.name = ART_BACK0;
348 s_firstconnect.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
349 s_firstconnect.back.generic.callback = FirstConnect_Event;
350 s_firstconnect.back.generic.id = ID_BACK;
351 s_firstconnect.back.generic.x = 0;
352 s_firstconnect.back.generic.y = 480-64;
353 s_firstconnect.back.width = 128;
354 s_firstconnect.back.height = 64;
355 s_firstconnect.back.focuspic = ART_BACK1;
356
357 y = 144;
358 s_firstconnect.name.generic.type = MTYPE_FIELD;
359 s_firstconnect.name.generic.flags = QMF_NODEFAULTINIT;
360 s_firstconnect.name.generic.ownerdraw = PlayerSettings_DrawName2;
361 s_firstconnect.name.field.widthInChars = MAX_NAMELENGTH;
362 s_firstconnect.name.field.maxchars = MAX_NAMELENGTH;
363 s_firstconnect.name.generic.x = 192;
364 s_firstconnect.name.generic.y = y;
365 s_firstconnect.name.generic.left = 192 - 8;
366 s_firstconnect.name.generic.top = y - 8;
367 s_firstconnect.name.generic.right = 192 + 200;
368 s_firstconnect.name.generic.bottom = y + 2 * PROP_HEIGHT;
369 s_firstconnect.name.generic.statusbar = FirstConnect_StatusBar_Name;
370
371 y+= 4*PROP_HEIGHT;
372 s_firstconnect.rate.generic.type = MTYPE_SPINCONTROL;
373 s_firstconnect.rate.generic.name = "Data Rate:";
374 s_firstconnect.rate.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
375 s_firstconnect.rate.generic.callback = FirstConnect_Event;
376 s_firstconnect.rate.generic.id = ID_RATE;
377 s_firstconnect.rate.generic.x = 320;
378 s_firstconnect.rate.generic.y = y;
379 s_firstconnect.rate.itemnames = rate_items;
380 s_firstconnect.rate.generic.statusbar = FirstConnect_StatusBar_Rate;
381
382 y += BIGCHAR_HEIGHT+2;
383 s_firstconnect.delaghitscan.generic.type = MTYPE_RADIOBUTTON;
384 s_firstconnect.delaghitscan.generic.name = "Compensate latency:";
385 s_firstconnect.delaghitscan.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
386 s_firstconnect.delaghitscan.generic.callback = FirstConnect_Event;
387 s_firstconnect.delaghitscan.generic.id = ID_DELAGHITSCAN;
388 s_firstconnect.delaghitscan.generic.x = 320;
389 s_firstconnect.delaghitscan.generic.y = y;
390 s_firstconnect.delaghitscan.generic.statusbar = FirstConnect_StatusBar_Delag;
391
392 y += BIGCHAR_HEIGHT+2;
393 s_firstconnect.allowdownload.generic.type = MTYPE_RADIOBUTTON;
394 s_firstconnect.allowdownload.generic.name = "Automatic Downloading:";
395 s_firstconnect.allowdownload.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
396 s_firstconnect.allowdownload.generic.callback = FirstConnect_Event;
397 s_firstconnect.allowdownload.generic.id = ID_ALLOWDOWNLOAD;
398 s_firstconnect.allowdownload.generic.x = 320;
399 s_firstconnect.allowdownload.generic.y = y;
400 s_firstconnect.allowdownload.generic.statusbar = FirstConnect_StatusBar_Download;
401
402 s_firstconnect.info.generic.type = MTYPE_TEXT;
403 s_firstconnect.info.generic.x = 320;
404 s_firstconnect.info.generic.y = 400;
405 s_firstconnect.info.color = color_white;
406 s_firstconnect.info.style = UI_CENTER|UI_SMALLFONT;
407 s_firstconnect.info.string = "Note: All settings can be changed later in SETUP";
408
409 s_firstconnect.info2.generic.type = MTYPE_TEXT;
410 s_firstconnect.info2.generic.x = 320;
411 s_firstconnect.info2.generic.y = 80;
412 s_firstconnect.info2.color = color_white;
413 s_firstconnect.info2.style = UI_CENTER|UI_SMALLFONT;
414 s_firstconnect.info2.string = "Please verify these settings";
415
416 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.banner );
417 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.framel );
418 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.framer );
419 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.go );
420 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.back );
421
422 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.name );
423 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.rate );
424
425 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.delaghitscan );
426 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.allowdownload );
427
428 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.info );
429 Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.info2 );
430
431 FirstConnect_SetMenuItems();
432 }
433
434 /*
435 =================
436 FirstConnect_Cache
437 =================
438 */
439 void FirstConnect_Cache( void )
440 {
441 int i;
442
443 // touch all our pics
444 for (i=0; ;i++)
445 {
446 if (!art_artlist[i])
447 break;
448 trap_R_RegisterShaderNoMip(art_artlist[i]);
449 }
450 }
451
452 /*
453 =================
454 UI_FirstConnectMenu
455 =================
456 */
457 void UI_FirstConnectMenu( void )
458 {
459 FirstConnect_MenuInit();
460 UI_PushMenu( &s_firstconnect.menu );
461 }