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