Debian Codegraph @

code/q3_ui/ui_mods.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 #include "ui_local.h"
24
25 #define ART_BACK0 "menu/art/back_0"
26 #define ART_BACK1 "menu/art/back_1"
27 #define ART_FIGHT0 "menu/art/load_0"
28 #define ART_FIGHT1 "menu/art/load_1"
29 #define ART_FRAMEL "menu/art/frame2_l"
30 #define ART_FRAMER "menu/art/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 /*
110 ===============
111 UI_Mods_LoadMods
112 ===============
113 */
114 static void UI_Mods_LoadMods( void ) {
115 int numdirs;
116 char dirlist[2048];
117 char *dirptr;
118 char *descptr;
119 int i;
120 int dirlen;
121
122 s_mods.list.itemnames = (const char **)s_mods.descriptionList;
123 s_mods.descriptionPtr = s_mods.description;
124 s_mods.fs_gamePtr = s_mods.fs_game;
125
126 // always start off with baseq3
127 s_mods.list.numitems = 1;
128 s_mods.list.itemnames[0] = s_mods.descriptionList[0] = "Quake III Arena";
129 s_mods.fs_gameList[0] = "";
130
131 numdirs = trap_FS_GetFileList( "$modlist", "", dirlist, sizeof(dirlist) );
132 dirptr = dirlist;
133 for( i = 0; i < numdirs; i++ ) {
134 dirlen = strlen( dirptr ) + 1;
135 descptr = dirptr + dirlen;
136 UI_Mods_ParseInfos( dirptr, descptr);
137 dirptr += dirlen + strlen(descptr) + 1;
138 }
139
140 trap_Print( va( "%i mods parsed\n", s_mods.list.numitems ) );
141 if (s_mods.list.numitems > MAX_MODS) {
142 s_mods.list.numitems = MAX_MODS;
143 }
144 }
145
146
147 /*
148 ===============
149 UI_Mods_MenuInit
150 ===============
151 */
152 static void UI_Mods_MenuInit( void ) {
153 UI_ModsMenu_Cache();
154
155 memset( &s_mods, 0 ,sizeof(mods_t) );
156 s_mods.menu.wrapAround = qtrue;
157 s_mods.menu.fullscreen = qtrue;
158
159 s_mods.banner.generic.type = MTYPE_BTEXT;
160 s_mods.banner.generic.x = 320;
161 s_mods.banner.generic.y = 16;
162 s_mods.banner.string = "MODS";
163 s_mods.banner.color = color_white;
164 s_mods.banner.style = UI_CENTER;
165
166 s_mods.framel.generic.type = MTYPE_BITMAP;
167 s_mods.framel.generic.name = ART_FRAMEL;
168 s_mods.framel.generic.flags = QMF_INACTIVE;
169 s_mods.framel.generic.x = 0;
170 s_mods.framel.generic.y = 78;
171 s_mods.framel.width = 256;
172 s_mods.framel.height = 329;
173
174 s_mods.framer.generic.type = MTYPE_BITMAP;
175 s_mods.framer.generic.name = ART_FRAMER;
176 s_mods.framer.generic.flags = QMF_INACTIVE;
177 s_mods.framer.generic.x = 376;
178 s_mods.framer.generic.y = 76;
179 s_mods.framer.width = 256;
180 s_mods.framer.height = 334;
181
182 s_mods.back.generic.type = MTYPE_BITMAP;
183 s_mods.back.generic.name = ART_BACK0;
184 s_mods.back.generic.flags = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
185 s_mods.back.generic.id = ID_BACK;
186 s_mods.back.generic.callback = UI_Mods_MenuEvent;
187 s_mods.back.generic.x = 0;
188 s_mods.back.generic.y = 480-64;
189 s_mods.back.width = 128;
190 s_mods.back.height = 64;
191 s_mods.back.focuspic = ART_BACK1;
192
193 s_mods.go.generic.type = MTYPE_BITMAP;
194 s_mods.go.generic.name = ART_FIGHT0;
195 s_mods.go.generic.flags = QMF_RIGHT_JUSTIFY|QMF_PULSEIFFOCUS;
196 s_mods.go.generic.id = ID_GO;
197 s_mods.go.generic.callback = UI_Mods_MenuEvent;
198 s_mods.go.generic.x = 640;
199 s_mods.go.generic.y = 480-64;
200 s_mods.go.width = 128;
201 s_mods.go.height = 64;
202 s_mods.go.focuspic = ART_FIGHT1;
203
204 // scan for mods
205 s_mods.list.generic.type = MTYPE_SCROLLLIST;
206 s_mods.list.generic.flags = QMF_PULSEIFFOCUS|QMF_CENTER_JUSTIFY;
207 s_mods.list.generic.callback = UI_Mods_MenuEvent;
208 s_mods.list.generic.id = ID_LIST;
209 s_mods.list.generic.x = 320;
210 s_mods.list.generic.y = 130;
211 s_mods.list.width = 48;
212 s_mods.list.height = 14;
213
214 UI_Mods_LoadMods();
215
216 Menu_AddItem( &s_mods.menu, &s_mods.banner );
217 Menu_AddItem( &s_mods.menu, &s_mods.framel );
218 Menu_AddItem( &s_mods.menu, &s_mods.framer );
219 Menu_AddItem( &s_mods.menu, &s_mods.list );
220 Menu_AddItem( &s_mods.menu, &s_mods.back );
221 Menu_AddItem( &s_mods.menu, &s_mods.go );
222 }
223
224 /*
225 =================
226 UI_Mods_Cache
227 =================
228 */
229 void UI_ModsMenu_Cache( void ) {
230 trap_R_RegisterShaderNoMip( ART_BACK0 );
231 trap_R_RegisterShaderNoMip( ART_BACK1 );
232 trap_R_RegisterShaderNoMip( ART_FIGHT0 );
233 trap_R_RegisterShaderNoMip( ART_FIGHT1 );
234 trap_R_RegisterShaderNoMip( ART_FRAMEL );
235 trap_R_RegisterShaderNoMip( ART_FRAMER );
236 }
237
238
239 /*
240 ===============
241 UI_ModsMenu
242 ===============
243 */
244 void UI_ModsMenu( void ) {
245 UI_Mods_MenuInit();
246 UI_PushMenu( &s_mods.menu );
247 }