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)
92 void makeMulti(entity e, string otherCvars)
94 e.cvarNames_Multi = otherCvars;
95 e.saveCvars_Multi = e.saveCvars;
96 e.saveCvars = saveCvarsMulti;
99 .void(entity me) saveCvars_Callback;
100 .entity saveCvars_Callback_ent;
101 .void(entity me, entity cb) saveCvars_Callback_func;
102 void saveCvarsCallback(entity me)
104 me.saveCvars_Callback(me);
105 me.saveCvars_Callback_func(me.saveCvars_Callback_ent, me);
107 void makeCallback(entity e, entity cbent, void(entity, entity) cbfunc)
109 e.saveCvars_Callback = e.saveCvars;
110 e.saveCvars = saveCvarsCallback;
111 e.saveCvars_Callback_ent = cbent;
112 e.saveCvars_Callback_func = cbfunc;
115 .void(entity) draw_setDependent;
116 .string cvar_setDependent;
117 .float cvarMin_setDependent;
118 .float cvarMax_setDependent;
119 .string cvar2_setDependent;
120 .float cvar2Min_setDependent;
121 .float cvar2Max_setDependent;
122 .string cvar3_setDependent;
123 .float cvar3Min_setDependent;
124 .float cvar3Max_setDependent;
125 .float op_setDependent;
126 .string cvarString_setDependent;
127 .string cvarValue_setDependent;
128 .float(entity) func_setDependent;
129 void setDependent_Check(entity e)
133 if(e.func_setDependent)
135 e.disabled = !(e.func_setDependent(e));
137 else if(e.cvarString_setDependent)
139 s = cvar_string(e.cvarString_setDependent);
140 e.disabled = (cvar_string(e.cvarString_setDependent) == e.cvarValue_setDependent);
144 if(e.cvar_setDependent)
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));
150 e.disabled = ((f >= e.cvarMax_setDependent) && (f <= e.cvarMin_setDependent));
152 if(e.cvar2_setDependent)
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);
158 e.disabled = (e.disabled + ((f >= e.cvar2Max_setDependent) && (f <= e.cvar2Min_setDependent)) > e.op_setDependent);
160 if(e.cvar3_setDependent)
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);
166 e.disabled = (e.disabled + ((f >= e.cvar3Max_setDependent) && (f <= e.cvar3Min_setDependent)) > e.op_setDependent);
170 void setDependent_Draw(entity e)
172 setDependent_Check(e);
173 e.draw_setDependent(e);
175 void setDependent(entity e, string theCvarName, float theCvarMin, float theCvarMax)
177 e.draw_setDependent = e.draw;
178 e.cvar_setDependent = theCvarName;
179 e.cvarMin_setDependent = theCvarMin;
180 e.cvarMax_setDependent = theCvarMax;
181 e.cvar2_setDependent = string_null;
182 e.cvar3_setDependent = string_null;
183 e.func_setDependent = func_null;
184 e.draw = setDependent_Draw;
185 setDependent_Check(e);
187 void setDependentStringNotEqual(entity e, string theCvarName, string theCvarValue)
189 e.draw_setDependent = e.draw;
190 e.cvarString_setDependent = theCvarName;
191 e.cvarValue_setDependent = theCvarValue;
192 e.cvar_setDependent = string_null;
193 e.cvar2_setDependent = string_null;
194 e.cvar3_setDependent = string_null;
195 e.func_setDependent = func_null;
196 e.draw = setDependent_Draw;
197 setDependent_Check(e);
199 void setDependentAND(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
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 = theCvar2Name;
206 e.cvar2Min_setDependent = theCvar2Min;
207 e.cvar2Max_setDependent = theCvar2Max;
208 e.cvar3_setDependent = string_null;
209 e.op_setDependent = 0;
210 e.func_setDependent = func_null;
211 e.draw = setDependent_Draw;
212 setDependent_Check(e);
214 void setDependentOR(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
216 e.draw_setDependent = e.draw;
217 e.cvar_setDependent = theCvarName;
218 e.cvarMin_setDependent = theCvarMin;
219 e.cvarMax_setDependent = theCvarMax;
220 e.cvar2_setDependent = theCvar2Name;
221 e.cvar2Min_setDependent = theCvar2Min;
222 e.cvar2Max_setDependent = theCvar2Max;
223 e.cvar3_setDependent = string_null;
224 e.op_setDependent = 1;
225 e.func_setDependent = func_null;
226 e.draw = setDependent_Draw;
227 setDependent_Check(e);
229 void setDependentAND3(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max, string theCvar3Name, float theCvar3Min, float theCvar3Max)
231 e.draw_setDependent = e.draw;
232 e.cvar_setDependent = theCvarName;
233 e.cvarMin_setDependent = theCvarMin;
234 e.cvarMax_setDependent = theCvarMax;
235 e.cvar2_setDependent = theCvar2Name;
236 e.cvar2Min_setDependent = theCvar2Min;
237 e.cvar2Max_setDependent = theCvar2Max;
238 e.cvar3_setDependent = theCvar3Name;
239 e.cvar3Min_setDependent = theCvar3Min;
240 e.cvar3Max_setDependent = theCvar3Max;
241 e.op_setDependent = 0;
242 e.func_setDependent = func_null;
243 e.draw = setDependent_Draw;
244 setDependent_Check(e);
246 void setDependentWeird(entity e, float(entity) func)
248 e.draw_setDependent = e.draw;
249 e.func_setDependent = func;
250 e.draw = setDependent_Draw;
251 setDependent_Check(e);
254 // URI SYSTEM ////////////////////////////////////////////////////////
256 float _Nex_ExtResponseSystem_Queried;
257 string _Nex_ExtResponseSystem_UpdateTo;
258 string _Nex_ExtResponseSystem_UpdateToURL;
259 string _Nex_ExtResponseSystem_Packs;
260 float _Nex_ExtResponseSystem_PacksStep;
262 void URI_Get_Callback(float id, float status, string data)
264 if(url_URI_Get_Callback(id, status, data))
268 else if (id == URI_GET_DISCARD)
272 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
275 Curl_URI_Get_Callback(id, status, data);
277 else if (id == URI_GET_UPDATENOTIFICATION)
279 UpdateNotification_URI_Get_Callback(id, status, data);
283 print(sprintf("Received HTTP request data for an invalid id %d.\n", id));
287 void UpdateNotification_URI_Get_Callback(float id, float status, string data)
291 if(_Nex_ExtResponseSystem_UpdateTo)
293 dprint("error: UpdateNotification_URI_Get_Callback has been called before\n");
298 print(sprintf(_("error receiving update notification: status is %d\n"), status));
301 if(substring(data, 0, 1) == "<")
303 print(_("error: received HTML instead of an update notification\n"));
306 if(strstrofs(data, "\r", 0) != -1)
308 print(_("error: received carriage returns from update notification server\n"));
315 n = tokenizebyseparator(data, "\n");
320 string un_version = "";
321 string un_download = "";
323 string un_bannedservers = "";
324 string un_emergency_pk3s = "";
325 string un_promoted = "";
326 string un_recommended = "";
328 for(i = 0; i < n; ++i)
330 s = substring(argv(i), 2, -1);
331 if(s == "") { continue; } // ignore empty lines
333 switch(substring(argv(i), 0, 1))
335 #define APPEND_TO_STRING(list,sep,add) ((list) = (((list) != "") ? strcat(list, sep, add) : (add)))
353 APPEND_TO_STRING(un_bannedservers, " ", s);
358 if(cvar("menu_updatecheck_getpacks"))
359 APPEND_TO_STRING(un_emergency_pk3s, " ", s);
364 APPEND_TO_STRING(un_promoted, " ", s);
369 APPEND_TO_STRING(un_recommended, " ", s);
377 if(vercmp(cvar_string("g_xonoticversion"), un_version) < 0)
380 _Nex_ExtResponseSystem_UpdateTo = strzone(un_version);
381 if(un_download) { print(sprintf(_("Update can be downloaded at:\n%s\n"), un_download)); }
382 if(un_url) { _Nex_ExtResponseSystem_UpdateToURL = strzone(un_url); }
386 if(un_emergency_pk3s != "")
388 _Nex_ExtResponseSystem_Packs = strzone(argv(4));
389 _Nex_ExtResponseSystem_PacksStep = 1;
392 if(un_promoted != "")
394 _Nex_ExtResponseSystem_PromotedServers = strzone(un_promoted);
395 _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 1;
398 if(un_recommended != "")
400 _Nex_ExtResponseSystem_RecommendedServers = strzone(un_recommended);
401 _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 1;
406 // END OF URI SYSTEM ////////////////////////////////////////////////////////
410 if(cvar("menu_updatecheck"))
412 if(!_Nex_ExtResponseSystem_Queried)
414 _Nex_ExtResponseSystem_Queried = 1;
418 cvar_set("cl_startcount", ftos(startcnt = cvar("cl_startcount") + 1));
420 // for privacy, munge the start count a little
421 startcnt = floor((floor(startcnt / 10) + random()) * 10);
422 uri = sprintf("http://www.xonotic.org/dl/checkupdate.txt?format=keys&version=%s&cnt=%d", uri_escape(cvar_string("g_xonoticversion")), startcnt);
425 float cvar_handle, popcon_handle;
428 cvar_handle = buf_create();
429 buf_cvarlist(cvar_handle, "", "");
430 n = buf_getsize(cvar_handle);
431 popcon_handle = buf_create();
432 for(i= 0, j = 0; i < n; ++i)
434 k = bufstr_get(cvar_handle, i);
435 if(!(cvar_type(k) & CVAR_TYPEFLAG_SAVED))
437 s = sprintf("%s=%d", uri_escape(k), cvar_string(k) != cvar_defstring(k));
438 bufstr_set(popcon_handle, j, s);
441 buf_del(cvar_handle);
443 uri, URI_GET_UPDATENOTIFICATION,
444 "application/x-www-form-urlencoded",
448 buf_del(popcon_handle);
450 uri_get(uri, URI_GET_UPDATENOTIFICATION);
455 if(_Nex_ExtResponseSystem_PacksStep > 0)
459 n = tokenize_console(_Nex_ExtResponseSystem_Packs);
461 for(i = 0; i+1 < n; i += 2)
463 if(fexists(argv(i+1)))
466 if(_Nex_ExtResponseSystem_PacksStep == 1) // first run
467 localcmd("\ncurl --pak \"", argv(i), "\"\n");
471 if(_Nex_ExtResponseSystem_PacksStep == 2)
474 cvar_set("_menu_initialized", "0");
475 // HACK: cause m_hide call on next start
476 localcmd("\nmenu_restart\n");
478 _Nex_ExtResponseSystem_PacksStep = 0;
481 _Nex_ExtResponseSystem_PacksStep = 2;
493 MapInfo_Cache_Create();
495 if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
497 draw_reset_cropped();
499 sz = eX * 0.025 + eY * 0.025 * (draw_scale_x / draw_scale_y);
500 draw_CenterText('0.5 0.5 0' - 1.25 * sz_y * eY, _("Autogenerating mapinfo for newly added maps..."), sz, '1 1 1', 1, 0);
502 boxA = '0.05 0.5 0' + 0.25 * sz_y * eY;
503 boxB = '0.95 0.5 0' + 1.25 * sz_y * eY;
504 draw_Fill(boxA, boxB - boxA, '1 1 1', 1);
508 draw_Fill(boxA, boxB - boxA, '0.1 0.1 0.1', 1);
510 boxB_x = boxA_x * (1 - MapInfo_progress) + boxB_x * MapInfo_progress;
511 draw_Fill(boxA, boxB - boxA, '0 0 1', 1);
518 string campaign_name_previous;
519 float campaign_won_previous;
521 var string autocvar_menu_watermark = WATERMARK;
523 var string autocvar_menu_watermark = "";
527 if(autocvar_menu_watermark != "")
529 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);
534 vector fs, sz = '0 0 0', line, mid;
538 if(_Nex_ExtResponseSystem_UpdateTo != "")
540 // TODO rather turn this into a dialog
541 fs = ((1/draw_scale_x) * eX + (1/draw_scale_y) * eY) * 12;
544 l1 = sprintf(_("Update to %s now!"), _Nex_ExtResponseSystem_UpdateTo);
545 l2 = "http://www.xonotic.org/";
546 if(_Nex_ExtResponseSystem_UpdateToURL)
547 l2 = _Nex_ExtResponseSystem_UpdateToURL;
549 sz_x = draw_TextWidth(" ", 0, fs) + max(
550 draw_TextWidth(l1, 0, fs),
551 draw_TextWidth(l2, 0, fs)
555 draw_alpha = bound(0, sin(time * 0.112 - 0.3) * 10, 1);
556 mid = eX * (0.5 + 0.5 * (1 - sz_x) * cos(time * 0.071))
557 + eY * (0.5 + 0.5 * (1 - sz_y) * sin(time * 0.071));
559 draw_Fill(mid - 0.5 * sz, sz, '1 1 0', 1);
560 draw_CenterText(mid - 1 * line, l1, fs, '1 0 0', 1, 0);
561 draw_CenterText(mid - 0 * line, l2, fs, '0 0 1', 1, 0);
563 if not(campaign_name_previous)
564 campaign_name_previous = strzone(strcat(campaign_name, "x")); // force unequal
565 if(campaign_name == campaign_name_previous)
567 if(cvar(strcat("g_campaign", campaign_name, "_won")))
569 if(!campaign_won_previous)
572 DialogOpenButton_Click_withCoords(NULL, main.winnerDialog, '0 0 0', eX * conwidth + eY * conheight);
574 campaign_won_previous = 1;
577 campaign_won_previous = 0;
581 strunzone(campaign_name_previous);
582 campaign_name_previous = strzone(campaign_name);
583 campaign_won_previous = cvar(strcat("g_campaign", campaign_name, "_won"));
587 string resolvemod(string m)
590 return getcurrentmod();
595 float updateCompression()
597 float have_dds, have_jpg, have_tga;
599 have_dds = (fexists("dds/particles/particlefont.dds"));
600 have_jpg = (fexists("particles/particlefont.jpg"));
601 have_tga = (fexists("particles/particlefont.tga"));
602 can_dds = GL_Have_TextureCompression();
603 if(have_dds && (have_jpg || have_tga))
605 // both? Let's only use good quality precompressed files
606 // but ONLY if we actually support it!
609 // these builds are meant to have GOOD quality, so let's not compress non-skinframes
610 cvar_set("gl_texturecompression", "0");
613 //cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
618 cvar_set("gl_texturecompression", "0");
619 cvar_set("r_texture_dds_load", "0");
625 // DDS only? We probably always want texture compression
626 cvar_set("gl_texturecompression", "1");
627 cvar_set("r_texture_dds_load", "1");
629 print(_("^1ERROR: Texture compression is required but not supported.\n^1Expect visual problems.\n"));
634 // TGA only? Allow runtime compression
637 cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
642 cvar_set("gl_texturecompression", "0");
643 cvar_set("r_texture_dds_load", "0");
649 // note: include only those that should be in the menu!
651 GAMETYPE(MAPINFO_TYPE_ARENA) \
652 GAMETYPE(MAPINFO_TYPE_ASSAULT) \
653 GAMETYPE(MAPINFO_TYPE_CTF) \
654 GAMETYPE(MAPINFO_TYPE_CA) \
655 GAMETYPE(MAPINFO_TYPE_DEATHMATCH) \
656 GAMETYPE(MAPINFO_TYPE_DOMINATION) \
657 GAMETYPE(MAPINFO_TYPE_FREEZETAG) \
658 GAMETYPE(MAPINFO_TYPE_KEEPAWAY) \
659 GAMETYPE(MAPINFO_TYPE_KEYHUNT) \
660 GAMETYPE(MAPINFO_TYPE_LMS) \
661 GAMETYPE(MAPINFO_TYPE_NEXBALL) \
662 GAMETYPE(MAPINFO_TYPE_ONSLAUGHT) \
663 GAMETYPE(MAPINFO_TYPE_RACE) \
664 GAMETYPE(MAPINFO_TYPE_CTS) \
665 GAMETYPE(MAPINFO_TYPE_TEAM_DEATHMATCH) \
668 float GameType_GetID(float cnt)
673 #define GAMETYPE(id) if(i++ == cnt) return id;
682 float GameType_GetCount()
687 #define GAMETYPE(id) ++i;
694 string GameType_GetName(float cnt)
696 float i = GameType_GetID(cnt);
699 return MapInfo_Type_ToText(i);
704 string GameType_GetIcon(float cnt)
706 float i = GameType_GetID(cnt);
709 return strcat("gametype_", MapInfo_Type_ToString(i));
714 /*string GameType_GetTeams(float cnt) // poor implementation, later something else could be done that's better?
716 float i = GameType_GetID(cnt);
717 string s = _MapInfo_GetDefaultEx(i);
721 if(strstrofs(s, "teams", 0) >= 0)
722 return _("teamplay");
724 return _("free for all");
727 return _("tuba for all");
730 void dialog_hudpanel_common_notoggle(entity me, string panelname)
736 me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Background:")));
737 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg"))));
738 e.addValue(e, _("Default"), "");
739 e.addValue(e, _("Disable"), "0");
740 e.addValue(e, strzone(strcat("border_", panelname)), strzone(strcat("border_", panelname)));
741 e.configureXonoticTextSliderValues(e);
744 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Color:")));
745 me.TD(me, 2, 2.6, e = makeXonoticColorpickerString(strzone(strcat("hud_panel_", panelname, "_bg_color")), "hud_panel_bg_color"));
746 setDependentStringNotEqual(e, strzone(strcat("hud_panel_", panelname, "_bg_color")), "");
749 me.TD(me, 1, 1.0, e = makeXonoticCheckBoxString("", "1 1 1", strzone(strcat("hud_panel_", panelname, "_bg_color")), _("Use default")));
752 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Border size:")));
753 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_border"))));
754 e.addValue(e, _("Default"), "");
755 e.addValue(e, _("Disable"), "0");
756 for(i = 1; i <= 10; ++i)
757 e.addValue(e, strzone(ftos_decimals(i * 2, 0)), strzone(ftos(i * 2)));
758 e.configureXonoticTextSliderValues(e);
761 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:")));
762 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_alpha"))));
763 e.addValue(e, _("Default"), "");
764 for(i = 1; i <= 10; ++i)
765 e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
766 e.configureXonoticTextSliderValues(e);
769 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Team Color:")));
770 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_color_team"))));
771 e.addValue(e, _("Default"), "");
772 e.addValue(e, _("Disable"), "0");
773 for(i = 1; i <= 10; ++i)
774 e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10)));
775 e.configureXonoticTextSliderValues(e);
778 me.TD(me, 1, 3.6, e = makeXonoticCheckBox(0, "hud_configure_teamcolorforced", _("Test team color in configure mode")));
781 me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Padding:")));
782 me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_bg_padding"))));
783 e.addValue(e, _("Default"), "");
784 for(i = 0; i <= 10; ++i)
785 e.addValue(e, strzone(ftos_decimals(i - 5, 0)), strzone(ftos(i - 5)));
786 e.configureXonoticTextSliderValues(e);