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