File: ui_firstconnect.c

package info (click to toggle)
openarena 0.8.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,396 kB
  • sloc: ansic: 102,278; makefile: 1,851; asm: 396; xml: 339; sh: 133
file content (474 lines) | stat: -rw-r--r-- 14,579 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/*
===========================================================================
Copyright (C) 2009 Poul Sander

This file is part of the Open Arena source code.

Open Arena source code 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.

Open Arena source code 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 Open Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
//
#include "ui_local.h"

/******************************************************************************
 * This is the menu displayed the first time the player selects "Multiplayer" *
 * It only has the must set or know about options!                            *
 * Options: Name, Network Rate, Delag, Auto Download                          *
 ******************************************************************************/

#define ART_BACK0		"menu/art_blueish/back_0"
#define ART_BACK1		"menu/art_blueish/back_1"
#define ART_FRAMEL		"menu/art_blueish/frame2_l"
#define ART_FRAMER		"menu/art_blueish/frame1_r"
#define ART_FIGHT0              "menu/art_blueish/accept_0"
#define ART_FIGHT1              "menu/art_blueish/accept_1"


#define ID_NAME			10
#define ID_RATE                 11
#define ID_DELAGHITSCAN		12
#define ID_ALLOWDOWNLOAD	13

#define ID_GO                   100
#define ID_BACK                 101


#define MAX_NAMELENGTH	20

/*static const char *rate_items[] = {
	"<= 28.8K",
	"33.6K",
	"56K",
	"ISDN",
	"LAN/Cable/xDSL",
	NULL
};*/
extern const char *rate_items[];

static char* art_artlist[] =
{
	ART_FRAMEL,
	ART_FRAMER,
	ART_BACK0,
	ART_BACK1,
	ART_FIGHT0,
	ART_FIGHT1,
	NULL
};

typedef struct
{
	menuframework_s	menu;
	menutext_s	banner;
	menubitmap_s	framel;
	menubitmap_s	framer;
	menubitmap_s	go;
	menubitmap_s	back;
        menutext_s	info;
        menutext_s	info2;

        //Important options
        menufield_s	name;
        menulist_s	rate;

        //Optional options
        menuradiobutton_s	delaghitscan;
	menuradiobutton_s	allowdownload;
} firstconnect_t;

static firstconnect_t	s_firstconnect;

/*
=================
PlayerSettings_DrawName2
=================
*/
static void PlayerSettings_DrawName2( void *self ) {
	menufield_s		*f;
	qboolean		focus;
	int				style;
	char			*txt;
	char			c;
	float			*color;
	int				n;
	int				basex, x, y;
	char			name[32];

	f = (menufield_s*)self;
	basex = f->generic.x;
	y = f->generic.y;
	focus = (f->generic.parent->cursor == f->generic.menuPosition);

	style = UI_LEFT|UI_SMALLFONT;
	color = text_color_normal;
	if( focus ) {
		style |= UI_PULSE;
		color = text_color_highlight;
	}

	UI_DrawProportionalString( basex, y, "Name:", style, color );

	// draw the actual name
	basex += 64+10;
	//y += PROP_HEIGHT;
        y+= 4;
	txt = f->field.buffer;
	color = g_color_table[ColorIndex(COLOR_WHITE)];
	x = basex;
	while ( (c = *txt) != 0 ) {
		if ( !focus && Q_IsColorString( txt ) ) {
			n = ColorIndex( *(txt+1) );
			if( n == 0 ) {
				n = 7;
			}
			color = g_color_table[n];
			txt += 2;
			continue;
		}
		UI_DrawChar( x, y, c, style, color );
		txt++;
		x += SMALLCHAR_WIDTH;
	}

	// draw cursor if we have focus
	if( focus ) {
		if ( trap_Key_GetOverstrikeMode() ) {
			c = 11;
		} else {
			c = 10;
		}

		style &= ~UI_PULSE;
		style |= UI_BLINK;

		UI_DrawChar( basex + f->field.cursor * SMALLCHAR_WIDTH, y, c, style, color_white );
	}

	// draw at bottom also using proportional font
	Q_strncpyz( name, f->field.buffer, sizeof(name) );
	Q_CleanStr( name );
}

