]> icculus.org git repositories - divverent/nexuiz.git/blob - scmenu/source/custom/creategame.qm
-The Loading/Saving messageboxes now also have the settings type in their title.
[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 there is a new selected map, the info panel is updated accordingly
19         if( lIndex != self.minValue ) {
20                 self.minValue = lIndex;
21
22                 lItem = Menu_GetItem( "Picture" );
23                 String_EntitySet( lItem, picture, lInfo.picture );
24
25                 lItem = Menu_GetItem( "Name" );
26                 String_EntitySet( lItem, text, lInfo.normal );
27
28                 lItem = Menu_GetItem( "Description" );
29                 String_EntitySet( lItem, text, lInfo.text );
30         }
31
32         lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
33         DataLink_Nex_MapList_SetFirst( lItem, lInfo.normal, lInfo.link );
34 };
35
36 void() Nex_MapSelector_Synchronize =
37 {
38         local entity lCycle;
39         local entity lSelector;
40
41         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
42         lSelector = Menu_GetItem( "::Data::Server::Map::Selector" );
43
44         if( lCycle.stepValue == 0.0 ) {
45                 Raise_DataEvent( lCycle, ITEM_DATA_RESET );
46         } else {
47                 local string lPath;
48                 local entity lMapInfo;
49
50                 lPath = Util_GetAltStringItem( lCycle.valueList, 0 );
51                 lMapInfo = Nex_MapDB_GetByPath( lPath );
52                 String_Free( lPath );
53
54                 if( lMapInfo == null_entity ) {
55                         Raise_DataEvent( lCycle, ITEM_DATA_RESET );
56                 } else {
57                         lSelector._realValue = Nex_MapDB_GetIndex( lMapInfo );
58                         Raise_DataEvent( lSelector, ITEM_DATALINK_SET );
59                 }
60         }
61 };
62
63 // more concrete functions
64 void() Nex_Action_MapSelector_Next =
65 {
66         local entity lItem;
67
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 );
72 };
73
74 void() Nex_Action_MapSelector_Prev =
75 {
76         local entity lItem;
77
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 );
82 };
83
84 // TODO: Make MaxPlayers real Data items (no container with correct set behavior)
85 void() Nex_Action_Map_Start =
86 {
87         local entity lItem;
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 );
94
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) );
99         // Set maxplayers
100         lItem = Menu_GetItem( "::Data::Server::MaxPlayers" );
101         cmd( "maxplayers \"" );
102         cmd( lItem.value );
103         cmd( "\"\n" );
104
105         lItem = Menu_GetItem( "::Data::Server::Map::Cycle" );
106         cmd( "map \"" );
107         cmd( String_Normal( Util_GetAltStringItem( lItem.valueList, 0 ) ) );
108         cmd( "\"\n");
109
110         Raise_DataEvent( lItem, ITEM_DATA_SEND );
111
112         // force the menu to hide
113         m_hide();
114 };
115
116 // cycle list edit features
117 void() Nex_Action_Cycle_Add =
118 {
119         local entity lList;
120         local entity lCycle;
121         local string lPath;
122         local string lName;
123
124         lList = Menu_GetItem( "::Data::Server::Map::List" );
125         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
126
127         lName = DataLink_Nex_MapList_GetCurrentName( lList );
128         lPath = DataLink_Nex_MapList_GetCurrentPath( lList );
129
130         if( lCycle.stepValue == 1.0 ) {
131                 DataLink_Nex_MapList_InsertEntryAfter( lCycle, lName, lPath );
132         } else {
133                 DataLink_Nex_MapList_SetFirst( lCycle, lName, lPath );
134         }
135
136         String_Free( lName );
137         String_Free( lPath );
138
139         lCycle._realValue = lCycle._realValue + 1;
140         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
141
142         Nex_MapSelector_Synchronize();
143 };
144
145 void() Nex_Action_Cycle_Remove =
146 {
147         local entity lCycle;
148
149         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
150         DataLink_Nex_MapList_DeleteEntry( lCycle );
151
152         Nex_MapSelector_Synchronize();
153 };
154
155 void() Nex_Action_Cycle_MoveUp =
156 {
157         local entity lCycle;
158
159         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
160         DataLink_Nex_MapList_MoveEntryUp( lCycle );
161
162         lCycle._realValue = lCycle._realValue - 1;
163         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
164
165         Nex_MapSelector_Synchronize();
166 };
167
168 void() Nex_Action_Cycle_MoveDown =
169 {
170         local entity lCycle;
171
172         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
173         DataLink_Nex_MapList_MoveEntryDown( lCycle );
174
175         lCycle._realValue = lCycle._realValue + 1;
176         Raise_DataEvent( lCycle, ITEM_DATALINK_SET );
177
178         Nex_MapSelector_Synchronize();
179 };
180
181 void() Nex_Action_Cycle_Clear =
182 {
183         local entity lCycle;
184
185         lCycle = Menu_GetItem( "::Data::Server::Map::Cycle" );
186         DataLink_Nex_MapList_Clear( lCycle );
187
188         Nex_MapSelector_Synchronize();
189 };
190
191 // mangement
192
193 entity( float pType ) Nex_Management_GetFileList =
194 {
195         switch( pType ) {
196                 case 0:
197                         return Menu_GetItem( "::Data::Management::FileList::Weapon" );
198                 case 1:
199                         return Menu_GetItem( "::Data::Management::FileList::Game" );
200                 case 2:
201                         return Menu_GetItem( "::Data::Management::FileList::MapList" );
202         }
203         crash();
204         return null_entity;
205 };
206
207 entity( float pType ) Nex_Management_GetContainer =
208 {
209         switch( pType ) {
210                 case 0:
211                         return Menu_GetItem( "::Data::Weapon" );
212                 case 1:
213                         return Menu_GetItem( "::Data::Game" );
214                 case 2:
215                         return Menu_GetItem( "::Data::Server::Map::Cycle" );
216         }
217         crash();
218         return null_entity;
219 };
220
221 float() Nex_Management_GetType =
222 {
223         local entity lTypeData;
224
225         lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
226         return stof( lTypeData.value );
227 };
228
229 string() Nex_Management_GetTypeName =
230 {
231         local entity lTypeSwitch;
232
233         lTypeSwitch = Menu_GetItem( "::Data::Management::ConfigType::Switch" );
234         Raise_DataEvent( lTypeSwitch, ITEM_DATALINK_GET );
235         return String_Zone( lTypeSwitch.value );
236 };
237
238 void( float pType ) Nex_Management_SetType =
239 {
240         local entity lItem;
241         local entity lList;
242         local entity lTypeData;
243
244         lTypeData = Menu_GetItem( "::Data::Management::ConfigType" );
245         String_EntitySet( lTypeData, value, ftos( pType ) );
246         Raise_DataEvent( lTypeData, ITEM_DATALINK_SET );
247
248         // update the filename
249         /*lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
250         String_EntitySet( lItem, value, "" );
251         Raise_DataEvent( lItem, ITEM_DATALINK_SET );*/
252
253         lItem = Menu_GetItem( "FileList" );
254         lList = Nex_Management_GetFileList( pType );
255         String_EntitySet( lItem, target, lList.name );
256 };
257
258 void() Nex_Action_CopyToFilename =
259 {
260         local entity lItem;
261
262         if( !self._target ) {
263                 return;
264         }
265
266         Raise_DataEvent( self._target, ITEM_DATALINK_GET );
267
268         lItem = Menu_GetItem( "::Data::Management::Filename::Text" );
269         String_EntitySet( lItem, value, self._target.value );
270         Raise_DataEvent( lItem, ITEM_DATALINK_SET );
271 };
272
273 void() Nex_Update_Management_SyncData =
274 {
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;
278         }
279 };
280
281 void() Nex_Action_Management_Refresh =
282 {
283         local entity lItem;
284
285         lItem = Menu_GetItem( "::Data::Management::FileList" );
286         Raise_DataEvent( lItem, ITEM_DATA_SYNC );
287 };
288
289 void() Nex_Action_Management_LoadConfig =
290 {
291         local entity lFileList;
292         local entity lFilenameData;
293         local entity lSyncItem;
294
295         lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
296         lFilenameData = Menu_GetItem( "::Data::Management::Filename" );
297
298         cmd( strcat( "exec \"", lFileList.selected, "/", lFilenameData.value, ".", lFileList.normal, "\"\n" ) );
299
300         lSyncItem = Menu_GetItem( "CreateGame::Panel::Management::SyncCategory" );
301         lSyncItem._realValue = Timer_Time;
302 };
303
304 void() Nex_Action_Management_Load =
305 {
306         local entity lItem;
307         local string lQuestion;
308         local string lTitle;
309
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 );
313                 return;
314         }
315
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 );
321 };
322
323 void() Nex_Action_Management_SaveConfig =
324 {
325         local float lType;
326         local entity lFileList;
327         local entity lFilename;
328         local entity lContainer;
329         local float lHandle;
330
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 );
337                 return;
338         }
339         lHandle = fopen( strcat( lFileList.selected, "/", lFilename.value, ".", lFileList.normal ), FILE_WRITE );
340
341         if( lHandle < 0 ) {
342                 return;
343         }
344
345         Data_ExecString_BeginUse();
346         Raise_DataEvent( lContainer, ITEM_DATA_SAVE_EXECSTRING );
347
348         fputs( lHandle, Data_ExecString );
349
350         Data_ExecString_EndUse();
351
352         fclose( lHandle );
353
354         Nex_Action_Management_Refresh();
355 };
356
357 void() Nex_Action_Management_Save =
358 {
359         local entity lFileList;
360         local entity lFilename;
361         local float lHandle;
362
363         print( "Bla\n" );
364
365         lFileList = Nex_Management_GetFileList( Nex_Management_GetType() );
366         lFilename = Menu_GetItem( "::Data::Management::Filename" );
367
368         lHandle = fopen( strcat( lFileList.selected, "/", lFilename.value, ".", lFileList.normal ), FILE_READ );
369
370         if( lHandle == ERR_CANNOTOPEN ) {
371                 Nex_Action_Management_SaveConfig();
372                 fclose( lHandle );
373         } else if( lHandle > 0 ) {
374                 local string lQuestion;
375                 local string lTitle;
376
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 );
383         }
384 };
385
386 void() Nex_Action_Management_TypeWeapon =
387 {
388         Nex_Management_SetType( 0 );
389 };
390
391 void() Nex_Action_Management_TypeGame =
392 {
393         Nex_Management_SetType( 1 );
394 };
395
396 void() Nex_Action_Management_TypeMapList =
397 {
398         Nex_Management_SetType( 2 );
399 };