0bc966cfb46dcf1901874d94065dfd0f0b9e46e7
[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 DisableServerBackwardsCompatibility()
288 {
289         cvar_set("gameversion_min", ftos(100 * floor(cvar("gameversion") / 100)));
290 }
291
292 void UpdateNotification_URI_Get_Callback(float id, float status, string data)
293 {
294         float n;
295
296         if(_Nex_ExtResponseSystem_UpdateTo)
297         {
298                 dprint("error: UpdateNotification_URI_Get_Callback has been called before\n");
299                 return;
300         }
301         if(status != 0)
302         {
303                 print(sprintf(_("error receiving update notification: status is %d\n"), status));
304                 return;
305         }
306         if(substring(data, 0, 1) == "<")
307         {
308                 print(_("error: received HTML instead of an update notification\n"));
309                 return;
310         }
311         if(strstrofs(data, "\r", 0) != -1)
312         {
313                 print(_("error: received carriage returns from update notification server\n"));
314                 return;
315         }
316
317         if(data == "")
318                 n = 0;
319         else
320                 n = tokenizebyseparator(data, "\n");
321
322         float i;
323         string s; 
324         
325         string un_version = "";
326         string un_download = "";
327         string un_url = "";
328         string un_bannedservers = "";
329         string un_emergency_pk3s = "";
330         string un_promoted = "";
331         string un_recommended = "";
332         string un_compatexpire = "";
333         
334         for(i = 0; i < n; ++i)
335         {
336                 s = substring(argv(i), 2, -1);
337                 if(s == "") { continue; } // ignore empty lines
338                 
339                 switch(substring(argv(i), 0, 1))
340                 {
341                         #define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
342                         case "V":
343                         {
344                                 un_version = s;
345                                 break;
346                         }
347                         case "C":
348                         {
349                                 un_compatexpire = s;
350                                 break;
351                         }
352                         case "D":
353                         {
354                                 un_download = s;
355                                 break;
356                         }
357                         case "U":
358                         {
359                                 un_url = s;
360                                 break;
361                         }
362                         case "B":
363                         {
364                                 APPEND_TO_STRING(un_bannedservers, " ", s);
365                                 break;
366                         }
367                         case "E":
368                         {
369                                 if(cvar("menu_updatecheck_getpacks"))
370                                         APPEND_TO_STRING(un_emergency_pk3s, " ", s);
371                                 break;
372                         }
373                         case "P":
374                         {
375                                 APPEND_TO_STRING(un_promoted, " ", s);
376                                 break;
377                         }
378                         case "R":
379                         {
380                                 APPEND_TO_STRING(un_recommended, " ", s);
381                                 break;
382                         }
383                 }
384         }
385
386         if(un_version != "")
387         {
388                 if(vercmp(cvar_string("g_xonoticversion"), un_version) < 0)
389                 {
390                         // update needed
391                         _Nex_ExtResponseSystem_UpdateTo = strzone(un_version);
392                         if(un_download) { print(sprintf(_("Update can be downloaded at:\n%s\n"), un_download)); }
393                         if(un_url) { _Nex_ExtResponseSystem_UpdateToURL = strzone(un_url); }
394                         DisableServerBackwardsCompatibility();
395                 }
396                 else if(cvar_string("g_xonoticversion") == un_version)
397                 {
398                         if(un_compatexpire != "")
399                         {
400                                 string curdate = strftime(FALSE, "%Y%m%d%H%M%S");
401                                 if (strcmp(curdate, un_compatexpire) >= 0)
402                                         DisableServerBackwardsCompatibility();
403                         }
404                 }
405         }
406         
407         if(un_emergency_pk3s != "")
408         {
409                 _Nex_ExtResponseSystem_Packs = strzone(un_emergency_pk3s);
410                 _Nex_ExtResponseSystem_PacksStep = 1;
411         }
412
413         if(un_promoted != "")
414         {
415                 _Nex_ExtResponseSystem_PromotedServers = strzone(un_promoted);
416                 _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 1;
417         }
418
419         if(un_recommended != "")
420         {
421                 _Nex_ExtResponseSystem_RecommendedServers = strzone(un_recommended);
422                 _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 1;
423         }
424 }
425
426 // END OF URI SYSTEM ////////////////////////////////////////////////////////
427
428 void updateCheck()
429 {
430         if(cvar("menu_updatecheck"))
431         {
432                 if(!_Nex_ExtResponseSystem_Queried)
433                 {
434                         _Nex_ExtResponseSystem_Queried = 1;
435                         float startcnt;
436                         string uri;
437
438                         cvar_set("cl_startcount", ftos(startcnt = cvar("cl_startcount") + 1));
439
440                         // for privacy, munge the start count a little
441                         startcnt = floor((floor(startcnt / 10) + random()) * 10);
442                         uri = sprintf("http://www.xonotic.org/dl/checkupdate.txt?format=keys&version=%s&cnt=%d", uri_escape(cvar_string("g_xonoticversion")), startcnt);
443
444 #ifdef CVAR_POPCON
445                         float cvar_handle, popcon_handle;
446                         float n, i, j;
447                         string k, s;
448                         cvar_handle = buf_create();
449                         buf_cvarlist(cvar_handle, "", "");
450                         n = buf_getsize(cvar_handle);
451                         popcon_handle = buf_create();
452                         for(i= 0, j = 0; i < n; ++i)
453                         {
454                                 k = bufstr_get(cvar_handle, i);
455                                 if(!(cvar_type(k) & CVAR_TYPEFLAG_SAVED))
456                                         continue;
457                                 s = sprintf("%s=%d", uri_escape(k), cvar_string(k) != cvar_defstring(k));
458                                 bufstr_set(popcon_handle, j, s);
459                                 ++j;
460                         }
461                         buf_del(cvar_handle);
462                         uri_postbuf(
463                                 uri, URI_GET_UPDATENOTIFICATION,
464                                 "application/x-www-form-urlencoded",
465                                 "&",
466                                 popcon_handle
467                         );
468                         buf_del(popcon_handle);
469 #else
470                         uri_get(uri, URI_GET_UPDATENOTIFICATION);
471 #endif
472                 }
473         }
474
475         if(_Nex_ExtResponseSystem_PacksStep > 0)
476         {
477                 float n, i;
478                 float allgood;
479                 n = tokenize_console(_Nex_ExtResponseSystem_Packs);
480                 allgood = TRUE;
481                 for(i = 0; i+1 < n; i += 2)
482                 {
483                         if(fexists(argv(i+1)))
484                                 continue;
485                         allgood = FALSE;
486                         if(_Nex_ExtResponseSystem_PacksStep == 1) // first run
487                                 localcmd("\ncurl --pak \"", argv(i), "\"\n");
488                 }
489                 if(allgood)
490                 {
491                         if(_Nex_ExtResponseSystem_PacksStep == 2)
492                         {
493                                 if(!Menu_Active)
494                                         cvar_set("_menu_initialized", "0");
495                                         // HACK: cause m_hide call on next start
496                                 localcmd("\nmenu_restart\n");
497                         }
498                         _Nex_ExtResponseSystem_PacksStep = 0;
499                 }
500                 else
501                         _Nex_ExtResponseSystem_PacksStep = 2;
502         }
503
504 }
505
506 float preMenuInit()
507 {
508         vector sz;
509         vector boxA, boxB;
510
511         updateCheck();
512
513         MapInfo_Cache_Create();
514         MapInfo_Enumerate();
515         if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
516         {
517                 draw_reset_cropped();
518
519                 sz = eX * 0.025 + eY * 0.025 * (draw_scale_x / draw_scale_y);
520                 draw_CenterText('0.5 0.5 0' - 1.25 * sz_y * eY, _("Autogenerating mapinfo for newly added maps..."), sz, '1 1 1', 1, 0);
521
522                 boxA = '0.05 0.5 0' + 0.25 * sz_y * eY;
523                 boxB = '0.95 0.5 0' + 1.25 * sz_y * eY;
524                 draw_Fill(boxA, boxB - boxA, '1 1 1', 1);
525                 
526                 boxA += sz * 0.1;
527                 boxB -= sz * 0.1;
528                 draw_Fill(boxA, boxB - boxA, '0.1 0.1 0.1', 1);
529
530                 boxB_x = boxA_x * (1 - MapInfo_progress) + boxB_x * MapInfo_progress;
531                 draw_Fill(boxA, boxB - boxA, '0 0 1', 1);
532
533                 return FALSE;
534         }
535         return TRUE;
536 }
537
538 string campaign_name_previous;
539 float campaign_won_previous;
540 #ifdef WATERMARK
541 var string autocvar_menu_watermark = WATERMARK;
542 #else
543 var string autocvar_menu_watermark = "";
544 #endif
545 void postMenuDraw()
546 {
547         if(autocvar_menu_watermark != "")
548         {
549                 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);
550         }
551 }
552 void preMenuDraw()
553 {
554         vector fs, sz = '0 0 0', line, mid;
555
556         updateCheck();
557
558         if(_Nex_ExtResponseSystem_UpdateTo != "")
559         {
560                 // TODO rather turn this into a dialog
561                 fs = ((1/draw_scale_x) * eX + (1/draw_scale_y) * eY) * 12;
562                 line = eY * fs_y;
563                 string l1, l2;
564                 l1 = sprintf(_("Update to %s now!"), _Nex_ExtResponseSystem_UpdateTo);
565                 l2 = "http://www.xonotic.org/";
566                 if(_Nex_ExtResponseSystem_UpdateToURL)
567                         l2 = _Nex_ExtResponseSystem_UpdateToURL;
568
569                 sz_x = draw_TextWidth("    ", 0, fs) + max(
570                                 draw_TextWidth(l1, 0, fs),
571                                 draw_TextWidth(l2, 0, fs)
572                         );
573                 sz_y = 3 * fs_y;
574
575                 draw_alpha = bound(0, sin(time * 0.112 - 0.3) * 10, 1);
576                 mid = eX * (0.5 + 0.5 * (1 - sz_x) * cos(time * 0.071))
577                     + eY * (0.5 + 0.5 * (1 - sz_y) * sin(time * 0.071));
578
579                 draw_Fill(mid - 0.5 * sz, sz, '1 1 0', 1);
580                 draw_CenterText(mid - 1 * line, l1, fs, '1 0 0', 1, 0);
581                 draw_CenterText(mid - 0 * line, l2, fs, '0 0 1', 1, 0);
582         }
583         if not(campaign_name_previous)
584                 campaign_name_previous = strzone(strcat(campaign_name, "x")); // force unequal
585         if(campaign_name == campaign_name_previous)
586         {
587                 if(cvar(strcat("g_campaign", campaign_name, "_won")))
588                 {
589                         if(!campaign_won_previous)
590                         {
591                                 m_display();
592                                 DialogOpenButton_Click_withCoords(NULL, main.winnerDialog, '0 0 0', eX * conwidth + eY * conheight);
593                         }
594                         campaign_won_previous = 1;
595                 }
596                 else
597                         campaign_won_previous = 0;
598         }
599         else
600         {
601                 strunzone(campaign_name_previous);
602                 campaign_name_previous = strzone(campaign_name);
603                 campaign_won_previous = cvar(strcat("g_campaign", campaign_name, "_won"));
604         }
605 }
606
607 string resolvemod(string m)
608 {
609         if(m == "=")
610                 return getcurrentmod();
611         else
612                 return m;
613 }
614
615 float updateCompression()
616 {
617         float have_dds, have_jpg, have_tga;
618         float can_dds;
619         have_dds = (fexists("dds/particles/particlefont.dds"));
620         have_jpg = (fexists("particles/particlefont.jpg"));
621         have_tga = (fexists("particles/particlefont.tga"));
622         can_dds = GL_Have_TextureCompression();
623         if(have_dds && (have_jpg || have_tga))
624         {
625                 // both? Let's only use good quality precompressed files
626                 // but ONLY if we actually support it!
627                 if(can_dds)
628                 {
629                         // these builds are meant to have GOOD quality, so let's not compress non-skinframes
630                         cvar_set("gl_texturecompression", "0");
631                         return 1;
632
633                         //cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
634                         //return 2;
635                 }
636                 else
637                 {
638                         cvar_set("gl_texturecompression", "0");
639                         cvar_set("r_texture_dds_load", "0");
640                         return 0;
641                 }
642         }
643         else if(have_dds)
644         {
645                 // DDS only? We probably always want texture compression
646                 cvar_set("gl_texturecompression", "1");
647                 cvar_set("r_texture_dds_load", "1");
648                 if(!can_dds)
649                         print(_("^1ERROR: Texture compression is required but not supported.\n^1Expect visual problems.\n"));
650                 return 0;
651         }
652         else
653         {
654                 // TGA only? Allow runtime compression
655                 if(can_dds)
656                 {
657                         cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
658                         return 2;
659                 }
660                 else
661                 {
662                         cvar_set("gl_texturecompression", "0");
663                         cvar_set("r_texture_dds_load", "0");
664                         return 0;
665                 }
666         }
667 }
668
669 // note: include only those that should be in the menu!
670 #define GAMETYPES \
671         GAMETYPE(MAPINFO_TYPE_ARENA) \
672         GAMETYPE(MAPINFO_TYPE_ASSAULT) \
673         GAMETYPE(MAPINFO_TYPE_CTF) \
674         GAMETYPE(MAPINFO_TYPE_CA) \
675         GAMETYPE(MAPINFO_TYPE_DEATHMATCH) \
676         GAMETYPE(MAPINFO_TYPE_DOMINATION) \
677         GAMETYPE(MAPINFO_TYPE_FREEZETAG) \
678         GAMETYPE(MAPINFO_TYPE_KEEPAWAY) \
679         GAMETYPE(MAPINFO_TYPE_KEYHUNT) \
680         GAMETYPE(MAPINFO_TYPE_LMS) \
681         GAMETYPE(MAPINFO_TYPE_NEXBALL) \
682         GAMETYPE(MAPINFO_TYPE_ONSLAUGHT) \
683         GAMETYPE(MAPINFO_TYPE_RACE) \
684         GAMETYPE(MAPINFO_TYPE_CTS) \
685         GAMETYPE(MAPINFO_TYPE_TEAM_DEATHMATCH) \
686         /* nothing */
687
688 float GameType_GetID(float cnt)
689 {
690         float i;
691         i = 0;
692         
693         #define GAMETYPE(id) if(i++ == cnt) return id;
694         GAMETYPES
695         #undef GAMETYPE
696
697         unused_float = i;
698         
699         return 0;
700 }
701
702 float GameType_GetCount()
703 {
704         float i;
705         i = 0;
706         
707         #define GAMETYPE(id) ++i;
708         GAMETYPES
709         #undef GAMETYPE
710         
711         return i;
712 }
713
714 string GameType_GetName(float cnt)
715 {
716         float i = GameType_GetID(cnt);
717         
718         if(i)
719                 return MapInfo_Type_ToText(i);
720         
721         return "";
722 }
723
724 string GameType_GetIcon(float cnt)
725 {
726         float i = GameType_GetID(cnt);
727         
728         if(i)
729                 return strcat("gametype_", MapInfo_Type_ToString(i));
730         
731         return "";
732 }
733
734 /*string GameType_GetTeams(float cnt) // poor implementation, later something else could be done that's better?
735 {
736         float i = GameType_GetID(cnt);
737         string s = _MapInfo_GetDefaultEx(i);
738         
739         if(i)
740         {
741                 if(strstrofs(s, "teams", 0) >= 0)
742                         return _("teamplay");
743                 else
744                         return _("free for all");
745         }
746         
747         return _("tuba for all");
748 }*/
749
750 void dialog_hudpanel_common_notoggle(entity me, string panelname)
751 {
752         float i;
753         entity e;
754
755         me.TR(me);
756                 me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Background:")));
757                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg"))));
758                                 e.addValue(e, _("Default"), "");
759                                 e.addValue(e, _("Disable"), "0");
760                                 e.addValue(e, strzone(strcat("border_", panelname)), strzone(strcat("border_", panelname)));
761                                 e.configureXonoticTextSliderValues(e);
762         me.TR(me);
763                 me.TDempty(me, 0.2);
764                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Color:")));
765                 me.TD(me, 2, 2.6, e = makeXonoticColorpickerString(strzone(strcat("hud_panel_", panelname, "_bg_color")), "hud_panel_bg_color"));
766                         setDependentStringNotEqual(e, strzone(strcat("hud_panel_", panelname, "_bg_color")), "");
767         me.TR(me);
768                 me.TDempty(me, 0.2);
769                 me.TD(me, 1, 1.0, e = makeXonoticCheckBoxString("", "1 1 1", strzone(strcat("hud_panel_", panelname, "_bg_color")), _("Use default")));
770         me.TR(me);
771                 me.TDempty(me, 0.2);
772                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Border size:")));
773                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_border"))));
774                                 e.addValue(e, _("Default"), "");
775                                 e.addValue(e, _("Disable"), "0");
776                                 for(i = 1; i <= 10; ++i)
777                                         e.addValue(e, strzone(ftos_decimals(i * 2, 0)), strzone(ftos(i * 2)));
778                                 e.configureXonoticTextSliderValues(e);
779         me.TR(me);
780                 me.TDempty(me, 0.2);
781                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:")));
782                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_alpha"))));
783                                 e.addValue(e, _("Default"), "");
784                                 for(i = 1; i <= 10; ++i)
785                                         e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
786                                 e.configureXonoticTextSliderValues(e);
787         me.TR(me);
788                 me.TDempty(me, 0.2);
789                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Team Color:")));
790                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_color_team"))));
791                                 e.addValue(e, _("Default"), "");
792                                 e.addValue(e, _("Disable"), "0");
793                                 for(i = 1; i <= 10; ++i)
794                                         e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
795                                 e.configureXonoticTextSliderValues(e);
796         me.TR(me);
797                 me.TDempty(me, 0.4);
798                 me.TD(me, 1, 3.6, e = makeXonoticCheckBox(0, "hud_configure_teamcolorforced", _("Test team color in configure mode")));
799         me.TR(me);
800                 me.TDempty(me, 0.2);
801                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Padding:")));
802                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_padding"))));
803                                 e.addValue(e, _("Default"), "");
804                                 for(i = 0; i <= 10; ++i)
805                                         e.addValue(e, strzone(ftos_decimals(i - 5, 0)), strzone(ftos(i - 5)));
806                                 e.configureXonoticTextSliderValues(e);
807 }