/*
=================
FirstConnect_StatusBar_Name
=================
*/
static void FirstConnect_StatusBar_Name( void* ptr ) {
		UI_DrawString( 320, 440, "Your nickname", UI_CENTER|UI_SMALLFONT, colorWhite );
}

/*
=================
FirstConnect_StatusBar_Rate
=================
*/
static void FirstConnect_StatusBar_Rate( void* ptr ) {
		UI_DrawString( 320, 440, "Your connection speed", UI_CENTER|UI_SMALLFONT, colorWhite );
}

/*
=================
FirstConnect_StatusBar_Delag
=================
*/
static void FirstConnect_StatusBar_Delag( void* ptr ) {
		UI_DrawString( 320, 440, "Reliable Instanthit weapons", UI_CENTER|UI_SMALLFONT, colorWhite );
}

/*
=================
FirstConnect_StatusBar_Download
=================
*/
static void FirstConnect_StatusBar_Download( void* ptr ) {
		UI_DrawString( 320, 440, "Security risk, see <http://deb.li/Q3DL>", UI_CENTER|UI_SMALLFONT, colorWhite );
}

static void AutoDownloadAction( qboolean result )
{
	if (result) {
		trap_Cvar_SetValue( "cl_allowDownload", 1 );
	} else {
		trap_Cvar_SetValue( "cl_allowDownload", 0 );
	}
	s_firstconnect.allowdownload.curvalue = result;
}

/*
=================
FirstConnect_SaveChanges
=================
*/
static void FirstConnect_SaveChanges( void ) {
	// name
	trap_Cvar_Set( "name", s_firstconnect.name.field.buffer );
}

/*
=================
FirstConnect_Event
=================
*/
static void FirstConnect_Event( void* ptr, int event )
{
	switch (((menucommon_s*)ptr)->id)
	{
		case ID_GO:
			if (event != QM_ACTIVATED)
				break;
                        FirstConnect_SaveChanges();
                        UI_PopMenu();
                        trap_Cvar_SetValue( "ui_setupchecked", 1 );
                        UI_ArenaServersMenu();
			break;

		case ID_BACK:
			if (event != QM_ACTIVATED)
				break;

			UI_PopMenu();
			break;

                case ID_RATE:
                        if( s_firstconnect.rate.curvalue == 0 ) {
                                trap_Cvar_SetValue( "rate", 2500 );
                        }
                        else if( s_firstconnect.rate.curvalue == 1 ) {
                                trap_Cvar_SetValue( "rate", 3000 );
                        }
                        else if( s_firstconnect.rate.curvalue == 2 ) {
                                trap_Cvar_SetValue( "rate", 4000 );
                        }
                        else if( s_firstconnect.rate.curvalue == 3 ) {
                                trap_Cvar_SetValue( "rate", 5000 );
                        }
                        else if( s_firstconnect.rate.curvalue == 4 ) {
                                trap_Cvar_SetValue( "rate", 25000 );
                        }
                        break;

                case ID_ALLOWDOWNLOAD:
                        trap_Cvar_SetValue( "sv_allowDownload", s_firstconnect.allowdownload.curvalue );
                        if ( s_firstconnect.allowdownload.curvalue )
				UI_ConfirmAutoDownload( AutoDownloadAction );
			else
				trap_Cvar_SetValue( "cl_allowDownload", 0 );
                        break;

                case ID_DELAGHITSCAN:
                        trap_Cvar_SetValue( "g_delagHitscan", s_firstconnect.delaghitscan.curvalue );
                        trap_Cvar_SetValue( "cg_delag", s_firstconnect.delaghitscan.curvalue );
                        break;
	}
}

