Debian Codegraph @

code/q3_ui/ui_votemenu_timelimit.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_Timelmit_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_50 102
43 #define ID_10 103
44 #define ID_15 104
45 #define ID_20 105
46 #define ID_30 106
47 #define ID_40 107
48 #define ID_INF 108
49
50 #define TimeLIMIT_MENU_VERTICAL_SPACING 28
51
52 typedef struct
53 {
54 menuframework_s menu;
55 menutext_s banner;
56 menubitmap_s back;
57 menubitmap_s go;
58
59 //Buttons:
60 menutext_s bLimit50;
61 menutext_s bLimit10;
62 menutext_s bLimit15;
63 menutext_s bLimit20;
64 menutext_s bLimit30;
65 menutext_s bLimit40;
66 menutext_s bLimitInf;
67
68 int min, max; //Values restricted by server
69 int selection;
70 } votemenu_t;
71
72 static votemenu_t s_votemenu_Timelmit;
73
74 void UI_VoteTimelimitMenuInternal( void );
75
76 /*
77 =================
78 VoteMenu_Timelimit_Event
79 =================
80 */
81 static void VoteMenu_Timelimit_Event( void* ptr, int event )
82 {
83 switch (((menucommon_s*)ptr)->id)
84 {
85 case ID_BACK:
86 if (event != QM_ACTIVATED)
87 break;
88
89 UI_PopMenu();
90 break;
91 case ID_GO:
92 if( event != QM_ACTIVATED ) {
93 return;
94 }
95 switch(s_votemenu_Timelmit.selection) {
96 case ID_10:
97 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote timelimit 10" );
98 UI_PopMenu();
99 UI_PopMenu();
100 break;
101 case ID_15:
102 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote timelimit 15" );
103 UI_PopMenu();
104 UI_PopMenu();
105 break;
106 case ID_20:
107 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote timelimit 20" );
108 UI_PopMenu();
109 UI_PopMenu();
110 break;
111 case ID_30:
112 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote timelimit 30" );
113 UI_PopMenu();
114 UI_PopMenu();
115 break;
116 case ID_40:
117 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote timelimit 40" );
118 UI_PopMenu();
119 UI_PopMenu();
120 break;
121 case ID_50:
122 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote timelimit 50" );
123 UI_PopMenu();
124 UI_PopMenu();
125 break;
126 case ID_INF:
127 trap_Cmd_ExecuteText( EXEC_APPEND, "callvote timelimit 0" );
128 UI_PopMenu();
129 UI_PopMenu();
130 break;
131 };
132 break;
133 default:
134 if( event != QM_ACTIVATED ) {
135 return;
136 }
137 if(s_votemenu_Timelmit.selection != ((menucommon_s*)ptr)->id) {
138 s_votemenu_Timelmit.selection = ((menucommon_s*)ptr)->id;
139 UI_VoteTimelimitMenuInternal();
140 }
141 break;
142 }
143 }
144
145 static void setTimeMenutext(menutext_s *menu,int y,int id,int value,char *text) {
146 menu->generic.type = MTYPE_PTEXT;
147 menu->color = color_red;
148 menu->generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
149 if((s_votemenu_Timelmit.min > value && value!=0) ||
150 (s_votemenu_Timelmit.max < value && s_votemenu_Timelmit.max!=0) ||
151 (s_votemenu_Timelmit.max != 0 && value==0))
152 menu->generic.flags |= QMF_INACTIVE|QMF_GRAYED;
153 else
154 if(s_votemenu_Timelmit.selection == id)
155 menu->color = color_orange;
156 menu->generic.x = 320;
157 menu->generic.y = y;
158 menu->generic.id = id;
159 menu->generic.callback = VoteMenu_Timelimit_Event;
160 menu->string = text;
161 menu->style = UI_CENTER|UI_SMALLFONT;
162 }
163
164 /*
165 =================
166 VoteMenu_Timelimit_Cache
167 =================
168 */
169 static void VoteMenu_Timelimit_Cache( void )
170 {
171 int i;
172
173 // touch all our pics
174 for (i=0; ;i++)
175 {
176 if (!votemenu_Timelmit_artlist[i])
177 break;
178 trap_R_RegisterShaderNoMip(votemenu_Timelmit_artlist[i]);
179 }
180 }
181
182 /*
183 =================
184 UI_VoteMenu_Timelimit_Draw
185 =================
186 */
187 static void UI_VoteMenu_Timelimit_Draw( void ) {
188 UI_DrawBannerString( 320, 16, "CALL VOTE - TIMELIMIT", UI_CENTER, color_white );
189 UI_DrawNamedPic( 320-233, 240-166, 466, 332, ART_BACKGROUND );
190
191 // standard menu drawing
192 Menu_Draw( &s_votemenu_Timelmit.menu );
193 }
194
195 /*
196 =================
197 UI_VoteTimelimitMenuInternal
198 *Used then forcing a redraw
199 =================
200 */
201 void UI_VoteTimelimitMenuInternal( void )
202 {
203 int y;
204
205 VoteMenu_Timelimit_Cache();
206
207 s_votemenu_Timelmit.menu.wrapAround = qtrue;
208 s_votemenu_Timelmit.menu.fullscreen = qfalse;
209 s_votemenu_Timelmit.menu.draw = UI_VoteMenu_Timelimit_Draw;
210
211 s_votemenu_Timelmit.banner.generic.type = MTYPE_BTEXT;
212 s_votemenu_Timelmit.banner.generic.x = 320;
213 s_votemenu_Timelmit.banner.generic.y = 16;
214 s_votemenu_Timelmit.banner.string = "CALL VOTE - TIMELIMIT";
215 s_votemenu_Timelmit.banner.color = color_white;
216 s_votemenu_Timelmit.banner.style = UI_CENTER;
217
218 y = 98;
219 setTimeMenutext(&s_votemenu_Timelmit.bLimit10,y,ID_10,10,"10 minutes");
220 y+=TimeLIMIT_MENU_VERTICAL_SPACING;
221 setTimeMenutext(&s_votemenu_Timelmit.bLimit15,y,ID_15,15,"15 minutes");
222 y+=TimeLIMIT_MENU_VERTICAL_SPACING;
223 setTimeMenutext(&s_votemenu_Timelmit.bLimit20,y,ID_20,20,"20 minutes");
224 y+=TimeLIMIT_MENU_VERTICAL_SPACING;
225 setTimeMenutext(&s_votemenu_Timelmit.bLimit30,y,ID_30,30,"30 minutes");
226 y+=TimeLIMIT_MENU_VERTICAL_SPACING;
227 setTimeMenutext(&s_votemenu_Timelmit.bLimit40,y,ID_40,40,"40 minutes");
228 y+=TimeLIMIT_MENU_VERTICAL_SPACING;
229 setTimeMenutext(&s_votemenu_Timelmit.bLimit50,y,ID_50,50,"50 minutes");
230 y+=TimeLIMIT_MENU_VERTICAL_SPACING;
231 setTimeMenutext(&s_votemenu_Timelmit.bLimitInf,y,ID_INF,0,"No limit");
232
233 s_votemenu_Timelmit.back.generic.type = MTYPE_BITMAP;
234 s_votemenu_Timelmit.back.generic.name = VOTEMENU_BACK0;
235 s_votemenu_Timelmit.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
236 s_votemenu_Timelmit.back.generic.callback = VoteMenu_Timelimit_Event;
237 s_votemenu_Timelmit.back.generic.id = ID_BACK;
238 s_votemenu_Timelmit.back.generic.x = 320-128;
239 s_votemenu_Timelmit.back.generic.y = 256+128-64;
240 s_votemenu_Timelmit.back.width = 128;
241 s_votemenu_Timelmit.back.height = 64;
242 s_votemenu_Timelmit.back.focuspic = VOTEMENU_BACK1;
243
244 s_votemenu_Timelmit.go.generic.type = MTYPE_BITMAP;
245 s_votemenu_Timelmit.go.generic.name = ART_FIGHT0;
246 s_votemenu_Timelmit.go.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
247 s_votemenu_Timelmit.go.generic.callback = VoteMenu_Timelimit_Event;
248 s_votemenu_Timelmit.go.generic.id = ID_GO;
249 s_votemenu_Timelmit.go.generic.x = 320;
250 s_votemenu_Timelmit.go.generic.y = 256+128-64;
251 s_votemenu_Timelmit.go.width = 128;
252 s_votemenu_Timelmit.go.height = 64;
253 s_votemenu_Timelmit.go.focuspic = ART_FIGHT1;
254 }
255
256 /*
257 =================
258 UI_VoteTimelimitMenu
259 *Called from outside
260 =================
261 */
262 void UI_VoteTimelimitMenu( void ) {
263 char serverinfo[MAX_INFO_STRING];
264 // zero set all our globals
265 memset( &s_votemenu_Timelmit, 0 ,sizeof(votemenu_t) );
266 trap_GetConfigString( CS_SERVERINFO, serverinfo, MAX_INFO_STRING );
267 s_votemenu_Timelmit.min = atoi(Info_ValueForKey(serverinfo,"g_voteMinTimelimit"));
268 s_votemenu_Timelmit.max = atoi(Info_ValueForKey(serverinfo,"g_voteMaxTimelimit"));
269 UI_VoteTimelimitMenuInternal();
270
271 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.banner );
272 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.back );
273 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.go );
274 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.bLimit10 );
275 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.bLimit15 );
276 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.bLimit20 );
277 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.bLimit30 );
278 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.bLimit40 );
279 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.bLimit50 );
280 Menu_AddItem( &s_votemenu_Timelmit.menu, (void*) &s_votemenu_Timelmit.bLimitInf );
281
282 UI_PushMenu( &s_votemenu_Timelmit.menu );
283 }