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