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_GetByIndex( lIndex );
18 // If there is a new selected map, the info panel is updated accordingly
19 if( lIndex != self.minValue ) {
20 self.minValue = lIndex;
22 lItem = Menu_GetItem( "Picture" );
23 String_EntitySet( lItem, picture, lInfo.picture );
25 lItem = Menu_GetItem( "Name" );
26 String_EntitySet( lItem, text, lInfo.normal );
28 lItem = Menu_GetItem( "Description" );
29 String_EntitySet( lItem, text, lInfo.text );
32 lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
33 DataLink_Nex_MapList_SetFirst( lItem, lInfo.normal, lInfo.link );
36 void() Nex_MapSelector_Synchronize =
39 local entity lSelector;
41 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
42 lSelector = Menu_GetItem( "::Data::Server::Map::Selector" );
44 if( lCycle.stepValue == 0.0 ) {
45 Raise_DataEvent( lCycle, ITEM_DATA_RESET );
48 local entity lMapInfo;
50 lPath = Util_GetAltStringItem( lCycle.valueList, 0 );
51 lMapInfo = Nex_MapDB_GetByPath( lPath );
54 if( lMapInfo == null_entity ) {
55 Raise_DataEvent( lCycle, ITEM_DATA_RESET );
57 lSelector._realValue = Nex_MapDB_GetIndex( lMapInfo );
58 Raise_DataEvent( lSelector, ITEM_DATALINK_SET );
63 // more concrete functions
64 void() Nex_Action_MapSelector_Next =
68 lItem = Menu_GetItem( "::Data::Server::Map::Selector" );
69 Raise_DataEvent( lItem, ITEM_DATALINK_GET );
70 lItem._realValue = lItem._realValue + 1;
71 Raise_DataEvent( lItem, ITEM_DATALINK_SET );
74 void() Nex_Action_MapSelector_Prev =
78 lItem = Menu_GetItem( "::Data::Server::Map::Selector" );
79 Raise_DataEvent( lItem, ITEM_DATALINK_GET );
80 lItem._realValue = lItem._realValue - 1;
81 Raise_DataEvent( lItem, ITEM_DATALINK_SET );
84 // TODO: Make MaxPlayers real Data items (no container with correct set behavior)
85 void() Nex_Action_Map_Start =
88 local float lNumBots, lSkill;
89 // we need to set the following var
90 lItem = Menu_GetItem( "::Data::Server::NumBots" );
91 lNumBots = stof( lItem.value );
92 lItem = Menu_GetItem( "::Data::Server::BotSkill" );
93 lSkill = stof( lItem.value );
95 cvar_set( "saved1", "1" );
96 cvar_set( "scratch1", ftos( pow( 2, lNumBots ) - 1 ) );
97 cvar_set( "scratch2", ftos( lSkill * (pow(4, min(lNumBots, 8)) - 1) / 3) );
98 cvar_set( "scratch3", ftos( lSkill * (pow(4, min(lNumBots - 8, 8)) - 1) / 3) );
100 lItem = Menu_GetItem( "::Data::Server::MaxPlayers" );
101 cmd( "maxplayers \"" );
105 lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
107 cmd( String_Normal( Util_GetAltStringItem( lItem.valueList, 0 ) ) );
110 Raise_DataEvent( lItem, ITEM_DATA_SEND );
112 // force the menu to hide
116 // cycle list edit features
117 void() Nex_Action_Cycle_Add =
124 lList = Menu_GetItem( "::Data::Server::Map::List" );
125 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
127 lName = DataLink_Nex_MapList_GetCurrentName( lList );
128 lPath = DataLink_Nex_MapList_GetCurrentPath( lList );
130 if( lCycle.stepValue == 1.0 ) {
131 DataLink_Nex_MapList_InsertEntryAfter( lCycle, lName, lPath );
133 DataLink_Nex_MapList_SetFirst( lCycle, lName, lPath );
136 String_Free( lName );
137 String_Free( lPath );
139 lCycle._realValue = lCycle._realValue + 1;
140 Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
142 Nex_MapSelector_Synchronize();
145 void() Nex_Action_Cycle_Remove =
149 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
150 DataLink_Nex_MapList_DeleteEntry( lCycle );
152 Nex_MapSelector_Synchronize();
155 void() Nex_Action_Cycle_MoveUp =
159 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
160 DataLink_Nex_MapList_MoveEntryUp( lCycle );
162 lCycle._realValue = lCycle._realValue - 1;
163 Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
165 Nex_MapSelector_Synchronize();
168 void() Nex_Action_Cycle_MoveDown =
172 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
173 DataLink_Nex_MapList_MoveEntryDown( lCycle );
175 lCycle._realValue = lCycle._realValue + 1;
176 Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
178 Nex_MapSelector_Synchronize();
181 void() Nex_Action_Cycle_Clear =
185 lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
186 DataLink_Nex_MapList_Clear( lCycle );
188 Nex_MapSelector_Synchronize();
193 entity( float pType ) Nex_Management_GetFileList =
197 return Menu_GetItem( "::Data::Management::FileList::Weapon" );
199 return Menu_GetItem( "::Data::Management::FileList::Game" );
201 return Menu_GetItem( "::Data::Management::FileList::MapList" );
207 entity( float pType ) Nex_Management_GetContainer =
211 return Menu_GetItem( "::Data::Weapon" );
213 return Menu_GetItem( "::Data::Game" );
215 return Menu_GetItem( "::Data::Server::Map::Cycle" );
221 float() Nex_Management_GetType =
223 local entity lTypeData;
225 lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
226 return stof( lTypeData.value );
229 string() Nex_Management_GetTypeName =
231 local entity lTypeSwitch;
233 lTypeSwitch = Menu_GetItem( "::Data::Management::ConfigType::Switch" );
234 Raise_DataEvent( lTypeSwitch, ITEM_DATALINK_GET );
235 return String_Zone( lTypeSwitch.value );
238 void( float pType ) Nex_Management_SetType =
242 local entity lTypeData;
244 lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
245 String_EntitySet( lTypeData, value, ftos( pType ) );
246 Raise_DataEvent( lTypeData, ITEM_DATALINK_SET );
248 // update the filename
249 /*lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
250 String_EntitySet( lItem, value, "" );
251 Raise_DataEvent( lItem, ITEM_DATALINK_SET );*/
253 lItem = Menu_GetItem( "FileList" );
254 lList = Nex_Management_GetFileList( pType );
255 String_EntitySet( lItem, target, lList.name );
258 void() Nex_Action_CopyToFilename =
262 if( !self._target ) {
266 Raise_DataEvent( self._target, ITEM_DATALINK_GET );
268 lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
269 String_EntitySet( lItem, value, self._target.value );
270 Raise_DataEvent( lItem, ITEM_DATALINK_SET );
273 void() Nex_Update_Management_SyncData =
275 if( self._realValue < Timer_Time && self._realValue > 0.0 ) {
276 Raise_DataEvent( Nex_Management_GetContainer( Nex_Management_GetType() ), ITEM_DATA_SYNC );
277 self._realValue = 0.0;
281 void() Nex_Action_Management_Refresh =
285 lItem = Menu_GetItem( "::Data::Management::FileList" );
286 Raise_DataEvent( lItem, ITEM_DATA_SYNC );
289 void() Nex_Action_Management_LoadConfig =
291 local entity lFileList;
292 local entity lFilenameData;
293 local entity lSyncItem;
295 lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
296 lFilenameData = Menu_GetItem( "::Data::Management::Filename" );
298 cmd( strcat( "exec \"", lFileList.selected, "/", lFilenameData.value, ".", lFileList.normal, "\"\n" ) );
300 lSyncItem = Menu_GetItem( "CreateGame::Panel::Management::SyncCategory" );
301 lSyncItem._realValue = Timer_Time;
304 void() Nex_Action_Management_Load =
307 local string lQuestion;
310 lItem = Menu_GetItem( "::Data::Management::Filename" );
311 if( lItem.value == "" ) {
312 Nex_MessageBox( "Loading", "You must specify a filename!", "Ok", "", Util_NullFunction, Util_NullFunction );
316 lTitle = String_Zone( strcat( "Loading ", String_Normal( Nex_Management_GetTypeName() ) ) );
317 lQuestion = String_Zone( strcat( "Do you want to load '", lItem.value, "'?" ) );
318 Nex_MessageBox( lTitle, lQuestion, "Yes", "No", Nex_Action_Management_LoadConfig, Util_NullFunction );
319 String_Free( lQuestion );
320 String_Free( lTitle );
323 void() Nex_Action_Management_SaveConfig =
326 local entity lFileList;
327 local entity lFilename;
328 local entity lContainer;
331 lType = Nex_Management_GetType();
332 lFileList = Nex_Management_GetFileList( lType );
333 lContainer = Nex_Management_GetContainer( lType );
334 lFilename = Menu_GetItem( "::Data::Management::Filename" );
335 if( lFilename.value == "" ) {
336 Nex_MessageBox( "Saving", "You must specify a filename!", "Ok", "", Util_NullFunction, Util_NullFunction );
339 lHandle = fopen( strcat( lFileList.selected, "/", lFilename.value, ".", lFileList.normal ), FILE_WRITE );
345 Data_ExecString_BeginUse();
346 Raise_DataEvent( lContainer, ITEM_DATA_SAVE_EXECSTRING );
348 fputs( lHandle, Data_ExecString );
350 Data_ExecString_EndUse();
354 Nex_Action_Management_Refresh();
357 void() Nex_Action_Management_Save =
359 local entity lFileList;
360 local entity lFilename;
365 lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
366 lFilename = Menu_GetItem( "::Data::Management::Filename" );
368 lHandle = fopen( strcat( lFileList.selected, "/", lFilename.value, ".", lFileList.normal ), FILE_READ );
370 if( lHandle == ERR_CANNOTOPEN ) {
371 Nex_Action_Management_SaveConfig();
373 } else if( lHandle > 0 ) {
374 local string lQuestion;
377 lTitle = String_Zone( strcat( "Saving ", String_Normal( Nex_Management_GetTypeName() ) ) );
378 print( lTitle, "\n" );
379 lQuestion = String_Zone( strcat( "Do you want to overwrite '", lFilename.value, "'?" ) );
380 Nex_MessageBox( lTitle, lQuestion, "Yes", "No", Nex_Action_Management_SaveConfig, Util_NullFunction );
381 String_Free( lQuestion );
382 String_Free( lTitle );
386 void() Nex_Action_Management_TypeWeapon =
388 Nex_Management_SetType( 0 );
391 void() Nex_Action_Management_TypeGame =
393 Nex_Management_SetType( 1 );
396 void() Nex_Action_Management_TypeMapList =
398 Nex_Management_SetType( 2 );