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