Debian Codegraph @

code/q3_ui/ui_mods.c

raw
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 #include "ui_local.h"
24
25 #define ART_BACK0 "menu/art_blueish/back_0"
26 #define ART_BACK1 "menu/art_blueish/back_1"
27 #define ART_FIGHT0 "menu/art_blueish/load_0"
28 #define ART_FIGHT1 "menu/art_blueish/load_1"
29 #define ART_FRAMEL "menu/art_blueish/frame2_l"
30 #define ART_FRAMER "menu/art_blueish/frame1_r"
31
32 #define MAX_MODS 64
33 #define NAMEBUFSIZE ( MAX_MODS * 48 )
34 #define GAMEBUFSIZE ( MAX_MODS * 16 )
35
36 #define ID_BACK 10
37 #define ID_GO 11
38 #define ID_LIST 12
39
40
41 typedef struct {
42 menuframework_s menu;
43
44 menutext_s banner;
45 menubitmap_s framel;
46 menubitmap_s framer;
47
48 menulist_s list;
49
50 menubitmap_s back;
51 menubitmap_s go;
52
53 char description[NAMEBUFSIZE];
54 char fs_game[GAMEBUFSIZE];
55
56 char *descriptionPtr;
57 char *fs_gamePtr;
58
59 char *descriptionList[MAX_MODS];
60 char *fs_gameList[MAX_MODS];
61 } mods_t;
62
63 static mods_t s_mods;
64
65
66 /*
67 ===============
68 UI_Mods_MenuEvent
69 ===============
70 */
71 static void UI_Mods_MenuEvent( void *ptr, int event ) {
72 if( event != QM_ACTIVATED ) {
73 return;
74 }
75
76 switch ( ((menucommon_s*)ptr)->id ) {
77 case ID_GO:
78 trap_Cvar_Set( "fs_game", s_mods.fs_gameList[s_mods.list.curvalue] );
79 trap_Cmd_ExecuteText( EXEC_APPEND, "vid_restart;" );
80 UI_PopMenu();
81 break;
82
83 case ID_BACK:
84 UI_PopMenu();
85 break;
86 }
87 }
88
89
90 /*
91 ===============
92 UI_Mods_ParseInfos
93 ===============
94 */
95 static void UI_Mods_ParseInfos( char *modDir, char *modDesc ) {
96 s_mods.fs_gameList[s_mods.list.numitems] = s_mods.fs_gamePtr;
97 Q_strncpyz( s_mods.fs_gamePtr, modDir, 16 );
98
99 s_mods.descriptionList[s_mods.list.numitems] = s_mods.descriptionPtr;
100 Q_strncpyz( s_mods.descriptionPtr, modDesc, 48 );
101
102 s_mods.list.itemnames[s_mods.list.numitems] = s_mods.descriptionPtr;
103 s_mods.descriptionPtr += strlen( s_mods.descriptionPtr ) + 1;
104 s_mods.fs_gamePtr += strlen( s_mods.fs_gamePtr ) + 1;
105 s_mods.list.numitems++;
106 }
107
108
109 #if 0 // bk001204 - unused
110 /*
111 ===============
112 UI_Mods_LoadModsFromFile
113 ===============
114 */
115 static void UI_Mods_LoadModsFromFile( char *filename ) {
116 int len;
117 fileHandle_t f;
118 char buf[1024];
119
120 len = trap_FS_FOpenFile( filename, &f, FS_READ );
121 if ( !f ) {
122 trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) );
123 return;
124 }
125 if ( len >= sizeof(buf) ) {
126 trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, sizeof(buf) ) );
127 trap_FS_FCloseFile( f );
128 return;
129 }
130
131 trap_FS_Read( buf, len, f );
132 buf[len] = 0;
133 trap_FS_FCloseFile( f );
134
135 len = strlen( filename );
136 if( !Q_stricmp(filename + len - 4,".mod") ) {
137 filename[len-4] = '\0';
138 }
139
140 UI_Mods_ParseInfos( filename, buf );
141 }
142 #endif
143
144
145 /*
146 ===============
147 UI_Mods_LoadMods
148 ===============
149 */
150 static void UI_Mods_LoadMods( void ) {
151 int numdirs;
152 char dirlist[2048];
153 char *dirptr;
154 char *descptr;
155 int i;
156 int dirlen;
157
158 s_mods.list.itemnames = (const char **)s_mods.descriptionList;
159 s_mods.descriptionPtr = s_mods.description;
160 s_mods.fs_gamePtr = s_mods.fs_game;
161
162 // always start off with baseoa
163 s_mods.list.numitems = 1;
164 s_mods.list.itemnames[0] = s_mods.descriptionList[0] = "OpenArena";
165 s_mods.fs_gameList[0] = "";
166
167 numdirs = trap_FS_GetFileList( "$modlist", "", dirlist, sizeof(dirlist) );
168 dirptr = dirlist;
169 for( i = 0; i < numdirs; i++ ) {
170 dirlen = strlen( dirptr ) + 1;
171 descptr = dirptr + dirlen;
172 UI_Mods_ParseInfos( dirptr, descptr);
173 dirptr += dirlen + strlen(descptr) + 1;
174 }
175
176 trap_Print( va( "%i mods parsed\n", s_mods.list.numitems ) );
177 if (s_mods.list.numitems > MAX_MODS) {
178 s_mods.list.numitems = MAX_MODS;
179 }
180 }
181
182 /*
183 =================
184 UI_ModsMenu_Key
185 =================
186 */
187 static sfxHandle_t UI_ModsMenu_Key( int key ) {
188 menucommon_s *item;
189
190 item = Menu_ItemAtCursor( &s_mods.menu );
191
192 if( key == K_MWHEELUP ) {
193 ScrollList_Key( &s_mods.list, K_UPARROW );
194 }
195
196 if( key == K_MWHEELDOWN ) {
197 ScrollList_Key( &s_mods.list, K_DOWNARROW );
198 }
199
200 return Menu_DefaultKey( &s_mods.menu, key );
201 }
202
203 /*
204 ===============
205 UI_Mods_MenuInit
206 ===============
207 */
208 static void UI_Mods_MenuInit( void ) {
209 UI_ModsMenu_Cache();
210
211 memset( &s_mods, 0 ,sizeof(mods_t) );
212
213 s_mods.menu.key = UI_ModsMenu_Key;
214
215 s_mods.menu.wrapAround = qtrue;
216 s_mods.menu.fullscreen = qtrue;
217
218 s_mods.banner.generic.type = MTYPE_BTEXT;
219 s_mods.banner.generic.x = 320;
220 s_mods.banner.generic.y = 16;
221 s_mods.banner.string = "MODS";
222 s_mods.banner.color = color_white;
223 s_mods.banner.style = UI_CENTER;
224
225 s_mods.framel.generic.type = MTYPE_BITMAP;
226 s_mods.framel.generic.name = ART_FRAMEL;
227 s_mods.framel.generic.flags = QMF_INACTIVE;
228 s_mods.framel.generic.x = 0;
229 s_mods.framel.generic.y = 78;
230 s_mods.framel.width = 256;
231 s_mods.framel.height = 329;
232
233 s_mods.framer.generic.type = MTYPE_BITMAP;
234 s_mods.framer.generic.name = ART_FRAMER;
235 s_mods.framer.generic.flags = QMF_INACTIVE;
236 s_mods.framer.generic.x = 376;
237 s_mods.framer.generic.y = 76;
238 s_mods.framer.width = 256;
239 s_mods.framer.height = 334;
240
241 s_mods.back.generic.type = MTYPE_BITMAP;
242 s_mods.back.generic.name = ART_BACK0;
243 s_mods.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
244 s_mods.back.generic.id = ID_BACK;
245 s_mods.back.generic.callback = UI_Mods_MenuEvent;
246 s_mods.back.generic.x = 0;
247 s_mods.back.generic.y = 480-64;
248 s_mods.back.width = 128;
249 s_mods.back.height = 64;
250 s_mods.back.focuspic = ART_BACK1;
251
252 s_mods.go.generic.type = MTYPE_BITMAP;
253 s_mods.go.generic.name = ART_FIGHT0;
254 s_mods.go.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
255 s_mods.go.generic.id = ID_GO;
256 s_mods.go.generic.callback = UI_Mods_MenuEvent;
257 s_mods.go.generic.x = 640;
258 s_mods.go.generic.y = 480-64;
259 s_mods.go.width = 128;
260 s_mods.go.height = 64;
261 s_mods.go.focuspic = ART_FIGHT1;
262
263 // scan for mods
264 s_mods.list.generic.type = MTYPE_SCROLLLIST;
265 s_mods.list.generic.flags = QMF_PULSEIFFOCUS|QMF_CENTER_JUSTIFY;
266 s_mods.list.generic.callback = UI_Mods_MenuEvent;
267 s_mods.list.generic.id = ID_LIST;
268 s_mods.list.generic.x = 320;
269 s_mods.list.generic.y = 130;
270 s_mods.list.width = 48;
271 s_mods.list.height = 14;
272
273 UI_Mods_LoadMods();
274
275 Menu_AddItem( &s_mods.menu, &s_mods.banner );
276 Menu_AddItem( &s_mods.menu, &s_mods.framel );
277 Menu_AddItem( &s_mods.menu, &s_mods.framer );
278 Menu_AddItem( &s_mods.menu, &s_mods.list );
279 Menu_AddItem( &s_mods.menu, &s_mods.back );
280 Menu_AddItem( &s_mods.menu, &s_mods.go );
281 }
282
283 /*
284 =================
285 UI_Mods_Cache
286 =================
287 */
288 void UI_ModsMenu_Cache( void ) {
289 trap_R_RegisterShaderNoMip( ART_BACK0 );
290 trap_R_RegisterShaderNoMip( ART_BACK1 );
291 trap_R_RegisterShaderNoMip( ART_FIGHT0 );
292 trap_R_RegisterShaderNoMip( ART_FIGHT1 );
293 trap_R_RegisterShaderNoMip( ART_FRAMEL );
294 trap_R_RegisterShaderNoMip( ART_FRAMER );
295 }
296
297
298 /*
299 ===============
300 UI_ModsMenu
301 ===============
302 */
303 void UI_ModsMenu( void ) {
304 UI_Mods_MenuInit();
305 UI_PushMenu( &s_mods.menu );
306 }