00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "ui_local.h"
00033
00034
00035 #define ART_FRAME "menu/art/addbotframe"
00036 #define ART_BACK0 "menu/art/back_0"
00037 #define ART_BACK1 "menu/art/back_1"
00038
00039 #define ID_LIST_BOTS 10
00040 #define ID_LIST_CTF_ORDERS 11
00041 #define ID_LIST_TEAM_ORDERS 12
00042
00043
00044 typedef struct {
00045 menuframework_s menu;
00046
00047 menutext_s banner;
00048 menubitmap_s frame;
00049
00050 menulist_s list;
00051
00052 menubitmap_s back;
00053
00054 int gametype;
00055 int numBots;
00056 int selectedBot;
00057 char *bots[9];
00058 char botNames[9][16];
00059 } teamOrdersMenuInfo_t;
00060
00061 static teamOrdersMenuInfo_t teamOrdersMenuInfo;
00062
00063 #define NUM_CTF_ORDERS 7
00064 static const char *ctfOrders[] = {
00065 "I Am the Leader",
00066 "Defend the Base",
00067 "Follow Me",
00068 "Get Enemy Flag",
00069 "Camp Here",
00070 "Report",
00071 "I Relinquish Command",
00072 NULL
00073 };
00074 static const char *ctfMessages[] = {
00075 "i am the leader",
00076 "%s defend the base",
00077 "%s follow me",
00078 "%s get enemy flag",
00079 "%s camp here",
00080 "%s report",
00081 "i stop being the leader",
00082 NULL
00083 };
00084
00085 #define NUM_TEAM_ORDERS 6
00086 static const char *teamOrders[] = {
00087 "I Am the Leader",
00088 "Follow Me",
00089 "Roam",
00090 "Camp Here",
00091 "Report",
00092 "I Relinquish Command",
00093 NULL
00094 };
00095 static const char *teamMessages[] = {
00096 "i am the leader",
00097 "%s follow me",
00098 "%s roam",
00099 "%s camp here",
00100 "%s report",
00101 "i stop being the leader",
00102 NULL
00103 };
00104
00105
00106
00107
00108
00109
00110
00111 static void UI_TeamOrdersMenu_BackEvent( void *ptr, int event ) {
00112 if( event != QM_ACTIVATED ) {
00113 return;
00114 }
00115 UI_PopMenu();
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 static void UI_TeamOrdersMenu_SetList( int id ) {
00125 switch( id ) {
00126 default:
00127 case ID_LIST_BOTS:
00128 teamOrdersMenuInfo.list.generic.id = id;
00129 teamOrdersMenuInfo.list.numitems = teamOrdersMenuInfo.numBots;
00130 teamOrdersMenuInfo.list.itemnames = (const char **)teamOrdersMenuInfo.bots;
00131 break;
00132
00133 case ID_LIST_CTF_ORDERS:
00134 teamOrdersMenuInfo.list.generic.id = id;
00135 teamOrdersMenuInfo.list.numitems = NUM_CTF_ORDERS;
00136 teamOrdersMenuInfo.list.itemnames = ctfOrders;
00137 break;
00138
00139 case ID_LIST_TEAM_ORDERS:
00140 teamOrdersMenuInfo.list.generic.id = id;
00141 teamOrdersMenuInfo.list.numitems = NUM_TEAM_ORDERS;
00142 teamOrdersMenuInfo.list.itemnames = teamOrders;
00143 break;
00144 }
00145
00146 teamOrdersMenuInfo.list.generic.bottom = teamOrdersMenuInfo.list.generic.top + teamOrdersMenuInfo.list.numitems * PROP_HEIGHT;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155 sfxHandle_t UI_TeamOrdersMenu_Key( int key ) {
00156 menulist_s *l;
00157 int x;
00158 int y;
00159 int index;
00160
00161 l = (menulist_s *)Menu_ItemAtCursor( &teamOrdersMenuInfo.menu );
00162 if( l != &teamOrdersMenuInfo.list ) {
00163 return Menu_DefaultKey( &teamOrdersMenuInfo.menu, key );
00164 }
00165
00166 switch( key ) {
00167 case K_MOUSE1:
00168 x = l->generic.left;
00169 y = l->generic.top;
00170 if( UI_CursorInRect( x, y, l->generic.right - x, l->generic.bottom - y ) ) {
00171 index = (uis.cursory - y) / PROP_HEIGHT;
00172 l->oldvalue = l->curvalue;
00173 l->curvalue = index;
00174
00175 if( l->generic.callback ) {
00176 l->generic.callback( l, QM_ACTIVATED );
00177 return menu_move_sound;
00178 }
00179 }
00180 return menu_null_sound;
00181
00182 case K_KP_UPARROW:
00183 case K_UPARROW:
00184 l->oldvalue = l->curvalue;
00185
00186 if( l->curvalue == 0 ) {
00187 l->curvalue = l->numitems - 1;
00188 }
00189 else {
00190 l->curvalue--;
00191 }
00192 return menu_move_sound;
00193
00194 case K_KP_DOWNARROW:
00195 case K_DOWNARROW:
00196 l->oldvalue = l->curvalue;
00197
00198 if( l->curvalue == l->numitems - 1 ) {
00199 l->curvalue = 0;;
00200 }
00201 else {
00202 l->curvalue++;
00203 }
00204 return menu_move_sound;
00205 }
00206
00207 return Menu_DefaultKey( &teamOrdersMenuInfo.menu, key );
00208 }
00209
00210
00211
00212
00213
00214
00215
00216 static void UI_TeamOrdersMenu_ListDraw( void *self ) {
00217 menulist_s *l;
00218 int x;
00219 int y;
00220 int i;
00221 float *color;
00222 qboolean hasfocus;
00223 int style;
00224
00225 l = (menulist_s *)self;
00226
00227 hasfocus = (l->generic.parent->cursor == l->generic.menuPosition);
00228
00229 x = 320;
00230 y = l->generic.y;
00231 for( i = 0; i < l->numitems; i++ ) {
00232 style = UI_LEFT|UI_SMALLFONT|UI_CENTER;
00233 if( i == l->curvalue ) {
00234 color = color_yellow;
00235 if( hasfocus ) {
00236 style |= UI_PULSE;
00237 }
00238 }
00239 else {
00240 color = color_orange;
00241 }
00242
00243 UI_DrawProportionalString( x, y, l->itemnames[i], style, color );
00244 y += PROP_HEIGHT;
00245 }
00246 }
00247
00248
00249
00250
00251
00252
00253
00254 static void UI_TeamOrdersMenu_ListEvent( void *ptr, int event ) {
00255 int id;
00256 int selection;
00257 char message[256];
00258
00259 if (event != QM_ACTIVATED)
00260 return;
00261
00262 id = ((menulist_s *)ptr)->generic.id;
00263 selection = ((menulist_s *)ptr)->curvalue;
00264
00265 if( id == ID_LIST_BOTS ) {
00266 teamOrdersMenuInfo.selectedBot = selection;
00267 if( teamOrdersMenuInfo.gametype == GT_CTF ) {
00268 UI_TeamOrdersMenu_SetList( ID_LIST_CTF_ORDERS );
00269 }
00270 else {
00271 UI_TeamOrdersMenu_SetList( ID_LIST_TEAM_ORDERS );
00272 }
00273 return;
00274 }
00275
00276 if( id == ID_LIST_CTF_ORDERS ) {
00277 Com_sprintf( message, sizeof(message), ctfMessages[selection], teamOrdersMenuInfo.botNames[teamOrdersMenuInfo.selectedBot] );
00278 }
00279 else {
00280 Com_sprintf( message, sizeof(message), teamMessages[selection], teamOrdersMenuInfo.botNames[teamOrdersMenuInfo.selectedBot] );
00281 }
00282
00283 trap_Cmd_ExecuteText( EXEC_APPEND, va( "say_team \"%s\"\n", message ) );
00284 UI_PopMenu();
00285 }
00286
00287
00288
00289
00290
00291
00292
00293 static void UI_TeamOrdersMenu_BuildBotList( void ) {
00294 uiClientState_t cs;
00295 int numPlayers;
00296 int isBot;
00297 int n;
00298 char playerTeam;
00299 char botTeam;
00300 char info[MAX_INFO_STRING];
00301
00302 for( n = 0; n < 9; n++ ) {
00303 teamOrdersMenuInfo.bots[n] = teamOrdersMenuInfo.botNames[n];
00304 }
00305
00306 trap_GetClientState( &cs );
00307
00308 Q_strncpyz( teamOrdersMenuInfo.botNames[0], "Everyone", 16 );
00309 teamOrdersMenuInfo.numBots = 1;
00310
00311 trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) );
00312 numPlayers = atoi( Info_ValueForKey( info, "sv_maxclients" ) );
00313 teamOrdersMenuInfo.gametype = atoi( Info_ValueForKey( info, "g_gametype" ) );
00314
00315 for( n = 0; n < numPlayers && teamOrdersMenuInfo.numBots < 9; n++ ) {
00316 trap_GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING );
00317
00318 playerTeam = TEAM_SPECTATOR;
00319
00320 if( n == cs.clientNum ) {
00321 playerTeam = *Info_ValueForKey( info, "t" );
00322 continue;
00323 }
00324
00325 isBot = atoi( Info_ValueForKey( info, "skill" ) );
00326 if( !isBot ) {
00327 continue;
00328 }
00329
00330 botTeam = *Info_ValueForKey( info, "t" );
00331 if( botTeam != playerTeam ) {
00332 continue;
00333 }
00334
00335 Q_strncpyz( teamOrdersMenuInfo.botNames[teamOrdersMenuInfo.numBots], Info_ValueForKey( info, "n" ), 16 );
00336 Q_CleanStr( teamOrdersMenuInfo.botNames[teamOrdersMenuInfo.numBots] );
00337 teamOrdersMenuInfo.numBots++;
00338 }
00339 }
00340
00341
00342
00343
00344
00345
00346
00347 static void UI_TeamOrdersMenu_Init( void ) {
00348 UI_TeamOrdersMenu_Cache();
00349
00350 memset( &teamOrdersMenuInfo, 0, sizeof(teamOrdersMenuInfo) );
00351 teamOrdersMenuInfo.menu.fullscreen = qfalse;
00352 teamOrdersMenuInfo.menu.key = UI_TeamOrdersMenu_Key;
00353
00354 UI_TeamOrdersMenu_BuildBotList();
00355
00356 teamOrdersMenuInfo.banner.generic.type = MTYPE_BTEXT;
00357 teamOrdersMenuInfo.banner.generic.x = 320;
00358 teamOrdersMenuInfo.banner.generic.y = 16;
00359 teamOrdersMenuInfo.banner.string = "TEAM ORDERS";
00360 teamOrdersMenuInfo.banner.color = color_white;
00361 teamOrdersMenuInfo.banner.style = UI_CENTER;
00362
00363 teamOrdersMenuInfo.frame.generic.type = MTYPE_BITMAP;
00364 teamOrdersMenuInfo.frame.generic.flags = QMF_INACTIVE;
00365 teamOrdersMenuInfo.frame.generic.name = ART_FRAME;
00366 teamOrdersMenuInfo.frame.generic.x = 320-233;
00367 teamOrdersMenuInfo.frame.generic.y = 240-166;
00368 teamOrdersMenuInfo.frame.width = 466;
00369 teamOrdersMenuInfo.frame.height = 332;
00370
00371 teamOrdersMenuInfo.list.generic.type = MTYPE_SCROLLLIST;
00372 teamOrdersMenuInfo.list.generic.flags = QMF_PULSEIFFOCUS;
00373 teamOrdersMenuInfo.list.generic.ownerdraw = UI_TeamOrdersMenu_ListDraw;
00374 teamOrdersMenuInfo.list.generic.callback = UI_TeamOrdersMenu_ListEvent;
00375 teamOrdersMenuInfo.list.generic.x = 320-64;
00376 teamOrdersMenuInfo.list.generic.y = 120;
00377
00378 teamOrdersMenuInfo.back.generic.type = MTYPE_BITMAP;
00379 teamOrdersMenuInfo.back.generic.name = ART_BACK0;
00380 teamOrdersMenuInfo.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00381 teamOrdersMenuInfo.back.generic.callback = UI_TeamOrdersMenu_BackEvent;
00382 teamOrdersMenuInfo.back.generic.x = 0;
00383 teamOrdersMenuInfo.back.generic.y = 480-64;
00384 teamOrdersMenuInfo.back.width = 128;
00385 teamOrdersMenuInfo.back.height = 64;
00386 teamOrdersMenuInfo.back.focuspic = ART_BACK1;
00387
00388 Menu_AddItem( &teamOrdersMenuInfo.menu, &teamOrdersMenuInfo.banner );
00389 Menu_AddItem( &teamOrdersMenuInfo.menu, &teamOrdersMenuInfo.frame );
00390 Menu_AddItem( &teamOrdersMenuInfo.menu, &teamOrdersMenuInfo.list );
00391 Menu_AddItem( &teamOrdersMenuInfo.menu, &teamOrdersMenuInfo.back );
00392
00393 teamOrdersMenuInfo.list.generic.left = 220;
00394 teamOrdersMenuInfo.list.generic.top = teamOrdersMenuInfo.list.generic.y;
00395 teamOrdersMenuInfo.list.generic.right = 420;
00396 UI_TeamOrdersMenu_SetList( ID_LIST_BOTS );
00397 }
00398
00399
00400
00401
00402
00403
00404
00405 void UI_TeamOrdersMenu_Cache( void ) {
00406 trap_R_RegisterShaderNoMip( ART_FRAME );
00407 trap_R_RegisterShaderNoMip( ART_BACK0 );
00408 trap_R_RegisterShaderNoMip( ART_BACK1 );
00409 }
00410
00411
00412
00413
00414
00415
00416
00417 void UI_TeamOrdersMenu( void ) {
00418 UI_TeamOrdersMenu_Init();
00419 UI_PushMenu( &teamOrdersMenuInfo.menu );
00420 }
00421
00422
00423
00424
00425
00426
00427
00428 void UI_TeamOrdersMenu_f( void ) {
00429 uiClientState_t cs;
00430 char info[MAX_INFO_STRING];
00431 int team;
00432
00433
00434 trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) );
00435 teamOrdersMenuInfo.gametype = atoi( Info_ValueForKey( info, "g_gametype" ) );
00436 if( teamOrdersMenuInfo.gametype < GT_TEAM ) {
00437 return;
00438 }
00439
00440
00441 trap_GetClientState( &cs );
00442 trap_GetConfigString( CS_PLAYERS + cs.clientNum, info, MAX_INFO_STRING );
00443 team = atoi( Info_ValueForKey( info, "t" ) );
00444 if( team == TEAM_SPECTATOR ) {
00445 return;
00446 }
00447
00448 UI_TeamOrdersMenu();
00449 }