1 // Property of Alientrap
2 // custom/creategame.qm
4 // uses target and _target
5 // requires neighbors: Picture, Name, Description
6 void() Nex_MapSelector_UpdateMap =
10 local entity lSelector;
13 lSelector = Menu_GetItem( "::Data::Server::Map::Selector" );
14 Raise_DataEvent( lSelector, ITEM_DATALINK_GET );
15 lIndex = lSelector._realValue;
16 lInfo = Nex_MapDB_GetFilteredByIndex( lIndex );
18 if( lInfo == null_entity ) {
19 lItem = Menu_GetItem( "Picture" );
20 String_EntitySet( lItem, picture, "gfx/m_nomap" );
22 lItem = Menu_GetItem( "Name" );
23 String_EntitySet( lItem, text, "No maps found" );
25 lItem = Menu_GetItem( "Description" );
26 String_EntitySet( lItem, text, "---" );
30 lItem = Menu_GetItem( "Picture" );
31 String_EntitySet( lItem, picture, lInfo.picture );
33 lItem = Menu_GetItem( "Name" );
34 String_EntitySet( lItem, text, lInfo.normal );
36 lItem = Menu_GetItem( "Description" );
37 String_EntitySet( lItem, text, lInfo.text );
39 lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
40 DataLink_Nex_MapList_SetFirst( lItem, lInfo.normal, lInfo.link );
43 void() Nex_MapSelector_Synchronize =
46 local entity lSelector;
48 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
49 lSelector = Menu_GetItem( "::Data::Server::Map::Selector" );
51 if( lCycle.stepValue == 0.0 ) {
52 Raise_DataEvent( lCycle, ITEM_DATA_RESET );
55 local entity lMapInfo;
57 lPath = Util_GetAltStringItem( lCycle.valueList, 0 );
58 lMapInfo = Nex_MapDB_GetByPath( lPath );
61 if( lMapInfo == null_entity ) {
62 Raise_DataEvent( lCycle, ITEM_DATA_RESET );
64 lSelector._realValue = Nex_MapDB_GetFilteredIndex( lMapInfo );
65 Raise_DataEvent( lSelector, ITEM_DATALINK_SET );
70 // more concrete functions
71 void() Nex_Action_MapSelector_Next =
75 lItem = Menu_GetItem( "::Data::Server::Map::Selector" );
76 Raise_DataEvent( lItem, ITEM_DATALINK_GET );
77 lItem._realValue = lItem._realValue + 1;
78 Raise_DataEvent( lItem, ITEM_DATALINK_SET );
81 void() Nex_Action_MapSelector_Prev =
85 lItem = Menu_GetItem( "::Data::Server::Map::Selector" );
86 Raise_DataEvent( lItem, ITEM_DATALINK_GET );
87 lItem._realValue = lItem._realValue - 1;
88 Raise_DataEvent( lItem, ITEM_DATALINK_SET );
91 // TODO: Make MaxPlayers real Data items (no container with correct set behavior)
92 void() Nex_Action_Map_Start =
95 local string exit_cfg;
98 lItem = Menu_GetItem( "::Data::Server::MaxPlayers" );
99 cmd( "maxplayers \"", lItem.value, "\"\n" );
101 lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
102 Raise_DataEvent( lItem, ITEM_DATA_SEND );
104 // if an old exit cfg file was set up, exec it
105 // to reset old values before starting the server
106 exit_cfg = cvar_string("exit_cfg");
109 cmd( "exec ", exit_cfg, "\n" );
111 // exec the game reset cfg and then the mapcfg
112 cmd( "exec game_reset.cfg \nwait \nexec \"maps/", String_Normal( Util_GetAltStringItem( lItem.valueList, 0 ) ), ".mapcfg\"\n" );
114 // force the menu to hide
118 void() Nex_Action_Instant_Action =
120 local string exit_cfg;
121 local float randommap;
122 local float lSearchHandle;
123 local float lSearchSize;
124 local string lFilename;
126 lSearchHandle = search_begin( "maps/*.instantaction", true, true );
127 if( lSearchHandle < 0 )
130 lSearchSize = search_getsize( lSearchHandle );
131 randommap = random() * lSearchSize;
132 lFilename = search_getfilename( lSearchHandle, randommap );
134 search_end( lSearchHandle );
136 // if an old exit cfg file was set up, exec it
137 // to reset old values before starting the server
138 exit_cfg = cvar_string("exit_cfg");
141 cmd( "exec ", exit_cfg, "\n" );
143 // exec the game reset cfg and then the mapcfg
144 cmd( strcat( "exec game_reset.cfg \n wait \n exec \"", lFilename, "\"\n") );
146 // force the menu to hide
150 // cycle list edit features
151 void() Nex_Action_Cycle_Add =
158 lList = Menu_GetItem( "::Data::Server::Map::List" );
159 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
161 lName = DataLink_Nex_MapList_GetCurrentName( lList );
162 lPath = DataLink_Nex_MapList_GetCurrentPath( lList );
164 if( lCycle.stepValue == 1.0 ) {
165 DataLink_Nex_MapList_InsertEntryAfter( lCycle, lName, lPath );
167 DataLink_Nex_MapList_SetFirst( lCycle, lName, lPath );
170 String_Free( lName );
171 String_Free( lPath );
173 lCycle._realValue = lCycle._realValue + 1;
174 Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
176 Nex_MapSelector_Synchronize();
179 void() Nex_Action_Cycle_Remove =
183 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
184 DataLink_Nex_MapList_DeleteEntry( lCycle );
186 Nex_MapSelector_Synchronize();
189 void() Nex_Action_Cycle_MoveUp =
193 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
194 DataLink_Nex_MapList_MoveEntryUp( lCycle );
196 lCycle._realValue = lCycle._realValue - 1;
197 Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
199 Nex_MapSelector_Synchronize();
202 void() Nex_Action_Cycle_MoveDown =
206 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
207 DataLink_Nex_MapList_MoveEntryDown( lCycle );
209 lCycle._realValue = lCycle._realValue + 1;
210 Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
212 Nex_MapSelector_Synchronize();
215 void() Nex_Action_Cycle_Clear =
219 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
220 DataLink_Nex_MapList_Clear( lCycle );
222 Nex_MapSelector_Synchronize();
226 void() Nex_Action_Maplist_ChangeMapType = {
227 local entity lMapQuery;
228 local entity lOldSelf;
230 lMapQuery = Menu_GetItem( "::Data::Server::Map::Query" );
232 Raise_DataEvent( self._target, ITEM_DATALINK_SET );
234 Nex_MapDB_FilterMaps( lMapQuery.value );
237 self = Menu_GetItem( "::Data::Server::Map::Selector" );
238 Item_DataLink_Nex_MapList_InitWithMapList();
239 self = Menu_GetItem( "::Data::Server::Map::List" );
240 Item_DataLink_Nex_MapList_InitWithMapList();
246 entity( float pType ) Nex_Management_GetFileList =
250 return Menu_GetItem( "::Data::Management::FileList::Weapon" );
252 return Menu_GetItem( "::Data::Management::FileList::Game" );
254 return Menu_GetItem( "::Data::Management::FileList::MapList" );
260 entity( float pType ) Nex_Management_GetContainer =
264 return Menu_GetItem( "::Data::Weapon" );
266 return Menu_GetItem( "::Data::Game" );
268 return Menu_GetItem( "::Data::Server::Map::Cycle" );
274 float() Nex_Management_GetType =
276 local entity lTypeData;
278 lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
279 return stof( lTypeData.value );
282 string() Nex_Management_GetTypeName =
284 local entity lTypeSwitch;
286 lTypeSwitch = Menu_GetItem( "::Data::Management::ConfigType::Switch" );
287 Raise_DataEvent( lTypeSwitch, ITEM_DATALINK_GET );
288 return String_Zone( lTypeSwitch.value );
291 void( float pType ) Nex_Management_SetType =
295 local entity lTypeData;
297 lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
298 String_EntitySet( lTypeData, value, ftos( pType ) );
299 Raise_DataEvent( lTypeData, ITEM_DATALINK_SET );
301 // update the filename
302 /*lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
303 String_EntitySet( lItem, value, "" );
304 Raise_DataEvent( lItem, ITEM_DATALINK_SET );*/
306 lItem = Menu_GetItem( "FileList" );
307 lList = Nex_Management_GetFileList( pType );
308 String_EntitySet( lItem, target, lList.name );
311 void() Nex_Action_CopyToFilename =
315 if( !self._target ) {
319 Raise_DataEvent( self._target, ITEM_DATALINK_GET );
321 lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
322 String_EntitySet( lItem, value, self._target.value );
323 Raise_DataEvent( lItem, ITEM_DATALINK_SET );
326 void() Nex_Update_Management_SyncData =
328 if( self._realValue < Timer_Time && self._realValue > 0.0 ) {
329 Raise_DataEvent( Nex_Management_GetContainer( Nex_Management_GetType() ), ITEM_DATA_SYNC );
330 self._realValue = 0.0;
334 void() Nex_Action_Management_Refresh =
338 lItem = Menu_GetItem( "::Data::Management::FileList" );
339 Raise_DataEvent( lItem, ITEM_DATA_SYNC );
342 void() Nex_Action_Management_LoadConfig =
344 local entity lFileList;
345 local entity lFilenameData;
346 local entity lSyncItem;
348 lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
349 lFilenameData = Menu_GetItem( "::Data::Management::Filename" );
351 cmd( strcat( "exec \"", lFileList.selected, lFilenameData.value, ".", lFileList.normal, "\"\n" ) );
353 lSyncItem = Menu_GetItem( "CreateGame::Panel::Management::SyncCategory" );
354 lSyncItem._realValue = Timer_Time;
357 void() Nex_Action_Management_Load =
360 local string lQuestion;
363 lItem = Menu_GetItem( "::Data::Management::Filename" );
364 if( lItem.value == "" ) {
365 Nex_MessageBox( "Loading", "You must specify a filename!", "Ok", "", Util_NullFunction, Util_NullFunction );
369 lTitle = String_Zone( strcat( "Loading ", String_Normal( Nex_Management_GetTypeName() ) ) );
370 lQuestion = String_Zone( strcat( "Do you want to load '", lItem.value, "'?" ) );
371 Nex_MessageBox( lTitle, lQuestion, "Yes", "No", Nex_Action_Management_LoadConfig, Util_NullFunction );
372 String_Free( lQuestion );
373 String_Free( lTitle );
376 void() Nex_Action_Management_SaveConfig =
379 local entity lFileList;
380 local entity lFilename;
381 local entity lContainer;
384 lType = Nex_Management_GetType();
385 lFileList = Nex_Management_GetFileList( lType );
386 lContainer = Nex_Management_GetContainer( lType );
387 lFilename = Menu_GetItem( "::Data::Management::Filename" );
388 if( lFilename.value == "" ) {
389 Nex_MessageBox( "Saving", "You must specify a filename!", "Ok", "", Util_NullFunction, Util_NullFunction );
392 lHandle = fopen( strcat( lFileList.selected, lFilename.value, ".", lFileList.normal ), FILE_WRITE );
398 Data_ExecString_BeginUse();
399 Raise_DataEvent( lContainer, ITEM_DATA_SAVE_EXECSTRING );
401 fputs( lHandle, Data_ExecString );
403 Data_ExecString_EndUse();
407 Nex_Action_Management_Refresh();
410 void() Nex_Action_Management_Save =
412 local entity lFileList;
413 local entity lFilename;
416 lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
417 lFilename = Menu_GetItem( "::Data::Management::Filename" );
419 lHandle = fopen( strcat( lFileList.selected, "/", lFilename.value, ".", lFileList.normal ), FILE_READ );
421 if( lHandle == ERR_CANNOTOPEN ) {
422 Nex_Action_Management_SaveConfig();
423 } else if( lHandle > 0 ) {
424 local string lQuestion;
429 lTitle = String_Zone( strcat( "Saving ", String_Normal( Nex_Management_GetTypeName() ) ) );
430 lQuestion = String_Zone( strcat( "Do you want to overwrite '", lFilename.value, "'?" ) );
431 Nex_MessageBox( lTitle, lQuestion, "Yes", "No", Nex_Action_Management_SaveConfig, Util_NullFunction );
432 String_Free( lQuestion );
433 String_Free( lTitle );
437 void() Nex_Action_Management_TypeWeapon =
439 Nex_Management_SetType( 0 );
442 void() Nex_Action_Management_TypeGame =
444 Nex_Management_SetType( 1 );
447 void() Nex_Action_Management_TypeMapList =
449 Nex_Management_SetType( 2 );