1 // Property of Alientrap/AK
2 // custom/player/avatar.qm
12 Item_Nex_Map_Info_Destroy
15 void() Item_Nex_Map_Info_Destroy =
17 String_EntityFree( self, link );
18 String_EntityFree( self, picture );
19 String_EntityFree( self, text );
20 String_EntityFree( self, normal );
25 Item_Nex_Map_Info_Spawn
28 void() Item_Nex_Map_Info_Spawn =
30 String_EntityZone( self, link );
31 String_EntityZone( self, picture );
32 String_EntityZone( self, text );
33 String_EntityZone( self, normal );
35 Gfx_Precache( self.picture );
37 self._destroy = Item_Nex_Map_Info_Destroy;
45 string _Nex_MapList_FullPath;
46 string _Nex_MapList_Name;
47 entity _Nex_MapList_Root;
51 Item_Nex_MapDB_EnumFiles
54 // map definition format
56 // rest: description text
57 void() Item_Nex_MapDB_EnumFiles =
59 local float lSearchHandle;
60 local float lSearchSize;
61 local float lSearchCounter;
64 lSearchHandle = search_begin( "maps/*.bsp", true, true );
65 if( lSearchHandle < 0 )
67 for( lSearchSize = search_getsize( lSearchHandle ), lSearchCounter = 0;
68 lSearchCounter < lSearchSize; ++lSearchCounter ) {
71 local string lFilename;
72 local string lStripped;
74 local string lDescription;
77 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
78 lStripped = String_Zone( substring( lFilename, 0, strlen( lFilename ) - 4 ) );
79 lName = String_Zone( substring( lStripped, 5, 100000 ) );
81 lHandle = fopen( strcat( lStripped, ".txt" ), FILE_READ );
83 lTitle = String_Zone( lName );
84 lDescription = String_Zone( strcat( "--NO INFORMATION AVAILABLE--\n", lFilename ) );
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 ) );
90 lDescription = String_Create();
94 lLine = fgets( lHandle );
95 lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
96 } while( validstring( lLine ) );
101 // save this in a new Map_Info
102 lMap = Menu_CreateItem( "Item_Nex_Map_Info", ftos( lSearchCounter ), self.name );
106 if( Gfx_Precache( lStripped ) ) {
107 lMap.picture = lStripped;
109 lMap.picture = "gfx/m_nomap";
111 lMap.normal = lTitle;
112 lMap.text = lDescription;
114 _Nex_MapList_FullPath = Util_AltStringPushBack( _Nex_MapList_FullPath, lName );
115 _Nex_MapList_Name = Util_AltStringPushBack( _Nex_MapList_Name, lTitle );
117 Menu_LinkItem( lMap );
119 String_Free( lTitle );
120 String_Free( lName );
121 String_Free( lStripped );
122 String_Free( lDescription );
125 search_end( lSearchHandle );
127 Menu_LinkChildren( self );
131 self.maxValue = fabs( lMap.orderPos );
136 Item_Nex_MapDB_Destroy
139 void() Item_Nex_MapDB_Destroy =
141 String_Free( _Nex_MapList_FullPath );
142 String_Free( _Nex_MapList_Name );
144 _Nex_MapList_Root = null_entity;
152 void() Item_Nex_MapDB_Spawn =
154 if( _Nex_MapList_Root )
155 error( "There is already another Item_Nex_MapDB object!" );
157 _Nex_MapList_FullPath = String_Create();
158 _Nex_MapList_Name = String_Create();
159 _Nex_MapList_Root = self;
161 Item_Nex_MapDB_EnumFiles();
163 self._destroy = Item_Nex_MapDB_Destroy;
171 entity( string pPath ) Nex_MapDB_GetByPath =
175 if( !_Nex_MapList_Root )
176 error( "No Item_Nex_MapDB found!" );
178 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
179 if( lNode.link == pPath ) {
192 entity( float pIndex ) Nex_MapDB_GetByIndex =
196 if( !_Nex_MapList_Root )
197 error( "No Item_Nex_MapDB found!" );
199 pIndex = fabs( pIndex );
200 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
201 if( fabs( lNode.orderPos ) == pIndex ) {
211 Nex_MapDB_GetPathAltString
214 string() Nex_MapDB_GetPathAltString =
216 return _Nex_MapList_FullPath;
221 Nex_MapDB_GetNameAltString
224 string() Nex_MapDB_GetNameAltString =
226 return _Nex_MapList_Name;
234 float( entity pItem ) Nex_MapDB_GetIndex =
236 return fabs( pItem.orderPos );
241 Item_DataLink_Nex_MapList_DataEvent
244 void( float pEvent ) Item_DataLink_Nex_MapList_DataEvent =
251 case ITEM_DATA_RESET:
252 self._realValue = 1.0;
254 case ITEM_DATA_TEST_START:
256 case ITEM_DATA_TEST_END:
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;
273 Item_DataLink_Nex_MapList_Destroy
276 void() Item_DataLink_Nex_MapList_Destroy =
278 String_EntityFree( self, valueList );
280 Item_DataLink_Switch_Destroy();
285 Item_DataLink_Nex_MapList_Spawn
288 void() Item_DataLink_Nex_MapList_Spawn =
290 Item_DataLink_Switch_Init();
291 String_EntityZone( self, valueList );
295 self.stepValue = 0.0;
297 self._dataEvent = Item_DataLink_Nex_MapList_DataEvent;
298 self._destroy = Item_DataLink_Nex_MapList_Destroy;
305 Item_DataLink_Nex_MapList_InitWithMapList
308 void() Item_DataLink_Nex_MapList_InitWithMapList =
310 String_EntitySet( self, valueList, Nex_MapDB_GetPathAltString() );
311 String_EntitySet( self, descList, Nex_MapDB_GetNameAltString() );
313 DataLink_Nex_MapList_UpdateRange( self );
318 DataLink_Nex_MapList_UpdateRange
321 void( entity pItem ) DataLink_Nex_MapList_UpdateRange =
323 pItem.minValue = 1.0;
324 pItem.maxValue = Util_GetAltStringCount( pItem.descList );
326 if( pItem.maxValue >= 1 ) {
327 pItem.stepValue = 1.0;
329 pItem.maxValue = 1.0;
330 pItem.stepValue = 0.0;
336 DataLink_Nex_MapList_InsertEntryAfter
339 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_InsertEntryAfter =
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 );
349 DataLink_Nex_MapList_UpdateRange( pItem );
354 DataLink_Nex_MapList_DeleteEntry
357 void( entity pItem ) DataLink_Nex_MapList_DeleteEntry =
361 if( pItem.stepValue == 0.0 )
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 );
369 DataLink_Nex_MapList_UpdateRange( pItem );
374 DataLink_Nex_MapList_MoveEntryUp
377 void( entity pItem ) DataLink_Nex_MapList_MoveEntryUp =
381 local float lIndexNew;
382 local float lIndexOld;
384 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
385 if( pItem._realValue == 1 )
388 // map 1..n to 0..n-1
389 lIndexOld = pItem._realValue - 1;
391 // we want to insert it up by one, ie. insert it after up by two
392 lIndexNew = lIndexOld - 2;
394 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
395 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
397 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
398 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
400 // adjust lIndexOld for the entry that has been inserted before it
401 lIndexOld = lIndexOld + 1;
403 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
404 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
406 DataLink_Nex_MapList_UpdateRange( pItem );
411 DataLink_Nex_MapList_MoveEntryDown
414 void( entity pItem ) DataLink_Nex_MapList_MoveEntryDown =
418 local float lIndexNew;
419 local float lIndexOld;
421 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
422 if( pItem._realValue == pItem.maxValue )
425 // map 1..n to 0..n-1
426 lIndexOld = pItem._realValue - 1;
428 // we want to insert it down by one
429 lIndexNew = lIndexOld + 1;
431 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
432 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
434 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
435 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
437 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
438 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
440 DataLink_Nex_MapList_UpdateRange( pItem );
445 DataLink_Nex_MapList_SetFirst
448 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_SetFirst =
450 if( pItem.stepValue == 0.0 ) {
451 pItem.descList = Util_AltStringPush( pItem.descList, pName );
452 pItem.valueList = Util_AltStringPush( pItem.valueList, pPath );
454 pItem.descList = Util_SetAltStringItem( pItem.descList, 0, pName );
455 pItem.valueList = Util_SetAltStringItem( pItem.valueList, 0, pPath );
458 DataLink_Nex_MapList_UpdateRange( pItem );
463 DataLink_Nex_MapList_Clear
466 void( entity pItem ) DataLink_Nex_MapList_Clear =
468 String_EntitySet( pItem, descList, "" );
469 String_EntitySet( pItem, valueList, "" );
471 DataLink_Nex_MapList_UpdateRange( pItem );
476 DataLink_Nex_MapList_GetCurrentName
479 string( entity pItem ) DataLink_Nex_MapList_GetCurrentName =
481 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
482 return Util_GetAltStringItem( pItem.descList, pItem._realValue - 1 );
487 DataLink_Nex_MapList_GetCurrentPath
490 string( entity pItem ) DataLink_Nex_MapList_GetCurrentPath =
492 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
493 return Util_GetAltStringItem( pItem.valueList, pItem._realValue - 1 );