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"));
14 tooltipdb = db_load("tooltips.db");
21 string getZonedTooltipForIdentifier(string s)
24 if(s == "" || tooltipdb < 0)
26 t = db_get(tooltipdb, s);
31 t = cvar_description(s);
32 if(t != "" && t != "custom cvar")
34 dprint("WARNING: no tooltip set for ", s, "\n");
38 void forAllDescendants(entity root, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
40 depthfirst(root, parent, firstChild, nextSibling, funcPre, funcPost, pass);
44 void SUB_Null_ee(entity e1, entity e2)
47 void saveCvarsOf(entity ignore, entity e)
52 void loadCvarsOf(entity ignore, entity e)
57 void saveAllCvars(entity root)
59 forAllDescendants(root, saveCvarsOf, SUB_Null_ee, NULL);
61 void loadAllCvars(entity root)
63 forAllDescendants(root, loadCvarsOf, SUB_Null_ee, NULL);
66 .string cvarNames_Multi;
67 .void(entity me) saveCvars_Multi;
68 string getCvarsMulti(entity me)
70 if (me.cvarNames_Multi)
71 return me.cvarNames_Multi;
74 void saveCvarsMulti(entity me)
79 me.saveCvars_Multi(me);
80 s = cvar_string(me.cvarName);
82 n = tokenize_console(me.cvarNames_Multi);
83 for(i = 0; i < n; ++i)
86 void makeMulti(entity e, string otherCvars)
88 e.cvarNames_Multi = otherCvars;
89 e.saveCvars_Multi = e.saveCvars;
90 e.saveCvars = saveCvarsMulti;
93 .void(entity me) saveCvars_Callback;
94 .entity saveCvars_Callback_ent;
95 .void(entity me, entity cb) saveCvars_Callback_func;
96 void saveCvarsCallback(entity me)
98 me.saveCvars_Callback(me);
99 me.saveCvars_Callback_func(me.saveCvars_Callback_ent, me);
101 void makeCallback(entity e, entity cbent, void(entity, entity) cbfunc)
103 e.saveCvars_Callback = e.saveCvars;
104 e.saveCvars = saveCvarsCallback;
105 e.saveCvars_Callback_ent = cbent;
106 e.saveCvars_Callback_func = cbfunc;
109 .void(entity) draw_setDependent;
110 .string cvar_setDependent;
111 .float cvarMin_setDependent;
112 .float cvarMax_setDependent;
113 .string cvar2_setDependent;
114 .float cvar2Min_setDependent;
115 .float cvar2Max_setDependent;
116 .string cvar3_setDependent;
117 .float cvar3Min_setDependent;
118 .float cvar3Max_setDependent;
119 .float op_setDependent;
120 .string cvarString_setDependent;
121 .string cvarValue_setDependent;
122 .float(entity) func_setDependent;
123 void setDependent_Check(entity e)
127 if(e.func_setDependent)
129 e.disabled = !(e.func_setDependent(e));
131 else if(e.cvarString_setDependent)
133 s = cvar_string(e.cvarString_setDependent);
134 e.disabled = (cvar_string(e.cvarString_setDependent) == e.cvarValue_setDependent);
138 if(e.cvar_setDependent)
140 f = cvar(e.cvar_setDependent);
141 if(e.cvarMin_setDependent <= e.cvarMax_setDependent)
142 e.disabled = ((f < e.cvarMin_setDependent) || (f > e.cvarMax_setDependent));
144 e.disabled = ((f >= e.cvarMax_setDependent) && (f <= e.cvarMin_setDependent));
146 if(e.cvar2_setDependent)
148 f = cvar(e.cvar2_setDependent);
149 if(e.cvar2Min_setDependent <= e.cvar2Max_setDependent)
150 e.disabled = (e.disabled + ((f < e.cvar2Min_setDependent) || (f > e.cvar2Max_setDependent)) > e.op_setDependent);
152 e.disabled = (e.disabled + ((f >= e.cvar2Max_setDependent) && (f <= e.cvar2Min_setDependent)) > e.op_setDependent);
154 if(e.cvar3_setDependent)
156 f = cvar(e.cvar3_setDependent);
157 if(e.cvar3Min_setDependent <= e.cvar3Max_setDependent)
158 e.disabled = (e.disabled + ((f < e.cvar3Min_setDependent) || (f > e.cvar3Max_setDependent)) > e.op_setDependent);
160 e.disabled = (e.disabled + ((f >= e.cvar3Max_setDependent) && (f <= e.cvar3Min_setDependent)) > e.op_setDependent);
164 void setDependent_Draw(entity e)
166 setDependent_Check(e);
167 e.draw_setDependent(e);
169 void setDependent(entity e, string theCvarName, float theCvarMin, float theCvarMax)
171 e.draw_setDependent = e.draw;
172 e.cvar_setDependent = theCvarName;
173 e.cvarMin_setDependent = theCvarMin;
174 e.cvarMax_setDependent = theCvarMax;
175 e.cvar2_setDependent = string_null;
176 e.cvar3_setDependent = string_null;
177 e.func_setDependent = func_null;
178 e.draw = setDependent_Draw;
179 setDependent_Check(e);
181 void setDependentStringNotEqual(entity e, string theCvarName, string theCvarValue)
183 e.draw_setDependent = e.draw;
184 e.cvarString_setDependent = theCvarName;
185 e.cvarValue_setDependent = theCvarValue;
186 e.cvar_setDependent = string_null;
187 e.cvar2_setDependent = string_null;
188 e.cvar3_setDependent = string_null;
189 e.func_setDependent = func_null;
190 e.draw = setDependent_Draw;
191 setDependent_Check(e);
193 void setDependentAND(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
195 e.draw_setDependent = e.draw;
196 e.cvar_setDependent = theCvarName;
197 e.cvarMin_setDependent = theCvarMin;
198 e.cvarMax_setDependent = theCvarMax;
199 e.cvar2_setDependent = theCvar2Name;
200 e.cvar2Min_setDependent = theCvar2Min;
201 e.cvar2Max_setDependent = theCvar2Max;
202 e.cvar3_setDependent = string_null;
203 e.op_setDependent = 0;
204 e.func_setDependent = func_null;
205 e.draw = setDependent_Draw;
206 setDependent_Check(e);
208 void setDependentOR(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
210 e.draw_setDependent = e.draw;
211 e.cvar_setDependent = theCvarName;
212 e.cvarMin_setDependent = theCvarMin;
213 e.cvarMax_setDependent = theCvarMax;
214 e.cvar2_setDependent = theCvar2Name;
215 e.cvar2Min_setDependent = theCvar2Min;
216 e.cvar2Max_setDependent = theCvar2Max;
217 e.cvar3_setDependent = string_null;
218 e.op_setDependent = 1;
219 e.func_setDependent = func_null;
220 e.draw = setDependent_Draw;
221 setDependent_Check(e);
223 void setDependentAND3(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max, string theCvar3Name, float theCvar3Min, float theCvar3Max)
225 e.draw_setDependent = e.draw;
226 e.cvar_setDependent = theCvarName;
227 e.cvarMin_setDependent = theCvarMin;
228 e.cvarMax_setDependent = theCvarMax;
229 e.cvar2_setDependent = theCvar2Name;
230 e.cvar2Min_setDependent = theCvar2Min;
231 e.cvar2Max_setDependent = theCvar2Max;
232 e.cvar3_setDependent = theCvar3Name;
233 e.cvar3Min_setDependent = theCvar3Min;
234 e.cvar3Max_setDependent = theCvar3Max;
235 e.op_setDependent = 0;
236 e.func_setDependent = func_null;
237 e.draw = setDependent_Draw;
238 setDependent_Check(e);
240 void setDependentWeird(entity e, float(entity) func)
242 e.draw_setDependent = e.draw;
243 e.func_setDependent = func;
244 e.draw = setDependent_Draw;
245 setDependent_Check(e);
248 // URI SYSTEM ////////////////////////////////////////////////////////
250 float _Nex_ExtResponseSystem_Queried;
251 string _Nex_ExtResponseSystem_UpdateTo;
253 void URI_Get_Callback(float id, float status, string data)
255 if (id == URI_GET_DISCARD)
259 else if(id == URI_GET_UPDATENOTIFICATION)
261 UpdateNotification_URI_Get_Callback(id, status, data);
263 else if(id >= URI_GET_CURL && id <= URI_GET_CURL_END)
265 Curl_URI_Get_Callback(id, status, data);
269 print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
273 void UpdateNotification_URI_Get_Callback(float id, float status, string data)
277 if(_Nex_ExtResponseSystem_UpdateTo)
279 print("error: UpdateNotification_URI_Get_Callback has been called before\n");
284 print(sprintf("error receiving update notification: status is %d\n", status));
287 if(substring(data, 0, 1) == "<")
289 print("error: received HTML instead of an update notification\n");
292 if(strstrofs(data, "\r", 0) != -1)
294 print("error: received carriage returns from update notification server\n");
301 n = tokenizebyseparator(data, "\n");
305 _Nex_ExtResponseSystem_UpdateTo = argv(0);
307 if(vercmp(cvar_string("g_xonoticversion"), _Nex_ExtResponseSystem_UpdateTo) >= 0)
309 _Nex_ExtResponseSystem_UpdateTo = ""; // no update needed
315 print(sprintf("Update can be downloaded at:\n%s\n", argv(1)));
318 _Nex_ExtResponseSystem_UpdateTo = strzone(_Nex_ExtResponseSystem_UpdateTo);
322 // END OF URI SYSTEM ////////////////////////////////////////////////////////
329 MapInfo_Cache_Create();
331 if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
333 draw_reset_cropped();
335 sz = eX * 0.025 + eY * 0.025 * (draw_scale_x / draw_scale_y);
336 draw_CenterText('0.5 0.5 0' - 1.25 * sz_y * eY, "Autogenerating mapinfo for newly added maps...", sz, '1 1 1', 1, 0);
338 boxA = '0.05 0.5 0' + 0.25 * sz_y * eY;
339 boxB = '0.95 0.5 0' + 1.25 * sz_y * eY;
340 draw_Fill(boxA, boxB - boxA, '1 1 1', 1);
344 draw_Fill(boxA, boxB - boxA, '0.1 0.1 0.1', 1);
346 boxB_x = boxA_x * (1 - MapInfo_progress) + boxB_x * MapInfo_progress;
347 draw_Fill(boxA, boxB - boxA, '0 0 1', 1);
354 string campaign_name_previous;
355 float campaign_won_previous;
357 var string autocvar_menu_watermark = WATERMARK();
359 var string autocvar_menu_watermark = "";
363 if(autocvar_menu_watermark != "")
365 vector fs = '48 48 0';
366 draw_CenterText('0.5 0.1 0', autocvar_menu_watermark, globalToBoxSize('32 32 0', draw_scale), '1 1 1', 0.05, 1);
371 vector fs, sz, line, mid;
373 if(cvar("menu_updatecheck"))
375 if(!_Nex_ExtResponseSystem_Queried)
377 _Nex_ExtResponseSystem_Queried = 1;
381 cvar_set("cl_startcount", ftos(startcnt = cvar("cl_startcount") + 1));
383 // for privacy, munge the start count a little
384 startcnt = floor((floor(startcnt / 10) + random()) * 10);
385 uri = sprintf("http://www.xonotic.org/dl/checkupdate.txt?version=%s&cnt=%d", uri_escape(cvar_string("g_xonoticversion")), startcnt);
388 float cvar_handle, popcon_handle;
391 cvar_handle = buf_create();
392 buf_cvarlist(cvar_handle, "", "");
393 n = buf_getsize(cvar_handle);
394 popcon_handle = buf_create();
395 for(i= 0, j = 0; i < n; ++i)
397 k = bufstr_get(cvar_handle, i);
398 if(!(cvar_type(k) & CVAR_TYPEFLAG_SAVED))
400 s = sprintf("%s=%d", uri_escape(k), cvar_string(k) != cvar_defstring(k));
401 bufstr_set(popcon_handle, j, s);
404 buf_del(cvar_handle);
406 uri, URI_GET_UPDATENOTIFICATION,
407 "application/x-www-form-urlencoded",
411 buf_del(popcon_handle);
413 uri_get(uri, URI_GET_UPDATENOTIFICATION);
418 if(_Nex_ExtResponseSystem_UpdateTo != "")
420 // TODO rather turn this into a dialog
421 fs = ((1/draw_scale_x) * eX + (1/draw_scale_y) * eY) * 12;
423 sz_x = draw_TextWidth(" http://www.xonotic.com/ ", 0, fs);
426 draw_alpha = sin(time * 0.112 - 0.3) * 10;
427 mid = eX * (0.5 + 0.5 * (1 - sz_x) * cos(time * 0.071))
428 + eY * (0.5 + 0.5 * (1 - sz_y) * sin(time * 0.071));
430 draw_Fill(mid - 0.5 * sz, sz, '1 1 0', 1);
431 draw_CenterText(mid - 1 * line, strcat("Update to ", _Nex_ExtResponseSystem_UpdateTo, " now!"), fs, '1 0 0', 1, 0);
432 draw_CenterText(mid - 0 * line, "http://www.xonotic.org/", fs, '0 0 1', 1, 0);
434 if not(campaign_name_previous)
435 campaign_name_previous = strzone(strcat(campaign_name, "x")); // force unequal
436 if(campaign_name == campaign_name_previous)
438 if(cvar(strcat("g_campaign", campaign_name, "_won")))
440 if(!campaign_won_previous)
443 DialogOpenButton_Click_withCoords(NULL, main.winnerDialog, '0 0 0', eX * conwidth + eY * conheight);
445 campaign_won_previous = 1;
448 campaign_won_previous = 0;
452 strunzone(campaign_name_previous);
453 campaign_name_previous = strzone(campaign_name);
454 campaign_won_previous = cvar(strcat("g_campaign", campaign_name, "_won"));
458 string resolvemod(string m)
461 return getcurrentmod();
466 string HUD_Panel_GetSettingName(float theSetting)
469 case HUD_MENU_ENABLE: return ""; break;
474 float updateCompression()
477 float have_dds, have_jpg, have_tga;
479 if((have_dds = ((fh = fopen("dds/particles/particlefont.dds", FILE_READ)) >= 0)))
481 if((have_jpg = ((fh = fopen("particles/particlefont.jpg", FILE_READ)) >= 0)))
483 if((have_tga = ((fh = fopen("particles/particlefont.tga", FILE_READ)) >= 0)))
485 can_dds = GL_Have_TextureCompression();
486 if(have_dds && (have_jpg || have_tga))
488 // both? Let's only use good quality precompressed files
489 // but ONLY if we actually support it!
492 cvar_set("gl_texturecompression", "0");
497 cvar_set("gl_texturecompression", "0");
498 cvar_set("r_texture_dds_load", "0");
504 // DDS only? We probably always want texture compression
505 cvar_set("gl_texturecompression", "1");
506 cvar_set("r_texture_dds_load", "1");
508 print("^1ERROR: Texture compression is required but not supported.\n^1Expect visual problems.\n");
513 // TGA only? Allow runtime compression
516 cvar_set("gl_texturecompression", cvar_string("r_texture_dds_load"));
521 cvar_set("gl_texturecompression", "0");
522 cvar_set("r_texture_dds_load", "0");