Debian Codegraph @

code/q3_ui/ui_votemenu.c

raw
1 /*
2 ===========================================================================
3 Copyright (C) 2009 Poul Sander
4
5 This file is part of the Open Arena source code.
6
7 Open 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 Open 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 Open 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 #include "ui_local.h"
24
25 #define VOTEMENU_BACK0 "menu/art_blueish/back_0"
26 #define VOTEMENU_BACK1 "menu/art_blueish/back_1"
27 #define ART_FIGHT0 "menu/art_blueish/accept_0"
28 #define ART_FIGHT1 "menu/art_blueish/accept_1"
29 #define ART_BACKGROUND "menu/art_blueish/addbotframe"
30
31 static char* votemenu_artlist[] =
32 {
33 VOTEMENU_BACK0,
34 VOTEMENU_BACK1,
35 ART_FIGHT0,
36 ART_FIGHT1,
37 NULL
38 };
39
40 #define ID_BACK 100
41 #define ID_GO 101
42 #define ID_NEXTMAP 102
43 #define ID_RESTART 103
44 #define ID_DOWARMUP 104
45 #define ID_MAP 105
46 #define ID_KICK 106
47 #define ID_FRAG 107
48 #define ID_TIME 108
49 #define ID_GAMETYPE 109
50 #define ID_CUSTOM 110
51 #define ID_SHUFFLE 111
52
53 //This sorta dependend on number of vote options
54 #define VOTEMENU_MENU_VERTICAL_SPACING 22
55
56 typedef struct
57 {
58 menuframework_s menu;
59 menutext_s banner;
60 menubitmap_s back;
61 menubitmap_s go;
62
63 //Allowed votes:
64 qboolean map_restart;
65 qboolean nextmap;
66 qboolean g_doWarmup;
67 qboolean g_doWarmupEnabled;
68 qboolean clientkick;
69 qboolean map;
70 qboolean gametype;
71 qboolean fraglimit;
72 qboolean timelimit;
73 qboolean custom;
74 qboolean shuffle;
75
76 //Buttons:
77 menutext_s bMapRestart;
78 menutext_s bNextmap;
79 menutext_s bDoWarmup;
80 menutext_s bKick;
81 menutext_s bMap;
82 menutext_s bGametype;
83 menutext_s bTimelimit;
84 menutext_s bFraglimit;
85 menutext_s bShuffle;
86 menutext_s bCustom;
87
88 int selection;
89 } votemenu_t;
90
91 static votemenu_t s_votemenu;
92
93 void UI_VoteMenuMenuInternal( void );
94
95
96 /*
97 =================
98 VoteMenu_CheckVoteNames
99 =================
100 */
101
102 static void VoteMenu_CheckVoteNames( void ) {
103 int voteflags;
104 voteflags = trap_Cvar_VariableValue("cg_voteflags");
105 s_votemenu.map_restart = voteflags&VF_map_restart;
106 s_votemenu.nextmap = voteflags&VF_nextmap;
107 s_votemenu.map = voteflags&VF_map;
108 s_votemenu.gametype = voteflags&VF_g_gametype;
109 //We never use "kick" in menues, always clientkick
110 s_votemenu.clientkick = voteflags&VF_clientkick;
111 s_votemenu.g_doWarmup = voteflags&VF_g_doWarmup;
112 s_votemenu.timelimit = voteflags&VF_timelimit;
113 s_votemenu.fraglimit = voteflags&VF_fraglimit;
114 s_votemenu.custom = voteflags&VF_custom;
115 s_votemenu.shuffle = voteflags&VF_shuffle;
116 }
117
118 /*
119 =================
120 VoteMenu_Event
121 =================
122 */
123 static void VoteMenu_Event( void* ptr, int event )
124 {
125 switch (((menucommon_s*)ptr)->id)
126 {
127 case ID_BACK:
128 if (event != QM_ACTIVATED)
129 break;
130
131 UI_PopMenu();
132 break;
133 case ID_GO:
134 if( event != QM_ACTIVATED ) {
135 return;
136 }
137 switch(s_votemenu.selection) {
138 case ID_NEXTMAP:
139 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote nextmap" );
140 UI_PopMenu();
141 break;
142 case ID_RESTART:
143 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote map_restart" );
144 UI_PopMenu();
145 break;
146 case ID_DOWARMUP:
147 if(s_votemenu.g_doWarmupEnabled)
148 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote g_doWarmup 0" );
149 else
150 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote g_doWarmup 1" );
151 UI_PopMenu();
152 break;
153 case ID_SHUFFLE:
154 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote shuffle" );
155 UI_PopMenu();
156 break;
157 case ID_FRAG:
158 UI_VoteFraglimitMenu();
159 //Don't pop! It will do a double pop if successfull
160 break;
161 case ID_CUSTOM:
162 UI_VoteCustomMenu();
163 //Don't pop! It will do a double pop if successfull
164 break;
165 case ID_TIME:
166 UI_VoteTimelimitMenu();
167 //Don't pop! It will do a double pop if successfull
168 break;
169 case ID_GAMETYPE:
170 UI_VoteGametypeMenu();
171 //Don't pop! It will do a double pop if successfull
172 break;
173 case ID_KICK:
174 UI_VoteKickMenu();
175 //Don't pop! It will do a double pop if successfull
176 break;
177 case ID_MAP:
178 UI_VoteMapMenu();
179 //Don't pop! It will do a double pop if successfull
180 break;
181 };
182 break;
183 default:
184 if( event != QM_ACTIVATED ) {
185 return;
186 }
187 if(s_votemenu.selection != ((menucommon_s*)ptr)->id) {
188 s_votemenu.selection = ((menucommon_s*)ptr)->id;
189 UI_VoteMenuMenuInternal();
190 }
191 break;
192 }
193 }
194
195 /*
196 =================
197 VoteMenu_Cache
198 =================
199 */
200 static void VoteMenu_Cache( void )
201 {
202 int i;
203
204 // touch all our pics
205 for (i=0; ;i++)
206 {
207 if (!votemenu_artlist[i])
208 break;
209 trap_R_RegisterShaderNoMip(votemenu_artlist[i]);
210 }
211
212 //Check all names
213 VoteMenu_CheckVoteNames();
214 }
215
216 /*
217 =================
218 UI_VoteMenu_Draw
219 =================
220 */
221 static void UI_VoteMenu_Draw( void ) {
222 UI_DrawBannerString( 320, 16, "CALL VOTE", UI_CENTER, color_white );
223 UI_DrawNamedPic( 320-233, 240-166, 466, 332, ART_BACKGROUND );
224
225 // standard menu drawing
226 Menu_Draw( &s_votemenu.menu );
227 }
228
229 /*
230 =================
231 UI_VoteMenuMenuInternal
232 *Used then forcing a redraw
233 =================
234 */
235 void UI_VoteMenuMenuInternal( void )
236 {
237 int y;
238
239 VoteMenu_Cache();
240
241 s_votemenu.menu.wrapAround = qtrue;
242 s_votemenu.menu.fullscreen = qfalse;
243 s_votemenu.menu.draw = UI_VoteMenu_Draw;
244
245 s_votemenu.banner.generic.type = MTYPE_BTEXT;
246 s_votemenu.banner.generic.x = 320;
247 s_votemenu.banner.generic.y = 16;
248 s_votemenu.banner.string = "CALL VOTE";
249 s_votemenu.banner.color = color_white;
250 s_votemenu.banner.style = UI_CENTER;
251
252 y = 98;
253 s_votemenu.bNextmap.generic.type = MTYPE_PTEXT;
254 s_votemenu.bNextmap.color = color_red;
255 s_votemenu.bNextmap.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
256 if(!s_votemenu.nextmap)
257 s_votemenu.bNextmap.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
258 else
259 if(s_votemenu.selection == ID_NEXTMAP)
260 s_votemenu.bNextmap.color = color_orange;
261 s_votemenu.bNextmap.generic.x = 320;
262 s_votemenu.bNextmap.generic.y = y;
263 s_votemenu.bNextmap.generic.id = ID_NEXTMAP;
264 s_votemenu.bNextmap.generic.callback = VoteMenu_Event;
265 s_votemenu.bNextmap.string = "Next map";
266 s_votemenu.bNextmap.style = UI_CENTER|UI_SMALLFONT;
267
268 y+=VOTEMENU_MENU_VERTICAL_SPACING;
269 s_votemenu.bMapRestart.generic.type = MTYPE_PTEXT;
270 s_votemenu.bMapRestart.color = color_red;
271 s_votemenu.bMapRestart.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
272 if(!s_votemenu.map_restart)
273 s_votemenu.bMapRestart.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
274 else
275 if(s_votemenu.selection==ID_RESTART)
276 s_votemenu.bMapRestart.color = color_orange;
277 s_votemenu.bMapRestart.generic.x = 320;
278 s_votemenu.bMapRestart.generic.y = y;
279 s_votemenu.bMapRestart.generic.id = ID_RESTART;
280 s_votemenu.bMapRestart.generic.callback = VoteMenu_Event;
281 s_votemenu.bMapRestart.string = "Restart match";
282 s_votemenu.bMapRestart.style = UI_CENTER|UI_SMALLFONT;
283
284 y+=VOTEMENU_MENU_VERTICAL_SPACING;
285 s_votemenu.bShuffle.generic.type = MTYPE_PTEXT;
286 s_votemenu.bShuffle.color = color_red;
287 s_votemenu.bShuffle.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
288 if(!s_votemenu.map_restart)
289 s_votemenu.bShuffle.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
290 else
291 if(s_votemenu.selection==ID_SHUFFLE)
292 s_votemenu.bShuffle.color = color_orange;
293 s_votemenu.bShuffle.generic.x = 320;
294 s_votemenu.bShuffle.generic.y = y;
295 s_votemenu.bShuffle.generic.id = ID_SHUFFLE;
296 s_votemenu.bShuffle.generic.callback = VoteMenu_Event;
297 s_votemenu.bShuffle.string = "Shuffle teams";
298 s_votemenu.bShuffle.style = UI_CENTER|UI_SMALLFONT;
299
300 y+=VOTEMENU_MENU_VERTICAL_SPACING;
301 s_votemenu.bMap.generic.type = MTYPE_PTEXT;
302 s_votemenu.bMap.color = color_red;
303 s_votemenu.bMap.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
304 if(!s_votemenu.map)
305 s_votemenu.bMap.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
306 else
307 if(s_votemenu.selection == ID_MAP)
308 s_votemenu.bMap.color = color_orange;
309 s_votemenu.bMap.generic.x = 320;
310 s_votemenu.bMap.generic.y = y;
311 s_votemenu.bMap.generic.id = ID_MAP;
312 s_votemenu.bMap.generic.callback = VoteMenu_Event;
313 s_votemenu.bMap.string = "Change map";
314 s_votemenu.bMap.style = UI_CENTER|UI_SMALLFONT;
315
316 y+=VOTEMENU_MENU_VERTICAL_SPACING;
317 s_votemenu.bGametype.generic.type = MTYPE_PTEXT;
318 s_votemenu.bGametype.color = color_red;
319 s_votemenu.bGametype.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
320 if(!s_votemenu.gametype)
321 s_votemenu.bGametype.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
322 else
323 if(s_votemenu.selection == ID_GAMETYPE)
324 s_votemenu.bGametype.color = color_orange;
325 s_votemenu.bGametype.generic.x = 320;
326 s_votemenu.bGametype.generic.y = y;
327 s_votemenu.bGametype.generic.id = ID_GAMETYPE;
328 s_votemenu.bGametype.generic.callback = VoteMenu_Event;
329 s_votemenu.bGametype.string = "Change gametype";
330 s_votemenu.bGametype.style = UI_CENTER|UI_SMALLFONT;
331
332 y+=VOTEMENU_MENU_VERTICAL_SPACING;
333 s_votemenu.bKick.generic.type = MTYPE_PTEXT;
334 s_votemenu.bKick.color = color_red;
335 s_votemenu.bKick.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
336 if(!s_votemenu.clientkick)
337 s_votemenu.bKick.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
338 else
339 if(s_votemenu.selection == ID_KICK)
340 s_votemenu.bKick.color = color_orange;
341 s_votemenu.bKick.generic.x = 320;
342 s_votemenu.bKick.generic.y = y;
343 s_votemenu.bKick.generic.id = ID_KICK;
344 s_votemenu.bKick.generic.callback = VoteMenu_Event;
345 s_votemenu.bKick.string = "Kick player";
346 s_votemenu.bKick.style = UI_CENTER|UI_SMALLFONT;
347
348 y+=VOTEMENU_MENU_VERTICAL_SPACING;
349 s_votemenu.bDoWarmup.generic.type = MTYPE_PTEXT;
350 s_votemenu.bDoWarmup.color = color_red;
351 s_votemenu.bDoWarmup.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
352 if(!s_votemenu.g_doWarmup)
353 s_votemenu.bDoWarmup.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
354 else
355 if(s_votemenu.selection == ID_DOWARMUP)
356 s_votemenu.bDoWarmup.color = color_orange;
357 s_votemenu.bDoWarmup.generic.x = 320;
358 s_votemenu.bDoWarmup.generic.y = y;
359 s_votemenu.bDoWarmup.generic.id = ID_DOWARMUP;
360 s_votemenu.bDoWarmup.generic.callback = VoteMenu_Event;
361 if(s_votemenu.g_doWarmupEnabled)
362 s_votemenu.bDoWarmup.string = "Disable warmup";
363 else
364 s_votemenu.bDoWarmup.string = "Enable warmup";
365 s_votemenu.bDoWarmup.style = UI_CENTER|UI_SMALLFONT;
366
367 y+=VOTEMENU_MENU_VERTICAL_SPACING;
368 s_votemenu.bFraglimit.generic.type = MTYPE_PTEXT;
369 s_votemenu.bFraglimit.color = color_red;
370 s_votemenu.bFraglimit.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
371 if(!s_votemenu.fraglimit)
372 s_votemenu.bFraglimit.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
373 else
374 if(s_votemenu.selection == ID_FRAG)
375 s_votemenu.bFraglimit.color = color_orange;
376 s_votemenu.bFraglimit.generic.x = 320;
377 s_votemenu.bFraglimit.generic.y = y;
378 s_votemenu.bFraglimit.generic.id = ID_FRAG;
379 s_votemenu.bFraglimit.generic.callback = VoteMenu_Event;
380 s_votemenu.bFraglimit.string = "Change fraglimit";
381 s_votemenu.bFraglimit.style = UI_CENTER|UI_SMALLFONT;
382
383 y+=VOTEMENU_MENU_VERTICAL_SPACING;
384 s_votemenu.bTimelimit.generic.type = MTYPE_PTEXT;
385 s_votemenu.bTimelimit.color = color_red;
386 s_votemenu.bTimelimit.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
387 if(!s_votemenu.timelimit)
388 s_votemenu.bTimelimit.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
389 else
390 if(s_votemenu.selection == ID_TIME)
391 s_votemenu.bTimelimit.color = color_orange;
392 s_votemenu.bTimelimit.generic.x = 320;
393 s_votemenu.bTimelimit.generic.y = y;
394 s_votemenu.bTimelimit.generic.id = ID_TIME;
395 s_votemenu.bTimelimit.generic.callback = VoteMenu_Event;
396 s_votemenu.bTimelimit.string = "Change timelimit";
397 s_votemenu.bTimelimit.style = UI_CENTER|UI_SMALLFONT;
398
399 y+=VOTEMENU_MENU_VERTICAL_SPACING;
400 s_votemenu.bCustom.generic.type = MTYPE_PTEXT;
401 s_votemenu.bCustom.color = color_red;
402 s_votemenu.bCustom.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
403 if(!s_votemenu.custom)
404 s_votemenu.bCustom.generic.flags |= QMF_INACTIVE|QMF_GRAYED;
405 else
406 if(s_votemenu.selection == ID_CUSTOM)
407 s_votemenu.bCustom.color = color_orange;
408 s_votemenu.bCustom.generic.x = 320;
409 s_votemenu.bCustom.generic.y = y;
410 s_votemenu.bCustom.generic.id = ID_CUSTOM;
411 s_votemenu.bCustom.generic.callback = VoteMenu_Event;
412 s_votemenu.bCustom.string = "Custom vote";
413 s_votemenu.bCustom.style = UI_CENTER|UI_SMALLFONT;
414
415 s_votemenu.back.generic.type = MTYPE_BITMAP;
416 s_votemenu.back.generic.name = VOTEMENU_BACK0;
417 s_votemenu.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
418 s_votemenu.back.generic.callback = VoteMenu_Event;
419 s_votemenu.back.generic.id = ID_BACK;
420 s_votemenu.back.generic.x = 320-128;
421 s_votemenu.back.generic.y = 256+128-64;
422 s_votemenu.back.width = 128;
423 s_votemenu.back.height = 64;
424 s_votemenu.back.focuspic = VOTEMENU_BACK1;
425
426 s_votemenu.go.generic.type = MTYPE_BITMAP;
427 s_votemenu.go.generic.name = ART_FIGHT0;
428 s_votemenu.go.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
429 s_votemenu.go.generic.callback = VoteMenu_Event;
430 s_votemenu.go.generic.id = ID_GO;
431 s_votemenu.go.generic.x = 320;
432 s_votemenu.go.generic.y = 256+128-64;
433 s_votemenu.go.width = 128;
434 s_votemenu.go.height = 64;
435 s_votemenu.go.focuspic = ART_FIGHT1;
436
437 }
438
439 /*
440 =================
441 UI_VoteMenuMenu
442 *Called from outside
443 =================
444 */
445 void UI_VoteMenuMenu( void ) {
446 // zero set all our globals
447 char serverinfo[MAX_INFO_STRING];
448 memset( &s_votemenu, 0 ,sizeof(votemenu_t) );
449 trap_GetConfigString( CS_SERVERINFO, serverinfo, MAX_INFO_STRING );
450 s_votemenu.g_doWarmupEnabled = atoi(Info_ValueForKey(serverinfo,"g_doWarmup"));
451 UI_VoteMenuMenuInternal();
452
453 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.banner );
454 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.back );
455 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.go );
456 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bNextmap );
457 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bMapRestart );
458 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bShuffle );
459 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bMap );
460 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bGametype );
461 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bKick );
462 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bDoWarmup );
463 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bFraglimit );
464 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bTimelimit );
465 Menu_AddItem( &s_votemenu.menu, (void*) &s_votemenu.bCustom );
466
467 UI_PushMenu( &s_votemenu.menu );
468 }