1 float GL_CheckExtension(string ext)
3 return (strstrofs(strcat(" ", cvar_string("gl_info_extensions"), " "), strcat(" ", ext, " "), 0) >= 0);
6 float GL_Have_TextureCompression()
8 return (GL_CheckExtension("GL_EXT_texture_compression_s3tc") && GL_CheckExtension("GL_ARB_texture_compression"));
13 tooltipdb = db_load(language_filename("tooltips.db"));
21 string getZonedTooltipForIdentifier(string s)
28 t = db_get(tooltipdb, s);
34 if(prvm_language == "en")
36 t = cvar_description(s);
37 if(t != "" && t != "custom cvar")
40 dprint("WARNING: no tooltip set for ", s, "\n");
44 void forAllDescendants(entity root, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
46 depthfirst(root, parent, firstChild, nextSibling, funcPre, funcPost, pass);
50 void SUB_Null_ee(entity e1, entity e2)
53 void saveCvarsOf(entity ignore, entity e)
58 void loadCvarsOf(entity ignore, entity e)
63 void saveAllCvars(entity root)
65 forAllDescendants(root, saveCvarsOf, SUB_Null_ee, NULL);
67 void loadAllCvars(entity root)
69 forAllDescendants(root, loadCvarsOf, SUB_Null_ee, NULL);
72 .string cvarNames_Multi;
73 .void(entity me) saveCvars_Multi;
74 string getCvarsMulti(entity me)
76 if (me.cvarNames_Multi)
77 return me.cvarNames_Multi;
80 void saveCvarsMulti(entity me)
85 me.saveCvars_Multi(me);
86 s = cvar_string(me.cvarName);
88 n = tokenize_console(me.cvarNames_Multi);
89 for(i = 0; i < n; ++i)
91 if(substring(argv(i), 0, 1) == "!")
92 cvar_set(substring(argv(i), 1, strlen(argv(i))), ((s == "0") ? "1" : "0"));
97 void makeMulti(entity e, string otherCvars)
99 e.cvarNames_Multi = otherCvars;
100 e.saveCvars_Multi = e.saveCvars;
101 e.saveCvars = saveCvarsMulti;
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)
109 me.saveCvars_Callback(me);
110 me.saveCvars_Callback_func(me.saveCvars_Callback_ent, me);
112 void makeCallback(entity e, entity cbent, void(entity, entity) cbfunc)
114 e.saveCvars_Callback = e.saveCvars;
115 e.saveCvars = saveCvarsCallback;
116 e.saveCvars_Callback_ent = cbent;
117 e.saveCvars_Callback_func = cbfunc;
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)
138 if(e.func_setDependent)
140 e.disabled = !(e.func_setDependent(e));
142 else if(e.cvarString_setDependent)
144 s = cvar_string(e.cvarString_setDependent);
145 e.disabled = (cvar_string(e.cvarString_setDependent) == e.cvarValue_setDependent);
149 if(e.cvar_setDependent)
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));
155 e.disabled = ((f >= e.cvarMax_setDependent) && (f <= e.cvarMin_setDependent));
157 if(e.cvar2_setDependent)
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);
163 e.disabled = (e.disabled + ((f >= e.cvar2Max_setDependent) && (f <= e.cvar2Min_setDependent)) > e.op_setDependent);
165 if(e.cvar3_setDependent)
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);
171 e.disabled = (e.disabled + ((f >= e.cvar3Max_setDependent) && (f <= e.cvar3Min_setDependent)) > e.op_setDependent);
175 void setDependent_Draw(entity e)
177 setDependent_Check(e);
178 e.draw_setDependent(e);
180 void setDependent(entity e, string theCvarName, float theCvarMin, float theCvarMax)
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);
192 void setDependentStringNotEqual(entity e, string theCvarName, string theCvarValue)
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);
204 void setDependentAND(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
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);
219 void setDependentOR(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
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);
234 void setDependentAND3(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max, string theCvar3Name, float theCvar3Min, float theCvar3Max)
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);
251 void setDependentWeird(entity e, float(entity) func)
253 e.draw_setDependent = e.draw;
254 e.func_setDependent = func;
255 e.draw = setDependent_Draw;
256 setDependent_Check(e);
259 // URI SYSTEM ////////////////////////////////////////////////////////
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;
267 void URI_Get_Callback(float id, float status, string data)
269 if(url_URI_Get_Callback(id, status, data))
273 else if (id == URI_GET_DISCARD)
277 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
280 Curl_URI_Get_Callback(id, status, data);
282 else if (id == URI_GET_UPDATENOTIFICATION)
284 UpdateNotification_URI_Get_Callback(id, status, data);
288 printf("Received HTTP request data for an invalid id %d.\n", id);
292 void DisableServerBackwardsCompatibility()
294 cvar_set("gameversion_min", ftos(100 * floor(cvar("gameversion") / 100)));
297 void UpdateNotification_URI_Get_Callback(float id, float status, string data)
301 if(_Nex_ExtResponseSystem_UpdateTo)
303 dprint("error: UpdateNotification_URI_Get_Callback has been called before\n");
308 printf(_("error receiving update notification: status is %d\n"), status);
311 if(substring(data, 0, 1) == "<")
313 print(_("error: received HTML instead of an update notification\n"));
316 if(strstrofs(data, "\r", 0) != -1)
318 print(_("error: received carriage returns from update notification server\n"));
325 n = tokenizebyseparator(data, "\n");
330 string un_version = "";
331 string un_download = "";
333 string un_bannedservers = "";
334 string un_emergency_pk3s = "";
335 string un_promoted = "";
336 string un_recommended = "";
337 string un_compatexpire = "";
339 for(i = 0; i < n; ++i)
341 s = substring(argv(i), 2, -1);
342 if(s == "") { continue; } // ignore empty lines
344 switch(substring(argv(i), 0, 1))
346 #define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
369 APPEND_TO_STRING(un_bannedservers, " ", s);
374 if(cvar("menu_updatecheck_getpacks"))
375 APPEND_TO_STRING(un_emergency_pk3s, " ", s);
380 APPEND_TO_STRING(un_promoted, " ", s);
385 APPEND_TO_STRING(un_recommended, " ", s);
393 if(vercmp(cvar_string("g_xonoticversion"), un_version) < 0)
396 _Nex_ExtResponseSystem_UpdateTo = strzone(un_version);
397 if(un_download) { printf(_("Update can be downloaded at:\n%s\n"), un_download); }
398 if(un_url) { _Nex_ExtResponseSystem_UpdateToURL = strzone(un_url); }
399 DisableServerBackwardsCompatibility();
401 else if(cvar_string("g_xonoticversion") == un_version)
403 if(un_compatexpire != "")
405 string curdate = strftime(FALSE, "%Y%m%d%H%M%S");
406 if (strcmp(curdate, un_compatexpire) >= 0)
407 DisableServerBackwardsCompatibility();
412 if(un_emergency_pk3s != "")
414 _Nex_ExtResponseSystem_Packs = strzone(un_emergency_pk3s);
415 _Nex_ExtResponseSystem_PacksStep = 1;
418 if(un_promoted != "")
420 _Nex_ExtResponseSystem_PromotedServers = strzone(un_promoted);
421 _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 1;
424 if(un_recommended != "")
426 _Nex_ExtResponseSystem_RecommendedServers = strzone(un_recommended);
427 _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 1;
431 // END OF URI SYSTEM ////////////////////////////////////////////////////////
435 if(cvar("menu_updatecheck"))
437 if(!_Nex_ExtResponseSystem_Queried)
439 _Nex_ExtResponseSystem_Queried = 1;
443 cvar_set("cl_startcount", ftos(startcnt = cvar("cl_startcount") + 1));
445 // for privacy, munge the start count a little
446 startcnt = floor((floor(startcnt / 10) + random()) * 10);
447 uri = sprintf("http://update.xonotic.org/checkupdate.txt?version=%s&cnt=%d", uri_escape(cvar_string("g_xonoticversion")), startcnt);
448 uri_get(uri, URI_GET_UPDATENOTIFICATION);
452 if(_Nex_ExtResponseSystem_PacksStep > 0)
456 n = tokenize_console(_Nex_ExtResponseSystem_Packs);
458 for(i = 0; i+1 < n; i += 2)
460 if(fexists(argv(i+1)))
463 if(_Nex_ExtResponseSystem_PacksStep == 1) // first run
464 localcmd("\ncurl --pak \"", argv(i), "\"\n");
468 if(_Nex_ExtResponseSystem_PacksStep == 2)
471 cvar_set("_menu_initialized", "0");
472 // HACK: cause m_hide call on next start
473 localcmd("\nmenu_restart\n");
475 _Nex_ExtResponseSystem_PacksStep = 0;
478 _Nex_ExtResponseSystem_PacksStep = 2;
490 MapInfo_Cache_Create();
492 if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
494 draw_reset_cropped();
496 sz = eX * 0.025 + eY * 0.025 * (draw_scale_x / draw_scale_y);
497 draw_CenterText('0.5 0.5 0' - 1.25 * sz_y * eY, _("Autogenerating mapinfo for newly added maps..."), sz, '1 1 1', 1, 0);
499 boxA = '0.05 0.5 0' + 0.25 * sz_y * eY;
500 boxB = '0.95 0.5 0' + 1.25 * sz_y * eY;
501 draw_Fill(boxA, boxB - boxA, '1 1 1', 1);
505 draw_Fill(boxA, boxB - boxA, '0.1 0.1 0.1', 1);
507 boxB_x = boxA_x * (1 - MapInfo_progress) + boxB_x * MapInfo_progress;
508 draw_Fill(boxA, boxB - boxA, '0 0 1', 1);
515 string campaign_name_previous;
516 float campaign_won_previous;
518 var string autocvar_menu_watermark = WATERMARK;
520 var string autocvar_menu_watermark = "";
524 if(autocvar_menu_watermark != "")
526 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);
531 vector fs, sz = '0 0 0', line, mid;
535 if(_Nex_ExtResponseSystem_UpdateTo != "")
537 // TODO rather turn this into a dialog
538 fs = ((1/draw_scale_x) * eX + (1/draw_scale_y) * eY) * 12;
541 l1 = sprintf(_("Update to %s now!"), _Nex_ExtResponseSystem_UpdateTo);
542 l2 = "http://www.xonotic.org/";
543 if(_Nex_ExtResponseSystem_UpdateToURL)
544 l2 = _Nex_ExtResponseSystem_UpdateToURL;
546 sz_x = draw_TextWidth(" ", 0, fs) + max(
547 draw_TextWidth(l1, 0, fs),
548 draw_TextWidth(l2, 0, fs)
552 draw_alpha = bound(0, sin(time * 0.112 - 0.3) * 10, 1);
553 mid = eX * (0.5 + 0.5 * (1 - sz_x) * cos(time * 0.071))
554 + eY * (0.5 + 0.5 * (1 - sz_y) * sin(time * 0.071));
556 draw_Fill(mid - 0.5 * sz, sz, '1 1 0', 1);
557 draw_CenterText(mid - 1 * line, l1, fs, '1 0 0', 1, 0);
558 draw_CenterText(mid - 0 * line, l2, fs, '0 0 1', 1, 0);
560 if (!campaign_name_previous)
561 campaign_name_previous = strzone(strcat(campaign_name, "x")); // force unequal
562 if(campaign_name == campaign_name_previous)
564 if(cvar(strcat("g_campaign", campaign_name, "_won")))
566 if(!campaign_won_previous)
569 DialogOpenButton_Click_withCoords(NULL, main.winnerDialog, '0 0 0', eX * conwidth + eY * conheight);
571 campaign_won_previous = 1;
574 campaign_won_previous = 0;
578 strunzone(campaign_name_previous);
579 campaign_name_previous = strzone(campaign_name);
580 campaign_won_previous = cvar(strcat("g_campaign", campaign_name, "_won"));
584 string resolvemod(string m)
587 return getcurrentmod();
592 float updateCompression()
594 float have_dds, have_jpg, have_tga;
596 have_dds = (fexists("dds/particles/particlefont.dds"));
597 have_jpg = (fexists("particles/particlefont.jpg"));
598 have_tga = (fexists("particles/particlefont.tga"));
599 can_dds = GL_Have_TextureCompression();
600 if(have_dds && (have_jpg || have_tga))
602 // both? Let's only use good quality precompressed files
603 // but ONLY if we actually support it!
606 // these builds are meant to have GOOD quality, so let's not compress non-skinframes
607 cvar_set("gl_texturecompression", "0");
610 //cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
615 cvar_set("gl_texturecompression", "0");
616 cvar_set("r_texture_dds_load", "0");
622 // DDS only? We probably always want texture compression
623 cvar_set("gl_texturecompression", "1");
624 cvar_set("r_texture_dds_load", "1");
626 print(_("^1ERROR: Texture compression is required but not supported.\n^1Expect visual problems.\n"));
631 // TGA only? Allow runtime compression
634 cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
639 cvar_set("gl_texturecompression", "0");
640 cvar_set("r_texture_dds_load", "0");
646 // note: include only those that should be in the menu!
648 GAMETYPE(MAPINFO_TYPE_ASSAULT) \
649 GAMETYPE(MAPINFO_TYPE_CTF) \
650 GAMETYPE(MAPINFO_TYPE_CA) \
651 GAMETYPE(MAPINFO_TYPE_DEATHMATCH) \
652 GAMETYPE(MAPINFO_TYPE_DOMINATION) \
653 GAMETYPE(MAPINFO_TYPE_FREEZETAG) \
654 GAMETYPE(MAPINFO_TYPE_KEEPAWAY) \
655 GAMETYPE(MAPINFO_TYPE_KEYHUNT) \
656 GAMETYPE(MAPINFO_TYPE_LMS) \
657 GAMETYPE(MAPINFO_TYPE_NEXBALL) \
658 GAMETYPE(MAPINFO_TYPE_ONSLAUGHT) \
659 if (cvar("developer")) GAMETYPE(MAPINFO_TYPE_RACE) \
660 GAMETYPE(MAPINFO_TYPE_CTS) \
661 GAMETYPE(MAPINFO_TYPE_TEAM_DEATHMATCH) \
662 //GAMETYPE(MAPINFO_TYPE_INVASION) \
665 float GameType_GetID(float cnt)
670 #define GAMETYPE(id) { if(i++ == cnt) return id; }
679 float GameType_GetCount()
684 #define GAMETYPE(id) ++i;
691 string GameType_GetName(float cnt)
693 float i = GameType_GetID(cnt);
696 return MapInfo_Type_ToText(i);
701 string GameType_GetIcon(float cnt)
703 float i = GameType_GetID(cnt);
706 return strcat("gametype_", MapInfo_Type_ToString(i));
711 /*string GameType_GetTeams(float cnt) // poor implementation, later something else could be done that's better?
713 float i = GameType_GetID(cnt);
714 string s = _MapInfo_GetDefaultEx(i);
718 if(strstrofs(s, "teams", 0) >= 0)
719 return _("teamplay");
721 return _("free for all");
724 return _("tuba for all");
727 void dialog_hudpanel_common_notoggle(entity me, string panelname)
733 me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Background:")));
734 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg"))));
735 e.addValue(e, _("Default"), "");
736 e.addValue(e, _("Disable"), "0");
737 e.addValue(e, strzone(strcat("border_", panelname)), strzone(strcat("border_", panelname)));
738 e.configureXonoticTextSliderValues(e);
741 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Color:")));
742 me.TD(me, 2, 2.6, e = makeXonoticColorpickerString(strzone(strcat("hud_panel_", panelname, "_bg_color")), "hud_panel_bg_color"));
743 setDependentStringNotEqual(e, strzone(strcat("hud_panel_", panelname, "_bg_color")), "");
746 me.TD(me, 1, 1.0, e = makeXonoticCheckBoxString("", "1 1 1", strzone(strcat("hud_panel_", panelname, "_bg_color")), _("Use default")));
749 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Border size:")));
750 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_border"))));
751 e.addValue(e, _("Default"), "");
752 e.addValue(e, _("Disable"), "0");
753 for(i = 1; i <= 10; ++i)
754 e.addValue(e, strzone(ftos_decimals(i * 2, 0)), strzone(ftos(i * 2)));
755 e.configureXonoticTextSliderValues(e);
758 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:")));
759 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_alpha"))));
760 e.addValue(e, _("Default"), "");
761 for(i = 1; i <= 10; ++i)
762 e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
763 e.configureXonoticTextSliderValues(e);
766 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Team Color:")));
767 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_color_team"))));
768 e.addValue(e, _("Default"), "");
769 e.addValue(e, _("Disable"), "0");
770 for(i = 1; i <= 10; ++i)
771 e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
772 e.configureXonoticTextSliderValues(e);
775 me.TD(me, 1, 3.6, e = makeXonoticCheckBox(0, "hud_configure_teamcolorforced", _("Test team color in configure mode")));
778 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Padding:")));
779 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_padding"))));
780 e.addValue(e, _("Default"), "");
781 for(i = 0; i <= 10; ++i)
782 e.addValue(e, strzone(ftos_decimals(i - 5, 0)), strzone(ftos(i - 5)));
783 e.configureXonoticTextSliderValues(e);