]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/custom/creategame.qm
moved menuqc to qcsrc/menu
[divverent/nexuiz.git] / data / qcsrc / menu / custom / creategame.qm
1 // Property of Alientrap
2 // custom/creategame.qm
3
4 // uses target and _target
5 // requires neighbors: Picture, Name, Description
6 void() Nex_MapSelector_UpdateMap =
7 {
8         local entity lInfo;
9         local entity lItem;
10         local entity lSelector;
11         local float lIndex;
12
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 );
17
18         if( lInfo == null_entity ) {
19                 lItem = Menu_GetItem( "Picture" );
20                 String_EntitySet( lItem, picture, "gfx/m_nomap" );
21
22                 lItem = Menu_GetItem( "Name" );
23                 String_EntitySet( lItem, text, "No maps found" );
24
25                 lItem = Menu_GetItem( "Description" );
26                 String_EntitySet( lItem, text, "---" );
27                 return;
28         }
29
30         lItem = Menu_GetItem( "Picture" );
31         String_EntitySet( lItem, picture, lInfo.picture );
32
33         lItem = Menu_GetItem( "Name" );
34         String_EntitySet( lItem, text, lInfo.normal );
35
36         lItem = Menu_GetItem( "Description" );
37         String_EntitySet( lItem, text, lInfo.text );
38
39         lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
40         DataLink_Nex_MapList_SetFirst( lItem, lInfo.normal, lInfo.link );
41 };
42
43 void() Nex_MapSelector_Synchronize =
44 {
45         local entity lCycle;
46         local entity lSelector;
47
48         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
49         lSelector = Menu_GetItem( "::Data::Server::Map::Selector" );
50
51         if( lCycle.stepValue == 0.0 ) {
52                 Raise_DataEvent( lCycle, ITEM_DATA_RESET );
53         } else {
54                 local string lPath;
55                 local entity lMapInfo;
56
57                 lPath = Util_GetAltStringItem( lCycle.valueList, 0 );
58                 lMapInfo = Nex_MapDB_GetByPath( lPath );
59                 String_Free( lPath );
60
61                 if( lMapInfo == null_entity ) {
62                         Raise_DataEvent( lCycle, ITEM_DATA_RESET );
63                 } else {
64                         lSelector._realValue = Nex_MapDB_GetFilteredIndex( lMapInfo );
65                         Raise_DataEvent( lSelector, ITEM_DATALINK_SET );
66                 }
67         }
68 };
69
70 // more concrete functions
71 void() Nex_Action_MapSelector_Next =
72 {
73         local entity lItem;
74
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 );
79 };
80
81 void() Nex_Action_MapSelector_Prev =
82 {
83         local entity lItem;
84
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 );
89 };
90
91 // TODO: Make MaxPlayers real Data items (no container with correct set behavior)
92 void() Nex_Action_Map_Start =
93 {
94         local entity lItem;
95         local string exit_cfg;
96
97         // Set maxplayers
98         lItem = Menu_GetItem( "::Data::Server::MaxPlayers" );
99         cmd( "maxplayers \"", lItem.value, "\"\n" );
100
101         lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
102         Raise_DataEvent( lItem, ITEM_DATA_SEND );
103
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");
107         if(exit_cfg)
108         {
109                 cmd( "exec ", exit_cfg, "\n" );
110         }
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" );
113
114         // force the menu to hide
115         m_hide();
116 };
117
118 void() Nex_Action_Instant_Action =
119 {
120         local string exit_cfg;
121         local float randommap;
122         local float lSearchHandle;
123         local float lSearchSize;
124         local string lFilename;
125
126         lSearchHandle = search_begin( "maps/*.instantaction", true, true );
127         if( lSearchHandle < 0 )
128                 return;
129
130         lSearchSize = search_getsize( lSearchHandle );
131         randommap = random() * lSearchSize;
132         lFilename = search_getfilename( lSearchHandle, randommap );
133
134         search_end( lSearchHandle );
135
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");
139         if(exit_cfg)
140         {
141                 cmd( "exec ", exit_cfg, "\n" );
142         }
143         // exec the game reset cfg and then the mapcfg
144         cmd( strcat( "exec game_reset.cfg \n wait \n exec \"", lFilename, "\"\n") );
145
146         // force the menu to hide
147         m_hide();
148 };
149
150 // cycle list edit features
151 void() Nex_Action_Cycle_Add =
152 {
153         local entity lList;
154         local entity lCycle;
155         local string lPath;
156         local string lName;
157
158         lList = Menu_GetItem( "::Data::Server::Map::List" );
159         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
160
161         lName = DataLink_Nex_MapList_GetCurrentName( lList );
162         lPath = DataLink_Nex_MapList_GetCurrentPath( lList );
163
164         if( lCycle.stepValue == 1.0 ) {
165                 DataLink_Nex_MapList_InsertEntryAfter( lCycle, lName, lPath );
166         } else {
167                 DataLink_Nex_MapList_SetFirst( lCycle, lName, lPath );
168         }
169
170         String_Free( lName );
171         String_Free( lPath );
172
173         lCycle._realValue = lCycle._realValue + 1;
174         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
175
176         Nex_MapSelector_Synchronize();
177 };
178
179 void() Nex_Action_Cycle_Remove =
180 {
181         local entity lCycle;
182
183         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
184         DataLink_Nex_MapList_DeleteEntry( lCycle );
185
186         Nex_MapSelector_Synchronize();
187 };
188
189 void() Nex_Action_Cycle_MoveUp =
190 {
191         local entity lCycle;
192
193         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
194         DataLink_Nex_MapList_MoveEntryUp( lCycle );
195
196         lCycle._realValue = lCycle._realValue - 1;
197         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
198
199         Nex_MapSelector_Synchronize();
200 };
201
202 void() Nex_Action_Cycle_MoveDown =
203 {
204         local entity lCycle;
205
206         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
207         DataLink_Nex_MapList_MoveEntryDown( lCycle );
208
209         lCycle._realValue = lCycle._realValue + 1;
210         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
211
212         Nex_MapSelector_Synchronize();
213 };
214
215 void() Nex_Action_Cycle_Clear =
216 {
217         local entity lCycle;
218
219         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
220         DataLink_Nex_MapList_Clear( lCycle );
221
222         Nex_MapSelector_Synchronize();
223 };
224
225
226 void() Nex_Action_Maplist_ChangeMapType = {
227         local entity lMapQuery;
228         local entity lOldSelf;
229
230         lMapQuery = Menu_GetItem( "::Data::Server::Map::Query" );
231
232         Raise_DataEvent( self._target, ITEM_DATALINK_SET );
233
234         Nex_MapDB_FilterMaps( lMapQuery.value );
235
236         // kind of a hack
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();
241         self = lOldSelf;
242 };
243
244 // mangement
245
246 entity( float pType ) Nex_Management_GetFileList =
247 {
248         switch( pType ) {
249                 case 0:
250                         return Menu_GetItem( "::Data::Management::FileList::Weapon" );
251                 case 1:
252                         return Menu_GetItem( "::Data::Management::FileList::Game" );
253                 case 2:
254                         return Menu_GetItem( "::Data::Management::FileList::MapList" );
255         }
256         crash();
257         return null_entity;
258 };
259
260 entity( float pType ) Nex_Management_GetContainer =
261 {
262         switch( pType ) {
263                 case 0:
264                         return Menu_GetItem( "::Data::Weapon" );
265                 case 1:
266                         return Menu_GetItem( "::Data::Game" );
267                 case 2:
268                         return Menu_GetItem( "::Data::Server::Map::Cycle" );
269         }
270         crash();
271         return null_entity;
272 };
273
274 float() Nex_Management_GetType =
275 {
276         local entity lTypeData;
277
278         lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
279         return stof( lTypeData.value );
280 };
281
282 string() Nex_Management_GetTypeName =
283 {
284         local entity lTypeSwitch;
285
286         lTypeSwitch = Menu_GetItem( "::Data::Management::ConfigType::Switch" );
287         Raise_DataEvent( lTypeSwitch, ITEM_DATALINK_GET );
288         return String_Zone( lTypeSwitch.value );
289 };
290
291 void( float pType ) Nex_Management_SetType =
292 {
293         local entity lItem;
294         local entity lList;
295         local entity lTypeData;
296
297         lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
298         String_EntitySet( lTypeData, value, ftos( pType ) );
299         Raise_DataEvent( lTypeData, ITEM_DATALINK_SET );
300
301         // update the filename
302         /*lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
303         String_EntitySet( lItem, value, "" );
304         Raise_DataEvent( lItem, ITEM_DATALINK_SET );*/
305
306         lItem = Menu_GetItem( "FileList" );
307         lList = Nex_Management_GetFileList( pType );
308         String_EntitySet( lItem, target, lList.name );
309 };
310
311 void() Nex_Action_CopyToFilename =
312 {
313         local entity lItem;
314
315         if( !self._target ) {
316                 return;
317         }
318
319         Raise_DataEvent( self._target, ITEM_DATALINK_GET );
320
321         lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
322         String_EntitySet( lItem, value, self._target.value );
323         Raise_DataEvent( lItem, ITEM_DATALINK_SET );
324 };
325
326 void() Nex_Update_Management_SyncData =
327 {
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;
331         }
332 };
333
334 void() Nex_Action_Management_Refresh =
335 {
336         local entity lItem;
337
338         lItem = Menu_GetItem( "::Data::Management::FileList" );
339         Raise_DataEvent( lItem, ITEM_DATA_SYNC );
340 };
341
342 void() Nex_Action_Management_LoadConfig =
343 {
344         local entity lFileList;
345         local entity lFilenameData;
346         local entity lSyncItem;
347
348         lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
349         lFilenameData = Menu_GetItem( "::Data::Management::Filename" );
350
351         cmd( strcat( "exec \"", lFileList.selected, lFilenameData.value, ".", lFileList.normal, "\"\n" ) );
352
353         lSyncItem = Menu_GetItem( "CreateGame::Panel::Management::SyncCategory" );
354         lSyncItem._realValue = Timer_Time;
355 };
356
357 void() Nex_Action_Management_Load =
358 {
359         local entity lItem;
360         local string lQuestion;
361         local string lTitle;
362
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 );
366                 return;
367         }
368
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 );
374 };
375
376 void() Nex_Action_Management_SaveConfig =
377 {
378         local float lType;
379         local entity lFileList;
380         local entity lFilename;
381         local entity lContainer;
382         local float lHandle;
383
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 );
390                 return;
391         }
392         lHandle = fopen( strcat( lFileList.selected, lFilename.value, ".", lFileList.normal ), FILE_WRITE );
393
394         if( lHandle < 0 ) {
395                 return;
396         }
397
398         Data_ExecString_BeginUse();
399         Raise_DataEvent( lContainer, ITEM_DATA_SAVE_EXECSTRING );
400
401         fputs( lHandle, Data_ExecString );
402
403         Data_ExecString_EndUse();
404
405         fclose( lHandle );
406
407         Nex_Action_Management_Refresh();
408 };
409
410 void() Nex_Action_Management_Save =
411 {
412         local entity lFileList;
413         local entity lFilename;
414         local float lHandle;
415
416         lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
417         lFilename = Menu_GetItem( "::Data::Management::Filename" );
418
419         lHandle = fopen( strcat( lFileList.selected, "/", lFilename.value, ".", lFileList.normal ), FILE_READ );
420
421         if( lHandle == ERR_CANNOTOPEN ) {
422                 Nex_Action_Management_SaveConfig();
423         } else if( lHandle > 0 ) {
424                 local string lQuestion;
425                 local string lTitle;
426
427                 fclose( lHandle );
428
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 );
434         }
435 };
436
437 void() Nex_Action_Management_TypeWeapon =
438 {
439         Nex_Management_SetType( 0 );
440 };
441
442 void() Nex_Action_Management_TypeGame =
443 {
444         Nex_Management_SetType( 1 );
445 };
446
447 void() Nex_Action_Management_TypeMapList =
448 {
449         Nex_Management_SetType( 2 );
450 };