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