dd022eb6996059f6a29ddf612b6bc915a816abc0
[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://update.xonotic.org/checkupdate.txt?version=%s&cnt=%d", uri_escape(cvar_string("g_xonoticversion")), startcnt);
443                         uri_get(uri, URI_GET_UPDATENOTIFICATION);
444                 }
445         }
446
447         if(_Nex_ExtResponseSystem_PacksStep > 0)
448         {
449                 float n, i;
450                 float allgood;
451                 n = tokenize_console(_Nex_ExtResponseSystem_Packs);
452                 allgood = TRUE;
453                 for(i = 0; i+1 < n; i += 2)
454                 {
455                         if(fexists(argv(i+1)))
456                                 continue;
457                         allgood = FALSE;
458                         if(_Nex_ExtResponseSystem_PacksStep == 1) // first run
459                                 localcmd("\ncurl --pak \"", argv(i), "\"\n");
460                 }
461                 if(allgood)
462                 {
463                         if(_Nex_ExtResponseSystem_PacksStep == 2)
464                         {
465                                 if(!Menu_Active)
466                                         cvar_set("_menu_initialized", "0");
467                                         // HACK: cause m_hide call on next start
468                                 localcmd("\nmenu_restart\n");
469                         }
470                         _Nex_ExtResponseSystem_PacksStep = 0;
471                 }
472                 else
473                         _Nex_ExtResponseSystem_PacksStep = 2;
474         }
475
476 }
477
478 float preMenuInit()
479 {
480         vector sz;
481         vector boxA, boxB;
482
483         updateCheck();
484
485         MapInfo_Cache_Create();
486         MapInfo_Enumerate();
487         if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
488         {
489                 draw_reset_cropped();
490
491                 sz = eX * 0.025 + eY * 0.025 * (draw_scale_x / draw_scale_y);
492                 draw_CenterText('0.5 0.5 0' - 1.25 * sz_y * eY, _("Autogenerating mapinfo for newly added maps..."), sz, '1 1 1', 1, 0);
493
494                 boxA = '0.05 0.5 0' + 0.25 * sz_y * eY;
495                 boxB = '0.95 0.5 0' + 1.25 * sz_y * eY;
496                 draw_Fill(boxA, boxB - boxA, '1 1 1', 1);
497                 
498                 boxA += sz * 0.1;
499                 boxB -= sz * 0.1;
500                 draw_Fill(boxA, boxB - boxA, '0.1 0.1 0.1', 1);
501
502                 boxB_x = boxA_x * (1 - MapInfo_progress) + boxB_x * MapInfo_progress;
503                 draw_Fill(boxA, boxB - boxA, '0 0 1', 1);
504
505                 return FALSE;
506         }
507         return TRUE;
508 }
509
510 string campaign_name_previous;
511 float campaign_won_previous;
512 #ifdef WATERMARK
513 var string autocvar_menu_watermark = WATERMARK;
514 #else
515 var string autocvar_menu_watermark = "";
516 #endif
517 void postMenuDraw()
518 {
519         if(autocvar_menu_watermark != "")
520         {
521                 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);
522         }
523 }
524 void preMenuDraw()
525 {
526         vector fs, sz = '0 0 0', line, mid;
527
528         updateCheck();
529
530         if(_Nex_ExtResponseSystem_UpdateTo != "")
531         {
532                 // TODO rather turn this into a dialog
533                 fs = ((1/draw_scale_x) * eX + (1/draw_scale_y) * eY) * 12;
534                 line = eY * fs_y;
535                 string l1, l2;
536                 l1 = sprintf(_("Update to %s now!"), _Nex_ExtResponseSystem_UpdateTo);
537                 l2 = "http://www.xonotic.org/";
538                 if(_Nex_ExtResponseSystem_UpdateToURL)
539                         l2 = _Nex_ExtResponseSystem_UpdateToURL;
540
541                 sz_x = draw_TextWidth("    ", 0, fs) + max(
542                                 draw_TextWidth(l1, 0, fs),
543                                 draw_TextWidth(l2, 0, fs)
544                         );
545                 sz_y = 3 * fs_y;
546
547                 draw_alpha = bound(0, sin(time * 0.112 - 0.3) * 10, 1);
548                 mid = eX * (0.5 + 0.5 * (1 - sz_x) * cos(time * 0.071))
549                     + eY * (0.5 + 0.5 * (1 - sz_y) * sin(time * 0.071));
550
551                 draw_Fill(mid - 0.5 * sz, sz, '1 1 0', 1);
552                 draw_CenterText(mid - 1 * line, l1, fs, '1 0 0', 1, 0);
553                 draw_CenterText(mid - 0 * line, l2, fs, '0 0 1', 1, 0);
554         }
555         if not(campaign_name_previous)
556                 campaign_name_previous = strzone(strcat(campaign_name, "x")); // force unequal
557         if(campaign_name == campaign_name_previous)
558         {
559                 if(cvar(strcat("g_campaign", campaign_name, "_won")))
560                 {
561                         if(!campaign_won_previous)
562                         {
563                                 m_display();
564                                 DialogOpenButton_Click_withCoords(NULL, main.winnerDialog, '0 0 0', eX * conwidth + eY * conheight);
565                         }
566                         campaign_won_previous = 1;
567                 }
568                 else
569                         campaign_won_previous = 0;
570         }
571         else
572         {
573                 strunzone(campaign_name_previous);
574                 campaign_name_previous = strzone(campaign_name);
575                 campaign_won_previous = cvar(strcat("g_campaign", campaign_name, "_won"));
576         }
577 }
578
579 string resolvemod(string m)
580 {
581         if(m == "=")
582                 return getcurrentmod();
583         else
584                 return m;
585 }
586
587 float updateCompression()
588 {
589         float have_dds, have_jpg, have_tga;
590         float can_dds;
591         have_dds = (fexists("dds/particles/particlefont.dds"));
592         have_jpg = (fexists("particles/particlefont.jpg"));
593         have_tga = (fexists("particles/particlefont.tga"));
594         can_dds = GL_Have_TextureCompression();
595         if(have_dds && (have_jpg || have_tga))
596         {
597                 // both? Let's only use good quality precompressed files
598                 // but ONLY if we actually support it!
599                 if(can_dds)
600                 {
601                         // these builds are meant to have GOOD quality, so let's not compress non-skinframes
602                         cvar_set("gl_texturecompression", "0");
603                         return 1;
604
605                         //cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
606                         //return 2;
607                 }
608                 else
609                 {
610                         cvar_set("gl_texturecompression", "0");
611                         cvar_set("r_texture_dds_load", "0");
612                         return 0;
613                 }
614         }
615         else if(have_dds)
616         {
617                 // DDS only? We probably always want texture compression
618                 cvar_set("gl_texturecompression", "1");
619                 cvar_set("r_texture_dds_load", "1");
620                 if(!can_dds)
621                         print(_("^1ERROR: Texture compression is required but not supported.\n^1Expect visual problems.\n"));
622                 return 0;
623         }
624         else
625         {
626                 // TGA only? Allow runtime compression
627                 if(can_dds)
628                 {
629                         cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
630                         return 2;
631                 }
632                 else
633                 {
634                         cvar_set("gl_texturecompression", "0");
635                         cvar_set("r_texture_dds_load", "0");
636                         return 0;
637                 }
638         }
639 }
640
641 // note: include only those that should be in the menu!
642 #define GAMETYPES \
643         GAMETYPE(MAPINFO_TYPE_ARENA) \
644         GAMETYPE(MAPINFO_TYPE_ASSAULT) \
645         GAMETYPE(MAPINFO_TYPE_CTF) \
646         GAMETYPE(MAPINFO_TYPE_CA) \
647         GAMETYPE(MAPINFO_TYPE_DEATHMATCH) \
648         GAMETYPE(MAPINFO_TYPE_DOMINATION) \
649         GAMETYPE(MAPINFO_TYPE_FREEZETAG) \
650         GAMETYPE(MAPINFO_TYPE_KEEPAWAY) \
651         GAMETYPE(MAPINFO_TYPE_KEYHUNT) \
652         GAMETYPE(MAPINFO_TYPE_LMS) \
653         GAMETYPE(MAPINFO_TYPE_NEXBALL) \
654         GAMETYPE(MAPINFO_TYPE_ONSLAUGHT) \
655         GAMETYPE(MAPINFO_TYPE_RACE) \
656         GAMETYPE(MAPINFO_TYPE_CTS) \
657         GAMETYPE(MAPINFO_TYPE_TEAM_DEATHMATCH) \
658         /* nothing */
659
660 float GameType_GetID(float cnt)
661 {
662         float i;
663         i = 0;
664         
665         #define GAMETYPE(id) if(i++ == cnt) return id;
666         GAMETYPES
667         #undef GAMETYPE
668
669         unused_float = i;
670         
671         return 0;
672 }
673
674 float GameType_GetCount()
675 {
676         float i;
677         i = 0;
678         
679         #define GAMETYPE(id) ++i;
680         GAMETYPES
681         #undef GAMETYPE
682         
683         return i;
684 }
685
686 string GameType_GetName(float cnt)
687 {
688         float i = GameType_GetID(cnt);
689         
690         if(i)
691                 return MapInfo_Type_ToText(i);
692         
693         return "";
694 }
695
696 string GameType_GetIcon(float cnt)
697 {
698         float i = GameType_GetID(cnt);
699         
700         if(i)
701                 return strcat("gametype_", MapInfo_Type_ToString(i));
702         
703         return "";
704 }
705
706 /*string GameType_GetTeams(float cnt) // poor implementation, later something else could be done that's better?
707 {
708         float i = GameType_GetID(cnt);
709         string s = _MapInfo_GetDefaultEx(i);
710         
711         if(i)
712         {
713                 if(strstrofs(s, "teams", 0) >= 0)
714                         return _("teamplay");
715                 else
716                         return _("free for all");
717         }
718         
719         return _("tuba for all");
720 }*/
721
722 void dialog_hudpanel_common_notoggle(entity me, string panelname)
723 {
724         float i;
725         entity e;
726
727         me.TR(me);
728                 me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Background:")));
729                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg"))));
730                                 e.addValue(e, _("Default"), "");
731                                 e.addValue(e, _("Disable"), "0");
732                                 e.addValue(e, strzone(strcat("border_", panelname)), strzone(strcat("border_", panelname)));
733                                 e.configureXonoticTextSliderValues(e);
734         me.TR(me);
735                 me.TDempty(me, 0.2);
736                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Color:")));
737                 me.TD(me, 2, 2.6, e = makeXonoticColorpickerString(strzone(strcat("hud_panel_", panelname, "_bg_color")), "hud_panel_bg_color"));
738                         setDependentStringNotEqual(e, strzone(strcat("hud_panel_", panelname, "_bg_color")), "");
739         me.TR(me);
740                 me.TDempty(me, 0.2);
741                 me.TD(me, 1, 1.0, e = makeXonoticCheckBoxString("", "1 1 1", strzone(strcat("hud_panel_", panelname, "_bg_color")), _("Use default")));
742         me.TR(me);
743                 me.TDempty(me, 0.2);
744                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Border size:")));
745                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_border"))));
746                                 e.addValue(e, _("Default"), "");
747                                 e.addValue(e, _("Disable"), "0");
748                                 for(i = 1; i <= 10; ++i)
749                                         e.addValue(e, strzone(ftos_decimals(i * 2, 0)), strzone(ftos(i * 2)));
750                                 e.configureXonoticTextSliderValues(e);
751         me.TR(me);
752                 me.TDempty(me, 0.2);
753                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:")));
754                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_alpha"))));
755                                 e.addValue(e, _("Default"), "");
756                                 for(i = 1; i <= 10; ++i)
757                                         e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
758                                 e.configureXonoticTextSliderValues(e);
759         me.TR(me);
760                 me.TDempty(me, 0.2);
761                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Team Color:")));
762                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_color_team"))));
763                                 e.addValue(e, _("Default"), "");
764                                 e.addValue(e, _("Disable"), "0");
765                                 for(i = 1; i <= 10; ++i)
766                                         e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
767                                 e.configureXonoticTextSliderValues(e);
768         me.TR(me);
769                 me.TDempty(me, 0.4);
770                 me.TD(me, 1, 3.6, e = makeXonoticCheckBox(0, "hud_configure_teamcolorforced", _("Test team color in configure mode")));
771         me.TR(me);
772                 me.TDempty(me, 0.2);
773                 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Padding:")));
774                         me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_padding"))));
775                                 e.addValue(e, _("Default"), "");
776                                 for(i = 0; i <= 10; ++i)
777                                         e.addValue(e, strzone(ftos_decimals(i - 5, 0)), strzone(ftos(i - 5)));
778                                 e.configureXonoticTextSliderValues(e);
779 }