Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

ui_removebots.c

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 //
00023 /*
00024 =======================================================================
00025 
00026 REMOVE BOTS MENU
00027 
00028 =======================================================================
00029 */
00030 
00031 
00032 #include "ui_local.h"
00033 
00034 
00035 #define ART_BACKGROUND      "menu/art/addbotframe"
00036 #define ART_BACK0           "menu/art/back_0"
00037 #define ART_BACK1           "menu/art/back_1"   
00038 #define ART_DELETE0         "menu/art/delete_0"
00039 #define ART_DELETE1         "menu/art/delete_1"
00040 #define ART_ARROWS          "menu/art/arrows_vert_0"
00041 #define ART_ARROWUP         "menu/art/arrows_vert_top"
00042 #define ART_ARROWDOWN       "menu/art/arrows_vert_bot"
00043 
00044 #define ID_UP               10
00045 #define ID_DOWN             11
00046 #define ID_DELETE           12
00047 #define ID_BACK             13
00048 #define ID_BOTNAME0         20
00049 #define ID_BOTNAME1         21
00050 #define ID_BOTNAME2         22
00051 #define ID_BOTNAME3         23
00052 #define ID_BOTNAME4         24
00053 #define ID_BOTNAME5         25
00054 #define ID_BOTNAME6         26
00055 
00056 
00057 typedef struct {
00058     menuframework_s menu;
00059 
00060     menutext_s      banner;
00061     menubitmap_s    background;
00062 
00063     menubitmap_s    arrows;
00064     menubitmap_s    up;
00065     menubitmap_s    down;
00066 
00067     menutext_s      bots[7];
00068 
00069     menubitmap_s    delete;
00070     menubitmap_s    back;
00071 
00072     int             numBots;
00073     int             baseBotNum;
00074     int             selectedBotNum;
00075     char            botnames[7][32];
00076     int             botClientNums[MAX_BOTS];
00077 } removeBotsMenuInfo_t;
00078 
00079 static removeBotsMenuInfo_t removeBotsMenuInfo;
00080 
00081 
00082 /*
00083 =================
00084 UI_RemoveBotsMenu_SetBotNames
00085 =================
00086 */
00087 static void UI_RemoveBotsMenu_SetBotNames( void ) {
00088     int     n;
00089     char    info[MAX_INFO_STRING];
00090 
00091     for ( n = 0; (n < 7) && (removeBotsMenuInfo.baseBotNum + n < removeBotsMenuInfo.numBots); n++ ) {
00092         trap_GetConfigString( CS_PLAYERS + removeBotsMenuInfo.botClientNums[removeBotsMenuInfo.baseBotNum + n], info, MAX_INFO_STRING );
00093         Q_strncpyz( removeBotsMenuInfo.botnames[n], Info_ValueForKey( info, "n" ), sizeof(removeBotsMenuInfo.botnames[n]) );
00094         Q_CleanStr( removeBotsMenuInfo.botnames[n] );
00095     }
00096 
00097 }
00098 
00099 
00100 /*
00101 =================
00102 UI_RemoveBotsMenu_DeleteEvent
00103 =================
00104 */
00105 static void UI_RemoveBotsMenu_DeleteEvent( void* ptr, int event ) {
00106     if (event != QM_ACTIVATED) {
00107         return;
00108     }
00109 
00110     trap_Cmd_ExecuteText( EXEC_APPEND, va("clientkick %i\n", removeBotsMenuInfo.botClientNums[removeBotsMenuInfo.baseBotNum + removeBotsMenuInfo.selectedBotNum]) );
00111 }
00112 
00113 
00114 /*
00115 =================
00116 UI_RemoveBotsMenu_BotEvent
00117 =================
00118 */
00119 static void UI_RemoveBotsMenu_BotEvent( void* ptr, int event ) {
00120     if (event != QM_ACTIVATED) {
00121         return;
00122     }
00123 
00124     removeBotsMenuInfo.bots[removeBotsMenuInfo.selectedBotNum].color = color_orange;
00125     removeBotsMenuInfo.selectedBotNum = ((menucommon_s*)ptr)->id - ID_BOTNAME0;
00126     removeBotsMenuInfo.bots[removeBotsMenuInfo.selectedBotNum].color = color_white;
00127 }
00128 
00129 
00130 /*
00131 =================
00132 UI_RemoveAddBotsMenu_BackEvent
00133 =================
00134 */
00135 static void UI_RemoveBotsMenu_BackEvent( void* ptr, int event ) {
00136     if (event != QM_ACTIVATED) {
00137         return;
00138     }
00139     UI_PopMenu();
00140 }
00141 
00142 
00143 /*
00144 =================
00145 UI_RemoveBotsMenu_UpEvent
00146 =================
00147 */
00148 static void UI_RemoveBotsMenu_UpEvent( void* ptr, int event ) {
00149     if (event != QM_ACTIVATED) {
00150         return;
00151     }
00152 
00153     if( removeBotsMenuInfo.baseBotNum > 0 ) {
00154         removeBotsMenuInfo.baseBotNum--;
00155         UI_RemoveBotsMenu_SetBotNames();
00156     }
00157 }
00158 
00159 
00160 /*
00161 =================
00162 UI_RemoveBotsMenu_DownEvent
00163 =================
00164 */
00165 static void UI_RemoveBotsMenu_DownEvent( void* ptr, int event ) {
00166     if (event != QM_ACTIVATED) {
00167         return;
00168     }
00169 
00170     if( removeBotsMenuInfo.baseBotNum + 7 < removeBotsMenuInfo.numBots ) {
00171         removeBotsMenuInfo.baseBotNum++;
00172         UI_RemoveBotsMenu_SetBotNames();
00173     }
00174 }
00175 
00176 
00177 /*
00178 =================
00179 UI_RemoveBotsMenu_GetBots
00180 =================
00181 */
00182 static void UI_RemoveBotsMenu_GetBots( void ) {
00183     int     numPlayers;
00184     int     isBot;
00185     int     n;
00186     char    info[MAX_INFO_STRING];
00187 
00188     trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) );
00189     numPlayers = atoi( Info_ValueForKey( info, "sv_maxclients" ) );
00190     removeBotsMenuInfo.numBots = 0;
00191 
00192     for( n = 0; n < numPlayers; n++ ) {
00193         trap_GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING );
00194 
00195         isBot = atoi( Info_ValueForKey( info, "skill" ) );
00196         if( !isBot ) {
00197             continue;
00198         }
00199 
00200         removeBotsMenuInfo.botClientNums[removeBotsMenuInfo.numBots] = n;
00201         removeBotsMenuInfo.numBots++;
00202     }
00203 }
00204 
00205 
00206 /*
00207 =================
00208 UI_RemoveBots_Cache
00209 =================
00210 */
00211 void UI_RemoveBots_Cache( void ) {
00212     trap_R_RegisterShaderNoMip( ART_BACKGROUND );
00213     trap_R_RegisterShaderNoMip( ART_BACK0 );
00214     trap_R_RegisterShaderNoMip( ART_BACK1 );
00215     trap_R_RegisterShaderNoMip( ART_DELETE0 );
00216     trap_R_RegisterShaderNoMip( ART_DELETE1 );
00217 }
00218 
00219 
00220 /*
00221 =================
00222 UI_RemoveBotsMenu_Init
00223 =================
00224 */
00225 static void UI_RemoveBotsMenu_Init( void ) {
00226     int     n;
00227     int     count;
00228     int     y;
00229 
00230     memset( &removeBotsMenuInfo, 0 ,sizeof(removeBotsMenuInfo) );
00231     removeBotsMenuInfo.menu.fullscreen = qfalse;
00232     removeBotsMenuInfo.menu.wrapAround = qtrue;
00233 
00234     UI_RemoveBots_Cache();
00235 
00236     UI_RemoveBotsMenu_GetBots();
00237     UI_RemoveBotsMenu_SetBotNames();
00238     count = removeBotsMenuInfo.numBots < 7 ? removeBotsMenuInfo.numBots : 7;
00239 
00240     removeBotsMenuInfo.banner.generic.type      = MTYPE_BTEXT;
00241     removeBotsMenuInfo.banner.generic.x         = 320;
00242     removeBotsMenuInfo.banner.generic.y         = 16;
00243     removeBotsMenuInfo.banner.string            = "REMOVE BOTS";
00244     removeBotsMenuInfo.banner.color             = color_white;
00245     removeBotsMenuInfo.banner.style             = UI_CENTER;
00246 
00247     removeBotsMenuInfo.background.generic.type  = MTYPE_BITMAP;
00248     removeBotsMenuInfo.background.generic.name  = ART_BACKGROUND;
00249     removeBotsMenuInfo.background.generic.flags = QMF_INACTIVE;
00250     removeBotsMenuInfo.background.generic.x     = 320-233;
00251     removeBotsMenuInfo.background.generic.y     = 240-166;
00252     removeBotsMenuInfo.background.width         = 466;
00253     removeBotsMenuInfo.background.height        = 332;
00254 
00255     removeBotsMenuInfo.arrows.generic.type      = MTYPE_BITMAP;
00256     removeBotsMenuInfo.arrows.generic.name      = ART_ARROWS;
00257     removeBotsMenuInfo.arrows.generic.flags     = QMF_INACTIVE;
00258     removeBotsMenuInfo.arrows.generic.x         = 200;
00259     removeBotsMenuInfo.arrows.generic.y         = 128;
00260     removeBotsMenuInfo.arrows.width             = 64;
00261     removeBotsMenuInfo.arrows.height            = 128;
00262 
00263     removeBotsMenuInfo.up.generic.type          = MTYPE_BITMAP;
00264     removeBotsMenuInfo.up.generic.flags         = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00265     removeBotsMenuInfo.up.generic.x             = 200;
00266     removeBotsMenuInfo.up.generic.y             = 128;
00267     removeBotsMenuInfo.up.generic.id            = ID_UP;
00268     removeBotsMenuInfo.up.generic.callback      = UI_RemoveBotsMenu_UpEvent;
00269     removeBotsMenuInfo.up.width                 = 64;
00270     removeBotsMenuInfo.up.height                = 64;
00271     removeBotsMenuInfo.up.focuspic              = ART_ARROWUP;
00272 
00273     removeBotsMenuInfo.down.generic.type        = MTYPE_BITMAP;
00274     removeBotsMenuInfo.down.generic.flags       = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00275     removeBotsMenuInfo.down.generic.x           = 200;
00276     removeBotsMenuInfo.down.generic.y           = 128+64;
00277     removeBotsMenuInfo.down.generic.id          = ID_DOWN;
00278     removeBotsMenuInfo.down.generic.callback    = UI_RemoveBotsMenu_DownEvent;
00279     removeBotsMenuInfo.down.width               = 64;
00280     removeBotsMenuInfo.down.height              = 64;
00281     removeBotsMenuInfo.down.focuspic            = ART_ARROWDOWN;
00282 
00283     for( n = 0, y = 120; n < count; n++, y += 20 ) {
00284         removeBotsMenuInfo.bots[n].generic.type     = MTYPE_PTEXT;
00285         removeBotsMenuInfo.bots[n].generic.flags    = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00286         removeBotsMenuInfo.bots[n].generic.id       = ID_BOTNAME0 + n;
00287         removeBotsMenuInfo.bots[n].generic.x        = 320 - 56;
00288         removeBotsMenuInfo.bots[n].generic.y        = y;
00289         removeBotsMenuInfo.bots[n].generic.callback = UI_RemoveBotsMenu_BotEvent;
00290         removeBotsMenuInfo.bots[n].string           = removeBotsMenuInfo.botnames[n];
00291         removeBotsMenuInfo.bots[n].color            = color_orange;
00292         removeBotsMenuInfo.bots[n].style            = UI_LEFT|UI_SMALLFONT;
00293     }
00294 
00295     removeBotsMenuInfo.delete.generic.type      = MTYPE_BITMAP;
00296     removeBotsMenuInfo.delete.generic.name      = ART_DELETE0;
00297     removeBotsMenuInfo.delete.generic.flags     = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00298     removeBotsMenuInfo.delete.generic.id        = ID_DELETE;
00299     removeBotsMenuInfo.delete.generic.callback  = UI_RemoveBotsMenu_DeleteEvent;
00300     removeBotsMenuInfo.delete.generic.x         = 320+128-128;
00301     removeBotsMenuInfo.delete.generic.y         = 256+128-64;
00302     removeBotsMenuInfo.delete.width             = 128;
00303     removeBotsMenuInfo.delete.height            = 64;
00304     removeBotsMenuInfo.delete.focuspic          = ART_DELETE1;
00305 
00306     removeBotsMenuInfo.back.generic.type        = MTYPE_BITMAP;
00307     removeBotsMenuInfo.back.generic.name        = ART_BACK0;
00308     removeBotsMenuInfo.back.generic.flags       = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00309     removeBotsMenuInfo.back.generic.id          = ID_BACK;
00310     removeBotsMenuInfo.back.generic.callback    = UI_RemoveBotsMenu_BackEvent;
00311     removeBotsMenuInfo.back.generic.x           = 320-128;
00312     removeBotsMenuInfo.back.generic.y           = 256+128-64;
00313     removeBotsMenuInfo.back.width               = 128;
00314     removeBotsMenuInfo.back.height              = 64;
00315     removeBotsMenuInfo.back.focuspic            = ART_BACK1;
00316 
00317     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.background );
00318     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.banner );
00319     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.arrows );
00320     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.up );
00321     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.down );
00322     for( n = 0; n < count; n++ ) {
00323         Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.bots[n] );
00324     }
00325     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.delete );
00326     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.back );
00327 
00328     removeBotsMenuInfo.baseBotNum = 0;
00329     removeBotsMenuInfo.selectedBotNum = 0;
00330     removeBotsMenuInfo.bots[0].color = color_white;
00331 }
00332 
00333 
00334 /*
00335 =================
00336 UI_RemoveBotsMenu
00337 =================
00338 */
00339 void UI_RemoveBotsMenu( void ) {
00340     UI_RemoveBotsMenu_Init();
00341     UI_PushMenu( &removeBotsMenuInfo.menu );
00342 }

Generated on Thu Aug 25 12:37:43 2005 for Quake III Arena by  doxygen 1.3.9.1