1 // Property of Alientrap/AK
2 // custom/creategame/maps.qc
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;
54 Nex_MapDB_RefreshFiles
60 <Black> use a switch for gametypes
61 <Black> and just set the action field to Nex_MapDB_RefreshFiles
63 <Black> Better to write a new action function though..
64 <Black> And call Nex_Action_TestOnChange to set the Data value
65 <Black> then set up the filter and then call RefreshFiles
66 <Black> or if you put the filter handling into RefrehFiles just call TestOnChange and then RefreshFiles
70 void() Nex_MapDB_RefreshFiles =
75 Nex_Action_TestOnChange();
77 Menu_EmptyWindow( _Nex_MapList_Root );
79 String_Free( _Nex_MapList_FullPath );
80 String_Free( _Nex_MapList_Name );
81 _Nex_MapList_FullPath = String_Create();
82 _Nex_MapList_Name = String_Create();
84 self = _Nex_MapList_Root;
85 Item_Nex_MapDB_EnumFiles();
88 self = Menu_GetItem( "::Data::Server::Map::Selector" );
89 Item_DataLink_Nex_MapList_InitWithMapList();
90 //DataLink_Nex_MapList_UpdateRange(self);
91 //Item_DataLink_Nex_MapList_Load();
94 // fixme: need to change which map the map selector is pointing to right now
96 Raise_DataEvent( self, ITEM_DATALINK_GET );
97 if(self._realValue > self.maxValue)
98 self._realValue = self.maxValue;
99 Raise_DataEvent( self, ITEM_DATALINK_SET );
101 //Nex_MapSelector_UpdateMap();
102 //Nex_MapSelector_Synchronize();
110 Item_Nex_MapDB_EnumFiles
113 // map definition format
115 // rest: description text
116 void() Item_Nex_MapDB_EnumFiles =
118 local float lSearchHandle;
119 local float lSearchSize;
120 local float lSearchCounter;
121 local entity lMap;//, lMapType;
122 local string map_query;
123 local float lMapType;
125 lMapType = cvar("menu_map_type");
126 //lMapType = Menu_GetItem( "::Data::Server::MapType" );
127 if(lMapType == 6)//.value == "Rune Match")
129 map_query = "maps/rune_*.mapcfg";
131 else if(lMapType == 5)//.value == "CTF")
133 map_query = "maps/ctf_*.mapcfg";
135 else if(lMapType == 4)//.value == "Domination")
137 map_query = "maps/dom_*.mapcfg";
139 else if(lMapType == 3)//.value == "Team Deathmatch")
141 map_query = "maps/tdm_*.mapcfg";
143 else if(lMapType == 2)//.value == "Classic Deathmatch")
145 map_query = "maps/dm_*.mapcfg";
149 map_query = "maps/*.mapcfg";
153 lSearchHandle = search_begin( map_query, true, true ); // "maps/*.mapcfg"
154 if( lSearchHandle < 0 )
156 for( lSearchSize = search_getsize( lSearchHandle ), lSearchCounter = 0;
157 lSearchCounter < lSearchSize; ++lSearchCounter ) {
160 local string lFilename;
161 local string lStripped;
164 local string lDescription;
167 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
168 lStripped = String_Zone( substring( lFilename, 0, strlen( lFilename ) - 7 ) ); // - 4
169 lName = String_Zone( substring( lStripped, 5, 100000 ) );
171 lHandle = fopen( strcat( lStripped, ".txt" ), FILE_READ );
173 lTitle = String_Zone( lName );
174 lDescription = String_Zone( strcat( "--NO INFORMATION AVAILABLE--\n", lFilename ) );
176 // uncomment this line and comment the other if you have the old map info files
177 //lTitle = String_Zone( lName );
178 lTitle = String_Zone( fgets( lHandle ) );
179 lPic = fgets( lHandle ); // also get picture
182 lStripped = String_Zone( lPic );
185 lDescription = String_Create();
189 lLine = fgets( lHandle );
190 lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
191 } while( validstring( lLine ) );
196 // save this in a new Map_Info
197 lMap = Menu_CreateItem( "Item_Nex_Map_Info", ftos( lSearchCounter ), self.name );
201 if( Gfx_Precache( lStripped ) ) {
202 lMap.picture = lStripped;
204 lMap.picture = "gfx/m_nomap";
206 lMap.normal = lTitle;
207 lMap.text = lDescription;
209 _Nex_MapList_FullPath = Util_AltStringPushBack( _Nex_MapList_FullPath, lName );
210 _Nex_MapList_Name = Util_AltStringPushBack( _Nex_MapList_Name, lTitle );
212 Menu_LinkItem( lMap );
214 String_Free( lTitle );
215 String_Free( lName );
216 String_Free( lStripped );
217 String_Free( lDescription );
220 search_end( lSearchHandle );
222 Menu_LinkChildren( self );
226 self.maxValue = fabs( lMap.orderPos );
231 Item_Nex_MapDB_Destroy
234 void() Item_Nex_MapDB_Destroy =
236 String_Free( _Nex_MapList_FullPath );
237 String_Free( _Nex_MapList_Name );
239 _Nex_MapList_Root = null_entity;
247 void() Item_Nex_MapDB_Spawn =
249 if( _Nex_MapList_Root )
250 error( "There is already another Item_Nex_MapDB object!" );
252 _Nex_MapList_FullPath = String_Create();
253 _Nex_MapList_Name = String_Create();
254 _Nex_MapList_Root = self;
256 Item_Nex_MapDB_EnumFiles();
258 self._destroy = Item_Nex_MapDB_Destroy;
266 entity( string pPath ) Nex_MapDB_GetByPath =
270 if( !_Nex_MapList_Root )
271 error( "No Item_Nex_MapDB found!" );
273 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
274 if( lNode.link == pPath ) {
287 entity( float pIndex ) Nex_MapDB_GetByIndex =
291 if( !_Nex_MapList_Root )
292 error( "No Item_Nex_MapDB found!" );
294 pIndex = fabs( pIndex );
295 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
296 if( fabs( lNode.orderPos ) == pIndex ) {
306 Nex_MapDB_GetPathAltString
309 string() Nex_MapDB_GetPathAltString =
311 return _Nex_MapList_FullPath;
316 Nex_MapDB_GetNameAltString
319 string() Nex_MapDB_GetNameAltString =
321 return _Nex_MapList_Name;
329 float( entity pItem ) Nex_MapDB_GetIndex =
331 return fabs( pItem.orderPos );
334 void() Item_DataLink_Nex_MapList_Save =
338 local string lOutput;
340 lOutput = String_Create();
342 lCount = Util_GetAltStringCount( self.valueList );
343 for( lIndex = 0 ; lIndex < lCount ; lIndex++ ) {
344 lOutput = String_Append( lOutput, strcat( "\'", String_Normal( Util_GetAltStringItem( self.valueList, lIndex ) ), "\'" ) );
347 cvar_set( self.cvarName, lOutput );
348 cvar_set( strcat( self.cvarName, "_index" ), "0" );
350 String_Free( lOutput );
353 void() Item_DataLink_Nex_MapList_Load =
356 local entity lMapInfo;
357 local float lCounter;
360 DataLink_Nex_MapList_Clear( self );
362 lCount = tokenize( cvar_string( self.cvarName ) );
364 lEntry = String_Create();
365 for( lCounter = 0 ; lCounter < lCount ; lCounter++ ) {
366 lEntry = String_Set( lEntry, argv( lCounter ) );
368 lMapInfo = Nex_MapDB_GetByPath( lEntry );
369 if( lMapInfo == null_entity ) {
370 print( self.cvarName, ": Map '", lEntry, "' not found in database - ignored\n" );
374 self.descList = Util_AltStringPushBack( self.descList, lMapInfo.normal );
375 self.valueList = Util_AltStringPushBack( self.valueList, lMapInfo.link );
377 String_Free( lEntry );
379 DataLink_Nex_MapList_UpdateRange( self );
380 Nex_MapSelector_Synchronize();
383 void() Item_DataLink_Nex_MapList_ExecString =
388 Data_ExecString = String_Append( Data_ExecString, strcat( "set \"", self.cvarName, "_index\" \"0\"\nset \"", self.cvarName, "\" \"" ) );
390 lCount = Util_GetAltStringCount( self.valueList );
391 for( lIndex = 0 ; lIndex < lCount ; lIndex++ ) {
392 Data_ExecString = String_Append( Data_ExecString, strcat( "\'", String_Normal( Util_GetAltStringItem( self.valueList, lIndex ) ), "\'" ) );
395 Data_ExecString = String_Append( Data_ExecString, "\"\n" );
400 Item_DataLink_Nex_MapList_DataEvent
403 void( float pEvent ) Item_DataLink_Nex_MapList_DataEvent =
407 if( self.cvarName != "" ) {
408 Item_DataLink_Nex_MapList_Load();
412 if( self.cvarName != "" ) {
413 Item_DataLink_Nex_MapList_Save();
416 case ITEM_DATA_RESET:
417 self._realValue = 1.0;
419 case ITEM_DATA_TEST_START:
421 case ITEM_DATA_TEST_END:
423 case ITEM_DATA_SAVE_EXECSTRING:
424 if( self.cvarName != "" ) {
425 Item_DataLink_Nex_MapList_ExecString();
428 case ITEM_DATALINK_SET:
429 case ITEM_DATALINK_GET:
430 self._realValue = floor( self._realValue );
431 if( self._realValue < 1.0 ) {
432 self._realValue = 1.0;
433 } else if( self._realValue > self.maxValue ) {
434 self._realValue = self.maxValue;
441 void() IDLNML_Reinit =
443 Raise_DataEvent( self, ITEM_DATA_SYNC );
448 Item_DataLink_Nex_MapList_Destroy
451 void() Item_DataLink_Nex_MapList_Destroy =
453 String_EntityFree( self, valueList );
454 String_EntityFree( self, cvarName );
456 Item_DataLink_Switch_Destroy();
461 Item_DataLink_Nex_MapList_Spawn
464 void() Item_DataLink_Nex_MapList_Spawn =
466 Item_DataLink_Switch_Init();
467 String_EntityZone( self, valueList );
468 String_EntityZone( self, cvarName );
470 if( self.cvarName != "" ) {
471 registercvar( self.cvarName, "", CVAR_SAVE );
472 registercvar( strcat( self.cvarName, "_index" ), "", CVAR_SAVE );
477 self.stepValue = 0.0;
479 self._reinit = IDLNML_Reinit;
480 self._dataEvent = Item_DataLink_Nex_MapList_DataEvent;
481 self._destroy = Item_DataLink_Nex_MapList_Destroy;
488 Item_DataLink_Nex_MapList_InitWithMapList
491 void() Item_DataLink_Nex_MapList_InitWithMapList =
493 String_EntitySet( self, valueList, Nex_MapDB_GetPathAltString() );
494 String_EntitySet( self, descList, Nex_MapDB_GetNameAltString() );
496 DataLink_Nex_MapList_UpdateRange( self );
501 DataLink_Nex_MapList_UpdateRange
504 void( entity pItem ) DataLink_Nex_MapList_UpdateRange =
506 pItem.minValue = 1.0;
507 pItem.maxValue = Util_GetAltStringCount( pItem.descList );
509 if( pItem.maxValue >= 1 ) {
510 pItem.stepValue = 1.0;
512 pItem.maxValue = 1.0;
513 pItem.stepValue = 0.0;
519 DataLink_Nex_MapList_InsertEntryAfter
522 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_InsertEntryAfter =
526 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
527 // - 1, because minValue == 1
528 lIndex = pItem._realValue - 1;
529 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndex, pName );
530 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndex, pPath );
532 DataLink_Nex_MapList_UpdateRange( pItem );
537 DataLink_Nex_MapList_DeleteEntry
540 void( entity pItem ) DataLink_Nex_MapList_DeleteEntry =
544 if( pItem.stepValue == 0.0 )
547 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
548 lIndex = pItem._realValue - 1;
549 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndex );
550 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndex );
552 DataLink_Nex_MapList_UpdateRange( pItem );
557 DataLink_Nex_MapList_MoveEntryUp
560 void( entity pItem ) DataLink_Nex_MapList_MoveEntryUp =
564 local float lIndexNew;
565 local float lIndexOld;
567 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
568 if( pItem._realValue == 1 )
571 // map 1..n to 0..n-1
572 lIndexOld = pItem._realValue - 1;
574 // we want to insert it up by one, ie. insert it after up by two
575 lIndexNew = lIndexOld - 2;
577 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
578 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
580 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
581 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
583 // adjust lIndexOld for the entry that has been inserted before it
584 lIndexOld = lIndexOld + 1;
586 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
587 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
589 DataLink_Nex_MapList_UpdateRange( pItem );
594 DataLink_Nex_MapList_MoveEntryDown
597 void( entity pItem ) DataLink_Nex_MapList_MoveEntryDown =
601 local float lIndexNew;
602 local float lIndexOld;
604 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
605 if( pItem._realValue == pItem.maxValue )
608 // map 1..n to 0..n-1
609 lIndexOld = pItem._realValue - 1;
611 // we want to insert it down by one
612 lIndexNew = lIndexOld + 1;
614 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
615 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
617 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
618 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
620 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
621 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
623 DataLink_Nex_MapList_UpdateRange( pItem );
628 DataLink_Nex_MapList_SetFirst
631 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_SetFirst =
633 if( pItem.stepValue == 0.0 ) {
634 pItem.descList = Util_AltStringPush( pItem.descList, pName );
635 pItem.valueList = Util_AltStringPush( pItem.valueList, pPath );
637 pItem.descList = Util_SetAltStringItem( pItem.descList, 0, pName );
638 pItem.valueList = Util_SetAltStringItem( pItem.valueList, 0, pPath );
641 DataLink_Nex_MapList_UpdateRange( pItem );
646 DataLink_Nex_MapList_Clear
649 void( entity pItem ) DataLink_Nex_MapList_Clear =
651 String_EntitySet( pItem, descList, "" );
652 String_EntitySet( pItem, valueList, "" );
654 DataLink_Nex_MapList_UpdateRange( pItem );
659 DataLink_Nex_MapList_GetCurrentName
662 string( entity pItem ) DataLink_Nex_MapList_GetCurrentName =
664 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
665 return Util_GetAltStringItem( pItem.descList, pItem._realValue - 1 );
670 DataLink_Nex_MapList_GetCurrentPath
673 string( entity pItem ) DataLink_Nex_MapList_GetCurrentPath =
675 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
676 return Util_GetAltStringItem( pItem.valueList, pItem._realValue - 1 );