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