Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

ui_network.c (9001B)


      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 Foobar; 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 NETWORK OPTIONS MENU
     27 
     28 =======================================================================
     29 */
     30 
     31 #include "ui_local.h"
     32 
     33 
     34 #define ART_FRAMEL			"menu/art/frame2_l"
     35 #define ART_FRAMER			"menu/art/frame1_r"
     36 #define ART_BACK0			"menu/art/back_0"
     37 #define ART_BACK1			"menu/art/back_1"
     38 
     39 #define ID_GRAPHICS			10
     40 #define ID_DISPLAY			11
     41 #define ID_SOUND			12
     42 #define ID_NETWORK			13
     43 #define ID_RATE				14
     44 #define ID_BACK				15
     45 
     46 
     47 static const char *rate_items[] = {
     48 	"<= 28.8K",
     49 	"33.6K",
     50 	"56K",
     51 	"ISDN",
     52 	"LAN/Cable/xDSL",
     53 	0
     54 };
     55 
     56 typedef struct {
     57 	menuframework_s	menu;
     58 
     59 	menutext_s		banner;
     60 	menubitmap_s	framel;
     61 	menubitmap_s	framer;
     62 
     63 	menutext_s		graphics;
     64 	menutext_s		display;
     65 	menutext_s		sound;
     66 	menutext_s		network;
     67 
     68 	menulist_s		rate;
     69 
     70 	menubitmap_s	back;
     71 } networkOptionsInfo_t;
     72 
     73 static networkOptionsInfo_t	networkOptionsInfo;
     74 
     75 
     76 /*
     77 =================
     78 UI_NetworkOptionsMenu_Event
     79 =================
     80 */
     81 static void UI_NetworkOptionsMenu_Event( void* ptr, int event ) {
     82 	if( event != QM_ACTIVATED ) {
     83 		return;
     84 	}
     85 
     86 	switch( ((menucommon_s*)ptr)->id ) {
     87 	case ID_GRAPHICS:
     88 		UI_PopMenu();
     89 		UI_GraphicsOptionsMenu();
     90 		break;
     91 
     92 	case ID_DISPLAY:
     93 		UI_PopMenu();
     94 		UI_DisplayOptionsMenu();
     95 		break;
     96 
     97 	case ID_SOUND:
     98 		UI_PopMenu();
     99 		UI_SoundOptionsMenu();
    100 		break;
    101 
    102 	case ID_NETWORK:
    103 		break;
    104 
    105 	case ID_RATE:
    106 		if( networkOptionsInfo.rate.curvalue == 0 ) {
    107 			trap_Cvar_SetValue( "rate", 2500 );
    108 		}
    109 		else if( networkOptionsInfo.rate.curvalue == 1 ) {
    110 			trap_Cvar_SetValue( "rate", 3000 );
    111 		}
    112 		else if( networkOptionsInfo.rate.curvalue == 2 ) {
    113 			trap_Cvar_SetValue( "rate", 4000 );
    114 		}
    115 		else if( networkOptionsInfo.rate.curvalue == 3 ) {
    116 			trap_Cvar_SetValue( "rate", 5000 );
    117 		}
    118 		else if( networkOptionsInfo.rate.curvalue == 4 ) {
    119 			trap_Cvar_SetValue( "rate", 25000 );
    120 		}
    121 		break;
    122 
    123 	case ID_BACK:
    124 		UI_PopMenu();
    125 		break;
    126 	}
    127 }
    128 
    129 
    130 /*
    131 ===============
    132 UI_NetworkOptionsMenu_Init
    133 ===============
    134 */
    135 static void UI_NetworkOptionsMenu_Init( void ) {
    136 	int		y;
    137 	int		rate;
    138 
    139 	memset( &networkOptionsInfo, 0, sizeof(networkOptionsInfo) );
    140 
    141 	UI_NetworkOptionsMenu_Cache();
    142 	networkOptionsInfo.menu.wrapAround = qtrue;
    143 	networkOptionsInfo.menu.fullscreen = qtrue;
    144 
    145 	networkOptionsInfo.banner.generic.type		= MTYPE_BTEXT;
    146 	networkOptionsInfo.banner.generic.flags		= QMF_CENTER_JUSTIFY;
    147 	networkOptionsInfo.banner.generic.x			= 320;
    148 	networkOptionsInfo.banner.generic.y			= 16;
    149 	networkOptionsInfo.banner.string			= "SYSTEM SETUP";
    150 	networkOptionsInfo.banner.color				= color_white;
    151 	networkOptionsInfo.banner.style				= UI_CENTER;
    152 
    153 	networkOptionsInfo.framel.generic.type		= MTYPE_BITMAP;
    154 	networkOptionsInfo.framel.generic.name		= ART_FRAMEL;
    155 	networkOptionsInfo.framel.generic.flags		= QMF_INACTIVE;
    156 	networkOptionsInfo.framel.generic.x			= 0;  
    157 	networkOptionsInfo.framel.generic.y			= 78;
    158 	networkOptionsInfo.framel.width				= 256;
    159 	networkOptionsInfo.framel.height			= 329;
    160 
    161 	networkOptionsInfo.framer.generic.type		= MTYPE_BITMAP;
    162 	networkOptionsInfo.framer.generic.name		= ART_FRAMER;
    163 	networkOptionsInfo.framer.generic.flags		= QMF_INACTIVE;
    164 	networkOptionsInfo.framer.generic.x			= 376;
    165 	networkOptionsInfo.framer.generic.y			= 76;
    166 	networkOptionsInfo.framer.width				= 256;
    167 	networkOptionsInfo.framer.height			= 334;
    168 
    169 	networkOptionsInfo.graphics.generic.type		= MTYPE_PTEXT;
    170 	networkOptionsInfo.graphics.generic.flags		= QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
    171 	networkOptionsInfo.graphics.generic.id			= ID_GRAPHICS;
    172 	networkOptionsInfo.graphics.generic.callback	= UI_NetworkOptionsMenu_Event;
    173 	networkOptionsInfo.graphics.generic.x			= 216;
    174 	networkOptionsInfo.graphics.generic.y			= 240 - 2 * PROP_HEIGHT;
    175 	networkOptionsInfo.graphics.string				= "GRAPHICS";
    176 	networkOptionsInfo.graphics.style				= UI_RIGHT;
    177 	networkOptionsInfo.graphics.color				= color_red;
    178 
    179 	networkOptionsInfo.display.generic.type			= MTYPE_PTEXT;
    180 	networkOptionsInfo.display.generic.flags		= QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
    181 	networkOptionsInfo.display.generic.id			= ID_DISPLAY;
    182 	networkOptionsInfo.display.generic.callback		= UI_NetworkOptionsMenu_Event;
    183 	networkOptionsInfo.display.generic.x			= 216;
    184 	networkOptionsInfo.display.generic.y			= 240 - PROP_HEIGHT;
    185 	networkOptionsInfo.display.string				= "DISPLAY";
    186 	networkOptionsInfo.display.style				= UI_RIGHT;
    187 	networkOptionsInfo.display.color				= color_red;
    188 
    189 	networkOptionsInfo.sound.generic.type			= MTYPE_PTEXT;
    190 	networkOptionsInfo.sound.generic.flags			= QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
    191 	networkOptionsInfo.sound.generic.id				= ID_SOUND;
    192 	networkOptionsInfo.sound.generic.callback		= UI_NetworkOptionsMenu_Event;
    193 	networkOptionsInfo.sound.generic.x				= 216;
    194 	networkOptionsInfo.sound.generic.y				= 240;
    195 	networkOptionsInfo.sound.string					= "SOUND";
    196 	networkOptionsInfo.sound.style					= UI_RIGHT;
    197 	networkOptionsInfo.sound.color					= color_red;
    198 
    199 	networkOptionsInfo.network.generic.type			= MTYPE_PTEXT;
    200 	networkOptionsInfo.network.generic.flags		= QMF_RIGHT_JUSTIFY;
    201 	networkOptionsInfo.network.generic.id			= ID_NETWORK;
    202 	networkOptionsInfo.network.generic.callback		= UI_NetworkOptionsMenu_Event;
    203 	networkOptionsInfo.network.generic.x			= 216;
    204 	networkOptionsInfo.network.generic.y			= 240 + PROP_HEIGHT;
    205 	networkOptionsInfo.network.string				= "NETWORK";
    206 	networkOptionsInfo.network.style				= UI_RIGHT;
    207 	networkOptionsInfo.network.color				= color_red;
    208 
    209 	y = 240 - 1 * (BIGCHAR_HEIGHT+2);
    210 	networkOptionsInfo.rate.generic.type		= MTYPE_SPINCONTROL;
    211 	networkOptionsInfo.rate.generic.name		= "Data Rate:";
    212 	networkOptionsInfo.rate.generic.flags		= QMF_PULSEIFFOCUS|QMF_SMALLFONT;
    213 	networkOptionsInfo.rate.generic.callback	= UI_NetworkOptionsMenu_Event;
    214 	networkOptionsInfo.rate.generic.id			= ID_RATE;
    215 	networkOptionsInfo.rate.generic.x			= 400;
    216 	networkOptionsInfo.rate.generic.y			= y;
    217 	networkOptionsInfo.rate.itemnames			= rate_items;
    218 
    219 	networkOptionsInfo.back.generic.type		= MTYPE_BITMAP;
    220 	networkOptionsInfo.back.generic.name		= ART_BACK0;
    221 	networkOptionsInfo.back.generic.flags		= QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
    222 	networkOptionsInfo.back.generic.callback	= UI_NetworkOptionsMenu_Event;
    223 	networkOptionsInfo.back.generic.id			= ID_BACK;
    224 	networkOptionsInfo.back.generic.x			= 0;
    225 	networkOptionsInfo.back.generic.y			= 480-64;
    226 	networkOptionsInfo.back.width				= 128;
    227 	networkOptionsInfo.back.height				= 64;
    228 	networkOptionsInfo.back.focuspic			= ART_BACK1;
    229 
    230 	Menu_AddItem( &networkOptionsInfo.menu, ( void * ) &networkOptionsInfo.banner );
    231 	Menu_AddItem( &networkOptionsInfo.menu, ( void * ) &networkOptionsInfo.framel );
    232 	Menu_AddItem( &networkOptionsInfo.menu, ( void * ) &networkOptionsInfo.framer );
    233 	Menu_AddItem( &networkOptionsInfo.menu, ( void * ) &networkOptionsInfo.graphics );
    234 	Menu_AddItem( &networkOptionsInfo.menu, ( void * ) &networkOptionsInfo.display );
    235 	Menu_AddItem( &networkOptionsInfo.menu, ( void * ) &networkOptionsInfo.sound );
    236 	Menu_AddItem( &networkOptionsInfo.menu, ( void * ) &networkOptionsInfo.network );
    237 	Menu_AddItem( &networkOptionsInfo.menu, ( void * ) &networkOptionsInfo.rate );
    238 	Menu_AddItem( &networkOptionsInfo.menu, ( void * ) &networkOptionsInfo.back );
    239 
    240 	rate = trap_Cvar_VariableValue( "rate" );
    241 	if( rate <= 2500 ) {
    242 		networkOptionsInfo.rate.curvalue = 0;
    243 	}
    244 	else if( rate <= 3000 ) {
    245 		networkOptionsInfo.rate.curvalue = 1;
    246 	}
    247 	else if( rate <= 4000 ) {
    248 		networkOptionsInfo.rate.curvalue = 2;
    249 	}
    250 	else if( rate <= 5000 ) {
    251 		networkOptionsInfo.rate.curvalue = 3;
    252 	}
    253 	else {
    254 		networkOptionsInfo.rate.curvalue = 4;
    255 	}
    256 }
    257 
    258 
    259 /*
    260 ===============
    261 UI_NetworkOptionsMenu_Cache
    262 ===============
    263 */
    264 void UI_NetworkOptionsMenu_Cache( void ) {
    265 	trap_R_RegisterShaderNoMip( ART_FRAMEL );
    266 	trap_R_RegisterShaderNoMip( ART_FRAMER );
    267 	trap_R_RegisterShaderNoMip( ART_BACK0 );
    268 	trap_R_RegisterShaderNoMip( ART_BACK1 );
    269 }
    270 
    271 
    272 /*
    273 ===============
    274 UI_NetworkOptionsMenu
    275 ===============
    276 */
    277 void UI_NetworkOptionsMenu( void ) {
    278 	UI_NetworkOptionsMenu_Init();
    279 	UI_PushMenu( &networkOptionsInfo.menu );
    280 	Menu_SetCursorToItem( &networkOptionsInfo.menu, &networkOptionsInfo.network );
    281 }