Debian Codegraph @

code/q3_ui/ui_addbots.c

raw symbols SCIP
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 Quake III Arena source code; 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 ADD BOTS MENU
27
28 =======================================================================
29 */
30
31
32 #include "ui_local.h"
33
34
35 #define ART_BACK0 "menu/art/back_0"
36 #define ART_BACK1 "menu/art/back_1"
37 #define ART_FIGHT0 "menu/art/accept_0"
38 #define ART_FIGHT1 "menu/art/accept_1"
39 #define ART_BACKGROUND "menu/art/addbotframe"
40 #define ART_ARROWS "menu/art/arrows_vert_0"
41 #define ART_ARROWUP "menu/art/arrows_vert_top"
42 #define ART_ARROWDOWN "menu/art/arrows_vert_bot"
43
44 #define ID_BACK 10
45 #define ID_GO 11
46 #define ID_LIST 12
47 #define ID_UP 13
48 #define ID_DOWN 14
49 #define ID_SKILL 15
50 #define ID_TEAM 16
51 #define ID_BOTNAME0 20
52 #define ID_BOTNAME1 21
53 #define ID_BOTNAME2 22
54 #define ID_BOTNAME3 23
55 #define ID_BOTNAME4 24
56 #define ID_BOTNAME5 25
57 #define ID_BOTNAME6 26
58
59
60 typedef struct {
61 menuframework_s menu;
62
63 menutext_s banner;
64 menubitmap_s background;
65
66 menubitmap_s arrows;
67 menubitmap_s up;
68 menubitmap_s down;
69
70 menutext_s bots[7];
71
72 menulist_s skill;
73 menulist_s team;
74 menubitmap_s go;
75 menubitmap_s back;
76
77 int numBots;
78 int delay;
79 int baseBotNum;
80 int selectedBotNum;
81 int sortedBotNums[MAX_BOTS];
82 char botnames[7][32];
83 } addBotsMenuInfo_t;
84
85 static addBotsMenuInfo_t addBotsMenuInfo;
86
87
88 /*
89 =================
90 UI_AddBotsMenu_FightEvent
91 =================
92 */
93 static void UI_AddBotsMenu_FightEvent( void* ptr, int event ) {
94 const char *team;
95 int skill;
96
97 if (event != QM_ACTIVATED) {
98 return;
99 }
100
101 team = addBotsMenuInfo.team.itemnames[addBotsMenuInfo.team.curvalue];
102 skill = addBotsMenuInfo.skill.curvalue + 1;
103
104 trap_Cmd_ExecuteText( EXEC_APPEND, va("addbot %s %i %s %i\n",
105 addBotsMenuInfo.botnames[addBotsMenuInfo.selectedBotNum], skill, team, addBotsMenuInfo.delay) );
106
107 addBotsMenuInfo.delay += 1500;
108 }
109
110
111 /*
112 =================
113 UI_AddBotsMenu_BotEvent
114 =================
115 */
116 static void UI_AddBotsMenu_BotEvent( void* ptr, int event ) {
117 if (event != QM_ACTIVATED) {
118 return;
119 }
120
121 addBotsMenuInfo.bots[addBotsMenuInfo.selectedBotNum].color = color_orange;
122 addBotsMenuInfo.selectedBotNum = ((menucommon_s*)ptr)->id - ID_BOTNAME0;
123 addBotsMenuInfo.bots[addBotsMenuInfo.selectedBotNum].color = color_white;
124 }
125
126
127 /*
128 =================
129 UI_AddBotsMenu_BackEvent
130 =================
131 */
132 static void UI_AddBotsMenu_BackEvent( void* ptr, int event ) {
133 if (event != QM_ACTIVATED) {
134 return;
135 }
136 UI_PopMenu();
137 }
138
139
140 /*
141 =================
142 UI_AddBotsMenu_SetBotNames
143 =================
144 */
145 static void UI_AddBotsMenu_SetBotNames( void ) {
146 int n;
147 const char *info;
148
149 for ( n = 0; n < 7; n++ ) {
150 info = UI_GetBotInfoByNumber( addBotsMenuInfo.sortedBotNums[addBotsMenuInfo.baseBotNum + n] );
151 Q_strncpyz( addBotsMenuInfo.botnames[n], Info_ValueForKey( info, "name" ), sizeof(addBotsMenuInfo.botnames[n]) );
152 }
153
154 }
155
156
157 /*
158 =================
159 UI_AddBotsMenu_UpEvent
160 =================
161 */
162 static void UI_AddBotsMenu_UpEvent( void* ptr, int event ) {
163 if (event != QM_ACTIVATED) {
164 return;
165 }
166
167 if( addBotsMenuInfo.baseBotNum > 0 ) {
168 addBotsMenuInfo.baseBotNum--;
169 UI_AddBotsMenu_SetBotNames();
170 }
171 }
172
173
174 /*
175 =================
176 UI_AddBotsMenu_DownEvent
177 =================
178 */
179 static void UI_AddBotsMenu_DownEvent( void* ptr, int event ) {
180 if (event != QM_ACTIVATED) {
181 return;
182 }
183
184 if( addBotsMenuInfo.baseBotNum + 7 < addBotsMenuInfo.numBots ) {
185 addBotsMenuInfo.baseBotNum++;
186 UI_AddBotsMenu_SetBotNames();
187 }
188 }
189
190
191 /*
192 =================
193 UI_AddBotsMenu_GetSortedBotNums
194 =================
195 */
196 static int QDECL UI_AddBotsMenu_SortCompare( const void *arg1, const void *arg2 ) {
197 int num1, num2;
198 const char *info1, *info2;
199 const char *name1, *name2;
200
201 num1 = *(int *)arg1;
202 num2 = *(int *)arg2;
203
204 info1 = UI_GetBotInfoByNumber( num1 );
205 info2 = UI_GetBotInfoByNumber( num2 );
206
207 name1 = Info_ValueForKey( info1, "name" );
208 name2 = Info_ValueForKey( info2, "name" );
209
210 return Q_stricmp( name1, name2 );
211 }
212
213 static void UI_AddBotsMenu_GetSortedBotNums( void ) {
214 int n;
215
216 // initialize the array
217 for( n = 0; n < addBotsMenuInfo.numBots; n++ ) {
218 addBotsMenuInfo.sortedBotNums[n] = n;
219 }
220
221 qsort( addBotsMenuInfo.sortedBotNums, addBotsMenuInfo.numBots, sizeof(addBotsMenuInfo.sortedBotNums[0]), UI_AddBotsMenu_SortCompare );
222 }
223
224 /*
225 =================
226 UI_AddBotsMenu_Init
227 =================
228 */
229 static const char *skillNames[] = {
230 "I Can Win",
231 "Bring It On",
232 "Hurt Me Plenty",
233 "Hardcore",
234 "Nightmare!",
235 NULL
236 };
237
238 static const char *teamNames1[] = {
239 "Free",
240 NULL
241 };
242
243 static const char *teamNames2[] = {
244 "Red",
245 "Blue",
246 NULL
247 };
248
249 static void UI_AddBotsMenu_Init( void ) {
250 int n;
251 int y;
252 int gametype;
253 int count;
254 char info[MAX_INFO_STRING];
255
256 trap_GetConfigString(CS_SERVERINFO, info, MAX_INFO_STRING);
257 gametype = atoi( Info_ValueForKey( info,"g_gametype" ) );
258
259 memset( &addBotsMenuInfo, 0 ,sizeof(addBotsMenuInfo) );
260 addBotsMenuInfo.menu.fullscreen = qfalse;
261 addBotsMenuInfo.menu.wrapAround = qtrue;
262 addBotsMenuInfo.delay = 1000;
263
264 UI_AddBots_Cache();
265
266 addBotsMenuInfo.numBots = UI_GetNumBots();
267 count = addBotsMenuInfo.numBots < 7 ? addBotsMenuInfo.numBots : 7;
268
269 addBotsMenuInfo.banner.generic.type = MTYPE_BTEXT;
270 addBotsMenuInfo.banner.generic.x = 320;
271 addBotsMenuInfo.banner.generic.y = 16;
272 addBotsMenuInfo.banner.string = "ADD BOTS";
273 addBotsMenuInfo.banner.color = color_white;
274 addBotsMenuInfo.banner.style = UI_CENTER;
275
276 addBotsMenuInfo.background.generic.type = MTYPE_BITMAP;
277 addBotsMenuInfo.background.generic.name = ART_BACKGROUND;
278 addBotsMenuInfo.background.generic.flags = QMF_INACTIVE;
279 addBotsMenuInfo.background.generic.x = 320-233;
280 addBotsMenuInfo.background.generic.y = 240-166;
281 addBotsMenuInfo.background.width = 466;
282 addBotsMenuInfo.background.height = 332;
283
284 addBotsMenuInfo.arrows.generic.type = MTYPE_BITMAP;
285 addBotsMenuInfo.arrows.generic.name = ART_ARROWS;
286 addBotsMenuInfo.arrows.generic.flags = QMF_INACTIVE;
287 addBotsMenuInfo.arrows.generic.x = 200;
288 addBotsMenuInfo.arrows.generic.y = 128;
289 addBotsMenuInfo.arrows.width = 64;
290 addBotsMenuInfo.arrows.height = 128;
291
292 addBotsMenuInfo.up.generic.type = MTYPE_BITMAP;
293 addBotsMenuInfo.up.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
294 addBotsMenuInfo.up.generic.x = 200;
295 addBotsMenuInfo.up.generic.y = 128;
296 addBotsMenuInfo.up.generic.id = ID_UP;
297 addBotsMenuInfo.up.generic.callback = UI_AddBotsMenu_UpEvent;
298 addBotsMenuInfo.up.width = 64;
299 addBotsMenuInfo.up.height = 64;
300 addBotsMenuInfo.up.focuspic = ART_ARROWUP;
301
302 addBotsMenuInfo.down.generic.type = MTYPE_BITMAP;
303 addBotsMenuInfo.down.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
304 addBotsMenuInfo.down.generic.x = 200;
305 addBotsMenuInfo.down.generic.y = 128+64;
306 addBotsMenuInfo.down.generic.id = ID_DOWN;
307 addBotsMenuInfo.down.generic.callback = UI_AddBotsMenu_DownEvent;
308 addBotsMenuInfo.down.width = 64;
309 addBotsMenuInfo.down.height = 64;
310 addBotsMenuInfo.down.focuspic = ART_ARROWDOWN;
311
312 for( n = 0, y = 120; n < count; n++, y += 20 ) {
313 addBotsMenuInfo.bots[n].generic.type = MTYPE_PTEXT;
314 addBotsMenuInfo.bots[n].generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
315 addBotsMenuInfo.bots[n].generic.id = ID_BOTNAME0 + n;
316 addBotsMenuInfo.bots[n].generic.x = 320 - 56;
317 addBotsMenuInfo.bots[n].generic.y = y;
318 addBotsMenuInfo.bots[n].generic.callback = UI_AddBotsMenu_BotEvent;
319 addBotsMenuInfo.bots[n].string = addBotsMenuInfo.botnames[n];
320 addBotsMenuInfo.bots[n].color = color_orange;
321 addBotsMenuInfo.bots[n].style = UI_LEFT|UI_SMALLFONT;
322 }
323
324 y += 12;
325 addBotsMenuInfo.skill.generic.type = MTYPE_SPINCONTROL;
326 addBotsMenuInfo.skill.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
327 addBotsMenuInfo.skill.generic.x = 320;
328 addBotsMenuInfo.skill.generic.y = y;
329 addBotsMenuInfo.skill.generic.name = "Skill:";
330 addBotsMenuInfo.skill.generic.id = ID_SKILL;
331 addBotsMenuInfo.skill.itemnames = skillNames;
332 addBotsMenuInfo.skill.curvalue = Com_Clamp( 0, 4, (int)trap_Cvar_VariableValue( "g_spSkill" ) - 1 );
333
334 y += SMALLCHAR_HEIGHT;
335 addBotsMenuInfo.team.generic.type = MTYPE_SPINCONTROL;
336 addBotsMenuInfo.team.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
337 addBotsMenuInfo.team.generic.x = 320;
338 addBotsMenuInfo.team.generic.y = y;
339 addBotsMenuInfo.team.generic.name = "Team: ";
340 addBotsMenuInfo.team.generic.id = ID_TEAM;
341 if( gametype >= GT_TEAM ) {
342 addBotsMenuInfo.team.itemnames = teamNames2;
343 }
344 else {
345 addBotsMenuInfo.team.itemnames = teamNames1;
346 addBotsMenuInfo.team.generic.flags = QMF_GRAYED;
347 }
348
349 addBotsMenuInfo.go.generic.type = MTYPE_BITMAP;
350 addBotsMenuInfo.go.generic.name = ART_FIGHT0;
351 addBotsMenuInfo.go.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
352 addBotsMenuInfo.go.generic.id = ID_GO;
353 addBotsMenuInfo.go.generic.callback = UI_AddBotsMenu_FightEvent;
354 addBotsMenuInfo.go.generic.x = 320+128-128;
355 addBotsMenuInfo.go.generic.y = 256+128-64;
356 addBotsMenuInfo.go.width = 128;
357 addBotsMenuInfo.go.height = 64;
358 addBotsMenuInfo.go.focuspic = ART_FIGHT1;
359
360 addBotsMenuInfo.back.generic.type = MTYPE_BITMAP;
361 addBotsMenuInfo.back.generic.name = ART_BACK0;
362 addBotsMenuInfo.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
363 addBotsMenuInfo.back.generic.id = ID_BACK;
364 addBotsMenuInfo.back.generic.callback = UI_AddBotsMenu_BackEvent;
365 addBotsMenuInfo.back.generic.x = 320-128;
366 addBotsMenuInfo.back.generic.y = 256+128-64;
367 addBotsMenuInfo.back.width = 128;
368 addBotsMenuInfo.back.height = 64;
369 addBotsMenuInfo.back.focuspic = ART_BACK1;
370
371 addBotsMenuInfo.baseBotNum = 0;
372 addBotsMenuInfo.selectedBotNum = 0;
373 addBotsMenuInfo.bots[0].color = color_white;
374
375 UI_AddBotsMenu_GetSortedBotNums();
376 UI_AddBotsMenu_SetBotNames();
377
378 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.background );
379 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.banner );
380 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.arrows );
381 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.up );
382 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.down );
383 for( n = 0; n < count; n++ ) {
384 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.bots[n] );
385 }
386 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.skill );
387 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.team );
388 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.go );
389 Menu_AddItem( &addBotsMenuInfo.menu, &addBotsMenuInfo.back );
390 }
391
392
393 /*
394 =================
395 UI_AddBots_Cache
396 =================
397 */
398 void UI_AddBots_Cache( void ) {
399 trap_R_RegisterShaderNoMip( ART_BACK0 );
400 trap_R_RegisterShaderNoMip( ART_BACK1 );
401 trap_R_RegisterShaderNoMip( ART_FIGHT0 );
402 trap_R_RegisterShaderNoMip( ART_FIGHT1 );
403 trap_R_RegisterShaderNoMip( ART_BACKGROUND );
404 trap_R_RegisterShaderNoMip( ART_ARROWS );
405 trap_R_RegisterShaderNoMip( ART_ARROWUP );
406 trap_R_RegisterShaderNoMip( ART_ARROWDOWN );
407 }
408
409
410 /*
411 =================
412 UI_AddBotsMenu
413 =================
414 */
415 void UI_AddBotsMenu( void ) {
416 UI_AddBotsMenu_Init();
417 UI_PushMenu( &addBotsMenuInfo.menu );
418 }