/*
=================
FirstConnect_SetMenuItems
=================
*/
static void FirstConnect_SetMenuItems( void ) {
    int rate;
    // name
	Q_strncpyz( s_firstconnect.name.field.buffer, UI_Cvar_VariableString("name"), sizeof(s_firstconnect.name.field.buffer) );

        rate = trap_Cvar_VariableValue( "rate" );
	if( rate <= 2500 ) {
		s_firstconnect.rate.curvalue = 0;
	}
	else if( rate <= 3000 ) {
		s_firstconnect.rate.curvalue = 1;
	}
	else if( rate <= 4000 ) {
		s_firstconnect.rate.curvalue = 2;
	}
	else if( rate <= 5000 ) {
		s_firstconnect.rate.curvalue = 3;
	}
	else {
		s_firstconnect.rate.curvalue = 4;
	}

        s_firstconnect.allowdownload.curvalue	= trap_Cvar_VariableValue( "cl_allowDownload" ) != 0;
        s_firstconnect.delaghitscan.curvalue	= trap_Cvar_VariableValue( "cg_delag" ) != 0;
}

/*
=================
FirstConnect_MenuInit
=================
*/
void FirstConnect_MenuInit( void )
{
    int y;
	// zero set all our globals
	memset( &s_firstconnect, 0 ,sizeof(firstconnect_t) );

	FirstConnect_Cache();

	s_firstconnect.menu.wrapAround = qtrue;
	s_firstconnect.menu.fullscreen = qtrue;

	s_firstconnect.banner.generic.type	 = MTYPE_BTEXT;
	s_firstconnect.banner.generic.x     = 320;
	s_firstconnect.banner.generic.y     = 16;
	s_firstconnect.banner.string		 = "FIRST CONNECT";
	s_firstconnect.banner.color  		 = color_white;
	s_firstconnect.banner.style  		 = UI_CENTER;

        s_firstconnect.framel.generic.type  = MTYPE_BITMAP;
	s_firstconnect.framel.generic.name  = ART_FRAMEL;
	s_firstconnect.framel.generic.flags = QMF_INACTIVE;
	s_firstconnect.framel.generic.x	 = 0;
	s_firstconnect.framel.generic.y	 = 78;
	s_firstconnect.framel.width  	     = 256;
	s_firstconnect.framel.height  	     = 329;

	s_firstconnect.framer.generic.type  = MTYPE_BITMAP;
	s_firstconnect.framer.generic.name  = ART_FRAMER;
	s_firstconnect.framer.generic.flags = QMF_INACTIVE;
	s_firstconnect.framer.generic.x	 = 376;
	s_firstconnect.framer.generic.y	 = 76;
	s_firstconnect.framer.width  	     = 256;
	s_firstconnect.framer.height  	     = 334;

        s_firstconnect.go.generic.type	    = MTYPE_BITMAP;
	s_firstconnect.go.generic.name     = ART_FIGHT0;
	s_firstconnect.go.generic.flags    = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
	s_firstconnect.go.generic.callback = FirstConnect_Event;
	s_firstconnect.go.generic.id	    = ID_GO;
	s_firstconnect.go.generic.x		= 640;
	s_firstconnect.go.generic.y		= 480-64;
	s_firstconnect.go.width  		    = 128;
	s_firstconnect.go.height  		    = 64;
	s_firstconnect.go.focuspic         = ART_FIGHT1;

	s_firstconnect.back.generic.type	  = MTYPE_BITMAP;
	s_firstconnect.back.generic.name     = ART_BACK0;
	s_firstconnect.back.generic.flags    = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
	s_firstconnect.back.generic.callback = FirstConnect_Event;
	s_firstconnect.back.generic.id	      = ID_BACK;
	s_firstconnect.back.generic.x		  = 0;
	s_firstconnect.back.generic.y		  = 480-64;
	s_firstconnect.back.width  		  = 128;
	s_firstconnect.back.height  		  = 64;
	s_firstconnect.back.focuspic         = ART_BACK1;

        y = 144;
	s_firstconnect.name.generic.type			= MTYPE_FIELD;
	s_firstconnect.name.generic.flags			= QMF_NODEFAULTINIT;
	s_firstconnect.name.generic.ownerdraw		= PlayerSettings_DrawName2;
	s_firstconnect.name.field.widthInChars	= MAX_NAMELENGTH;
	s_firstconnect.name.field.maxchars		= MAX_NAMELENGTH;
	s_firstconnect.name.generic.x				= 192;
	s_firstconnect.name.generic.y				= y;
	s_firstconnect.name.generic.left			= 192 - 8;
	s_firstconnect.name.generic.top			= y - 8;
	s_firstconnect.name.generic.right			= 192 + 200;
	s_firstconnect.name.generic.bottom		= y + 2 * PROP_HEIGHT;
        s_firstconnect.name.generic.statusbar  = FirstConnect_StatusBar_Name;

        y+= 4*PROP_HEIGHT;
        s_firstconnect.rate.generic.type		= MTYPE_SPINCONTROL;
	s_firstconnect.rate.generic.name		= "Data Rate:";
	s_firstconnect.rate.generic.flags		= QMF_PULSEIFFOCUS|QMF_SMALLFONT;
	s_firstconnect.rate.generic.callback	= FirstConnect_Event;
	s_firstconnect.rate.generic.id			= ID_RATE;
	s_firstconnect.rate.generic.x			= 320;
	s_firstconnect.rate.generic.y			= y;
	s_firstconnect.rate.itemnames			= rate_items;
        s_firstconnect.rate.generic.statusbar  = FirstConnect_StatusBar_Rate;

        y += BIGCHAR_HEIGHT+2;
	s_firstconnect.delaghitscan.generic.type     = MTYPE_RADIOBUTTON;
	s_firstconnect.delaghitscan.generic.name	   = "Compensate latency:";
	s_firstconnect.delaghitscan.generic.flags	   = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
	s_firstconnect.delaghitscan.generic.callback = FirstConnect_Event;
	s_firstconnect.delaghitscan.generic.id       = ID_DELAGHITSCAN;
	s_firstconnect.delaghitscan.generic.x	       = 320;
	s_firstconnect.delaghitscan.generic.y	       = y;
        s_firstconnect.delaghitscan.generic.statusbar  = FirstConnect_StatusBar_Delag;

	y += BIGCHAR_HEIGHT+2;
	s_firstconnect.allowdownload.generic.type     = MTYPE_RADIOBUTTON;
	s_firstconnect.allowdownload.generic.name	   = "Automatic Downloading:";
	s_firstconnect.allowdownload.generic.flags	   = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
	s_firstconnect.allowdownload.generic.callback = FirstConnect_Event;
	s_firstconnect.allowdownload.generic.id       = ID_ALLOWDOWNLOAD;
	s_firstconnect.allowdownload.generic.x	       = 320;
	s_firstconnect.allowdownload.generic.y	       = y;
        s_firstconnect.allowdownload.generic.statusbar  = FirstConnect_StatusBar_Download;

        s_firstconnect.info.generic.type	 = MTYPE_TEXT;
	s_firstconnect.info.generic.x     = 320;
	s_firstconnect.info.generic.y     = 400;
	s_firstconnect.info.color  		 = color_white;
	s_firstconnect.info.style  		 = UI_CENTER|UI_SMALLFONT;
        s_firstconnect.info.string           = "Note: All settings can be changed later in SETUP";

        s_firstconnect.info2.generic.type	 = MTYPE_TEXT;
	s_firstconnect.info2.generic.x     = 320;
	s_firstconnect.info2.generic.y     = 80;
	s_firstconnect.info2.color  		 = color_white;
	s_firstconnect.info2.style  		 = UI_CENTER|UI_SMALLFONT;
        s_firstconnect.info2.string           = "Please verify these settings";

        Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.banner );
	Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.framel );
	Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.framer );
	Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.go );
	Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.back );

        Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.name );
        Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.rate );

        Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.delaghitscan );
        Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.allowdownload );

        Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.info );
        Menu_AddItem( &s_firstconnect.menu, &s_firstconnect.info2 );

        FirstConnect_SetMenuItems();
}

/*
=================
FirstConnect_Cache
=================
*/
void FirstConnect_Cache( void )
{
	int	i;

	// touch all our pics
	for (i=0; ;i++)
	{
		if (!art_artlist[i])
			break;
		trap_R_RegisterShaderNoMip(art_artlist[i]);
	}
}

/*
=================
UI_FirstConnectMenu
=================
*/
void UI_FirstConnectMenu( void )
{
	FirstConnect_MenuInit();
	UI_PushMenu( &s_firstconnect.menu );
}