Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

ui_ingame.c (10139B)


      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 INGAME MENU
     27 
     28 =======================================================================
     29 */
     30 
     31 
     32 #include "ui_local.h"
     33 
     34 
     35 #define INGAME_FRAME					"menu/art/addbotframe"
     36 //#define INGAME_FRAME					"menu/art/cut_frame"
     37 #define INGAME_MENU_VERTICAL_SPACING	28
     38 
     39 #define ID_TEAM					10
     40 #define ID_ADDBOTS				11
     41 #define ID_REMOVEBOTS			12
     42 #define ID_SETUP				13
     43 #define ID_SERVERINFO			14
     44 #define ID_LEAVEARENA			15
     45 #define ID_RESTART				16
     46 #define ID_QUIT					17
     47 #define ID_RESUME				18
     48 #define ID_TEAMORDERS			19
     49 
     50 
     51 typedef struct {
     52 	menuframework_s	menu;
     53 
     54 	menubitmap_s	frame;
     55 	menutext_s		team;
     56 	menutext_s		setup;
     57 	menutext_s		server;
     58 	menutext_s		leave;
     59 	menutext_s		restart;
     60 	menutext_s		addbots;
     61 	menutext_s		removebots;
     62 	menutext_s		teamorders;
     63 	menutext_s		quit;
     64 	menutext_s		resume;
     65 } ingamemenu_t;
     66 
     67 static ingamemenu_t	s_ingame;
     68 
     69 
     70 /*
     71 =================
     72 InGame_RestartAction
     73 =================
     74 */
     75 static void InGame_RestartAction( qboolean result ) {
     76 	if( !result ) {
     77 		return;
     78 	}
     79 
     80 	UI_PopMenu();
     81 	trap_Cmd_ExecuteText( EXEC_APPEND, "map_restart 0\n" );
     82 }
     83 
     84 
     85 /*
     86 =================
     87 InGame_QuitAction
     88 =================
     89 */
     90 static void InGame_QuitAction( qboolean result ) {
     91 	if( !result ) {
     92 		return;
     93 	}
     94 	UI_PopMenu();
     95 	UI_CreditMenu();
     96 }
     97 
     98 
     99 /*
    100 =================
    101 InGame_Event
    102 =================
    103 */
    104 void InGame_Event( void *ptr, int notification ) {
    105 	if( notification != QM_ACTIVATED ) {
    106 		return;
    107 	}
    108 
    109 	switch( ((menucommon_s*)ptr)->id ) {
    110 	case ID_TEAM:
    111 		UI_TeamMainMenu();
    112 		break;
    113 
    114 	case ID_SETUP:
    115 		UI_SetupMenu();
    116 		break;
    117 
    118 	case ID_LEAVEARENA:
    119 		trap_Cmd_ExecuteText( EXEC_APPEND, "disconnect\n" );
    120 		break;
    121 
    122 	case ID_RESTART:
    123 		UI_ConfirmMenu( "RESTART ARENA?", (voidfunc_f)NULL, InGame_RestartAction );
    124 		break;
    125 
    126 	case ID_QUIT:
    127 		UI_ConfirmMenu( "EXIT GAME?",  (voidfunc_f)NULL, InGame_QuitAction );
    128 		break;
    129 
    130 	case ID_SERVERINFO:
    131 		UI_ServerInfoMenu();
    132 		break;
    133 
    134 	case ID_ADDBOTS:
    135 		UI_AddBotsMenu();
    136 		break;
    137 
    138 	case ID_REMOVEBOTS:
    139 		UI_RemoveBotsMenu();
    140 		break;
    141 
    142 	case ID_TEAMORDERS:
    143 		UI_TeamOrdersMenu();
    144 		break;
    145 
    146 	case ID_RESUME:
    147 		UI_PopMenu();
    148 		break;
    149 	}
    150 }
    151 
    152 
    153 /*
    154 =================
    155 InGame_MenuInit
    156 =================
    157 */
    158 void InGame_MenuInit( void ) {
    159 	int		y;
    160 	uiClientState_t	cs;
    161 	char	info[MAX_INFO_STRING];
    162 	int		team;
    163 
    164 	memset( &s_ingame, 0 ,sizeof(ingamemenu_t) );
    165 
    166 	InGame_Cache();
    167 
    168 	s_ingame.menu.wrapAround = qtrue;
    169 	s_ingame.menu.fullscreen = qfalse;
    170 
    171 	s_ingame.frame.generic.type			= MTYPE_BITMAP;
    172 	s_ingame.frame.generic.flags		= QMF_INACTIVE;
    173 	s_ingame.frame.generic.name			= INGAME_FRAME;
    174 	s_ingame.frame.generic.x			= 320-233;//142;
    175 	s_ingame.frame.generic.y			= 240-166;//118;
    176 	s_ingame.frame.width				= 466;//359;
    177 	s_ingame.frame.height				= 332;//256;
    178 
    179 	//y = 96;
    180 	y = 88;
    181 	s_ingame.team.generic.type			= MTYPE_PTEXT;
    182 	s_ingame.team.generic.flags			= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    183 	s_ingame.team.generic.x				= 320;
    184 	s_ingame.team.generic.y				= y;
    185 	s_ingame.team.generic.id			= ID_TEAM;
    186 	s_ingame.team.generic.callback		= InGame_Event; 
    187 	s_ingame.team.string				= "START";
    188 	s_ingame.team.color					= color_red;
    189 	s_ingame.team.style					= UI_CENTER|UI_SMALLFONT;
    190 
    191 	y += INGAME_MENU_VERTICAL_SPACING;
    192 	s_ingame.addbots.generic.type		= MTYPE_PTEXT;
    193 	s_ingame.addbots.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    194 	s_ingame.addbots.generic.x			= 320;
    195 	s_ingame.addbots.generic.y			= y;
    196 	s_ingame.addbots.generic.id			= ID_ADDBOTS;
    197 	s_ingame.addbots.generic.callback	= InGame_Event; 
    198 	s_ingame.addbots.string				= "ADD BOTS";
    199 	s_ingame.addbots.color				= color_red;
    200 	s_ingame.addbots.style				= UI_CENTER|UI_SMALLFONT;
    201 	if( !trap_Cvar_VariableValue( "sv_running" ) || !trap_Cvar_VariableValue( "bot_enable" ) || (trap_Cvar_VariableValue( "g_gametype" ) == GT_SINGLE_PLAYER)) {
    202 		s_ingame.addbots.generic.flags |= QMF_GRAYED;
    203 	}
    204 
    205 	y += INGAME_MENU_VERTICAL_SPACING;
    206 	s_ingame.removebots.generic.type		= MTYPE_PTEXT;
    207 	s_ingame.removebots.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    208 	s_ingame.removebots.generic.x			= 320;
    209 	s_ingame.removebots.generic.y			= y;
    210 	s_ingame.removebots.generic.id			= ID_REMOVEBOTS;
    211 	s_ingame.removebots.generic.callback	= InGame_Event; 
    212 	s_ingame.removebots.string				= "REMOVE BOTS";
    213 	s_ingame.removebots.color				= color_red;
    214 	s_ingame.removebots.style				= UI_CENTER|UI_SMALLFONT;
    215 	if( !trap_Cvar_VariableValue( "sv_running" ) || !trap_Cvar_VariableValue( "bot_enable" ) || (trap_Cvar_VariableValue( "g_gametype" ) == GT_SINGLE_PLAYER)) {
    216 		s_ingame.removebots.generic.flags |= QMF_GRAYED;
    217 	}
    218 
    219 	y += INGAME_MENU_VERTICAL_SPACING;
    220 	s_ingame.teamorders.generic.type		= MTYPE_PTEXT;
    221 	s_ingame.teamorders.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    222 	s_ingame.teamorders.generic.x			= 320;
    223 	s_ingame.teamorders.generic.y			= y;
    224 	s_ingame.teamorders.generic.id			= ID_TEAMORDERS;
    225 	s_ingame.teamorders.generic.callback	= InGame_Event; 
    226 	s_ingame.teamorders.string				= "TEAM ORDERS";
    227 	s_ingame.teamorders.color				= color_red;
    228 	s_ingame.teamorders.style				= UI_CENTER|UI_SMALLFONT;
    229 	if( !(trap_Cvar_VariableValue( "g_gametype" ) >= GT_TEAM) ) {
    230 		s_ingame.teamorders.generic.flags |= QMF_GRAYED;
    231 	}
    232 	else {
    233 		trap_GetClientState( &cs );
    234 		trap_GetConfigString( CS_PLAYERS + cs.clientNum, info, MAX_INFO_STRING );
    235 		team = atoi( Info_ValueForKey( info, "t" ) );
    236 		if( team == TEAM_SPECTATOR ) {
    237 			s_ingame.teamorders.generic.flags |= QMF_GRAYED;
    238 		}
    239 	}
    240 
    241 	y += INGAME_MENU_VERTICAL_SPACING;
    242 	s_ingame.setup.generic.type			= MTYPE_PTEXT;
    243 	s_ingame.setup.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    244 	s_ingame.setup.generic.x			= 320;
    245 	s_ingame.setup.generic.y			= y;
    246 	s_ingame.setup.generic.id			= ID_SETUP;
    247 	s_ingame.setup.generic.callback		= InGame_Event; 
    248 	s_ingame.setup.string				= "SETUP";
    249 	s_ingame.setup.color				= color_red;
    250 	s_ingame.setup.style				= UI_CENTER|UI_SMALLFONT;
    251 
    252 	y += INGAME_MENU_VERTICAL_SPACING;
    253 	s_ingame.server.generic.type		= MTYPE_PTEXT;
    254 	s_ingame.server.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    255 	s_ingame.server.generic.x			= 320;
    256 	s_ingame.server.generic.y			= y;
    257 	s_ingame.server.generic.id			= ID_SERVERINFO;
    258 	s_ingame.server.generic.callback	= InGame_Event; 
    259 	s_ingame.server.string				= "SERVER INFO";
    260 	s_ingame.server.color				= color_red;
    261 	s_ingame.server.style				= UI_CENTER|UI_SMALLFONT;
    262 
    263 	y += INGAME_MENU_VERTICAL_SPACING;
    264 	s_ingame.restart.generic.type		= MTYPE_PTEXT;
    265 	s_ingame.restart.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    266 	s_ingame.restart.generic.x			= 320;
    267 	s_ingame.restart.generic.y			= y;
    268 	s_ingame.restart.generic.id			= ID_RESTART;
    269 	s_ingame.restart.generic.callback	= InGame_Event; 
    270 	s_ingame.restart.string				= "RESTART ARENA";
    271 	s_ingame.restart.color				= color_red;
    272 	s_ingame.restart.style				= UI_CENTER|UI_SMALLFONT;
    273 	if( !trap_Cvar_VariableValue( "sv_running" ) ) {
    274 		s_ingame.restart.generic.flags |= QMF_GRAYED;
    275 	}
    276 
    277 	y += INGAME_MENU_VERTICAL_SPACING;
    278 	s_ingame.resume.generic.type			= MTYPE_PTEXT;
    279 	s_ingame.resume.generic.flags			= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    280 	s_ingame.resume.generic.x				= 320;
    281 	s_ingame.resume.generic.y				= y;
    282 	s_ingame.resume.generic.id				= ID_RESUME;
    283 	s_ingame.resume.generic.callback		= InGame_Event; 
    284 	s_ingame.resume.string					= "RESUME GAME";
    285 	s_ingame.resume.color					= color_red;
    286 	s_ingame.resume.style					= UI_CENTER|UI_SMALLFONT;
    287 
    288 	y += INGAME_MENU_VERTICAL_SPACING;
    289 	s_ingame.leave.generic.type			= MTYPE_PTEXT;
    290 	s_ingame.leave.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    291 	s_ingame.leave.generic.x			= 320;
    292 	s_ingame.leave.generic.y			= y;
    293 	s_ingame.leave.generic.id			= ID_LEAVEARENA;
    294 	s_ingame.leave.generic.callback		= InGame_Event; 
    295 	s_ingame.leave.string				= "LEAVE ARENA";
    296 	s_ingame.leave.color				= color_red;
    297 	s_ingame.leave.style				= UI_CENTER|UI_SMALLFONT;
    298 
    299 	y += INGAME_MENU_VERTICAL_SPACING;
    300 	s_ingame.quit.generic.type			= MTYPE_PTEXT;
    301 	s_ingame.quit.generic.flags			= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    302 	s_ingame.quit.generic.x				= 320;
    303 	s_ingame.quit.generic.y				= y;
    304 	s_ingame.quit.generic.id			= ID_QUIT;
    305 	s_ingame.quit.generic.callback		= InGame_Event; 
    306 	s_ingame.quit.string				= "EXIT GAME";
    307 	s_ingame.quit.color					= color_red;
    308 	s_ingame.quit.style					= UI_CENTER|UI_SMALLFONT;
    309 
    310 	Menu_AddItem( &s_ingame.menu, &s_ingame.frame );
    311 	Menu_AddItem( &s_ingame.menu, &s_ingame.team );
    312 	Menu_AddItem( &s_ingame.menu, &s_ingame.addbots );
    313 	Menu_AddItem( &s_ingame.menu, &s_ingame.removebots );
    314 	Menu_AddItem( &s_ingame.menu, &s_ingame.teamorders );
    315 	Menu_AddItem( &s_ingame.menu, &s_ingame.setup );
    316 	Menu_AddItem( &s_ingame.menu, &s_ingame.server );
    317 	Menu_AddItem( &s_ingame.menu, &s_ingame.restart );
    318 	Menu_AddItem( &s_ingame.menu, &s_ingame.resume );
    319 	Menu_AddItem( &s_ingame.menu, &s_ingame.leave );
    320 	Menu_AddItem( &s_ingame.menu, &s_ingame.quit );
    321 }
    322 
    323 
    324 /*
    325 =================
    326 InGame_Cache
    327 =================
    328 */
    329 void InGame_Cache( void ) {
    330 	trap_R_RegisterShaderNoMip( INGAME_FRAME );
    331 }
    332 
    333 
    334 /*
    335 =================
    336 UI_InGameMenu
    337 =================
    338 */
    339 void UI_InGameMenu( void ) {
    340 	// force as top level menu
    341 	uis.menusp = 0;  
    342 
    343 	// set menu cursor to a nice location
    344 	uis.cursorx = 319;
    345 	uis.cursory = 80;
    346 
    347 	InGame_MenuInit();
    348 	UI_PushMenu( &s_ingame.menu );
    349 }