]> icculus.org git repositories - divverent/nexuiz.git/blob - data/source/custom/creategame.qm
restructure
[divverent/nexuiz.git] / data / source / 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 \"" );
100         cmd( lItem.value );
101         cmd( "\"\n" );
102
103         lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
104         Raise_DataEvent( lItem, ITEM_DATA_SEND );
105
106         // if an old exit cfg file was set up, exec it
107         // to reset old values before starting the server
108         exit_cfg = cvar_string("exit_cfg");
109         if(exit_cfg)
110         {
111                 cmd( "exec ");
112                 cmd( exit_cfg );
113                 cmd( "\n" );
114         }
115         // exec the game reset cfg and then the mapcfg
116         cmd( "exec game_reset.cfg \nwait \nexec \"maps/" );
117         cmd( String_Normal( Util_GetAltStringItem( lItem.valueList, 0 ) ) );
118         cmd( ".mapcfg\"\n");
119
120         // force the menu to hide
121         m_hide();
122 };
123
124 // cycle list edit features
125 void() Nex_Action_Cycle_Add =
126 {
127         local entity lList;
128         local entity lCycle;
129         local string lPath;
130         local string lName;
131
132         lList = Menu_GetItem( "::Data::Server::Map::List" );
133         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
134
135         lName = DataLink_Nex_MapList_GetCurrentName( lList );
136         lPath = DataLink_Nex_MapList_GetCurrentPath( lList );
137
138         if( lCycle.stepValue == 1.0 ) {
139                 DataLink_Nex_MapList_InsertEntryAfter( lCycle, lName, lPath );
140         } else {
141                 DataLink_Nex_MapList_SetFirst( lCycle, lName, lPath );
142         }
143
144         String_Free( lName );
145         String_Free( lPath );
146
147         lCycle._realValue = lCycle._realValue + 1;
148         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
149
150         Nex_MapSelector_Synchronize();
151 };
152
153 void() Nex_Action_Cycle_Remove =
154 {
155         local entity lCycle;
156
157         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
158         DataLink_Nex_MapList_DeleteEntry( lCycle );
159
160         Nex_MapSelector_Synchronize();
161 };
162
163 void() Nex_Action_Cycle_MoveUp =
164 {
165         local entity lCycle;
166
167         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
168         DataLink_Nex_MapList_MoveEntryUp( lCycle );
169
170         lCycle._realValue = lCycle._realValue - 1;
171         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
172
173         Nex_MapSelector_Synchronize();
174 };
175
176 void() Nex_Action_Cycle_MoveDown =
177 {
178         local entity lCycle;
179
180         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
181         DataLink_Nex_MapList_MoveEntryDown( lCycle );
182
183         lCycle._realValue = lCycle._realValue + 1;
184         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
185
186         Nex_MapSelector_Synchronize();
187 };
188
189 void() Nex_Action_Cycle_Clear =
190 {
191         local entity lCycle;
192
193         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
194         DataLink_Nex_MapList_Clear( lCycle );
195
196         Nex_MapSelector_Synchronize();
197 };
198
199
200 void() Nex_Action_Maplist_ChangeMapType = {
201         local entity lMapQuery;
202         local entity lOldSelf;
203
204         lMapQuery = Menu_GetItem( "::Data::Server::Map::Query" );
205
206         Raise_DataEvent( self._target, ITEM_DATALINK_SET );
207
208         Nex_MapDB_FilterMaps( lMapQuery.value );
209
210         // kind of a hack
211         self = Menu_GetItem( "::Data::Server::Map::Selector" );
212         Item_DataLink_Nex_MapList_InitWithMapList();
213         self = Menu_GetItem( "::Data::Server::Map::List" );
214         Item_DataLink_Nex_MapList_InitWithMapList();
215         self = lOldSelf;
216 };
217
218 // mangement
219
220 entity( float pType ) Nex_Management_GetFileList =
221 {
222         switch( pType ) {
223                 case 0:
224                         return Menu_GetItem( "::Data::Management::FileList::Weapon" );
225                 case 1:
226                         return Menu_GetItem( "::Data::Management::FileList::Game" );
227                 case 2:
228                         return Menu_GetItem( "::Data::Management::FileList::MapList" );
229         }
230         crash();
231         return null_entity;
232 };
233
234 entity( float pType ) Nex_Management_GetContainer =
235 {
236         switch( pType ) {
237                 case 0:
238                         return Menu_GetItem( "::Data::Weapon" );
239                 case 1:
240                         return Menu_GetItem( "::Data::Game" );
241                 case 2:
242                         return Menu_GetItem( "::Data::Server::Map::Cycle" );
243         }
244         crash();
245         return null_entity;
246 };
247
248 float() Nex_Management_GetType =
249 {
250         local entity lTypeData;
251
252         lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
253         return stof( lTypeData.value );
254 };
255
256 string() Nex_Management_GetTypeName =
257 {
258         local entity lTypeSwitch;
259
260         lTypeSwitch = Menu_GetItem( "::Data::Management::ConfigType::Switch" );
261         Raise_DataEvent( lTypeSwitch, ITEM_DATALINK_GET );
262         return String_Zone( lTypeSwitch.value );
263 };
264
265 void( float pType ) Nex_Management_SetType =
266 {
267         local entity lItem;
268         local entity lList;
269         local entity lTypeData;
270
271         lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
272         String_EntitySet( lTypeData, value, ftos( pType ) );
273         Raise_DataEvent( lTypeData, ITEM_DATALINK_SET );
274
275         // update the filename
276         /*lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
277         String_EntitySet( lItem, value, "" );
278         Raise_DataEvent( lItem, ITEM_DATALINK_SET );*/
279
280         lItem = Menu_GetItem( "FileList" );
281         lList = Nex_Management_GetFileList( pType );
282         String_EntitySet( lItem, target, lList.name );
283 };
284
285 void() Nex_Action_CopyToFilename =
286 {
287         local entity lItem;
288
289         if( !self._target ) {
290                 return;
291         }
292
293         Raise_DataEvent( self._target, ITEM_DATALINK_GET );
294
295         lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
296         String_EntitySet( lItem, value, self._target.value );
297         Raise_DataEvent( lItem, ITEM_DATALINK_SET );
298 };
299
300 void() Nex_Update_Management_SyncData =
301 {
302         if( self._realValue < Timer_Time && self._realValue > 0.0 ) {
303                 Raise_DataEvent( Nex_Management_GetContainer( Nex_Management_GetType() ), ITEM_DATA_SYNC );
304                 self._realValue = 0.0;
305         }
306 };
307
308 void() Nex_Action_Management_Refresh =
309 {
310         local entity lItem;
311
312         lItem = Menu_GetItem( "::Data::Management::FileList" );
313         Raise_DataEvent( lItem, ITEM_DATA_SYNC );
314 };
315
316 void() Nex_Action_Management_LoadConfig =
317 {
318         local entity lFileList;
319         local entity lFilenameData;
320         local entity lSyncItem;
321
322         lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
323         lFilenameData = Menu_GetItem( "::Data::Management::Filename" );
324
325         cmd( strcat( "exec \"", lFileList.selected, lFilenameData.value, ".", lFileList.normal, "\"\n" ) );
326
327         lSyncItem = Menu_GetItem( "CreateGame::Panel::Management::SyncCategory" );
328         lSyncItem._realValue = Timer_Time;
329 };
330
331 void() Nex_Action_Management_Load =
332 {
333         local entity lItem;
334         local string lQuestion;
335         local string lTitle;
336
337         lItem = Menu_GetItem( "::Data::Management::Filename" );
338         if( lItem.value == "" ) {
339                 Nex_MessageBox( "Loading", "You must specify a filename!", "Ok", "", Util_NullFunction, Util_NullFunction );
340                 return;
341         }
342
343         lTitle = String_Zone( strcat( "Loading ", String_Normal( Nex_Management_GetTypeName() ) ) );
344         lQuestion = String_Zone( strcat( "Do you want to load '", lItem.value, "'?" ) );
345         Nex_MessageBox( lTitle, lQuestion, "Yes", "No", Nex_Action_Management_LoadConfig, Util_NullFunction );
346         String_Free( lQuestion );
347         String_Free( lTitle );
348 };
349
350 void() Nex_Action_Management_SaveConfig =
351 {
352         local float lType;
353         local entity lFileList;
354         local entity lFilename;
355         local entity lContainer;
356         local float lHandle;
357
358         lType = Nex_Management_GetType();
359         lFileList = Nex_Management_GetFileList( lType );
360         lContainer = Nex_Management_GetContainer( lType );
361         lFilename = Menu_GetItem( "::Data::Management::Filename" );
362         if( lFilename.value == "" ) {
363                 Nex_MessageBox( "Saving", "You must specify a filename!", "Ok", "", Util_NullFunction, Util_NullFunction );
364                 return;
365         }
366         lHandle = fopen( strcat( lFileList.selected, lFilename.value, ".", lFileList.normal ), FILE_WRITE );
367
368         if( lHandle < 0 ) {
369                 return;
370         }
371
372         Data_ExecString_BeginUse();
373         Raise_DataEvent( lContainer, ITEM_DATA_SAVE_EXECSTRING );
374
375         fputs( lHandle, Data_ExecString );
376
377         Data_ExecString_EndUse();
378
379         fclose( lHandle );
380
381         Nex_Action_Management_Refresh();
382 };
383
384 void() Nex_Action_Management_Save =
385 {
386         local entity lFileList;
387         local entity lFilename;
388         local float lHandle;
389
390         lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
391         lFilename = Menu_GetItem( "::Data::Management::Filename" );
392
393         lHandle = fopen( strcat( lFileList.selected, "/", lFilename.value, ".", lFileList.normal ), FILE_READ );
394
395         if( lHandle == ERR_CANNOTOPEN ) {
396                 Nex_Action_Management_SaveConfig();
397         } else if( lHandle > 0 ) {
398                 local string lQuestion;
399                 local string lTitle;
400
401                 fclose( lHandle );
402
403                 lTitle = String_Zone( strcat( "Saving ", String_Normal( Nex_Management_GetTypeName() ) ) );
404                 lQuestion = String_Zone( strcat( "Do you want to overwrite '", lFilename.value, "'?" ) );
405                 Nex_MessageBox( lTitle, lQuestion, "Yes", "No", Nex_Action_Management_SaveConfig, Util_NullFunction );
406                 String_Free( lQuestion );
407                 String_Free( lTitle );
408         }
409 };
410
411 void() Nex_Action_Management_TypeWeapon =
412 {
413         Nex_Management_SetType( 0 );
414 };
415
416 void() Nex_Action_Management_TypeGame =
417 {
418         Nex_Management_SetType( 1 );
419 };
420
421 void() Nex_Action_Management_TypeMapList =
422 {
423         Nex_Management_SetType( 2 );
424 };