]> icculus.org git repositories - divverent/nexuiz.git/blob - menu/mcustom.qc
Fixing the CVS:
[divverent/nexuiz.git] / menu / mcustom.qc
1 ///////////////////////////////////////////////
2 // Custom Menu Source File
3 ///////////////////////
4 // This file belongs to dpmod/darkplaces
5 // AK contains menu specific stuff that is made especially for dpmod
6 // AK this file is used e.g. for defining some special event functions
7 ////////////////////////////////////////////////
8
9 ////////////////
10 // global stuff
11 ///
12
13 void() nex_setposition =
14 {
15         self.pos_x = 0;
16         self.pos_y = (self.font_size_y + 5) * self.orderpos;
17         self.pos_z = 0;
18         
19         self.origin = self.pos;
20 };
21
22 void(entity item) nex_makeonlyvisible =
23 {
24         local entity node;
25         
26         if( item.flag & FLAG_HIDDEN )
27                 item.flag = item.flag - FLAG_HIDDEN;
28         for( node = item._next ; node ; node = node._next )
29                 node.flag = item.flag | FLAG_HIDDEN;
30         for( node = item._prev ; node ; node = node._prev )
31                 node.flag = item.flag | FLAG_HIDDEN;
32 };
33
34 void(void) nex_linkrelhack =
35 {
36         self._child._parent = self;
37 };
38
39 void(void) nex_maketextzone =
40 {
41         self.text = strzone(self.text);
42 };
43
44 void(void) nex_slidertext =
45 {
46         entity ent;
47         if(self.link == "")
48         {
49                 print("No link specified\n");
50                 eprint(self);
51                 self.init = null_function;
52                 return;
53         }
54
55                 ent = menu_getitem(self.link);
56         if(ent == null_entity)
57         {
58                 objerror("No link found for ", self.link,"\n");
59         }
60
61         self._link = ent;
62
63         self.flag = self.flag | FLAG_DRAWREFRESHONLY;
64
65         self.refresh = _nex_slidertext_refresh;
66 };
67
68 void(void) _nex_slidertext_refresh =
69 {
70         self.text = ftos(self._link.value);
71         if(self.maxlen > 0)
72                 self.text = substring(self.text,0, self.maxlen);
73         // reset the size, so its set
74         self.size = '0 0 0';
75 };
76
77 float(float keynr, float ascii) nex_redirect_key =
78 {
79         if((ascii>=20 && ascii <= 126) || keynr == K_BACKSPACE || keynr == K_ENTER || keynr == K_LEFTARROW || keynr == K_RIGHTARROW || (keynr >= K_MOUSE1 && keynr <= K_MOUSE10))
80         {
81                 raise_key(self._child, keynr, ascii);
82                 return true;
83         }
84         return false;
85 };
86
87 void(void) nex_cvar_slider =
88 {
89         self.value = cvar(self.cvarname);
90         self.slidermove = self.switchchange = _nex_cvar_slider;
91         self.refresh = _nex_cvar_slider_refresh;
92 };
93
94 void(void) _nex_cvar_slider_refresh =
95 {
96         if(self.cvartype == CVAR_INT || self.cvartype == CVAR_FLOAT || self.cvartype == CVAR_STEP)
97                 self.value = cvar(self.cvarname);
98 };
99
100 void(void) _nex_cvar_slider =
101 {
102         if(self.cvarname == "")
103                 return;
104         if(self.cvartype == CVAR_INT) // || self.cvartype == CVAR_STRING)
105                 self.value = rint(self.value);
106         if(self.cvartype == CVAR_STEP)
107                 self.value = rint(self.value / self.step) * self.step;
108         if(self.cvartype == CVAR_INT || self.cvartype == CVAR_FLOAT || self.cvartype == CVAR_STEP)
109                 cvar_set(self.cvarname, ftos(self.value));
110         /*if(cvartype == CVAR_STRING)
111         {
112                 string s;
113                 s = getaltstring(self.value, self.cvarvalues);
114                 cvar_set(self.cvarname, s);
115         }
116         */
117 };
118
119 //////////////
120 // main.menu
121 ///
122
123 void(void) nex_makeselfonlyvisible =
124 {
125         nex_makeonlyvisible( self );
126 };
127
128 // quit menu
129
130 void(void) nex_quit_choose =
131 {
132         entity e;
133         // because of the missing support for real array, we have to do it the stupid way
134         // (we also have to use strzone for the text, cause it the temporary strings wont work
135         // for it)
136         if(nex_quitrequest == 0)
137         {
138                 e = menu_getitem("quit_msg_0");
139                 e.text = getaltstring(0,nex_quitmsg_0);
140         }
141         if(nex_quitrequest == 1)
142         {
143                 e = menu_getitem("quit_msg_0");
144                 e.text = getaltstring(0,nex_quitmsg_1);
145         }
146         if(nex_quitrequest == 2)
147         {
148                 e = menu_getitem("quit_msg_0");
149                 e.text = getaltstring(0,nex_quitmsg_2);
150         }
151         if(nex_quitrequest == 3)
152         {
153                 e = menu_getitem("quit_msg_0");
154                 e.text = getaltstring(0,nex_quitmsg_3);
155         }
156         e.text = strzone(e.text);
157
158         if(nex_quitrequest == 0)
159         {
160                 e = menu_getitem("quit_msg_1");
161                 e.text = getaltstring(1,nex_quitmsg_0);
162         }
163         if(nex_quitrequest == 1)
164         {
165                 e = menu_getitem("quit_msg_1");
166                 e.text = getaltstring(1,nex_quitmsg_1);
167         }
168         if(nex_quitrequest == 2)
169         {
170                 e = menu_getitem("quit_msg_1");
171                 e.text = getaltstring(1,nex_quitmsg_2);
172         }
173         if(nex_quitrequest == 3)
174         {
175                 e = menu_getitem("quit_msg_1");
176                 e.text = getaltstring(1,nex_quitmsg_3);
177         }
178         e.text = strzone(e.text);
179
180         nex_quitrequest = nex_quitrequest + 1;
181         if(nex_quitrequest == DPMOD_QUIT_MSG_COUNT)
182                 nex_quitrequest = 0;
183 };
184
185 void(void) nex_quit =
186 {
187 /*  entity ent;
188         // choose a quit message
189         nex_quit_choose();
190
191         // change the flags
192         ent = menu_getitem("main");
193         ent.flag = ent.flag | FLAG_CHILDDRAWONLY;
194         ent = menu_getitem("quit");
195         ent.flag = FLAG_NOSELECT;
196         menu_jumptowindow(ent, false);*/
197         entity ent;
198
199         // change the flags
200         ent = menu_getitem("quitbox_ref");
201         ent._child = menu_activewindow;
202         ent = menu_getitem("quitbox");
203         menu_jumptowindow(ent, true);
204 };
205
206 void(void) nex_quit_yes =
207 {
208         cmd("quit\n");
209 };
210
211 void(void) nex_quit_no =
212 {
213 /*  entity ent;
214
215         ent = menu_getitem("quit_msg_0");
216         strunzone(ent.text);
217
218         ent = menu_getitem("quit_msg_1");
219         strunzone(ent.text);
220
221         ent = menu_getitem("quit");
222         ent.flag = FLAG_HIDDEN;
223         ent = menu_getitem("main");
224         ent.flag = ent.flag - FLAG_CHILDDRAWONLY;
225         menu_selectup();*/
226         menu_selectup();
227 };
228
229 float(float keynr, float ascii) nex_quit_key =
230 {
231         if(keynr == K_LEFTARROW)
232                 return false;
233         if(keynr == K_RIGHTARROW)
234                 return false;
235         if(keynr == K_ENTER)
236                 return false;
237         if(keynr == K_MOUSE1)
238                 return false;
239         if(ascii == 'Y' || ascii == 'y')
240                 nex_quit_yes();
241         if(ascii == 'N' || ascii == 'n' || keynr == K_ESCAPE)
242                 nex_quit_no();
243         return true;
244 };
245
246 // options menu
247
248 void(void) nex_display_options =
249 {
250         entity ent;
251
252         ent = menu_getitem( "options" );
253         
254         nex_makeonlyvisible( ent );
255         menu_jumptowindow( ent, false );
256 };
257
258 /////////////////
259 // video.menu
260
261 void(void) nex_display_video =
262 {
263         nex_makeonlyvisible( menu_getitem( "video" ) );
264         menu_jumptowindow( menu_getitem( "video" ), false );
265 };
266
267 void(void) nex_video_bpp_reinit =
268 {
269         if(cvar("vid_bitsperpixel") == 32)
270                 self.value = 1;
271         else
272                 self.value = 0;
273 };
274
275 void(void) nex_video_fullscreen_reinit =
276 {
277         self.value = cvar("vid_fullscreen");
278 };
279
280 string nex_video_resolutions;
281
282 void(void) nex_video_resolution_switch_reinit =
283 {
284         float c, i;
285         float pos86;
286
287         c = getaltstringcount(nex_video_resolutions);
288         for(i = 0; i < c; i=i+1)
289         {
290                 string s;
291                 vector t;
292                 s = getaltstring(i,nex_video_resolutions);
293                 s = strcat("'",s,"'");
294                 t = stov(s);
295                 if(t_x == cvar("vid_width") && t_y == cvar("vid_height"))
296                 {
297                         self.value = i;
298                         return;
299                 }
300                 if(t == '800 600 0')
301                         pos86 = i;
302         }
303
304         self.value = pos86;
305 };
306
307 void(void) nex_video_resolution_switch =
308 {
309         var float pos86 = 0;
310         var float counter = 0;
311         vector t;
312
313         nex_video_resolutions = "";
314         self.text = "";
315         self.value = -1;
316
317         while((t = getresolution(counter)) != '0 0 0')
318         {
319                 if(t == '800 600 0')
320                         pos86 = counter;
321                 if(t_x == cvar("vid_width") && t_y == cvar("vid_height"))
322                 {
323                         self.value = counter;
324                 }
325                 counter = counter + 1;
326                 self.text = strcat(self.text,"'",ftos(t_x),"x");
327                 self.text = strcat(self.text,ftos(t_y),"'");
328                 nex_video_resolutions = strcat(nex_video_resolutions,vtos(t));
329         }
330
331         if(self.value == -1)
332                 self.value = pos86;
333
334         self.text = strzone(self.text);
335         nex_video_resolutions = strzone(nex_video_resolutions);
336
337         self.reinit = nex_video_resolution_switch;
338 };
339
340 void(void) nex_video_apply =
341 {
342         vector set, res;
343         float changed;
344         entity tmp;
345
346         changed = false;
347
348         // resolution test
349         res_x = cvar("vid_width");
350         res_y = cvar("vid_height");
351         res_z = 0;
352
353         tmp = menu_getitem("video_resolution_switch");
354         set = stov(getaltstring(tmp.value, nex_video_resolutions));
355         if(set != res)
356         {
357                 cvar_set("vid_width",ftos(set_x));
358                 cvar_set("vid_height",ftos(set_y));
359                 changed = true;
360         }
361         // bpp test
362         tmp = menu_getitem("video_bpp_switch");
363         if((tmp.value+1)*16 != cvar("vid_bitsperpixel"))
364         {
365                 cvar_set("vid_bitsperpixel",ftos((tmp.value+1)*16));
366                 changed = true;
367         }
368         // fullscreen changed
369         tmp = menu_getitem("video_fullscreen_switch");
370         if(tmp.value != cvar("vid_fullscreen"))
371         {
372                 cvar_set("vid_fullscreen",ftos(tmp.value));
373                 changed = true;
374         }
375
376         if(changed)
377         {
378                 cmd("vid_restart\n");
379         }
380 };
381
382 /////////////////
383 // xplayer.menu
384 ///
385
386 float maxfrags;
387 float maxtime;
388 float maxbots;
389 entity selectmap;
390 var float selectnum  = 0;
391 float FRAME_WIDTH;
392 float PIC_WIDTH;
393 float mapnum;
394
395 string hostname;
396 float  maxclients;
397 float  publicserver;
398
399 // create the mapselection frame stuff
400 void(void) nex_xp_build_maplist =
401 {
402         entity pic;
403         entity mapname;
404         entity template_text;
405         entity template_pic;
406         float searchhandle;
407         float counter;
408
409         // search through maps for all bsps and add them to the list
410         // if a picture exists for them, add it to
411         searchhandle = search_begin("maps/*.bsp",true,true);
412         if(searchhandle == -1)
413         {
414                 print("menu: No maps found...\n");
415                 return;
416         }
417
418         template_text = menu_getitem("mapselection_template_text");
419         template_pic = menu_getitem("mapselection_template_picture");
420         template_text.pos_y = (template_pic.size_y - template_text.font_size_y) / 2;
421
422         // set FRAME_WIDTH
423         pic = menu_getitem("mapselection_frame");
424         FRAME_WIDTH = rint(pic.clip_size_x / template_pic.size_x);
425
426         // set PIC_WIDTH
427         PIC_WIDTH = template_pic.size_x;
428
429         // adjust the clip size of the frame
430         pic.clip_size_y = template_pic.size_y;
431
432         // adjust the selection square
433         pic = menu_getitem("mapselection_selsquare");
434
435         pic.size = template_pic.size;
436
437         mapnum = search_getsize(searchhandle);
438
439         for(counter = 0; counter < mapnum; counter = counter + 1)
440         {
441                 string extstripped;
442                 string allstripped;
443                 float filehandle;
444
445                 extstripped = search_getfilename(searchhandle, counter);
446                 extstripped = substring(extstripped, 0, strlen(extstripped) - 4); // .bsp off
447                 extstripped = strzone(extstripped);
448
449                 allstripped = substring(extstripped, 5, 400); // maps/ off
450                 allstripped = strzone(allstripped);
451
452                 pic = spawn();
453                 copyentity(template_pic, pic);
454
455                 pic.orderpos = counter + 1;
456                 pic.pos_x = counter * template_pic.size_x;
457                 pic.name = strzone(allstripped);
458
459                 // TODO: add support for other formats, too
460                 filehandle = search_begin(strcat(extstripped,".jpg"), true, true);
461                 if(filehandle != -1)
462                 {
463                         pic.picture = strcat(extstripped,".jpg");
464                         pic.picture = strzone(pic.picture);
465                         search_end(filehandle);
466                 }
467                 else
468                 {
469                         mapname = spawn();
470                         copyentity(template_text, mapname);
471
472                         mapname.name = strzone(strcat(allstripped, "_text"));
473                         mapname.text = strzone(allstripped);
474
475                         mapname.orderpos = counter + mapnum + 1;
476
477                         mapname.pos_x = counter * template_pic.size_x;
478
479                         mapname.size_x = template_pic.size_x;
480                         mapname.size_y = mapname.font_size_y;
481                         mapname.font_size = '0 0 0';
482
483                         {
484                                 entity old
485                                 old = self;
486                                 self = mapname;
487                                 ITEM_TEXT();
488                                 self = old;
489                         }
490                 }
491
492                 if(counter == 0)
493                         selectmap = pic;
494
495                 strunzone(extstripped);
496                 strunzone(allstripped);
497         }
498
499         search_end(searchhandle);
500 };
501
502 void(void) nex_xp_prev =
503 {
504         entity s;
505         if(selectnum <= 0)
506                 return;
507
508         selectnum = selectnum - 1;
509         selectmap = selectmap._prev;
510
511         s = menu_getitem("mapselection_selsquare");
512         s.pos_x = selectnum * PIC_WIDTH;
513
514         // scroll left ?
515         if((mapnum - 1 - selectnum) > floor(FRAME_WIDTH / 2) && selectnum + 1 >= ceil(FRAME_WIDTH / 2)) // 2,3
516         {
517                 s = menu_getitem("mapselection_frame");
518                 s.origin_x = s.origin_x + PIC_WIDTH;
519         }
520 };
521
522 void(void) nex_xp_next =
523 {
524         entity s;
525         if(selectnum >= mapnum - 1)
526                 return;
527
528         selectnum = selectnum + 1;
529         selectmap = selectmap._next;
530
531         s = menu_getitem("mapselection_selsquare");
532         s.pos_x = selectnum * PIC_WIDTH;
533
534         // scroll right ?
535         if((mapnum - 1 - selectnum) >= floor(FRAME_WIDTH / 2) && selectnum + 1 > ceil(FRAME_WIDTH / 2)) // 2,3
536         {
537                 s = menu_getitem("mapselection_frame");
538                 s.origin_x = s.origin_x - PIC_WIDTH;
539         }
540 };
541
542 void(void) nex_xp_click = // if one of the maplist entries get 'clicked' :-)
543 {
544         float deltapos;
545
546         // get the position
547         // HACKHACK
548         if(self.orderpos > mapnum)
549         {
550                 deltapos = self.orderpos - mapnum - selectnum - 1;
551         } else
552         {
553                 deltapos = self.orderpos - selectnum - 1;
554         }
555
556         if(deltapos == 0)
557                 return;
558
559         if(deltapos > 0)
560         {
561                 while(deltapos > 0)
562                 {
563                         deltapos = deltapos - 1;
564                         nex_xp_next();
565                 }
566         }
567         else
568         {
569                 while(deltapos < 0)
570                 {
571                         deltapos = deltapos + 1;
572                         nex_xp_prev();
573                 }
574         }
575 };
576
577 void(void) nex_display_singleplayer =
578 {
579         nex_makeonlyvisible( menu_getitem( "singleplayer" ) );
580         menu_jumptowindow( menu_getitem( "singleplayer"), false );
581 };
582
583 void(void) nex_display_multiplayer =
584 {
585         nex_makeonlyvisible( menu_getitem( "multiplayer" ) );
586         menu_jumptowindow( menu_getitem( "multiplayer" ), false );
587 };
588
589 void(void) nex_xp_maxfrags =
590 {
591         float x;
592         x = stof(self.text);
593         maxfrags = rint(x);
594
595         strunzone(self.text);
596         self.text = ftos(x);
597         self.text = strzone(self.text);
598 };
599
600 void(void) nex_xp_maxbots =
601 {
602         float x;
603         x = stof(self.text);
604         maxbots = rint(x);
605
606         strunzone(self.text);
607         self.text = ftos(x);
608         self.text = strzone(self.text);
609 };
610
611 void(void) nex_xp_maxtime =
612 {
613         float x;
614         x = stof(self.text);
615         maxtime = rint(x);
616
617         strunzone(self.text);
618         self.text = ftos(maxtime);
619         self.text = strzone(self.text);
620 };
621
622 void(void) nex_sp_start =
623 {
624         //local float i;
625
626         cvar_set("fraglimit", ftos(maxfrags));
627         cvar_set("timelimit", ftos(maxtime));
628         cvar_set("deathmatch", ftos(1));
629         cvar_set("maxplayers", ftos(maxbots + 1));
630         cmd("map ");
631         cmd(selectmap.name);
632         cmd(";wait;togglemenu;wait;");
633
634         // BLACK: TODO - change this somewhen into something cleaner - see bot/bot.qc
635         //if(maxbots && maxbots <= (99 - 40 + 1))
636         {
637                 string t;
638                 t = strcat("impulse ", ftos(40 + maxbots - 1));
639                 cmd(t);
640                 print(t);
641         }
642
643         cmd("\n");
644 };
645
646 void(void) nex_mp_hostname =
647 {
648         hostname = self.text;
649 };
650
651 void(void) nex_mp_maxclients =
652 {
653         local float i;
654         i = stof(self.text);
655         maxclients = rint(i);
656
657         strunzone(self.text);
658         self.text = strzone(ftos(maxclients));
659 };
660
661 void(void) nex_mp_publicserv =
662 {
663         publicserver = self.value;
664 };
665
666 void(void) nex_mp_start =
667 {
668         cvar_set("fraglimit", ftos(maxfrags));
669         cvar_set("timelimit", ftos(maxtime));
670         cvar_set("deathmatch", ftos(1));
671         cvar_set("maxplayers", ftos(maxclients));
672         cvar_set("sv_public", ftos(publicserver));
673         cvar_set("hostname", hostname);
674         cmd("map ");
675         cmd(selectmap.name);
676         cmd(";wait;togglemenu\n");
677 };
678
679 void(void) nex_goto_createserver =
680 {
681         menu_jumptowindow( menu_getitem( "multiplayer_frame"), false );
682 }
683
684 // server list
685 var float slist_selected = 0;
686 var float slist_start   = 0;
687 float slist_estimatedsize;
688
689 void(void) nex_display_serverlist =
690 {
691         if(menu_activewindow.name == "serverlist")
692                 return;
693         menu_jumptowindow(menu_getitem("serverlist"),true);
694         cmd("net_slist\n");
695 };
696
697 // use a ITEM_TEXT as base item for this
698 // we need another item to clip the slist
699 // (another reason for a new menu qc!)
700 void(void) slist_draw =
701 {
702         float c;
703         vector pos;
704         float listsize;
705
706         //print("slist drawing...", ftos(listsize), "\n");
707
708         pos = '0 0 0'; // the upper item sets the origin
709         listsize = gethostcachevalue(SLIST_HOSTCACHECOUNT);
710         if(!listsize)
711         {
712                 menu_drawstring(pos, "No Servers", self.font_size, self.color, self.alpha, self.drawflag);
713                 return;
714         }
715
716         for(c = 0; c < slist_estimatedsize + 1; c = c + 1)
717         {
718                 string line;
719
720                 if(listsize <= slist_start + c)
721                         break;
722
723                 //print("drawing ", ftos(c),"\n");
724
725                 if(slist_selected - slist_start == c)
726                 {
727                         vector s;
728                         s = self.size;
729                         s_y = self.font_size_y * 2;
730
731                         menu_fillarea(pos, s, self.color_selected, self.alpha_selected * (sin(time * 9) + 1) / 2, self.drawflag_selected);
732                 }
733
734                 line = gethostcachestring(SLIST_LINE1, slist_start + c);
735
736                 menu_drawstring(pos, line, self.font_size, self.color, self.alpha, self.drawflag);
737
738                 pos_y = pos_y + self.font_size_y;
739
740                 line = gethostcachestring(SLIST_LINE2, slist_start + c);
741
742                 menu_drawstring(pos, line, self.font_size, self.color, self.alpha, self.drawflag);
743
744                 pos_y = pos_y + self.font_size_y;
745         }
746 };
747
748 void(void) slist_init =
749 {
750         self.size = self._parent.size;
751         slist_estimatedsize = self.size_y / self.font_size_y / 2;
752 };
753
754 void(void) slist_refresh =
755 {
756         float hostcachesize;
757
758         hostcachesize = gethostcachevalue(SLIST_HOSTCACHECOUNT);
759         if(slist_start >= hostcachesize)
760                 slist_start = ceil(hostcachesize - slist_estimatedsize);
761         if(slist_start < 0)
762                 slist_start = 0;
763         if(slist_selected >= hostcachesize)
764                 slist_selected = hostcachesize;
765 };
766
767 void(void) slist_join =
768 {
769         string cname;
770         cname = gethostcachestring(SLIST_CNAME, slist_selected);
771
772         if(cname != "")
773         {
774                 cmd("connect ");
775                 cmd(cname);
776                 cmd(" ;togglemenu\n");
777         }
778 };
779
780 float(float keynr, float ascii ) slist_key =
781 {
782         float listsize;
783
784         if(keynr == K_UPARROW)
785         {
786                 if(slist_selected > 0)
787                         slist_selected = slist_selected - 1;
788                 if(slist_start > slist_selected)
789                         slist_start = slist_selected;
790                 return TRUE;
791         } else if(keynr == K_DOWNARROW)
792         {
793                 listsize = gethostcachevalue(SLIST_HOSTCACHECOUNT);
794                 if(slist_selected < listsize - 1)
795                         slist_selected = slist_selected + 1;
796                 if(slist_start + slist_estimatedsize - 0.5 < slist_selected)
797                         slist_start = ceil(slist_selected - slist_estimatedsize + 0.5);
798                 return TRUE;
799         } else if(keynr == K_ENTER)
800         {
801                 slist_join();
802                 return TRUE;
803         } else if(keynr == K_SPACE)
804         {
805                 cmd("net_slist\n");
806                 return TRUE;
807         } else if(keynr == K_MOUSE1)
808         {
809                 float pos;
810
811                 listsize = gethostcachevalue(SLIST_HOSTCACHECOUNT);
812                 pos = floor(menu_cursor_y / self.font_size_y / 2);
813
814                  if(pos + slist_start == slist_selected)
815                         slist_join();
816                 else if(pos + slist_start < listsize)
817                         slist_selected = pos;
818                 return TRUE;
819         }
820         return FALSE;
821 };
822
823 void(void) slist_info1 =
824 {
825         float query, reply;
826         string temp;
827
828         query = gethostcachevalue(SLIST_MASTERQUERYCOUNT);
829         reply = gethostcachevalue(SLIST_MASTERREPLYCOUNT);
830
831         strunzone(self.text);
832
833         temp = strcat(ftos(reply), "/");
834         temp = strcat(temp, ftos(query), " Master Servers");
835
836         self.text = strzone(temp);
837 };
838
839 void(void) slist_info2 =
840 {
841         float query, reply;
842         string temp;
843
844         query = gethostcachevalue(SLIST_SERVERQUERYCOUNT);
845         reply = gethostcachevalue(SLIST_SERVERREPLYCOUNT);
846
847         strunzone(self.text);
848
849         temp = strcat(ftos(reply), "/");
850         temp = strcat(temp, ftos(query), " Game Servers");
851
852         self.text = strzone(temp);
853 };
854
855 /////////////////
856 // options.menu
857 ///
858
859 void(void) nex_options_alwaysrun_switchchange =
860 {
861         if(self.value)
862         {
863                 cvar_set("cl_forwardspeed","400");
864                 cvar_set("cl_backspeed","400");
865         }
866         else
867         {
868                 cvar_set("cl_forwardspeed","200");
869                 cvar_set("cl_backspeed","200");
870         }
871 };
872
873 void(void) nex_options_alwaysrun_refresh =
874 {
875         if(cvar("cl_forwardspeed") > 200)
876                 self.value = 1;
877         else
878                 self.value = 0;
879 };
880
881 void(void) nex_options_invmouse_switchchange =
882 {
883         float old;
884         old = 0 - cvar("m_pitch");
885         cvar_set("m_pitch",ftos(old));
886 };
887
888 void(void) nex_options_invmouse_refresh =
889 {
890         if(cvar("m_pitch") > 0)
891                 self.value = 0;
892         else
893                 self.value = 1;
894 };
895
896 void(void) nex_snd =
897 {
898         entity ent;
899         ent = menu_getitem("options_sound");
900         nex_makeonlyvisible( ent );
901         menu_jumptowindow(ent, false);
902 }
903
904 void(void) nex_snd_cd_init =
905 {
906         if(cvar("cdaudioinitialized"))
907         {
908                 self.flag = FLAG_AUTOSETCLICK;
909                 self.color = ITEM_TEXT_NORMAL_COLOR;
910         }
911         else
912         {
913                 self.flag = FLAG_NOSELECT | FLAG_DRAWONLY | FLAG_CHILDDRAWONLY;
914                 self.color = '0.5 0.5 0.5';
915         }
916 };
917
918 void(void) nex_snd_snd_init =
919 {
920         if(cvar("snd_initialized"))
921         {
922                 self.flag = FLAG_AUTOSETCLICK;
923                 self.color = ITEM_TEXT_NORMAL_COLOR;
924         }
925         else
926         {
927                 self.flag = FLAG_NOSELECT | FLAG_DRAWONLY | FLAG_CHILDDRAWONLY;
928                 self.color = '0.5 0.5 0.5';
929         }
930 };
931
932 void(void) nex_cc =
933 {
934         entity ent;
935         ent = menu_getitem("options_cc");
936         nex_makeonlyvisible( ent );
937         menu_jumptowindow(ent, false);
938 }
939
940 void(void) nex_cc_reset =
941 {
942         cmd(
943         "v_hwgamma 1;"
944         "v_gamma 1;"
945         "v_contrast 1;"
946         "v_brightness 0;"
947         "v_color_enable 0;"
948         "v_color_black_r 0;"
949         "v_color_black_g 0;"
950         "v_color_black_b 0;"
951         "v_color_grey_r 0;"
952         "v_color_grey_g 0;"
953         "v_color_grey_b 0;"
954         "v_color_white_r 1;"
955         "v_color_white_g 1;"
956         "v_color_white_b 1;"
957         "\n");
958 };
959
960 void(void) nex_cc_check_hwgamma =
961 {
962         if(cvar("vid_hardwaregammasupported"))
963         {
964                 self.flag = FLAG_AUTOSETCLICK;
965                 self.color = ITEM_TEXT_NORMAL_COLOR;
966         }
967         else
968         {
969                 self.flag = FLAG_NOSELECT;
970                 self.color = '0.5 0.5 0.5';
971         }
972 };
973
974 void(void) nex_cc_check_gamma = // used in key -- BADBAD HACKHACK
975 {
976         if(cvar("v_hwgamma") && cvar("vid_hardwaregammasupported") && !cvar("v_color_enable"))
977         {
978                 self.flag = FLAG_AUTOSETCLICK;
979                 self.color = ITEM_TEXT_NORMAL_COLOR;
980         }
981         else
982         {
983                 self.flag = FLAG_NOSELECT;
984                 self.color = '0.5 0.5 0.5';
985         }
986 };
987
988 void(void) nex_cc_check_grey = // used in key -- BADBAD HACKHACK
989 {
990         if(cvar("v_hwgamma") && cvar("vid_hardwaregammasupported") && cvar("v_color_enable"))
991         {
992                 self.flag = FLAG_AUTOSETCLICK;
993                 self.color = ITEM_TEXT_NORMAL_COLOR;
994         }
995         else
996         {
997                 self.flag = FLAG_NOSELECT;
998                 self.color = '0.5 0.5 0.5';
999         }
1000 };
1001
1002 void(void) nex_cc_check_ncolor_enable =
1003 {
1004         if(!cvar("v_color_enable"))
1005         {
1006                 self.flag = FLAG_AUTOSETCLICK;
1007                 self.color = ITEM_TEXT_NORMAL_COLOR;
1008         }
1009         else
1010         {
1011                 self.flag = FLAG_NOSELECT;
1012                 self.color = '0.5 0.5 0.5';
1013         }
1014 };
1015
1016 void(void) nex_cc_check_color_enable =
1017 {
1018         if(cvar("v_color_enable"))
1019         {
1020                 self.flag = FLAG_AUTOSETCLICK;
1021                 self.color = ITEM_TEXT_NORMAL_COLOR;
1022         }
1023         else
1024         {
1025                 self.flag = FLAG_NOSELECT;
1026                 self.color = '0.5 0.5 0.5';
1027         }
1028 };
1029
1030 void(void) nex_cc_color_enable =
1031 {
1032         cvar_set("v_color_enable","1");
1033 };
1034
1035 void(void) nex_cc_ncolor_enable =
1036 {
1037         cvar_set("v_color_enable","0");
1038 };
1039
1040 void(void) nex_cc_grey_refresh =
1041 {
1042         self.value = cvar(strcat(self.cvarname,"_r"));
1043         self.value = self.value + cvar(strcat(self.cvarname,"_g"));
1044         self.value = self.value + cvar(strcat(self.cvarname,"_b"));
1045         self.value = self.value / 3;
1046 };
1047
1048
1049 void(void) nex_cc_grey_move =
1050 {
1051         string tmp;
1052         tmp = ftos(self.value);
1053         cvar_set(strcat(self.cvarname,"_r"), tmp);
1054         cvar_set(strcat(self.cvarname,"_g"), tmp);
1055         cvar_set(strcat(self.cvarname,"_b"), tmp);
1056 };
1057
1058 void(void) nex_cc_grey =
1059 {
1060         self.refresh = nex_cc_grey_refresh;
1061         self.slidermove = nex_cc_grey_move;
1062 };
1063
1064 // key control stuff
1065 void(void) nex_cntrl =
1066 {
1067         entity ent;
1068         ent = menu_getitem("options_control");
1069         nex_makeonlyvisible( ent );
1070         menu_jumptowindow(ent, false);
1071 }
1072
1073 const float NUMKEYS = 2;        // visible key count (first and secondary key)
1074 string bindcommand;
1075
1076 void(float keynr, float ascii) nex_con_keyhook =
1077 {
1078         entity ent;
1079
1080         //dprint("nex_con_keyhook called !\n");
1081
1082         if(keynr != K_ESCAPE)
1083         {
1084                 string tmp;
1085                 tmp = bind_getkeylist(bindcommand);
1086                 // remove the binds if we need more space
1087                 bind_limitbinds(NUMKEYS - 1, bindcommand);
1088                 // bind the new key
1089                 bind_bindkey(bind_getstringforkey(keynr), bindcommand);
1090         }
1091
1092         ent = menu_getitem("options_control_statemsg1");
1093         ent.value = 0;
1094
1095         ent = menu_getitem("options_control_statemsg2");
1096         ent.value = 0;
1097
1098         menu_keyhook = null_function;
1099 };
1100
1101 void(void) nex_con_action_key =
1102 {
1103         entity ent;
1104
1105         bindcommand = self.link;
1106
1107         //dprint("action called");
1108
1109         menu_keyhook = nex_con_keyhook;
1110
1111         ent = menu_getitem("options_control_statemsg1");
1112         ent.value = 1;
1113
1114         ent = menu_getitem("options_control_statemsg2");
1115         ent.value = 1;
1116 };
1117
1118 float(float keynr, float ascii) nex_con_key =
1119 {
1120         if(keynr == K_DEL)
1121         {
1122                 // the user wants to unbind this action
1123                 //dprint("Removing binds for '", self.link,"'\n");
1124                 bind_limitbinds(0, self.link);
1125                 return true;
1126         }
1127
1128         return false;
1129 };
1130
1131 void(void) nex_con_update_keys =
1132 {
1133         entity ent;
1134         string keystr;
1135         float num;
1136
1137         if(!self._child)
1138                 return;
1139
1140         keystr = strzone(bind_getkeylist(self.link));
1141
1142         num = 0;
1143
1144         for(ent = self._child; ent != null_entity; ent = ent._next)
1145         {
1146                 float keynr;
1147
1148                 keynr = stof(getaltstring(num, keystr));
1149
1150                 strunzone(ent.text);
1151
1152                 if(keynr == -1 )
1153                         ent.text = strzone("-");
1154                 else
1155                         ent.text = strzone(bind_getstringforkey(keynr));
1156
1157                 num = num + 1;
1158         }
1159
1160         strunzone(keystr);
1161 };
1162
1163 var float numkey = 0;
1164 void(void) CONTROL_KEY =
1165 {
1166         entity key1, key2, desc;
1167         entity temp_desc, temp_key;
1168
1169         temp_desc = menu_getitem("control_desc_template");
1170         temp_key = menu_getitem("control_key_template");
1171
1172         desc = spawn();
1173         copyentity(temp_desc, desc);
1174
1175         key1 = spawn();
1176         copyentity(temp_key, key1);
1177
1178         key2 = spawn();
1179         copyentity(temp_key, key2);
1180
1181         desc.name = self.text;
1182         key1.name = strzone(strcat(self.text, " key1"));
1183         key2.name = strzone(strcat(self.text, " key2"));
1184
1185         desc.pos_y = key1.pos_y = key2.pos_y = temp_desc.pos_y * numkey;
1186         key2.pos_x = 2 * key2.pos_x;
1187
1188         desc.text = self.text;
1189         desc.link = self.link;
1190
1191         key1.text = strzone("-");
1192         key2.text = strzone("-");
1193
1194         desc.alignment = 0;
1195
1196         // set the parents
1197         desc.parent = "options_control";
1198         desc._parent = menu_getitem("options_control");
1199
1200         key1.parent = key2.parent = desc.name;
1201         key1._parent = key2._parent = desc;
1202
1203         //eprint(key1);
1204         //eprint(key2);
1205         //eprint(desc);
1206
1207         numkey = numkey + 1;
1208 };
1209
1210 ////////////////////////////////////////////////////
1211 // Test Stuff
1212 ///
1213 void(void) initbrightness =
1214 {
1215         self.value = cvar("scr_conbrightness");
1216 };
1217
1218 void(void) setbrightness =
1219 {
1220         cvar_set("scr_conbrightness",ftos(self.value));
1221 };
1222
1223 void(void)  nex_main_exit =
1224 {
1225         entity e;
1226         e = menu_getitem("MAIN_MENU");
1227         e.flag = FLAG_NOSELECT + FLAG_CHILDDRAWONLY;
1228         e = menu_getitem("MAIN_EXIT_MENU");
1229         e.flag = FLAG_NOSELECT;
1230         menu_jumptowindow(e, false);
1231 };
1232
1233 void(void) nex_main_exit_no =
1234 {
1235         entity e;
1236         e = menu_getitem("MAIN_EXIT_MENU");
1237         e.flag = FLAG_NOSELECT + FLAG_HIDDEN;
1238         e = menu_getitem("MAIN_MENU");
1239         e.flag = FLAG_NOSELECT;
1240         menu_selectup();
1241 };
1242
1243 void(void) nex_main_exit_yes =
1244 {
1245         cmd("quit\n");
1246 };
1247
1248 float(float keynr, float ascii) nex_main_exit_key =
1249 {
1250         if(keynr == K_ESCAPE)
1251         {
1252                 nex_main_exit_no();
1253                 return true;
1254         }
1255         return false;
1256 }
1257
1258 void(void)  dorestart =
1259 {
1260         cmd("menu_restart\n");
1261 };
1262
1263 void(void) nex_text_cur_x =
1264 {
1265         self.text = ftos(rint(cursor_x));
1266 };
1267
1268 void(void) nex_text_cur_y =
1269 {
1270         self.text = ftos(rint(cursor_y));
1271 };