]> icculus.org git repositories - divverent/nexuiz.git/blob - scmenu/source/custom/creategame/maps.qc
-Changed Item_Nex_MapDB_EnumFiles to actually load m_nomap if no map picture
[divverent/nexuiz.git] / scmenu / source / custom / creategame / maps.qc
1 // Property of Alientrap/AK
2 // custom/player/avatar.qm
3
4 /*
5 ===================
6 Item_Nex_Map_Info
7 ===================
8 */
9
10 /*
11 ===================
12 Item_Nex_Map_Info_Destroy
13 ===================
14 */
15 void() Item_Nex_Map_Info_Destroy =
16 {
17         String_EntityFree( self, link );
18         String_EntityFree( self, picture );
19         String_EntityFree( self, text );
20         String_EntityFree( self, normal );
21 };
22
23 /*
24 ===================
25 Item_Nex_Map_Info_Spawn
26 ===================
27 */
28 void() Item_Nex_Map_Info_Spawn =
29 {
30         String_EntityZone( self, link );
31         String_EntityZone( self, picture );
32         String_EntityZone( self, text );
33         String_EntityZone( self, normal );
34
35         Gfx_Precache( self.picture );
36
37         self._destroy = Item_Nex_Map_Info_Destroy;
38 };
39
40 /*
41 ===================
42 Item_Nex_MapDB
43 ===================
44 */
45 string _Nex_MapList_FullPath;
46 string _Nex_MapList_Name;
47 entity _Nex_MapList_Root;
48
49 /*
50 ===================
51 Item_Nex_MapDB_EnumFiles
52 ===================
53 */
54 // map definition format
55 // name
56 // rest: description text
57 void() Item_Nex_MapDB_EnumFiles =
58 {
59         local float     lSearchHandle;
60         local float     lSearchSize;
61         local float     lSearchCounter;
62         local entity    lMap;
63
64         lSearchHandle = search_begin( "maps/*.bsp", true, true );
65         if( lSearchHandle < 0 )
66                 return;
67         for( lSearchSize = search_getsize( lSearchHandle ), lSearchCounter = 0;
68         lSearchCounter < lSearchSize; ++lSearchCounter ) {
69                 local float     lHandle;
70
71                 local string    lFilename;
72                 local string    lStripped;
73                 local string    lName;
74                 local string    lDescription;
75                 local string    lTitle;
76
77                 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
78                 lStripped = String_Zone( substring( lFilename, 0, strlen( lFilename ) - 4 ) );
79                 lName = String_Zone( substring( lStripped, 5, 100000 ) );
80
81                 lHandle = fopen( strcat( lStripped, ".txt" ), FILE_READ );
82                 if( lHandle < 0 ) {
83                         lTitle = String_Zone( lName );
84                         lDescription = String_Zone( strcat( "--NO INFORMATION AVAILABLE--\n", lFilename ) );
85                 } else {
86                         // uncomment this line and comment the other if you have the old map info files
87                         //lTitle = String_Zone( lName );
88                         lTitle = String_Zone( fgets( lHandle ) );
89
90                         lDescription = String_Create();
91                         do {
92                                 local string lLine;
93
94                                 lLine = fgets( lHandle );
95                                 lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
96                         } while( validstring( lLine ) );
97
98                         fclose( lHandle );
99                 }
100
101                 // save this in a new Map_Info
102                 lMap = Menu_CreateItem( "Item_Nex_Map_Info", ftos( lSearchCounter ), self.name );
103
104                 lMap.link = lName;
105                 // check the picture
106                 if( Gfx_Precache( lStripped ) ) {
107                         lMap.picture = lStripped;
108                 } else {
109                         lMap.picture = "gfx/m_nomap";
110                 }
111                 lMap.normal = lTitle;
112                 lMap.text = lDescription;
113
114                 _Nex_MapList_FullPath = Util_AltStringPushBack( _Nex_MapList_FullPath, lName );
115                 _Nex_MapList_Name = Util_AltStringPushBack( _Nex_MapList_Name, lTitle );
116
117                 Menu_LinkItem( lMap );
118
119                 String_Free( lTitle );
120                 String_Free( lName );
121                 String_Free( lStripped );
122                 String_Free( lDescription );
123         }
124
125         search_end( lSearchHandle );
126
127         Menu_LinkChildren( self );
128
129         self.minValue = 1;
130         self.stepValue = 1;
131         self.maxValue = fabs( lMap.orderPos );
132 };
133
134 /*
135 ===================
136 Item_Nex_MapDB_Destroy
137 ===================
138 */
139 void() Item_Nex_MapDB_Destroy =
140 {
141         String_Free( _Nex_MapList_FullPath );
142         String_Free( _Nex_MapList_Name );
143
144         _Nex_MapList_Root = null_entity;
145 };
146
147 /*
148 ===================
149 Item_Nex_MapDB_Spawn
150 ===================
151 */
152 void() Item_Nex_MapDB_Spawn =
153 {
154         if( _Nex_MapList_Root )
155                 error( "There is already another Item_Nex_MapDB object!" );
156
157         _Nex_MapList_FullPath = String_Create();
158         _Nex_MapList_Name = String_Create();
159         _Nex_MapList_Root = self;
160
161         Item_Nex_MapDB_EnumFiles();
162
163         self._destroy = Item_Nex_MapDB_Destroy;
164 };
165
166 /*
167 ===================
168 Nex_MapDB_GetByName
169 ===================
170 */
171 entity( string pPath ) Nex_MapDB_GetByPath =
172 {
173         local entity lNode;
174
175         if( !_Nex_MapList_Root )
176                 error( "No Item_Nex_MapDB found!" );
177
178         for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
179                 if( lNode.link == pPath ) {
180                         return lNode;
181                 }
182         }
183
184         return null_entity;
185 };
186
187 /*
188 ===================
189 Nex_MapDB_GetByIndex
190 ===================
191 */
192 entity( float pIndex ) Nex_MapDB_GetByIndex =
193 {
194         local entity lNode;
195
196         if( !_Nex_MapList_Root )
197                 error( "No Item_Nex_MapDB found!" );
198
199         pIndex = fabs( pIndex );
200         for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
201                 if( fabs( lNode.orderPos ) == pIndex ) {
202                         return lNode;
203                 }
204         }
205
206         return null_entity;
207 };
208
209 /*
210 ===================
211 Nex_MapDB_GetPathAltString
212 ===================
213 */
214 string() Nex_MapDB_GetPathAltString =
215 {
216         return _Nex_MapList_FullPath;
217 };
218
219 /*
220 ===================
221 Nex_MapDB_GetNameAltString
222 ===================
223 */
224 string() Nex_MapDB_GetNameAltString =
225 {
226         return _Nex_MapList_Name;
227 };
228
229 /*
230 ===================
231 Nex_MapDB_GetIndex
232 ===================
233 */
234 float( entity pItem ) Nex_MapDB_GetIndex =
235 {
236         return fabs( pItem.orderPos );
237 };
238
239 /*
240 ===================
241 Item_DataLink_Nex_MapList_DataEvent
242 ===================
243 */
244 void( float pEvent ) Item_DataLink_Nex_MapList_DataEvent =
245 {
246         switch( pEvent ) {
247         case ITEM_DATA_SYNC:
248                 break;
249         case ITEM_DATA_SEND:
250                 break;
251         case ITEM_DATA_RESET:
252                 self._realValue = 1.0;
253                 break;
254         case ITEM_DATA_TEST_START:
255                 break;
256         case ITEM_DATA_TEST_END:
257                 break;
258         case ITEM_DATALINK_SET:
259         case ITEM_DATALINK_GET:
260                 self._realValue = floor( self._realValue );
261                 if( self._realValue < 1.0 ) {
262                         self._realValue = 1.0;
263                 } else if( self._realValue > self.maxValue ) {
264                         self._realValue = self.maxValue;
265                 }
266
267                 break;
268         }
269 };
270
271 /*
272 ===================
273 Item_DataLink_Nex_MapList_Destroy
274 ===================
275 */
276 void() Item_DataLink_Nex_MapList_Destroy =
277 {
278         String_EntityFree( self, valueList );
279
280         Item_DataLink_Switch_Destroy();
281 };
282
283 /*
284 ===================
285 Item_DataLink_Nex_MapList_Spawn
286 ===================
287 */
288 void() Item_DataLink_Nex_MapList_Spawn =
289 {
290         Item_DataLink_Switch_Init();
291         String_EntityZone( self, valueList );
292
293         self.minValue = 1.0;
294         self.maxValue = 1.0;
295         self.stepValue = 0.0;
296
297         self._dataEvent = Item_DataLink_Nex_MapList_DataEvent;
298         self._destroy = Item_DataLink_Nex_MapList_Destroy;
299
300         CtCall_Init();
301 };
302
303 /*
304 ===================
305 Item_DataLink_Nex_MapList_InitWithMapList
306 ===================
307 */
308 void() Item_DataLink_Nex_MapList_InitWithMapList =
309 {
310         String_EntitySet( self, valueList, Nex_MapDB_GetPathAltString() );
311         String_EntitySet( self, descList, Nex_MapDB_GetNameAltString() );
312
313         DataLink_Nex_MapList_UpdateRange( self );
314 };
315
316 /*
317 ===================
318 DataLink_Nex_MapList_UpdateRange
319 ===================
320 */
321 void( entity pItem ) DataLink_Nex_MapList_UpdateRange =
322 {
323         pItem.minValue = 1.0;
324         pItem.maxValue = Util_GetAltStringCount( pItem.descList );
325
326         if( pItem.maxValue >= 1 ) {
327                 pItem.stepValue = 1.0;
328         } else {
329                 pItem.maxValue = 1.0;
330                 pItem.stepValue = 0.0;
331         }
332 };
333
334 /*
335 ===================
336 DataLink_Nex_MapList_InsertEntryAfter
337 ===================
338 */
339 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_InsertEntryAfter =
340 {
341         local float lIndex;
342
343         Raise_DataEvent( pItem, ITEM_DATALINK_GET );
344         // - 1, because minValue == 1
345         lIndex = pItem._realValue - 1;
346         pItem.descList = Util_InsAltStringItem( pItem.descList, lIndex, pName );
347         pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndex, pPath );
348
349         DataLink_Nex_MapList_UpdateRange( pItem );
350 };
351
352 /*
353 ===================
354 DataLink_Nex_MapList_DeleteEntry
355 ===================
356 */
357 void( entity pItem ) DataLink_Nex_MapList_DeleteEntry =
358 {
359         local float lIndex;
360
361         if( pItem.stepValue == 0.0 )
362                 return;
363
364         Raise_DataEvent( pItem, ITEM_DATALINK_GET );
365         lIndex = pItem._realValue - 1;
366         pItem.descList = Util_DelAltStringItem( pItem.descList, lIndex );
367         pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndex );
368
369         DataLink_Nex_MapList_UpdateRange( pItem );
370 };
371
372 /*
373 ===================
374 DataLink_Nex_MapList_MoveEntryUp
375 ===================
376 */
377 void( entity pItem ) DataLink_Nex_MapList_MoveEntryUp =
378 {
379         local string lName;
380         local string lPath;
381         local float lIndexNew;
382         local float lIndexOld;
383
384         Raise_DataEvent( pItem, ITEM_DATALINK_GET );
385         if( pItem._realValue == 1 )
386                 return;
387
388         // map 1..n to 0..n-1
389         lIndexOld = pItem._realValue - 1;
390
391         // we want to insert it up by one, ie. insert it after up by two
392         lIndexNew = lIndexOld - 2;
393
394         lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
395         lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
396
397         pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
398         pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
399
400         // adjust lIndexOld for the entry that has been inserted before it
401         lIndexOld = lIndexOld + 1;
402
403         pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
404         pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
405
406         DataLink_Nex_MapList_UpdateRange( pItem );
407 };
408
409 /*
410 ===================
411 DataLink_Nex_MapList_MoveEntryDown
412 ===================
413 */
414 void( entity pItem ) DataLink_Nex_MapList_MoveEntryDown =
415 {
416         local string lName;
417         local string lPath;
418         local float lIndexNew;
419         local float lIndexOld;
420
421         Raise_DataEvent( pItem, ITEM_DATALINK_GET );
422         if( pItem._realValue == pItem.maxValue )
423                 return;
424
425         // map 1..n to 0..n-1
426         lIndexOld = pItem._realValue - 1;
427
428         // we want to insert it down by one
429         lIndexNew = lIndexOld + 1;
430
431         lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
432         lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
433
434         pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
435         pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
436
437         pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
438         pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
439
440         DataLink_Nex_MapList_UpdateRange( pItem );
441 };
442
443 /*
444 ===================
445 DataLink_Nex_MapList_SetFirst
446 ===================
447 */
448 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_SetFirst =
449 {
450         if( pItem.stepValue == 0.0 ) {
451                 pItem.descList = Util_AltStringPush( pItem.descList, pName );
452                 pItem.valueList = Util_AltStringPush( pItem.valueList, pPath );
453         } else {
454                 pItem.descList = Util_SetAltStringItem( pItem.descList, 0, pName );
455                 pItem.valueList = Util_SetAltStringItem( pItem.valueList, 0, pPath );
456         }
457
458         DataLink_Nex_MapList_UpdateRange( pItem );
459 };
460
461 /*
462 ===================
463 DataLink_Nex_MapList_Clear
464 ===================
465 */
466 void( entity pItem ) DataLink_Nex_MapList_Clear =
467 {
468         String_EntitySet( pItem, descList, "" );
469         String_EntitySet( pItem, valueList, "" );
470
471         DataLink_Nex_MapList_UpdateRange( pItem );
472 };
473
474 /*
475 ===================
476 DataLink_Nex_MapList_GetCurrentName
477 ===================
478 */
479 string( entity pItem ) DataLink_Nex_MapList_GetCurrentName =
480 {
481         Raise_DataEvent( pItem, ITEM_DATALINK_GET );
482         return Util_GetAltStringItem( pItem.descList, pItem._realValue - 1 );
483 };
484
485 /*
486 ===================
487 DataLink_Nex_MapList_GetCurrentPath
488 ===================
489 */
490 string( entity pItem ) DataLink_Nex_MapList_GetCurrentPath =
491 {
492         Raise_DataEvent( pItem, ITEM_DATALINK_GET );
493         return Util_GetAltStringItem( pItem.valueList, pItem._realValue - 1 );
494 };