Debian Codegraph @

code/q3_ui/ui_votemenu_custom.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_custom_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_CUSTOM0 102
43 //next 11 for ID_CUSTOM1-CUSTOM11
44
45 #define CUSTOM_MENU_VERTICAL_SPACING 19
46 #define CUSTOM_MENU_MAX_ENTRIES 12
47
48 typedef struct
49 {
50 menuframework_s menu;
51 menutext_s banner;
52 menubitmap_s back;
53 menubitmap_s go;
54
55 //Buttons:
56 menutext_s bEntry[CUSTOM_MENU_MAX_ENTRIES];
57
58 //The text:
59 char text[CUSTOM_MENU_MAX_ENTRIES][32];
60
61 int selection;
62 } votemenu_t;
63
64 static votemenu_t s_votemenu_custom;
65
66 void UI_VoteCustomMenuInternal( void );
67
68 /*
69 =================
70 VoteMenu_custom_Event
71 =================
72 */
73 static void VoteMenu_custom_Event( void* ptr, int event )
74 {
75 switch (((menucommon_s*)ptr)->id)
76 {
77 case ID_BACK:
78 if (event != QM_ACTIVATED)
79 break;
80
81 UI_PopMenu();
82 break;
83 case ID_GO:
84 if( event != QM_ACTIVATED || !s_votemenu_custom.selection) {
85 return;
86 }
87 trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote custom %s",s_votemenu_custom.bEntry[s_votemenu_custom.selection-ID_CUSTOM0].string ) );
88 UI_PopMenu();
89 UI_PopMenu();
90 break;
91 default:
92 if( event != QM_ACTIVATED ) {
93 return;
94 }
95 if(s_votemenu_custom.selection != ((menucommon_s*)ptr)->id) {
96 s_votemenu_custom.selection = ((menucommon_s*)ptr)->id;
97 UI_VoteCustomMenuInternal();
98 }
99 break;
100 }
101
102 }
103
104 static void setCustomMenutext(menutext_s *menu,int y,int id,char *text) {
105 menu->generic.type = MTYPE_PTEXT;
106 menu->color = color_red;
107 menu->generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
108 if(strlen(text)<1)
109 menu->generic.flags |= QMF_INACTIVE|QMF_GRAYED;
110 else
111 if(s_votemenu_custom.selection == id)
112 menu->color = color_orange;
113 menu->generic.x = 320;
114 menu->generic.y = y;
115 menu->generic.id = id;
116 menu->generic.callback = VoteMenu_custom_Event;
117 menu->string = text;
118 menu->style = UI_CENTER|UI_SMALLFONT;
119 }
120
121 /*
122 =================
123 VoteMenu_Custom_Cache
124 =================
125 */
126 static void VoteMenu_Custom_Cache( void )
127 {
128 int i;
129
130 // touch all our pics
131 for (i=0; ;i++)
132 {
133 if (!votemenu_custom_artlist[i])
134 break;
135 trap_R_RegisterShaderNoMip(votemenu_custom_artlist[i]);
136 }
137 }
138
139 /*
140 =================
141 UI_VoteMenu_Custom_Draw
142 =================
143 */
144 static void UI_VoteMenu_Custom_Draw( void ) {
145 UI_DrawBannerString( 320, 16, "CALL VOTE CUSTOM", UI_CENTER, color_white );
146 UI_DrawNamedPic( 320-233, 240-166, 466, 332, ART_BACKGROUND );
147
148 // standard menu drawing
149 Menu_Draw( &s_votemenu_custom.menu );
150 }
151
152 /*
153 =================
154 UI_VoteCustomMenuInternal
155 *Used then forcing a redraw
156 =================
157 */
158 void UI_VoteCustomMenuInternal( void )
159 {
160 int y,i;
161 char custominfo[MAX_INFO_STRING], *token,*pointer;
162
163 VoteMenu_Custom_Cache();
164
165 memset( &custominfo, 0, sizeof(custominfo));
166 trap_Cvar_VariableStringBuffer("cg_vote_custom_commands",custominfo,sizeof(custominfo));
167
168 s_votemenu_custom.menu.wrapAround = qtrue;
169 s_votemenu_custom.menu.fullscreen = qfalse;
170 s_votemenu_custom.menu.draw = UI_VoteMenu_Custom_Draw;
171
172 s_votemenu_custom.banner.generic.type = MTYPE_BTEXT;
173 s_votemenu_custom.banner.generic.x = 320;
174 s_votemenu_custom.banner.generic.y = 16;
175 s_votemenu_custom.banner.string = "CALL VOTE CUSTOM";
176 s_votemenu_custom.banner.color = color_white;
177 s_votemenu_custom.banner.style = UI_CENTER;
178
179 pointer = custominfo;
180
181 y = 98;
182 for(i=0;i<CUSTOM_MENU_MAX_ENTRIES;i++) {
183 token = COM_Parse( &pointer );
184 Q_strncpyz(s_votemenu_custom.text[i],token,sizeof(s_votemenu_custom.text[0]));
185 setCustomMenutext(&s_votemenu_custom.bEntry[i],y,ID_CUSTOM0+i,s_votemenu_custom.text[i]);
186 y+=CUSTOM_MENU_VERTICAL_SPACING;
187 }
188
189 s_votemenu_custom.back.generic.type = MTYPE_BITMAP;
190 s_votemenu_custom.back.generic.name = VOTEMENU_BACK0;
191 s_votemenu_custom.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
192 s_votemenu_custom.back.generic.callback = VoteMenu_custom_Event;
193 s_votemenu_custom.back.generic.id = ID_BACK;
194 s_votemenu_custom.back.generic.x = 320-128;
195 s_votemenu_custom.back.generic.y = 256+128-64;
196 s_votemenu_custom.back.width = 128;
197 s_votemenu_custom.back.height = 64;
198 s_votemenu_custom.back.focuspic = VOTEMENU_BACK1;
199
200 s_votemenu_custom.go.generic.type = MTYPE_BITMAP;
201 s_votemenu_custom.go.generic.name = ART_FIGHT0;
202 s_votemenu_custom.go.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
203 s_votemenu_custom.go.generic.callback = VoteMenu_custom_Event;
204 s_votemenu_custom.go.generic.id = ID_GO;
205 s_votemenu_custom.go.generic.x = 320;
206 s_votemenu_custom.go.generic.y = 256+128-64;
207 s_votemenu_custom.go.width = 128;
208 s_votemenu_custom.go.height = 64;
209 s_votemenu_custom.go.focuspic = ART_FIGHT1;
210 }
211
212 /*
213 =================
214 UI_VoteCustomMenu
215 *Called from outside
216 =================
217 */
218 void UI_VoteCustomMenu( void ) {
219 int i;
220 // zero set all our globals
221 memset( &s_votemenu_custom, 0 ,sizeof(votemenu_t) );
222
223 UI_VoteCustomMenuInternal();
224
225 Menu_AddItem( &s_votemenu_custom.menu, (void*) &s_votemenu_custom.banner );
226 Menu_AddItem( &s_votemenu_custom.menu, (void*) &s_votemenu_custom.back );
227 Menu_AddItem( &s_votemenu_custom.menu, (void*) &s_votemenu_custom.go );
228 for(i=0;i<CUSTOM_MENU_MAX_ENTRIES;i++)
229 Menu_AddItem( &s_votemenu_custom.menu, (void*) &s_votemenu_custom.bEntry[i] );
230
231 UI_PushMenu( &s_votemenu_custom.menu );
232 }