]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/util.qc
replace the HugeSetOfIntegers by another string buffer... and add a progress indicato...
[divverent/nexuiz.git] / data / qcsrc / menu / nexuiz / util.qc
1 void forAllDescendants(entity root, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
2 {
3         depthfirst(root, parent, firstChild, nextSibling, funcPre, funcPost, pass);
4 }
5
6 .string cvarName;
7 void SUB_Null_ee(entity e1, entity e2)
8 {
9 }
10 void saveCvarsOf(entity ignore, entity e)
11 {
12         if(e.cvarName)
13                 e.saveCvars(e);
14 }
15 void loadCvarsOf(entity ignore, entity e)
16 {
17         if(e.cvarName)
18                 e.loadCvars(e);
19 }
20 void saveAllCvars(entity root)
21 {
22         forAllDescendants(root, saveCvarsOf, SUB_Null_ee, NULL);
23 }
24 void loadAllCvars(entity root)
25 {
26         forAllDescendants(root, loadCvarsOf, SUB_Null_ee, NULL);
27 }
28
29 .void(entity) draw_setDependent;
30 .string cvar_setDependent;
31 .float cvarMin_setDependent;
32 .float cvarMax_setDependent;
33 .string cvar2_setDependent;
34 .float cvar2Min_setDependent;
35 .float cvar2Max_setDependent;
36 .float op_setDependent;
37 void setDependent_Check(entity e)
38 {
39         float f;
40         f = cvar(e.cvar_setDependent);
41         if(e.cvarMin_setDependent <= e.cvarMax_setDependent)
42                 e.disabled = ((f < e.cvarMin_setDependent) || (f > e.cvarMax_setDependent));
43         else
44                 e.disabled = ((f >= e.cvarMax_setDependent) && (f <= e.cvarMin_setDependent));
45         if(e.cvar2_setDependent)
46         {
47                 f = cvar(e.cvar2_setDependent);
48                 if(e.cvar2Min_setDependent <= e.cvar2Max_setDependent)
49                         e.disabled = (e.disabled + ((f < e.cvar2Min_setDependent) || (f > e.cvar2Max_setDependent)) > e.op_setDependent);
50                 else
51                         e.disabled = (e.disabled + ((f >= e.cvar2Max_setDependent) && (f <= e.cvar2Min_setDependent)) > e.op_setDependent);
52         }
53 }
54 void setDependent_Draw(entity e)
55 {
56         setDependent_Check(e);
57         e.draw_setDependent(e);
58 }
59 void setDependent(entity e, string theCvarName, float theCvarMin, float theCvarMax)
60 {
61         e.draw_setDependent = e.draw;
62         e.cvar_setDependent = theCvarName;
63         e.cvarMin_setDependent = theCvarMin;
64         e.cvarMax_setDependent = theCvarMax;
65         e.cvar2_setDependent = string_null;
66         e.draw = setDependent_Draw;
67         setDependent_Check(e);
68 }
69 void setDependentAND(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
70 {
71         e.draw_setDependent = e.draw;
72         e.cvar_setDependent = theCvarName;
73         e.cvarMin_setDependent = theCvarMin;
74         e.cvarMax_setDependent = theCvarMax;
75         e.cvar2_setDependent = theCvar2Name;
76         e.cvar2Min_setDependent = theCvar2Min;
77         e.cvar2Max_setDependent = theCvar2Max;
78         e.op_setDependent = 0;
79         e.draw = setDependent_Draw;
80         setDependent_Check(e);
81 }
82 void setDependentOR(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max)
83 {
84         e.draw_setDependent = e.draw;
85         e.cvar_setDependent = theCvarName;
86         e.cvarMin_setDependent = theCvarMin;
87         e.cvarMax_setDependent = theCvarMax;
88         e.cvar2_setDependent = theCvar2Name;
89         e.cvar2Min_setDependent = theCvar2Min;
90         e.cvar2Max_setDependent = theCvar2Max;
91         e.op_setDependent = 1;
92         e.draw = setDependent_Draw;
93         setDependent_Check(e);
94 }
95
96 // EXTRESPONSE SYSTEM ////////////////////////////////////////////////////////
97
98 float _Nex_ExtResponseSystem_RequestsSent;
99 float _Nex_ExtResponseSystem_VersionHandled;
100 string _Nex_ExtResponseSystem_UpdateTo;
101 float _Nex_ExtResponseSystem_RetryTime;
102 float _Nex_ExtResponseSystem_RetryTime_LastDelay;
103
104 void() Item_Nex_ExtResponseSystem_SendQuery =
105 {
106         dprint("Sending extended response requests...\n");
107         localcmd(strcat("packet update.alientrap.org:27950 \"getExtResponse checkUpdates nexuiz ", cvar_string("g_nexuizversion"), "\"\n"));
108         _Nex_ExtResponseSystem_RequestsSent = TRUE;
109         _Nex_ExtResponseSystem_RetryTime_LastDelay = _Nex_ExtResponseSystem_RetryTime_LastDelay * 2 + 1;
110         _Nex_ExtResponseSystem_RetryTime = time + _Nex_ExtResponseSystem_RetryTime_LastDelay;
111 }
112
113 void(float argc) Item_Nex_ExtResponseSystem_Parse =
114 {
115         dprint("Received extended response packet from ", argv(0), "\n");
116         if(!_Nex_ExtResponseSystem_RequestsSent)
117         {
118                 dprint("  But I haven't sent a request yet! Ignoring.\n");
119                 return;
120         }
121         if(argv(1) == "noUpdateAvailable")
122         {
123                 if(_Nex_ExtResponseSystem_VersionHandled)
124                 {
125                         dprint("  duplicated update notice, ignored\n");
126                         return;
127                 }
128                 _Nex_ExtResponseSystem_VersionHandled = 1;
129         }
130         else if(argv(1) == "updateAvailable")
131         {
132                 if(_Nex_ExtResponseSystem_VersionHandled)
133                 {
134                         dprint("  duplicated update notice, ignored\n");
135                         return;
136                 }
137                 _Nex_ExtResponseSystem_VersionHandled = 1;
138                 _Nex_ExtResponseSystem_UpdateTo = strzone(argv(2)); // note: only one packet can be handled, so this can't be a leak
139         }
140         else
141                 dprint("  UNKNOWN RESPONSE TYPE: ", argv(1), "\n");
142 }
143
144 void() Item_Nex_ExtResponseSystem_CheckForResponse =
145 {
146         local string s;
147         local float argc;
148         while(strlen((s = getextresponse())))
149         {
150                 argc = tokenize(s);
151                 Item_Nex_ExtResponseSystem_Parse(argc);
152         }
153 }
154
155 // END OF EXTRESPONSE SYSTEM /////////////////////////////////////////////////
156
157 float preMenuInit()
158 {
159         vector sz;
160         vector boxA, boxB;
161
162         MapInfo_Cache_Create();
163         MapInfo_Enumerate();
164         if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 1))
165         {
166                 draw_reset();
167
168                 sz = eX * 0.025 + eY * 0.025 * (draw_scale_x / draw_scale_y);
169                 draw_CenterText('0.5 0.5 0' - 1.25 * sz_y * eY, "Autogenerating mapinfo for newly added maps...", sz, '1 1 1', 1, 0);
170
171                 boxA = '0.05 0.5 0' + 0.25 * sz_y * eY;
172                 boxB = '0.95 0.5 0' + 1.25 * sz_y * eY;
173                 draw_Fill(boxA, boxB - boxA, '1 1 1', 1);
174                 
175                 boxA += sz * 0.1;
176                 boxB -= sz * 0.1;
177                 draw_Fill(boxA, boxB - boxA, '0.1 0.1 0.1', 1);
178
179                 boxB_x = boxA_x * (1 - MapInfo_progress) + boxB_x * MapInfo_progress;
180                 draw_Fill(boxA, boxB - boxA, '0 0 1', 1);
181
182                 return FALSE;
183         }
184         return TRUE;
185 }
186
187 string campaign_name_previous;
188 float campaign_won_previous;
189 void postMenuDraw()
190 {
191 }
192 void preMenuDraw()
193 {
194         vector fs, sz, line, mid;
195         Item_Nex_ExtResponseSystem_CheckForResponse();
196         if(!_Nex_ExtResponseSystem_VersionHandled)
197                 if(time > _Nex_ExtResponseSystem_RetryTime)
198                         Item_Nex_ExtResponseSystem_SendQuery();
199
200         if(_Nex_ExtResponseSystem_UpdateTo != "")
201         {
202                 fs = ((1/draw_scale_x) * eX + (1/draw_scale_y) * eY) * 12;
203                 line = eY * fs_y;
204                 sz_x = draw_TextWidth("  http://www.nexuiz.com/  ", 0) * fs_x;
205                 sz_y = 3 * fs_y;
206
207                 draw_alpha = sin(time * 0.112 - 0.3) * 0.7;
208                 mid = eX * (0.5 + 0.5 * (1 - sz_x) * cos(time * 0.071))
209                     + eY * (0.5 + 0.5 * (1 - sz_y) * sin(time * 0.071));
210
211                 draw_Fill(mid - 0.5 * sz, sz, '1 1 0', 1);
212                 draw_CenterText(mid - 1 * line, strcat("Update to ", _Nex_ExtResponseSystem_UpdateTo, " now!"), fs, '1 0 0', 1, 0);
213                 draw_CenterText(mid - 0 * line, "http://www.nexuiz.com/", fs, '0 0 1', 1, 0);
214         }
215         if not(campaign_name_previous)
216                 campaign_name_previous = strzone(strcat(campaign_name, "x")); // force unequal
217         if(campaign_name == campaign_name_previous)
218         {
219                 if(cvar(strcat("g_campaign", campaign_name, "_won")))
220                 {
221                         if(!campaign_won_previous)
222                         {
223                                 m_display();
224                                 DialogOpenButton_Click_withCoords(NULL, main.winnerDialog, '0 0 0', eX * conwidth + eY * conheight);
225                         }
226                         campaign_won_previous = 1;
227                 }
228                 else
229                         campaign_won_previous = 0;
230         }
231         else
232         {
233                 strunzone(campaign_name_previous);
234                 campaign_name_previous = strzone(campaign_name);
235                 campaign_won_previous = cvar(strcat("g_campaign", campaign_name, "_won"));
236         }
237 }