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

ui_addbots.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 ADD BOTS MENU
00027 
00028 =======================================================================
00029 */
00030 
00031 
00032 #include "ui_local.h"
00033 
00034 
00035 #define ART_BACK0           "menu/art/back_0"
00036 #define ART_BACK1           "menu/art/back_1"   
00037 #define ART_FIGHT0          "menu/art/accept_0"
00038 #define ART_FIGHT1          "menu/art/accept_1"
00039 #define ART_BACKGROUND      "menu/art/addbotframe"
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_BACK             10
00045 #define ID_GO               11
00046 #define ID_LIST             12
00047 #define ID_UP               13
00048 #define ID_DOWN             14
00049 #define ID_SKILL            15
00050 #define ID_TEAM             16
00051 #define ID_BOTNAME0         20
00052 #define ID_BOTNAME1         21
00053 #define ID_BOTNAME2         22
00054 #define ID_BOTNAME3         23
00055 #define ID_BOTNAME4         24
00056 #define ID_BOTNAME5         25
00057 #define ID_BOTNAME6         26
00058 
00059 
00060 typedef struct {
00061     menuframework_s menu;
00062     menubitmap_s    arrows;
00063     menubitmap_s    up;
00064     menubitmap_s    down;
00065     menutext_s      bots[7];
00066     menulist_s      skill;
00067     menulist_s      team;
00068     menubitmap_s    go;
00069     menubitmap_s    back;
00070 
00071     int             numBots;
00072     int             delay;
00073     int             baseBotNum;
00074     int             selectedBotNum;
00075     int             sortedBotNums[MAX_BOTS];
00076     char            botnames[7][32];
00077 } addBotsMenuInfo_t;
00078 
00079 static addBotsMenuInfo_t    addBotsMenuInfo;
00080 
00081 
00082 /*
00083 =================
00084 UI_AddBotsMenu_FightEvent
00085 =================
00086 */
00087 static void UI_AddBotsMenu_FightEvent( void* ptr, int event ) {
00088     const char  *team;
00089     int         skill;
00090 
00091     if (event != QM_ACTIVATED) {
00092         return;
00093     }
00094 
00095     team = addBotsMenuInfo.team.itemnames[addBotsMenuInfo.team.curvalue];
00096     skill = addBotsMenuInfo.skill.curvalue + 1;
00097 
00098     trap_Cmd_ExecuteText( EXEC_APPEND, va("addbot %s %i %s %i\n",
00099         addBotsMenuInfo.botnames[addBotsMenuInfo.selectedBotNum], skill, team, addBotsMenuInfo.delay) );
00100 
00101     addBotsMenuInfo.delay += 1500;
00102 }
00103 
00104 
00105 /*
00106 =================
00107 UI_AddBotsMenu_BotEvent
00108 =================
00109 */
00110 static void UI_AddBotsMenu_BotEvent( void* ptr, int event ) {
00111     if (event != QM_ACTIVATED) {
00112         return;
00113     }
00114 
00115     addBotsMenuInfo.bots[addBotsMenuInfo.selectedBotNum].color = color_orange;
00116     addBotsMenuInfo.selectedBotNum = ((menucommon_s*)ptr)->id - ID_BOTNAME0;
00117     addBotsMenuInfo.bots[addBotsMenuInfo.selectedBotNum].color = color_white;
00118 }
00119 
00120 
00121 /*
00122 =================
00123 UI_AddBotsMenu_BackEvent
00124 =================
00125 */
00126 static void UI_AddBotsMenu_BackEvent( void* ptr, int event ) {
00127     if (event != QM_ACTIVATED) {
00128         return;
00129     }
00130     UI_PopMenu();
00131 }
00132 
00133 
00134 /*
00135 =================
00136 UI_AddBotsMenu_SetBotNames
00137 =================
00138 */
00139 static void UI_AddBotsMenu_SetBotNames( void ) {
00140     int         n;
00141     const char  *info;
00142 
00143     for ( n = 0; n < 7; n++ ) {
00144         info = UI_GetBotInfoByNumber( addBotsMenuInfo.sortedBotNums[addBotsMenuInfo.baseBotNum + n] );
00145         Q_strncpyz( addBotsMenuInfo.botnames[n], Info_ValueForKey( info, "name" ), sizeof(addBotsMenuInfo.botnames[n]) );
00146     }
00147 
00148 }
00149 
00150 
00151 /*
00152 =================
00153 UI_AddBotsMenu_UpEvent
00154 =================
00155 */
00156 static void UI_AddBotsMenu_UpEvent( void* ptr, int event ) {
00157     if (event != QM_ACTIVATED) {
00158         return;
00159     }
00160 
00161     if( addBotsMenuInfo.baseBotNum > 0 ) {
00162         addBotsMenuInfo.baseBotNum--;
00163         UI_AddBotsMenu_SetBotNames();
00164     }
00165 }
00166 
00167 
00168 /*
00169 =================
00170 UI_AddBotsMenu_DownEvent
00171 =================
00172 */
00173 static void UI_AddBotsMenu_DownEvent( void* ptr, int event ) {
00174     if (event != QM_ACTIVATED) {
00175         return;
00176     }
00177 
00178     if( addBotsMenuInfo.baseBotNum + 7 < addBotsMenuInfo.numBots ) {
00179         addBotsMenuInfo.baseBotNum++;
00180         UI_AddBotsMenu_SetBotNames();
00181     }
00182 }
00183 
00184 
00185 /*
00186 =================
00187 UI_AddBotsMenu_GetSortedBotNums
00188 =================
00189 */
00190 static int QDECL UI_AddBotsMenu_SortCompare( const void *arg1, const void *arg2 ) {
00191     int         num1, num2;
00192     const char  *info1, *info2;
00193     const char  *name1, *name2;
00194 
00195     num1 = *(int *)arg1;
00196     num2 = *(int *)arg2;
00197 
00198     info1 = UI_GetBotInfoByNumber( num1 );
00199     info2 = UI_GetBotInfoByNumber( num2 );
00200 
00201     name1 = Info_ValueForKey( info1, "name" );
00202     name2 = Info_ValueForKey( info2, "name" );
00203 
00204     return Q_stricmp( name1, name2 );
00205 }
00206 
00207 static void UI_AddBotsMenu_GetSortedBotNums( void ) {
00208     int     n;
00209 
00210     // initialize the array
00211     for( n = 0; n < addBotsMenuInfo.numBots; n++ ) {
00212         addBotsMenuInfo.sortedBotNums[n] = n;
00213     }
00214 
00215     qsort( addBotsMenuInfo.sortedBotNums, addBotsMenuInfo.numBots, sizeof(addBotsMenuInfo.sortedBotNums[0]), UI_AddBotsMenu_SortCompare );
00216 }
00217 
00218 
00219 /*
00220 =================
00221 UI_AddBotsMenu_Draw
00222 =================
00223 */
00224 static void UI_AddBotsMenu_Draw( void ) {
00225     UI_DrawBannerString( 320, 16, "ADD BOTS", UI_CENTER, color_white );
00226     UI_DrawNamedPic( 320-233, 240-166, 466, 332, ART_BACKGROUND );
00227 
00228     // standard menu drawing
00229     Menu_Draw( &addBotsMenuInfo.menu );
00230 }
00231 
00232     
00233 /*
00234 =================
00235 UI_AddBotsMenu_Init
00236 =================
00237 */
00238 static const char *skillNames[] = {
00239     "I Can Win",
00240     "Bring It On",
00241     "Hurt Me Plenty",
00242     "Hardcore",
00243     "Nightmare!",
00244     0
00245 };
00246 
00247 static const char *teamNames1[] = {
00248     "Free",
00249     0
00250 };
00251 
00252 static const char *teamNames2[] = {
00253     "Red",
00254     "Blue",
00255     0
00256 };
00257 
00258 static void UI_AddBotsMenu_Init( void ) {
00259     int     n;
00260     int     y;
00261     int     gametype;
00262     int     count;
00263     char    info[MAX_INFO_STRING];
00264 
00265     trap_GetConfigString(CS_SERVERINFO, info, MAX_INFO_STRING);   
00266     gametype = atoi( Info_ValueForKey( info,"g_gametype" ) );
00267 
00268     memset( &addBotsMenuInfo, 0 ,sizeof(addBotsMenuInfo) );
00269     addBotsMenuInfo.menu.draw = UI_AddBotsMenu_Draw;
00270     addBotsMenuInfo.menu.fullscreen = qfalse;
00271     addBotsMenuInfo.menu.wrapAround = qtrue;
00272     addBotsMenuInfo.delay = 1000;
00273 
00274     UI_AddBots_Cache();
00275 
00276     addBotsMenuInfo.numBots = UI_GetNumBots();
00277     count = addBotsMenuInfo.numBots < 7 ? addBotsMenuInfo.numBots : 7;
00278 
00279     addBotsMenuInfo.arrows.generic.type  = MTYPE_BITMAP;
00280     addBotsMenuInfo.arrows.generic.name  = ART_ARROWS;
00281     addBotsMenuInfo.arrows.generic.flags = QMF_INACTIVE;
00282     addBotsMenuInfo.arrows.generic.x     = 200;
00283     addBotsMenuInfo.arrows.generic.y     = 128;
00284     addBotsMenuInfo.arrows.width         = 64;
00285     addBotsMenuInfo.arrows.height        = 128;
00286 
00287     addBotsMenuInfo.up.generic.type     = MTYPE_BITMAP;
00288     addBotsMenuInfo.up.generic.flags    = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00289     addBotsMenuInfo.up.generic.x        = 200;
00290     addBotsMenuInfo.up.generic.y        = 128;
00291     addBotsMenuInfo.up.generic.id       = ID_UP;
00292     addBotsMenuInfo.up.generic.callback = UI_AddBotsMenu_UpEvent;
00293     addBotsMenuInfo.up.width            = 64;
00294     addBotsMenuInfo.up.height           = 64;
00295     addBotsMenuInfo.up.focuspic         = ART_ARROWUP;
00296 
00297     addBotsMenuInfo.down.generic.type     = MTYPE_BITMAP;
00298     addBotsMenuInfo.down.generic.flags    = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00299     addBotsMenuInfo.down.generic.x        = 200;
00300     addBotsMenuInfo.down.generic.y        = 128+64;
00301     addBotsMenuInfo.down.generic.id       = ID_DOWN;
00302     addBotsMenuInfo.down.generic.callback = UI_AddBotsMenu_DownEvent;
00303     addBotsMenuInfo.down.width            = 64;
00304     addBotsMenuInfo.down.height           = 64;
00305     addBotsMenuInfo.down.focuspic         = ART_ARROWDOWN;
00306 
00307     for( n = 0, y = 120; n < count; n++, y += 20 ) {
00308         addBotsMenuInfo.bots[n].generic.type        = MTYPE_PTEXT;
00309         addBotsMenuInfo.bots[n].generic.flags       = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00310         addBotsMenuInfo.bots[n].generic.id          = ID_BOTNAME0 + n;
00311         addBotsMenuInfo.bots[n].generic.x           = 320 - 56;
00312         addBotsMenuInfo.bots[n].generic.y           = y;
00313         addBotsMenuInfo.bots[n].generic.callback    = UI_AddBotsMenu_BotEvent;
00314         addBotsMenuInfo.bots[n].string              = addBotsMenuInfo.botnames[n];
00315         addBotsMenuInfo.bots[n].color               = color_orange;
00316         addBotsMenuInfo.bots[n].style               = UI_LEFT|UI_SMALLFONT;
00317     }
00318 
00319     y += 12;
00320     addBotsMenuInfo.skill.generic.type      = MTYPE_SPINCONTROL;
00321     addBotsMenuInfo.skill.generic.flags     = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
00322     addBotsMenuInfo.skill.generic.x         = 320;
00323     addBotsMenuInfo.skill.generic.y         = y;
00324     addBotsMenuInfo.skill.generic.name      = "Skill:";
00325     addBotsMenuInfo.skill.generic.id        = ID_SKILL;
00326     addBotsMenuInfo.skill.itemnames         = skillNames;
00327     addBotsMenuInfo.skill.curvalue          = Com_Clamp( 0, 4, (int)trap_Cvar_VariableValue( "g_spSkill" ) - 1 );
00328 
00329     y += SMALLCHAR_HEIGHT;
00330     addBotsMenuInfo.team.generic.type       = MTYPE_SPINCONTROL;
00331     addBotsMenuInfo.team.generic.flags      = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
00332     addBotsMenuInfo.team.generic.x          = 320;
00333     addBotsMenuInfo.team.generic.y          = y;
00334     addBotsMenuInfo.team.generic.name       = "Team: ";
00335     addBotsMenuInfo.team.generic.id         = ID_TEAM;
00336     if( gametype >= GT_TEAM ) {
00337         addBotsMenuInfo.team.itemnames      = teamNames2;
00338     }
00339     else {
00340         addBotsMenuInfo.team.itemnames      = teamNames1;
00341         addBotsMenuInfo.team.generic.flags  = QMF_GRAYED;
00342     }
00343 
00344     addBotsMenuInfo.go.generic.type         = MTYPE_BITMAP;
00345     addBotsMenuInfo.go.generic.name         = ART_FIGHT0;
00346     addBotsMenuInfo.go.generic.flags        = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00347     addBotsMenuInfo.go.generic.id           = ID_GO;
00348     addBotsMenuInfo.go.generic.callback     = UI_AddBotsMenu_FightEvent;
00349     addBotsMenuInfo.go.generic.x            = 320+128-128;
00350     addBotsMenuInfo.go.generic.y            = 256+128-64;
00351     addBotsMenuInfo.go.width                = 128;
00352     addBotsMenuInfo.go.height               = 64;
00353     addBotsMenuInfo.go.focuspic             = ART_FIGHT1;
00354 
00355     addBotsMenuInfo.back.generic.type       = MTYPE_BITMAP;
00356     addBotsMenuInfo.back.generic.name       = ART_BACK0;
00357     addBotsMenuInfo.back.generic.flags      = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
00358     addBotsMenuInfo.back.generic.id         = ID_BACK;
00359     addBotsMenuInfo.back.generic.callback   = UI_AddBotsMenu_BackEvent;
00360     addBotsMenuInfo.back.generic.x          = 320-128;
00361     addBotsMenuInfo.back.generic.y          = 256+128-64;
00362     addBotsMenuInfo.back.width              = 128;
00363     addBotsMenuInfo.back.height             = 64;
00364     addBotsMenuInfo.back.focuspic           = ART_BACK1;
00365 
00366     addBotsMenuInfo.baseBotNum = 0;
00367     addBotsMenuInfo.selectedBotNum = 0;
00368     addBotsMenuInfo.bots[0].color = color_white;
00369 
00370     UI_AddBotsMenu_GetSortedBotNums();
00371     UI_AddBotsMenu_SetBotNames();
00372 
00373     Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.arrows );
00374 
00375     Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.up );
00376     Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.down );
00377     for( n = 0; n < count; n++ ) {
00378         Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.bots[n] );
00379     }
00380     Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.skill );
00381     Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.team );
00382     Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.go );
00383     Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.back );
00384 }
00385 
00386 
00387 /*
00388 =================
00389 UI_AddBots_Cache
00390 =================
00391 */
00392 void UI_AddBots_Cache( void ) {
00393     trap_R_RegisterShaderNoMip( ART_BACK0 );
00394     trap_R_RegisterShaderNoMip( ART_BACK1 );
00395     trap_R_RegisterShaderNoMip( ART_FIGHT0 );
00396     trap_R_RegisterShaderNoMip( ART_FIGHT1 );
00397     trap_R_RegisterShaderNoMip( ART_BACKGROUND );
00398     trap_R_RegisterShaderNoMip( ART_ARROWS );
00399     trap_R_RegisterShaderNoMip( ART_ARROWUP );
00400     trap_R_RegisterShaderNoMip( ART_ARROWDOWN );
00401 }
00402 
00403 
00404 /*
00405 =================
00406 UI_AddBotsMenu
00407 =================
00408 */
00409 void UI_AddBotsMenu( void ) {
00410     UI_AddBotsMenu_Init();
00411     UI_PushMenu( &addBotsMenuInfo.menu );
00412 }

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