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