]> icculus.org git repositories - divverent/nexuiz.git/blob - scmenu/source/custom/creategame.qm
Commit round I. Im too tired to write the selector and maplist reset code right now...
[divverent/nexuiz.git] / scmenu / 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_GetByIndex( 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         // If there is a new selected map, the info panel is updated accordingly
31         if( lIndex != self.minValue ) {
32                 self.minValue = lIndex;
33
34                 lItem = Menu_GetItem( "Picture" );
35                 String_EntitySet( lItem, picture, lInfo.picture );
36
37                 lItem = Menu_GetItem( "Name" );
38                 String_EntitySet( lItem, text, lInfo.normal );
39
40                 lItem = Menu_GetItem( "Description" );
41                 String_EntitySet( lItem, text, lInfo.text );
42         }
43
44         lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
45         DataLink_Nex_MapList_SetFirst( lItem, lInfo.normal, lInfo.link );
46 };
47
48 void() Nex_MapSelector_Synchronize =
49 {
50         local entity lCycle;
51         local entity lSelector;
52
53         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
54         lSelector = Menu_GetItem( "::Data::Server::Map::Selector" );
55
56         if( lCycle.stepValue == 0.0 ) {
57                 Raise_DataEvent( lCycle, ITEM_DATA_RESET );
58         } else {
59                 local string lPath;
60                 local entity lMapInfo;
61
62                 lPath = Util_GetAltStringItem( lCycle.valueList, 0 );
63                 lMapInfo = Nex_MapDB_GetByPath( lPath );
64                 String_Free( lPath );
65
66                 if( lMapInfo == null_entity ) {
67                         Raise_DataEvent( lCycle, ITEM_DATA_RESET );
68                 } else {
69                         lSelector._realValue = Nex_MapDB_GetIndex( lMapInfo );
70                         Raise_DataEvent( lSelector, ITEM_DATALINK_SET );
71                 }
72         }
73 };
74
75 // more concrete functions
76 void() Nex_Action_MapSelector_Next =
77 {
78         local entity lItem;
79
80         lItem = Menu_GetItem( "::Data::Server::Map::Selector" );
81         Raise_DataEvent( lItem, ITEM_DATALINK_GET );
82         lItem._realValue = lItem._realValue + 1;
83         Raise_DataEvent( lItem, ITEM_DATALINK_SET );
84 };
85
86 void() Nex_Action_MapSelector_Prev =
87 {
88         local entity lItem;
89
90         lItem = Menu_GetItem( "::Data::Server::Map::Selector" );
91         Raise_DataEvent( lItem, ITEM_DATALINK_GET );
92         lItem._realValue = lItem._realValue - 1;
93         Raise_DataEvent( lItem, ITEM_DATALINK_SET );
94 };
95
96 // TODO: Make MaxPlayers real Data items (no container with correct set behavior)
97 void() Nex_Action_Map_Start =
98 {
99         local entity lItem;
100         local string exit_cfg;
101
102         // Set maxplayers
103         lItem = Menu_GetItem( "::Data::Server::MaxPlayers" );
104         cmd( "maxplayers \"" );
105         cmd( lItem.value );
106         cmd( "\"\n" );
107
108         lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
109
110         // if an old exit cfg file was set up, exec it
111         // to reset old values before starting the server
112         exit_cfg = cvar_string("exit_cfg");
113         if(exit_cfg)
114         {
115                 cmd( "exec ");
116                 cmd( exit_cfg );
117                 cmd( "\n" );
118         }
119         // exec the game reset cfg and then the mapcfg
120         cmd( "exec game_reset.cfg \nwait \nexec \"maps/" );
121         cmd( String_Normal( Util_GetAltStringItem( lItem.valueList, 0 ) ) );
122         cmd( ".mapcfg\"\n");
123
124         Raise_DataEvent( lItem, ITEM_DATA_SEND );
125
126         // force the menu to hide
127         m_hide();
128 };
129
130 // cycle list edit features
131 void() Nex_Action_Cycle_Add =
132 {
133         local entity lList;
134         local entity lCycle;
135         local string lPath;
136         local string lName;
137
138         lList = Menu_GetItem( "::Data::Server::Map::List" );
139         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
140
141         lName = DataLink_Nex_MapList_GetCurrentName( lList );
142         lPath = DataLink_Nex_MapList_GetCurrentPath( lList );
143
144         if( lCycle.stepValue == 1.0 ) {
145                 DataLink_Nex_MapList_InsertEntryAfter( lCycle, lName, lPath );
146         } else {
147                 DataLink_Nex_MapList_SetFirst( lCycle, lName, lPath );
148         }
149
150         String_Free( lName );
151         String_Free( lPath );
152
153         lCycle._realValue = lCycle._realValue + 1;
154         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
155
156         Nex_MapSelector_Synchronize();
157 };
158
159 void() Nex_Action_Cycle_Remove =
160 {
161         local entity lCycle;
162
163         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
164         DataLink_Nex_MapList_DeleteEntry( lCycle );
165
166         Nex_MapSelector_Synchronize();
167 };
168
169 void() Nex_Action_Cycle_MoveUp =
170 {
171         local entity lCycle;
172
173         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
174         DataLink_Nex_MapList_MoveEntryUp( lCycle );
175
176         lCycle._realValue = lCycle._realValue - 1;
177         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
178
179         Nex_MapSelector_Synchronize();
180 };
181
182 void() Nex_Action_Cycle_MoveDown =
183 {
184         local entity lCycle;
185
186         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
187         DataLink_Nex_MapList_MoveEntryDown( lCycle );
188
189         lCycle._realValue = lCycle._realValue + 1;
190         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
191
192         Nex_MapSelector_Synchronize();
193 };
194
195 void() Nex_Action_Cycle_Clear =
196 {
197         local entity lCycle;
198
199         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
200         DataLink_Nex_MapList_Clear( lCycle );
201
202         Nex_MapSelector_Synchronize();
203 };
204
205 // mangement
206
207 entity( float pType ) Nex_Management_GetFileList =
208 {
209         switch( pType ) {
210                 case 0:
211                         return Menu_GetItem( "::Data::Management::FileList::Weapon" );
212                 case 1:
213                         return Menu_GetItem( "::Data::Management::FileList::Game" );
214                 case 2:
215                         return Menu_GetItem( "::Data::Management::FileList::MapList" );
216         }
217         crash();
218         return null_entity;
219 };
220
221 entity( float pType ) Nex_Management_GetContainer =
222 {
223         switch( pType ) {
224                 case 0:
225                         return Menu_GetItem( "::Data::Weapon" );
226                 case 1:
227                         return Menu_GetItem( "::Data::Game" );
228                 case 2:
229                         return Menu_GetItem( "::Data::Server::Map::Cycle" );
230         }
231         crash();
232         return null_entity;
233 };
234
235 float() Nex_Management_GetType =
236 {
237         local entity lTypeData;
238
239         lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
240         return stof( lTypeData.value );
241 };
242
243 string() Nex_Management_GetTypeName =
244 {
245         local entity lTypeSwitch;
246
247         lTypeSwitch = Menu_GetItem( "::Data::Management::ConfigType::Switch" );
248         Raise_DataEvent( lTypeSwitch, ITEM_DATALINK_GET );
249         return String_Zone( lTypeSwitch.value );
250 };
251
252 void( float pType ) Nex_Management_SetType =
253 {
254         local entity lItem;
255         local entity lList;
256         local entity lTypeData;
257
258         lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
259         String_EntitySet( lTypeData, value, ftos( pType ) );
260         Raise_DataEvent( lTypeData, ITEM_DATALINK_SET );
261
262         // update the filename
263         /*lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
264         String_EntitySet( lItem, value, "" );
265         Raise_DataEvent( lItem, ITEM_DATALINK_SET );*/
266
267         lItem = Menu_GetItem( "FileList" );
268         lList = Nex_Management_GetFileList( pType );
269         String_EntitySet( lItem, target, lList.name );
270 };
271
272 void() Nex_Action_CopyToFilename =
273 {
274         local entity lItem;
275
276         if( !self._target ) {
277                 return;
278         }
279
280         Raise_DataEvent( self._target, ITEM_DATALINK_GET );
281
282         lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
283         String_EntitySet( lItem, value, self._target.value );
284         Raise_DataEvent( lItem, ITEM_DATALINK_SET );
285 };
286
287 void() Nex_Update_Management_SyncData =
288 {
289         if( self._realValue < Timer_Time && self._realValue > 0.0 ) {
290                 Raise_DataEvent( Nex_Management_GetContainer( Nex_Management_GetType() ), ITEM_DATA_SYNC );
291                 self._realValue = 0.0;
292         }
293 };
294
295 void() Nex_Action_Management_Refresh =
296 {
297         local entity lItem;
298
299         lItem = Menu_GetItem( "::Data::Management::FileList" );
300         Raise_DataEvent( lItem, ITEM_DATA_SYNC );
301 };
302
303 void() Nex_Action_Management_LoadConfig =
304 {
305         local entity lFileList;
306         local entity lFilenameData;
307         local entity lSyncItem;
308
309         lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
310         lFilenameData = Menu_GetItem( "::Data::Management::Filename" );
311
312         cmd( strcat( "exec \"", lFileList.selected, lFilenameData.value, ".", lFileList.normal, "\"\n" ) );
313
314         lSyncItem = Menu_GetItem( "CreateGame::Panel::Management::SyncCategory" );
315         lSyncItem._realValue = Timer_Time;
316 };
317
318 void() Nex_Action_Management_Load =
319 {
320         local entity lItem;
321         local string lQuestion;
322         local string lTitle;
323
324         lItem = Menu_GetItem( "::Data::Management::Filename" );
325         if( lItem.value == "" ) {
326                 Nex_MessageBox( "Loading", "You must specify a filename!", "Ok", "", Util_NullFunction, Util_NullFunction );
327                 return;
328         }
329
330         lTitle = String_Zone( strcat( "Loading ", String_Normal( Nex_Management_GetTypeName() ) ) );
331         lQuestion = String_Zone( strcat( "Do you want to load '", lItem.value, "'?" ) );
332         Nex_MessageBox( lTitle, lQuestion, "Yes", "No", Nex_Action_Management_LoadConfig, Util_NullFunction );
333         String_Free( lQuestion );
334         String_Free( lTitle );
335 };
336
337 void() Nex_Action_Management_SaveConfig =
338 {
339         local float lType;
340         local entity lFileList;
341         local entity lFilename;
342         local entity lContainer;
343         local float lHandle;
344
345         lType = Nex_Management_GetType();
346         lFileList = Nex_Management_GetFileList( lType );
347         lContainer = Nex_Management_GetContainer( lType );
348         lFilename = Menu_GetItem( "::Data::Management::Filename" );
349         if( lFilename.value == "" ) {
350                 Nex_MessageBox( "Saving", "You must specify a filename!", "Ok", "", Util_NullFunction, Util_NullFunction );
351                 return;
352         }
353         lHandle = fopen( strcat( lFileList.selected, lFilename.value, ".", lFileList.normal ), FILE_WRITE );
354
355         if( lHandle < 0 ) {
356                 return;
357         }
358
359         Data_ExecString_BeginUse();
360         Raise_DataEvent( lContainer, ITEM_DATA_SAVE_EXECSTRING );
361
362         fputs( lHandle, Data_ExecString );
363
364         Data_ExecString_EndUse();
365
366         fclose( lHandle );
367
368         Nex_Action_Management_Refresh();
369 };
370
371 void() Nex_Action_Management_Save =
372 {
373         local entity lFileList;
374         local entity lFilename;
375         local float lHandle;
376
377         lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
378         lFilename = Menu_GetItem( "::Data::Management::Filename" );
379
380         lHandle = fopen( strcat( lFileList.selected, "/", lFilename.value, ".", lFileList.normal ), FILE_READ );
381
382         if( lHandle == ERR_CANNOTOPEN ) {
383                 Nex_Action_Management_SaveConfig();
384         } else if( lHandle > 0 ) {
385                 local string lQuestion;
386                 local string lTitle;
387
388                 fclose( lHandle );
389
390                 lTitle = String_Zone( strcat( "Saving ", String_Normal( Nex_Management_GetTypeName() ) ) );
391                 print( lTitle, "\n" );
392                 lQuestion = String_Zone( strcat( "Do you want to overwrite '", lFilename.value, "'?" ) );
393                 Nex_MessageBox( lTitle, lQuestion, "Yes", "No", Nex_Action_Management_SaveConfig, Util_NullFunction );
394                 String_Free( lQuestion );
395                 String_Free( lTitle );
396         }
397 };
398
399 void() Nex_Action_Management_TypeWeapon =
400 {
401         Nex_Management_SetType( 0 );
402 };
403
404 void() Nex_Action_Management_TypeGame =
405 {
406         Nex_Management_SetType( 1 );
407 };
408
409 void() Nex_Action_Management_TypeMapList =
410 {
411         Nex_Management_SetType( 2 );
412 };
413
414 // FIXME: hackish
415 void() Nex_Action_Maplist_ChangeMapType = {
416         local entity lOldSelf;
417
418         // HACK
419         Nex_Action_TestOnChange();
420
421         lOldSelf = self;
422
423         Nex_MapDB_RefreshFiles();
424
425         self = Menu_GetItem( "::Data::Server::Map::Selector" );
426         Item_DataLink_Nex_MapList_InitWithMapList();
427         //DataLink_Nex_MapList_UpdateRange(self);
428         //Item_DataLink_Nex_MapList_Load();
429
430         // fixme: need to change which map the map selector is pointing to right now
431
432         Raise_DataEvent( self, ITEM_DATALINK_GET );
433         if(self._realValue > self.maxValue)
434                 self._realValue = self.maxValue;
435         Raise_DataEvent( self, ITEM_DATALINK_SET );
436
437         //Nex_MapSelector_UpdateMap();
438         //Nex_MapSelector_Synchronize();
439
440         self = lOldSelf;
441 };