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