356b92d3812a4327d82608df71fd567cdff6b8e5
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / util.qc
1 float GL_CheckExtension(string ext)
2 {
3         return (strstrofs(strcat(" ", cvar_string("gl_info_extensions"), " "), strcat(" ", ext, " "), 0) >= 0);
4 }
5
6 float GL_Have_TextureCompression()
7 {
8         return (GL_CheckExtension("GL_EXT_texture_compression_s3tc") && GL_CheckExtension("GL_ARB_texture_compression"));
9 }
10
11 void loadTooltips()
12 {
13         tooltipdb = db_load(language_filename("tooltips.db"));
14 }
15 void unloadTooltips()
16 {
17         if(tooltipdb >= 0)
18                 db_close(tooltipdb);
19         tooltipdb = -1;
20 }
21 string getZonedTooltipForIdentifier(string s)
22 {
23         string t;
24         if(s == "")
25                 return string_null;
26         if(tooltipdb >= 0)
27         {
28                 t = db_get(tooltipdb, s);
29                 if(t == "-")
30                         return string_null;
31                 if(t != "")
32                         return strzone(t);
33         }
34         if(prvm_language == "en")
35         {
36                 t = cvar_description(s);
37                 if(t != "" && t != "custom cvar")
38                         return strzone(t);
39         }
40         dprint("WARNING: no tooltip set for ", s, "\n");
41         return string_null;
42 }
43
44 void forAllDescendants(entity root, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
45 {
46         depthfirst(root, parent, firstChild, nextSibling, funcPre, funcPost, pass);
47 }
48
49 .string cvarName;
50 void SUB_Null_ee(entity e1, entity e2)
51 {
52 }
53 void saveCvarsOf(entity ignore, entity e)
54 {
55         if(e.saveCvars)
56                 e.saveCvars(e);
57 }
58 void loadCvarsOf(entity ignore, entity e)
59 {
60         if(e.loadCvars)
61                 e.loadCvars(e);
62 }
63 void saveAllCvars(entity root)
64 {
65         forAllDescendants(root, saveCvarsOf, SUB_Null_ee, NULL);
66 }
67 void loadAllCvars(entity root)
68 {
69         forAllDescendants(root, loadCvarsOf, SUB_Null_ee, NULL);
70 }
71
72 .string cvarNames_Multi;
73 .void(entity me) saveCvars_Multi;
74 string getCvarsMulti(entity me)
75 {
76         if (me.cvarNames_Multi)
77                 return me.cvarNames_Multi;
78         return string_null;
79 }
80 void saveCvarsMulti(entity me)
81 {
82         float n, i;
83         string s;
84
85         me.saveCvars_Multi(me);
86         s = cvar_string(me.cvarName);
87
88         n = tokenize_console(me.cvarNames_Multi);
89         for(i = 0; i < n; ++i)
90                 cvar_set(argv(i), s);
91 }
92 void makeMulti(entity e, string otherCvars)
93 {
94         e.cvarNames_Multi = otherCvars;
95         e.saveCvars_Multi = e.saveCvars;
96         e.saveCvars = saveCvarsMulti;
97 }
98
99 .void(entity me) saveCvars_Callback;
100 .entity saveCvars_Callback_ent;
101 .void(entity me, entity cb) saveCvars_Callback_func;
102 void saveCvarsCallback(entity me)
103 {
104         me.saveCvars_Callback(me);
105         me.saveCvars_Callback_func(me.saveCvars_Callback_ent, me);
106 }
107 void makeCallback(entity e, entity cbent, void(entity, entity) cbfunc)
108 {
109         e.saveCvars_Callback = e.saveCvars;
110         e.saveCvars = saveCvarsCallback;
111         e.saveCvars_Callback_ent = cbent;
112         e.saveCvars_Callback_func = cbfunc;
113 }
114
115 .void(entity) draw_setDependent;
116 .string cvar_setDependent;
117 .float cvarMin_setDependent;
118 .float cvarMax_setDependent;
119 .string cvar2_setDependent;
120 .float cvar2Min_setDependent;
121 .float cvar2Max_setDependent;
122 .string cvar3_setDependent;
123 .float cvar3Min_setDependent;
124 .float cvar3Max_setDependent;
125 .float op_setDependent;
126 .string cvarString_setDependent;
127 .string cvarValue_setDependent;
128 .float(entity) func_setDependent;
129 void setDependent_Check(entity e)
130 {
131         float f;
132         string s;
133         if(e.func_setDependent)
134         {
135                 e.disabled = !(e.func_setDependent(e));
136         }
137         else if(e.cvarString_setDependent)
138         {
139                 s = cvar_string(e.cvarString_setDependent);
140                 e.disabled = (cvar_string(e.cvarString_setDependent) == e.cvarValue_setDependent);
141         }
142         else
143         {
144                 if(e.cvar_setDependent)
145                 {
146                         f = cvar(e.cvar_setDependent);
147                         if(e.cvarMin_setDependent <= e.cvarMax_setDependent)
148                                 e.disabled = ((f < e.cvarMin_setDependent) || (f > e.cvarMax_setDependent));
149                         else
150                                 e.disabled = ((f >= e.cvarMax_setDependent) && (f <= e.cvarMin_setDependent));
151                 }
152                 if(e.cvar2_setDependent)
153                 {
154                         f = cvar(e.cvar2_setDependent);
155                         if(e.cvar2Min_setDependent <= e.cvar2Max_setDependent)
156                                 e.disabled = (e.disabled + ((f < e.cvar2Min_setDependent) || (f > e.cvar2Max_setDependent)) > e.op_setDependent);
157                         else
158                                 e.disabled = (e.disabled + ((f >= e.cvar2Max_setDependent) && (f <= e.cvar2Min_setDependent)) > e.op_setDependent);
159                 }
160                 if(e.cvar3_setDependent)
161                 {
162                         f = cvar(e.cvar3_setDependent);
163                         if(e.cvar3Min_setDependent <= e.cvar3Max_setDependent)
164                                 e.disabled = (e.disabled + ((f < e.cvar3Min_setDependent) || (f > e.cvar3Max_setDependent)) > e.op_setDependent);
165                         else
166                                 e.disabled = (e.disabled + ((f >= e.cvar3Max_setDependent) && (f <= e.cvar3Min_setDependent)) > e.op_setDependent);
167                 }
168         }
169 }
170 void setDependent_Draw(entity e)
171 {
172         setDependent_Check(e);
173         e.draw_setDependent(e);
174 }
175 void setDependent(entity e, string theCvarName, float theCvarMin, float theCvarMax)
176 {
177         e.draw_setDependent = e.draw;
178         e.cvar_setDependent = theCvarName;
179         e.cvarMin_setDependent = theCvarMin;
180         e.cvarMax_setDependent = theCvarMax;
181         e.cvar2_setDependent = string_null;
182         e.cvar3_setDependent = string_null;
183         e.func_setDependent = func_null;
184         e.draw = setDependent_Draw;
185         setDependent_Check(e);
186 }
187 void setDependentStringNotEqual(entity e, string theCvarName, string theCvarValue)
188 {
189         e.draw_setDependent = e.draw;
190         e.cvarString_setDependent = theCvarName;
191         e.cvarValue_setDependent = theCvarValue;
192         e.cvar_setDependent = string_null;
193         e.cvar2_setDependent = string_null;
194         e.cvar3_setDependent = string_null;
195         e.func_setDependent = func_null;
196         e.draw = setDependent_Draw;
197         setDependent_Check(e);
198 }
199 void setDependentAND(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
200 {
201         e.draw_setDependent = e.draw;
202         e.cvar_setDependent = theCvarName;
203         e.cvarMin_setDependent = theCvarMin;
204         e.cvarMax_setDependent = theCvarMax;
205         e.cvar2_setDependent = theCvar2Name;
206         e.cvar2Min_setDependent = theCvar2Min;
207         e.cvar2Max_setDependent = theCvar2Max;
208         e.cvar3_setDependent = string_null;
209         e.op_setDependent = 0;
210         e.func_setDependent = func_null;
211         e.draw = setDependent_Draw;
212         setDependent_Check(e);
213 }
214 void setDependentOR(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
215 {
216         e.draw_setDependent = e.draw;
217         e.cvar_setDependent = theCvarName;
218         e.cvarMin_setDependent = theCvarMin;
219         e.cvarMax_setDependent = theCvarMax;
220         e.cvar2_setDependent = theCvar2Name;
221         e.cvar2Min_setDependent = theCvar2Min;
222         e.cvar2Max_setDependent = theCvar2Max;
223         e.cvar3_setDependent = string_null;
224         e.op_setDependent = 1;
225         e.func_setDependent = func_null;
226         e.draw = setDependent_Draw;
227         setDependent_Check(e);
228 }
229 void setDependentAND3(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max, string theCvar3Name, float theCvar3Min, float theCvar3Max)
230 {
231         e.draw_setDependent = e.draw;
232         e.cvar_setDependent = theCvarName;
233         e.cvarMin_setDependent = theCvarMin;
234         e.cvarMax_setDependent = theCvarMax;
235         e.cvar2_setDependent = theCvar2Name;
236         e.cvar2Min_setDependent = theCvar2Min;
237         e.cvar2Max_setDependent = theCvar2Max;
238         e.cvar3_setDependent = theCvar3Name;
239         e.cvar3Min_setDependent = theCvar3Min;
240         e.cvar3Max_setDependent = theCvar3Max;
241         e.op_setDependent = 0;
242         e.func_setDependent = func_null;
243         e.draw = setDependent_Draw;
244         setDependent_Check(e);
245 }
246 void setDependentWeird(entity e, float(entity) func)
247 {
248         e.draw_setDependent = e.draw;
249         e.func_setDependent = func;
250         e.draw = setDependent_Draw;
251         setDependent_Check(e);
252 }
253
254 // URI SYSTEM ////////////////////////////////////////////////////////
255
256 float _Nex_ExtResponseSystem_Queried;
257 string _Nex_ExtResponseSystem_UpdateTo;
258 string _Nex_ExtResponseSystem_UpdateToURL;
259 string _Nex_ExtResponseSystem_Packs;
260 float _Nex_ExtResponseSystem_PacksStep;
261
262 void URI_Get_Callback(float id, float status, string data)
263 {
264         if(url_URI_Get_Callback(id, status, data))
265         {
266                 // handled
267         }
268         else if (id == URI_GET_DISCARD)
269         {
270                 // discard
271         }
272         else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
273         {
274                 // sv_cmd curl
275                 Curl_URI_Get_Callback(id, status, data);
276         }
277         else if (id == URI_GET_UPDATENOTIFICATION)
278         {
279                 UpdateNotification_URI_Get_Callback(id, status, data);
280         }
281         else
282         {
283                 print(sprintf("Received HTTP request data for an invalid id %d.\n", id));
284         }
285 }
286
287 void UpdateNotification_URI_Get_Callback(float id, float status, string data)
288 {
289         float n;
290
291         if(_Nex_ExtResponseSystem_UpdateTo)
292         {
293                 dprint("error: UpdateNotification_URI_Get_Callback has been called before\n");
294                 return;
295         }
296         if(status != 0)
297         {
298                 print(sprintf(_("error receiving update notification: status is %d\n"), status));
299                 return;
300         }
301         if(substring(data, 0, 1) == "<")
302         {
303                 print(_("error: received HTML instead of an update notification\n"));
304                 return;
305         }
306         if(strstrofs(data, "\r", 0) != -1)
307         {
308                 print(_("error: received carriage returns from update notification server\n"));
309                 return;
310         }
311
312         if(data == "")
313                 n = 0;
314         else
315                 n = tokenizebyseparator(data, "\n");
316
317         float i;
318         string s; 
319         
320         string un_version = "";
321         string un_download = "";
322         string un_url = "";
323         string un_bannedservers = "";
324         string un_emergency_pk3s = "";
325         string un_promoted = "";
326         string un_recommended = "";
327         
328         for(i = 0; i < n; ++i)
329         {
330                 s = substring(argv(i), 2, -1);
331                 if(s == "") { continue; } // ignore empty lines
332                 
333                 switch(substring(argv(i), 0, 1))
334                 {
335                         #define APPEND_STRING(list,sep,add) list = ((list != "") ? strcat(list, sep, add) : add);
336                         case "V":
337                         {
338                                 un_version = s;
339                                 break;
340                         }
341                         case "D":
342                         {
343                                 un_download = s;
344                                 break;
345                         }
346                         case "U":
347                         {
348                                 un_url = s;
349                                 break;
350                         }
351                         case "B":
352                         {
353                                 APPEND_STRING(un_bannedservers, " ", s)
354                                 break;
355                         }
356                         case "E":
357                         {
358                                 if(cvar("menu_updatecheck_getpacks"))
359                                         { APPEND_STRING(un_emergency_pk3s, " ", s) }
360                                 break;
361                         }
362                         case "P":
363                         {
364                                 APPEND_STRING(un_promoted, " ", s)
365                                 break;
366                         }
367                         case "R":
368                         {
369                                 APPEND_STRING(un_recommended, " ", s)
370                                 break;
371                         }
372                 }
373         }
374
375         if(un_version != "")
376         {
377                 if(vercmp(cvar_string("g_xonoticversion"), un_version) < 0)
378                 {
379                         // update needed
380                         _Nex_ExtResponseSystem_UpdateTo = strzone(un_version);
381                         if(un_download) { print(sprintf(_("Update can be downloaded at:\n%s\n"), un_download)); }
382                         if(un_url) { _Nex_ExtResponseSystem_UpdateToURL = strzone(un_url); }
383                 }
384         }
385         
386         if(un_emergency_pk3s != "")
387         {
388                 _Nex_ExtResponseSystem_Packs = strzone(argv(4));
389                 _Nex_ExtResponseSystem_PacksStep = 1;
390         }
391
392         if(un_promoted != "")
393         {
394                 _Nex_ExtResponseSystem_PromotedServers = strzone(un_promoted);
395                 _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 1;
396         }
397
398         if(un_recommended != "")
399         {
400                 _Nex_ExtResponseSystem_RecommendedServers = strzone(un_recommended);
401                 _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 1;
402         }
403
404 }
405
406 // END OF URI SYSTEM ////////////////////////////////////////////////////////
407
408 void updateCheck()
409 {
410         if(cvar("menu_updatecheck"))
411         {
412                 if(!_Nex_ExtResponseSystem_Queried)
413                 {
414                         _Nex_ExtResponseSystem_Queried = 1;
415                         float startcnt;
416                         string uri;
417
418                         cvar_set("cl_startcount", ftos(startcnt = cvar("cl_startcount") + 1));
419
420                         // for privacy, munge the start count a little
421                         startcnt = floor((floor(startcnt / 10) + random()) * 10);
422                         uri = sprintf("http://www.xonotic.org/dl/checkupdate.txt?format=keys&version=%s&cnt=%d", uri_escape(cvar_string("g_xonoticversion")), startcnt);
423
424 #ifdef CVAR_POPCON
425                         float cvar_handle, popcon_handle;
426                         float n, i, j;
427                         string k, s;
428                         cvar_handle = buf_create();
429                         buf_cvarlist(cvar_handle, "", "");
430                         n = buf_getsize(cvar_handle);
431                         popcon_handle = buf_create();
432                         for(i= 0, j = 0; i < n; ++i)
433                         {
434                                 k = bufstr_get(cvar_handle, i);
435                                 if(!(cvar_type(k) & CVAR_TYPEFLAG_SAVED))
436                                         continue;
437                                 s = sprintf("%s=%d", uri_escape(k), cvar_string(k) != cvar_defstring(k));
438                                 bufstr_set(popcon_handle, j, s);
439                                 ++j;
440                         }
441                         buf_del(cvar_handle);
442                         uri_postbuf(
443                                 uri, URI_GET_UPDATENOTIFICATION,
444                                 "application/x-www-form-urlencoded",
445                                 "&",
446                                 popcon_handle
447                         );
448                         buf_del(popcon_handle);
449 #else
450                         uri_get(uri, URI_GET_UPDATENOTIFICATION);
451 #endif
452                 }
453         }
454
455         if(_Nex_ExtResponseSystem_PacksStep > 0)
456         {
457                 float n, i;
458                 float allgood;
459                 n = tokenize_console(_Nex_ExtResponseSystem_Packs);
460                 allgood = TRUE;
461                 for(i = 0; i+1 < n; i += 2)
462                 {
463                         if(fexists(argv(i+1)))
464                                 continue;
465                         allgood = FALSE;
466                         if(_Nex_ExtResponseSystem_PacksStep == 1) // first run
467                                 localcmd("\ncurl --pak \"", argv(i), "\"\n");
468                 }
469                 if(allgood)
470                 {
471                         if(_Nex_ExtResponseSystem_PacksStep == 2)
472                         {
473                                 if(!Menu_Active)
474                                         cvar_set("_menu_initialized", "0");
475                                         // HACK: cause m_hide call on next start
476                                 localcmd("\nmenu_restart\n");
477                         }
478                         _Nex_ExtResponseSystem_PacksStep = 0;
479                 }
480                 else
481                         _Nex_ExtResponseSystem_PacksStep = 2;
482         }
483
484 }
485
486 float preMenuInit()
487 {
488         vector sz;
489         vector boxA, boxB;
490
491         updateCheck();
492
493         MapInfo_Cache_Create();
494         MapInfo_Enumerate();
495         if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
496         {
497                 draw_reset_cropped();
498
499                 sz = eX * 0.025 + eY * 0.025 * (draw_scale_x / draw_scale_y);
500                 draw_CenterText('0.5 0.5 0' - 1.25 * sz_y * eY, _("Autogenerating mapinfo for newly added maps..."), sz, '1 1 1', 1, 0);
501
502                 boxA = '0.05 0.5 0' + 0.25 * sz_y * eY;
503                 boxB = '0.95 0.5 0' + 1.25 * sz_y * eY;
504                 draw_Fill(boxA, boxB - boxA, '1 1 1', 1);
505                 
506                 boxA += sz * 0.1;
507                 boxB -= sz * 0.1;
508                 draw_Fill(boxA, boxB - boxA, '0.1 0.1 0.1', 1);
509
510                 boxB_x = boxA_x * (1 - MapInfo_progress) + boxB_x * MapInfo_progress;
511                 draw_Fill(boxA, boxB - boxA, '0 0 1', 1);
512
513                 return FALSE;
514         }
515         return TRUE;
516 }
517
518 string campaign_name_previous;
519 float campaign_won_previous;
520 #ifdef WATERMARK
521 var string autocvar_menu_watermark = WATERMARK;
522 #else
523 var string autocvar_menu_watermark = "";
524 #endif
525 void postMenuDraw()
526 {
527         if(autocvar_menu_watermark != "")
528         {
529                 draw_CenterText('0.5 0.1 0', sprintf(_("^1%s TEST BUILD"), autocvar_menu_watermark), globalToBoxSize('32 32 0', draw_scale), '1 1 1', 0.05, 1);
530         }
531 }
532 void preMenuDraw()
533 {
534         vector fs, sz = '0 0 0', line, mid;
535
536         updateCheck();
537
538         if(_Nex_ExtResponseSystem_UpdateTo != "")
539         {
540                 // TODO rather turn this into a dialog
541                 fs = ((1/draw_scale_x) * eX + (1/draw_scale_y) * eY) * 12;
542                 line = eY * fs_y;
543                 string l1, l2;
544                 l1 = sprintf(_("Update to %s now!"), _Nex_ExtResponseSystem_UpdateTo);
545                 l2 = "http://www.xonotic.org/";
546                 if(_Nex_ExtResponseSystem_UpdateToURL)
547                         l2 = _Nex_ExtResponseSystem_UpdateToURL;
548
549                 sz_x = draw_TextWidth("    ", 0, fs) + max(
550                                 draw_TextWidth(l1, 0, fs),
551                                 draw_TextWidth(l2, 0, fs)
552                         );
553                 sz_y = 3 * fs_y;
554
555                 draw_alpha = bound(0, sin(time * 0.112 - 0.3) * 10, 1);
556                 mid = eX * (0.5 + 0.5 * (1 - sz_x) * cos(time * 0.071))
557                     + eY * (0.5 + 0.5 * (1 - sz_y) * sin(time * 0.071));
558
559                 draw_Fill(mid - 0.5 * sz, sz, '1 1 0', 1);
560                 draw_CenterText(mid - 1 * line, l1, fs, '1 0 0', 1, 0);
561                 draw_CenterText(mid - 0 * line, l2, fs, '0 0 1', 1, 0);
562         }
563         if not(campaign_name_previous)
564                 campaign_name_previous = strzone(strcat(campaign_name, "x")); // force unequal
565         if(campaign_name == campaign_name_previous)
566         {
567                 if(cvar(strcat("g_campaign", campaign_name, "_won")))
568                 {
569                         if(!campaign_won_previous)
570                         {
571                                 m_display();
572                                 DialogOpenButton_Click_withCoords(NULL, main.winnerDialog, '0 0 0', eX * conwidth + eY * conheight);
573                         }
574                         campaign_won_previous = 1;
575                 }
576                 else
577                         campaign_won_previous = 0;
578         }
579         else
580         {
581                 strunzone(campaign_name_previous);
582                 campaign_name_previous = strzone(campaign_name);
583                 campaign_won_previous = cvar(strcat("g_campaign", campaign_name, "_won"));
584         }
585 }
586
587 string resolvemod(string m)
588 {
589         if(m == "=")
590                 return getcurrentmod();
591         else
592                 return m;
593 }
594
595 float updateCompression()
596 {
597         float have_dds, have_jpg, have_tga;
598         float can_dds;
599         have_dds = (fexists("dds/particles/particlefont.dds"));
600         have_jpg = (fexists("particles/particlefont.jpg"));
601         have_tga = (fexists("particles/particlefont.tga"));
602         can_dds = GL_Have_TextureCompression();
603         if(have_dds && (have_jpg || have_tga))
604         {
605                 // both? Let's only use good quality precompressed files
606                 // but ONLY if we actually support it!
607                 if(can_dds)
608                 {
609                         // these builds are meant to have GOOD quality, so let's not compress non-skinframes
610                         cvar_set("gl_texturecompression", "0");
611                         return 1;
612
613                         //cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
614                         //return 2;
615                 }
616                 else
617                 {
618                         cvar_set("gl_texturecompression", "0");
619                         cvar_set("r_texture_dds_load", "0");
620                         return 0;
621                 }
622         }
623         else if(have_dds)
624         {
625                 // DDS only? We probably always want texture compression
626                 cvar_set("gl_texturecompression", "1");
627                 cvar_set("r_texture_dds_load", "1");
628                 if(!can_dds)
629                         print(_("^1ERROR: Texture compression is required but not supported.\n^1Expect visual problems.\n"));
630                 return 0;
631         }
632         else
633         {
634                 // TGA only? Allow runtime compression
635                 if(can_dds)
636                 {
637                         cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
638                         return 2;
639                 }
640                 else
641                 {
642                         cvar_set("gl_texturecompression", "0");
643                         cvar_set("r_texture_dds_load", "0");
644                         return 0;
645                 }
646         }
647 }
648
649 // note: include only those that should be in the menu!
650 #define GAMETYPES \
651         GAMETYPE(MAPINFO_TYPE_ARENA) \
652         GAMETYPE(MAPINFO_TYPE_ASSAULT) \
653         GAMETYPE(MAPINFO_TYPE_CTF) \
654         GAMETYPE(MAPINFO_TYPE_CA) \
655         GAMETYPE(MAPINFO_TYPE_DEATHMATCH) \
656         GAMETYPE(MAPINFO_TYPE_DOMINATION) \
657         GAMETYPE(MAPINFO_TYPE_FREEZETAG) \
658         GAMETYPE(MAPINFO_TYPE_KEEPAWAY) \
659         GAMETYPE(MAPINFO_TYPE_KEYHUNT) \
660         GAMETYPE(MAPINFO_TYPE_LMS) \
661         GAMETYPE(MAPINFO_TYPE_NEXBALL) \
662         GAMETYPE(MAPINFO_TYPE_ONSLAUGHT) \
663         GAMETYPE(MAPINFO_TYPE_RACE) \
664         GAMETYPE(MAPINFO_TYPE_CTS) \
665         GAMETYPE(MAPINFO_TYPE_TEAM_DEATHMATCH) \
666         /* nothing */
667
668 float GameType_GetID(float cnt)
669 {
670         float i;
671         i = 0;
672         
673         #define GAMETYPE(id) if(i++ == cnt) return id;
674         GAMETYPES
675         #undef GAMETYPE
676
677         unused_float = i;
678         
679         return 0;
680 }
681
682 float GameType_GetCount()
683 {
684         float i;
685         i = 0;
686         
687         #define GAMETYPE(id) ++i;
688         GAMETYPES
689         #undef GAMETYPE
690         
691         return i;
692 }
693
694 string GameType_GetName(float cnt)
695 {
696         float i = GameType_GetID(cnt);
697         
698         if(i)
699                 return MapInfo_Type_ToText(i);
700         
701         return "";
702 }
703
704 string GameType_GetIcon(float cnt)
705 {
706         float i = GameType_GetID(cnt);
707         
708         if(i)
709                 return strcat("gametype_", MapInfo_Type_ToString(i));
710         
711         return "";
712 }
713
714 /*string GameType_GetTeams(float cnt) // poor implementation, later something else could be done that's better?
715 {
716         float i = GameType_GetID(cnt);
717         string s = _MapInfo_GetDefaultEx(i);
718         
719         if(i)
720         {
721                 if(strstrofs(s, "teams", 0) >= 0)
722                         return _("teamplay");
723                 else
724                         return _("free for all");
725         }
726         
727         return _("tuba for all");
728 }*/
729
730 void dialog_hudpanel_common_notoggle(entity me, string panelname)
731 {
732         float i;
733         entity e;
734
735         me.TR(me);
736                 me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Background:")));
737                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg"))));
738                                 e.addValue(e, _("Default"), "");
739                                 e.addValue(e, _("Disable"), "0");
740                                 e.addValue(e, strzone(strcat("border_", panelname)), strzone(strcat("border_", panelname)));
741                                 e.configureXonoticTextSliderValues(e);
742         me.TR(me);
743                 me.TDempty(me, 0.2);
744                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Color:")));
745                 me.TD(me, 2, 2.6, e = makeXonoticColorpickerString(strzone(strcat("hud_panel_", panelname, "_bg_color")), "hud_panel_bg_color"));
746                         setDependentStringNotEqual(e, strzone(strcat("hud_panel_", panelname, "_bg_color")), "");
747         me.TR(me);
748                 me.TDempty(me, 0.2);
749                 me.TD(me, 1, 1.0, e = makeXonoticCheckBoxString("", "1 1 1", strzone(strcat("hud_panel_", panelname, "_bg_color")), _("Use default")));
750         me.TR(me);
751                 me.TDempty(me, 0.2);
752                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Border size:")));
753                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_border"))));
754                                 e.addValue(e, _("Default"), "");
755                                 e.addValue(e, _("Disable"), "0");
756                                 for(i = 1; i <= 10; ++i)
757                                         e.addValue(e, strzone(ftos_decimals(i * 2, 0)), strzone(ftos(i * 2)));
758                                 e.configureXonoticTextSliderValues(e);
759         me.TR(me);
760                 me.TDempty(me, 0.2);
761                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:")));
762                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_alpha"))));
763                                 e.addValue(e, _("Default"), "");
764                                 for(i = 1; i <= 10; ++i)
765                                         e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
766                                 e.configureXonoticTextSliderValues(e);
767         me.TR(me);
768                 me.TDempty(me, 0.2);
769                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Team Color:")));
770                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_color_team"))));
771                                 e.addValue(e, _("Default"), "");
772                                 e.addValue(e, _("Disable"), "0");
773                                 for(i = 1; i <= 10; ++i)
774                                         e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
775                                 e.configureXonoticTextSliderValues(e);
776         me.TR(me);
777                 me.TDempty(me, 0.4);
778                 me.TD(me, 1, 3.6, e = makeXonoticCheckBox(0, "hud_configure_teamcolorforced", _("Test team color in configure mode")));
779         me.TR(me);
780                 me.TDempty(me, 0.2);
781                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Padding:")));
782                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_padding"))));
783                                 e.addValue(e, _("Default"), "");
784                                 for(i = 0; i <= 10; ++i)
785                                         e.addValue(e, strzone(ftos_decimals(i - 5, 0)), strzone(ftos(i - 5)));
786                                 e.configureXonoticTextSliderValues(e);
787 }