]> icculus.org git repositories - divverent/nexuiz.git/blob - menu/mcustom.qc
Added the player name editbox and a apply changes button to the player
[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 float skilllevel;
390 string hostname;
391 float  maxclients;
392 float  publicserver;
393 float  gamemode;
394
395 entity maps_list;
396 entity maps_current;
397
398 // text = info text
399 // picture = picture filename
400 // name = map name
401 void(entity node) _nex_xp_remove =
402 {
403         strunzone( node.picture );
404         strunzone( node.text );
405         strunzone( node.name );
406         remove( node );
407 }
408
409 void(void) _nex_xp_update =
410 {
411         entity item;
412
413         item = menu_getitem( "creategame_map_name" );
414         item.text = maps_current.name;
415
416         item = menu_getitem( "creategame_map_picture" );
417         item.picture = maps_current.picture;
418
419         item = menu_getitem( "creategame_map_info" );
420         item.text = maps_current.text;
421 };
422
423 void(void) nex_xp_enummaps =
424 {
425         float count;
426         float searchhandle;
427         float counter;
428
429         // remove the old list
430         if( maps_list ) {
431                 entity node;
432
433                 node = maps_list;
434                 while( node._next ) {
435                         node = node._next;
436                         _nex_xp_remove( node._prev );
437                 }
438                 _nex_xp_remove( node );
439         }
440         maps_list = maps_current = null_entity;
441
442         searchhandle = search_begin( "maps/*.bsp", true, true );
443         if( searchhandle == -1 ) {
444                 print( "menu: No maps found!\n" );
445                 return;
446         } else if( searchhandle == -2)
447                 return;
448
449         maps_list = maps_current = spawn();
450         count = search_getsize( searchhandle );
451         for( counter = 0 ; counter < count ; counter = counter + 1 ) {
452                 float file;
453                 string fname;
454
455                 fname = search_getfilename( searchhandle, counter );
456                 fname = substring( fname, 0, strlen( fname ) -  4 );
457                 fname = strzone( fname );
458
459                 //try to find the information text
460                 file = fopen( strcat( fname, ".txt" ), FILE_READ );
461                 if( file == -1 )
462                         maps_current.text = strzone( "--NO INFORMATION AVAILABLE--" );
463                 else {
464                         string temp, old;
465                         maps_current.text = strzone( "" );
466                         do {
467                                 old = maps_current.text;
468                                 temp = fgets( file );
469                                 maps_current.text = strzone( strcat( old, temp, "\n" ) );
470                                 strunzone( old );
471                         } while( temp );
472                         fclose( file );
473                 }
474
475                 //try to find the picture
476                 file = search_begin( strcat( fname, ".jpg" ), true, true );
477                 if( file == -1 )
478                         maps_current.picture = strzone( "gfx/m_nomap" );
479                 else {
480                         maps_current.picture = strzone( strcat( fname, ".jpg" ) );
481                         search_end( file );
482                 }
483
484                 maps_current.name = strzone( substring( fname, 5, strlen( fname ) - 5 ) ); // remove the 'maps/'
485                 strunzone( fname );
486
487                 // create next item and link it with the list
488                 maps_current._next = spawn();
489                 maps_current._next._prev = maps_current;
490                 maps_current = maps_current._next;
491         }
492         // remove the last item
493         maps_current = maps_current._prev;
494         remove( maps_current._next );
495         maps_current._next = null_entity;
496
497         search_end( searchhandle );
498
499         maps_current = maps_list;
500         _nex_xp_update();
501 };
502
503 void(void) nex_xp_prev =
504 {
505         if( maps_current._prev )
506                 maps_current = maps_current._prev;
507         _nex_xp_update();
508 };
509
510 void(void) nex_xp_next =
511 {
512         if( maps_current._next )
513                 maps_current = maps_current._next;
514         _nex_xp_update();
515 };
516
517
518 void(void) nex_display_creategame =
519 {
520         nex_makeonlyvisible( menu_getitem( "creategame" ) );
521         menu_jumptowindow( menu_getitem( "creategame" ), false );
522 };
523
524 void(void) nex_xp_maxfrags =
525 {
526         float x;
527         x = stof(self.text);
528         maxfrags = rint(x);
529
530         strunzone(self.text);
531         self.text = ftos(x);
532         self.text = strzone(self.text);
533 };
534
535 void(void) nex_xp_maxbots =
536 {
537         float x;
538         x = stof(self.text);
539         maxbots = min( fabs(rint(x)), maxclients - 1, 16 ); // 16 is currently max in frikbot - see below
540
541         strunzone(self.text);
542         self.text = ftos(x);
543         self.text = strzone(self.text);
544 };
545
546 void(void) nex_xp_maxtime =
547 {
548         float x;
549         x = stof(self.text);
550         maxtime = rint(x);
551
552         strunzone(self.text);
553         self.text = ftos(maxtime);
554         self.text = strzone(self.text);
555 };
556
557 void(void) nex_xp_hostname =
558 {
559         hostname = self.text;
560 };
561
562 void(void) nex_xp_maxclients =
563 {
564         local float i;
565         i = stof(self.text);
566         maxclients = rint(i);
567
568         strunzone(self.text);
569         self.text = strzone(ftos(maxclients));
570 };
571
572 void(void) nex_xp_publicserv =
573 {
574         publicserver = self.value;
575 };
576
577 void(void) nex_xp_gamemode =
578 {
579         gamemode = self.value;
580 };
581
582 void(void) nex_xp_skilllevel =
583 {
584         skilllevel = self.value;
585 }
586
587 void(void) nex_xp_start =
588 {
589         cvar_set( "fraglimit", ftos( maxfrags ) );
590         cvar_set( "timelimit", ftos( maxtime ) );
591         cvar_set( "deathmatch", "1" );
592
593         cmd( "maxplayers " );
594         cmd( ftos( maxclients ) );
595         cmd( "\n" );
596
597         cvar_set( "sv_public", ftos( publicserver ) );
598         cvar_set( "hostname", hostname );
599
600         // see bot/bot.qc: BotInit
601         cvar_set( "saved1", "1" );
602         cvar_set( "scratch1", ftos( pow( 2, maxbots ) - 1 ) );
603         cvar_set( "scratch2", ftos( skilllevel * (pow(4, min(maxbots, 8)) - 1) / 3) );
604         cvar_set( "scratch3", ftos( skilllevel * (pow(4, min(maxbots - 8, 8)) - 1) / 3) );
605
606         cmd( "map " );
607         cmd( maps_current.name );
608         cmd( "\n" );
609         cmd( "togglemenu\n" );
610 };
611
612 void(void) nex_goto_createserver =
613 {
614         menu_jumptowindow( menu_getitem( "multiplayer_frame"), false );
615 }
616
617 void(void) nex_draw_text =
618 {
619         local vector drawpos;
620         local float cpos, end;
621
622         cpos = 0;
623         drawpos = self.pos;
624         drawpos_y = drawpos_y + self.font_size_y;
625         do {
626                 local string l;
627                 local float i;
628
629                 end = strlen( self.text );
630                 i = cpos;
631                 do {
632                         l = substring( self.text, i, 1 );
633
634                         if( l == "\n" ) {
635                                 end = i;
636                                 break;
637                         }
638
639                         i = i + 1;
640                 } while( l != "" );
641
642                 l = substring( self.text, cpos, end - cpos );
643                 if( l != "" )
644                         menu_drawstring( drawpos, l, self.font_size, self.color, self.alpha, self.drawflag );
645                 drawpos_y = drawpos_y + self.font_size_y;
646
647                 cpos = end + 1;
648         } while( end != strlen( self.text ) );
649 }
650
651 // server list
652 var float slist_selected = 0;
653 var float slist_start   = 0;
654 float slist_estimatedsize;
655
656 void(void) nex_display_serverlist =
657 {
658         if(menu_activewindow.name == "serverlist")
659                 return;
660         menu_jumptowindow(menu_getitem("serverlist"),true);
661         cmd("net_slist\n");
662 };
663
664 // use a ITEM_TEXT as base item for this
665 // we need another item to clip the slist
666 // (another reason for a new menu qc!)
667 void(void) slist_draw =
668 {
669         float c;
670         vector pos;
671         float listsize;
672
673         //print("slist drawing...", ftos(listsize), "\n");
674
675         pos = '0 0 0'; // the upper item sets the origin
676         listsize = gethostcachevalue(SLIST_HOSTCACHECOUNT);
677         if(!listsize)
678         {
679                 menu_drawstring(pos, "No Servers", self.font_size, self.color, self.alpha, self.drawflag);
680                 return;
681         }
682
683         for(c = 0; c < slist_estimatedsize + 1; c = c + 1)
684         {
685                 string line;
686
687                 if(listsize <= slist_start + c)
688                         break;
689
690                 //print("drawing ", ftos(c),"\n");
691
692                 if(slist_selected - slist_start == c)
693                 {
694                         vector s;
695                         s = self.size;
696                         s_y = self.font_size_y * 2;
697
698                         menu_fillarea(pos, s, self.color_selected, self.alpha_selected * (sin(time * 9) + 1) / 2, self.drawflag_selected);
699                 }
700
701                 line = gethostcachestring(SLIST_LINE1, slist_start + c);
702
703                 menu_drawstring(pos, line, self.font_size, self.color, self.alpha, self.drawflag);
704
705                 pos_y = pos_y + self.font_size_y;
706
707                 line = gethostcachestring(SLIST_LINE2, slist_start + c);
708
709                 menu_drawstring(pos, line, self.font_size, self.color, self.alpha, self.drawflag);
710
711                 pos_y = pos_y + self.font_size_y;
712         }
713 };
714
715 void(void) slist_init =
716 {
717         self.size = self._parent.size;
718         slist_estimatedsize = self.size_y / self.font_size_y / 2;
719 };
720
721 void(void) slist_refresh =
722 {
723         float hostcachesize;
724
725         hostcachesize = gethostcachevalue(SLIST_HOSTCACHECOUNT);
726         if(slist_start >= hostcachesize)
727                 slist_start = ceil(hostcachesize - slist_estimatedsize);
728         if(slist_start < 0)
729                 slist_start = 0;
730         if(slist_selected >= hostcachesize)
731                 slist_selected = hostcachesize;
732 };
733
734 void(void) slist_join =
735 {
736         string cname;
737         cname = gethostcachestring(SLIST_CNAME, slist_selected);
738
739         if(cname != "")
740         {
741                 cmd("connect ");
742                 cmd(cname);
743                 cmd(" ;togglemenu\n");
744         }
745 };
746
747 float(float keynr, float ascii ) slist_key =
748 {
749         float listsize;
750
751         if(keynr == K_UPARROW)
752         {
753                 if(slist_selected > 0)
754                         slist_selected = slist_selected - 1;
755                 if(slist_start > slist_selected)
756                         slist_start = slist_selected;
757                 return TRUE;
758         } else if(keynr == K_DOWNARROW)
759         {
760                 listsize = gethostcachevalue(SLIST_HOSTCACHECOUNT);
761                 if(slist_selected < listsize - 1)
762                         slist_selected = slist_selected + 1;
763                 if(slist_start + slist_estimatedsize - 0.5 < slist_selected)
764                         slist_start = ceil(slist_selected - slist_estimatedsize + 0.5);
765                 return TRUE;
766         } else if(keynr == K_ENTER)
767         {
768                 slist_join();
769                 return TRUE;
770         } else if(keynr == K_SPACE)
771         {
772                 cmd("net_slist\n");
773                 return TRUE;
774         } else if(keynr == K_MOUSE1)
775         {
776                 float pos;
777
778                 listsize = gethostcachevalue(SLIST_HOSTCACHECOUNT);
779                 pos = floor(menu_cursor_y / self.font_size_y / 2);
780
781                  if(pos + slist_start == slist_selected)
782                         slist_join();
783                 else if(pos + slist_start < listsize)
784                         slist_selected = pos;
785                 return TRUE;
786         }
787         return FALSE;
788 };
789
790 void(void) slist_info1 =
791 {
792         float query, reply;
793         string temp;
794
795         query = gethostcachevalue(SLIST_MASTERQUERYCOUNT);
796         reply = gethostcachevalue(SLIST_MASTERREPLYCOUNT);
797
798         strunzone(self.text);
799
800         temp = strcat(ftos(reply), "/");
801         temp = strcat(temp, ftos(query), " Master Servers");
802
803         self.text = strzone(temp);
804 };
805
806 void(void) slist_info2 =
807 {
808         float query, reply;
809         string temp;
810
811         query = gethostcachevalue(SLIST_SERVERQUERYCOUNT);
812         reply = gethostcachevalue(SLIST_SERVERREPLYCOUNT);
813
814         strunzone(self.text);
815
816         temp = strcat(ftos(reply), "/");
817         temp = strcat(temp, ftos(query), " Game Servers");
818
819         self.text = strzone(temp);
820 };
821
822 /////////////////
823 // options.menu
824 ///
825
826 // player options
827 var entity mlist_list = null_entity;
828 entity mlist_current;
829 string mlist_saved;
830
831 string player_name;
832
833 string player_model_cvar = "player_model";
834 string player_name_cvar = "_cl_name";
835 string player_skin_cvar = "player_skin";
836 string player_fov_cvar = "player_fov";
837
838 void(void) nex_player_init =
839 {
840         entity ent;
841
842         if( mlist_saved )
843                 strunzone( mlist_saved );
844         mlist_saved = strzone( str_cvar( player_model_cvar ) );
845
846         ent = menu_getitem( "options_player_opt_playername_switch" );
847         ent.text = str_cvar( player_name_cvar);
848 };
849
850 void(void) nex_player_name =
851 {
852         player_name = self.text;
853 };
854
855 void(void) nex_player_apply =
856 {
857         cvar_set( player_model_cvar, mlist_current.picture_selected );
858         cvar_set( player_skin_cvar, mlist_current.picture_pressed );
859
860         cmd( strcat( "name ", player_name, "\n" ) );
861 };
862
863 // name = name
864 // picture_selected = model name
865 // picture_pressed = skin name
866 // picture = picture
867 // text = desc text
868 void(entity e) _nex_player_remove =
869 {
870         strunzone( e.name );
871         strunzone( e.picture_selected );
872         strunzone( e.picture_pressed );
873         strunzone( e.picture );
874         strunzone( e.text );
875
876         remove( e );
877 };
878
879 void() _nex_player_model_update =
880 {
881         entity item;
882
883         if( !mlist_list )
884                 return;
885
886         item = menu_getitem( "options_player_model_name" );
887         item.text = mlist_current.name;
888
889         item = menu_getitem( "options_player_model_picture" );
890         item.picture = mlist_current.picture;
891
892         item = menu_getitem( "options_player_model_info" );
893         item.text = mlist_current.text;
894 };
895
896 /*
897 .mdef file format
898 name
899 picture\n
900 skin filename\n
901 model filename\n
902 rest text*/
903 void(void) nex_player_buildlist =
904 {
905         float shandle;
906         float count;
907         float counter;
908         float loaded;
909         entity hit;
910
911         // remove the old player list
912         if( mlist_list ) {
913                 entity node;
914
915                 // save the old selected model
916                 mlist_saved = strzone( mlist_current.name );
917
918                 node = mlist_list;
919                 while( node._next ) {
920                         node = node._next;
921                         _nex_player_remove( node._prev );
922                 }
923                 _nex_player_remove( node );
924
925                 mlist_list = mlist_current = null_entity;
926         }
927
928         shandle = search_begin( "models/player/*.txt", false, true );
929         if( shandle < 0 )
930                 return;
931
932         count = search_getsize( shandle );
933         mlist_list = mlist_current = spawn();
934         hit = null_entity;
935         loaded = 0;
936         for ( counter = 0 ; counter < count ; counter = counter + 1 ) {
937                 string dname;
938                 string dpicture;
939                 string dskin;
940                 string dmodel;
941                 string dtext;
942
943                 float handle;
944
945                 handle = fopen( search_getfilename( handle, counter ), FILE_READ );
946
947                 if( handle < 0 )
948                         continue;
949
950                 dname = strzone( fgets( handle ) );
951                 dpicture = strzone( fgets( handle ) );
952                 dskin = strzone( fgets( handle ) );
953                 dmodel = strzone( fgets( handle ) );
954                 {
955                         string temp, old;
956                         dtext = strzone( "" );
957                         do {
958                                 old = dtext;
959                                 temp = fgets( handle );
960                                 dtext = strzone( strcat( old, temp, "\n" ) );
961                                 strunzone( old );
962                         } while( temp );
963                 }
964
965                 if( !dname || !dpicture || !dskin || !dmodel || !dtext ) {
966                         print( "Bad model definition file '", search_getfilename( shandle, counter ), "'\n" );
967
968                         strunzone( dname );
969                         strunzone( dpicture );
970                         strunzone( dskin );
971                         strunzone( dmodel );
972
973                         fclose( handle );
974                         continue;
975                 }
976
977                 // is this the previous selected model?
978                 if( dname == mlist_saved )
979                         hit = mlist_current;
980
981                 mlist_current.name = dname;
982                 mlist_current.picture = dpicture;
983                 mlist_current.picture_pressed = dskin;
984                 mlist_current.picture_selected = dmodel;
985                 mlist_current.text = dtext;
986
987                 loaded = loaded + 1;
988
989                 mlist_current._next = spawn();
990                 mlist_current._next._prev = mlist_current;
991                 mlist_current = mlist_current._next;
992
993                 fclose( handle );
994         }
995         mlist_current._prev._next = null_entity;
996         remove( mlist_current );
997
998         search_end( shandle );
999
1000         if( loaded == 0 ) {
1001                 print( "No model description files found in models/player\n" );
1002                 mlist_list = mlist_current = null_entity;
1003         } else
1004                 print( ftos( loaded ), " model description files loaded from models/player\n" );
1005
1006         if( hit )
1007                 mlist_current = hit;
1008         else
1009                 mlist_current = mlist_list;
1010
1011         _nex_player_model_update();
1012 };
1013
1014 void(void) nex_player_model_next =
1015 {
1016         if( mlist_current._next )
1017                 mlist_current = mlist_current._next;
1018         _nex_player_model_update();
1019 };
1020
1021 void(void) nex_player_model_prev =
1022 {
1023         if( mlist_current._prev )
1024                 mlist_current = mlist_current._prev;
1025         _nex_player_model_update();
1026 };
1027
1028 void(void) nex_player =
1029 {
1030         entity ent;
1031         ent = menu_getitem("options_player");
1032         nex_makeonlyvisible( ent );
1033         menu_jumptowindow(ent, false);
1034 };
1035
1036 // old/other options
1037
1038 void(void) nex_options_alwaysrun_switchchange =
1039 {
1040         if(self.value)
1041         {
1042                 cvar_set("cl_forwardspeed","400");
1043                 cvar_set("cl_backspeed","400");
1044         }
1045         else
1046         {
1047                 cvar_set("cl_forwardspeed","200");
1048                 cvar_set("cl_backspeed","200");
1049         }
1050 };
1051
1052 void(void) nex_options_alwaysrun_refresh =
1053 {
1054         if(cvar("cl_forwardspeed") > 200)
1055                 self.value = 1;
1056         else
1057                 self.value = 0;
1058 };
1059
1060 void(void) nex_options_invmouse_switchchange =
1061 {
1062         float old;
1063         old = 0 - cvar("m_pitch");
1064         cvar_set("m_pitch",ftos(old));
1065 };
1066
1067 void(void) nex_options_invmouse_refresh =
1068 {
1069         if(cvar("m_pitch") > 0)
1070                 self.value = 0;
1071         else
1072                 self.value = 1;
1073 };
1074
1075 void(void) nex_snd =
1076 {
1077         entity ent;
1078         ent = menu_getitem("options_sound");
1079         nex_makeonlyvisible( ent );
1080         menu_jumptowindow(ent, false);
1081 }
1082
1083 void(void) nex_snd_cd_init =
1084 {
1085         if(cvar("cdaudioinitialized"))
1086         {
1087                 self.flag = FLAG_AUTOSETCLICK;
1088                 self.color = ITEM_TEXT_NORMAL_COLOR;
1089         }
1090         else
1091         {
1092                 self.flag = FLAG_NOSELECT | FLAG_DRAWONLY | FLAG_CHILDDRAWONLY;
1093                 self.color = '0.5 0.5 0.5';
1094         }
1095 };
1096
1097 void(void) nex_snd_snd_init =
1098 {
1099         if(cvar("snd_initialized"))
1100         {
1101                 self.flag = FLAG_AUTOSETCLICK;
1102                 self.color = ITEM_TEXT_NORMAL_COLOR;
1103         }
1104         else
1105         {
1106                 self.flag = FLAG_NOSELECT | FLAG_DRAWONLY | FLAG_CHILDDRAWONLY;
1107                 self.color = '0.5 0.5 0.5';
1108         }
1109 };
1110
1111 void(void) nex_cc =
1112 {
1113         entity ent;
1114         ent = menu_getitem("options_cc");
1115         nex_makeonlyvisible( ent );
1116         menu_jumptowindow(ent, false);
1117 }
1118
1119 void(void) nex_cc_reset =
1120 {
1121         cmd(
1122         "v_hwgamma 1;"
1123         "v_gamma 1;"
1124         "v_contrast 1;"
1125         "v_brightness 0;"
1126         "v_color_enable 0;"
1127         "v_color_black_r 0;"
1128         "v_color_black_g 0;"
1129         "v_color_black_b 0;"
1130         "v_color_grey_r 0;"
1131         "v_color_grey_g 0;"
1132         "v_color_grey_b 0;"
1133         "v_color_white_r 1;"
1134         "v_color_white_g 1;"
1135         "v_color_white_b 1;"
1136         "\n");
1137 };
1138
1139 void(void) nex_cc_check_hwgamma =
1140 {
1141         if(cvar("vid_hardwaregammasupported"))
1142         {
1143                 self.flag = FLAG_AUTOSETCLICK;
1144                 self.color = ITEM_TEXT_NORMAL_COLOR;
1145         }
1146         else
1147         {
1148                 self.flag = FLAG_NOSELECT;
1149                 self.color = '0.5 0.5 0.5';
1150         }
1151 };
1152
1153 void(void) nex_cc_check_gamma = // used in key -- BADBAD HACKHACK
1154 {
1155         if(cvar("v_hwgamma") && cvar("vid_hardwaregammasupported") && !cvar("v_color_enable"))
1156         {
1157                 self.flag = FLAG_AUTOSETCLICK;
1158                 self.color = ITEM_TEXT_NORMAL_COLOR;
1159         }
1160         else
1161         {
1162                 self.flag = FLAG_NOSELECT;
1163                 self.color = '0.5 0.5 0.5';
1164         }
1165 };
1166
1167 void(void) nex_cc_check_grey = // used in key -- BADBAD HACKHACK
1168 {
1169         if(cvar("v_hwgamma") && cvar("vid_hardwaregammasupported") && cvar("v_color_enable"))
1170         {
1171                 self.flag = FLAG_AUTOSETCLICK;
1172                 self.color = ITEM_TEXT_NORMAL_COLOR;
1173         }
1174         else
1175         {
1176                 self.flag = FLAG_NOSELECT;
1177                 self.color = '0.5 0.5 0.5';
1178         }
1179 };
1180
1181 void(void) nex_cc_check_ncolor_enable =
1182 {
1183         if(!cvar("v_color_enable"))
1184         {
1185                 self.flag = FLAG_AUTOSETCLICK;
1186                 self.color = ITEM_TEXT_NORMAL_COLOR;
1187         }
1188         else
1189         {
1190                 self.flag = FLAG_NOSELECT;
1191                 self.color = '0.5 0.5 0.5';
1192         }
1193 };
1194
1195 void(void) nex_cc_check_color_enable =
1196 {
1197         if(cvar("v_color_enable"))
1198         {
1199                 self.flag = FLAG_AUTOSETCLICK;
1200                 self.color = ITEM_TEXT_NORMAL_COLOR;
1201         }
1202         else
1203         {
1204                 self.flag = FLAG_NOSELECT;
1205                 self.color = '0.5 0.5 0.5';
1206         }
1207 };
1208
1209 void(void) nex_cc_color_enable =
1210 {
1211         cvar_set("v_color_enable","1");
1212 };
1213
1214 void(void) nex_cc_ncolor_enable =
1215 {
1216         cvar_set("v_color_enable","0");
1217 };
1218
1219 void(void) nex_cc_grey_refresh =
1220 {
1221         self.value = cvar(strcat(self.cvarname,"_r"));
1222         self.value = self.value + cvar(strcat(self.cvarname,"_g"));
1223         self.value = self.value + cvar(strcat(self.cvarname,"_b"));
1224         self.value = self.value / 3;
1225 };
1226
1227
1228 void(void) nex_cc_grey_move =
1229 {
1230         string tmp;
1231         tmp = ftos(self.value);
1232         cvar_set(strcat(self.cvarname,"_r"), tmp);
1233         cvar_set(strcat(self.cvarname,"_g"), tmp);
1234         cvar_set(strcat(self.cvarname,"_b"), tmp);
1235 };
1236
1237 void(void) nex_cc_grey =
1238 {
1239         self.refresh = nex_cc_grey_refresh;
1240         self.slidermove = nex_cc_grey_move;
1241 };
1242
1243 // key control stuff
1244 void(void) nex_cntrl =
1245 {
1246         entity ent;
1247         ent = menu_getitem("options_control");
1248         nex_makeonlyvisible( ent );
1249         menu_jumptowindow(ent, false);
1250 }
1251
1252 const float NUMKEYS = 2;        // visible key count (first and secondary key)
1253 string bindcommand;
1254
1255 void(float keynr, float ascii) nex_con_keyhook =
1256 {
1257         entity ent;
1258
1259         //dprint("nex_con_keyhook called !\n");
1260
1261         if(keynr != K_ESCAPE)
1262         {
1263                 string tmp;
1264                 tmp = bind_getkeylist(bindcommand);
1265                 // remove the binds if we need more space
1266                 bind_limitbinds(NUMKEYS - 1, bindcommand);
1267                 // bind the new key
1268                 bind_bindkey(bind_getstringforkey(keynr), bindcommand);
1269         }
1270
1271         ent = menu_getitem("options_control_statemsg1");
1272         ent.value = 0;
1273
1274         ent = menu_getitem("options_control_statemsg2");
1275         ent.value = 0;
1276
1277         menu_keyhook = null_function;
1278 };
1279
1280 void(void) nex_con_action_key =
1281 {
1282         entity ent;
1283
1284         bindcommand = self.link;
1285
1286         //dprint("action called");
1287
1288         menu_keyhook = nex_con_keyhook;
1289
1290         ent = menu_getitem("options_control_statemsg1");
1291         ent.value = 1;
1292
1293         ent = menu_getitem("options_control_statemsg2");
1294         ent.value = 1;
1295 };
1296
1297 float(float keynr, float ascii) nex_con_key =
1298 {
1299         if(keynr == K_DEL)
1300         {
1301                 // the user wants to unbind this action
1302                 //dprint("Removing binds for '", self.link,"'\n");
1303                 bind_limitbinds(0, self.link);
1304                 return true;
1305         }
1306
1307         return false;
1308 };
1309
1310 void(void) nex_con_update_keys =
1311 {
1312         entity ent;
1313         string keystr;
1314         float num;
1315
1316         if(!self._child)
1317                 return;
1318
1319         keystr = strzone(bind_getkeylist(self.link));
1320
1321         num = 0;
1322
1323         for(ent = self._child; ent != null_entity; ent = ent._next)
1324         {
1325                 float keynr;
1326
1327                 keynr = stof(getaltstring(num, keystr));
1328
1329                 strunzone(ent.text);
1330
1331                 if(keynr == -1 )
1332                         ent.text = strzone("-");
1333                 else
1334                         ent.text = strzone(bind_getstringforkey(keynr));
1335
1336                 num = num + 1;
1337         }
1338
1339         strunzone(keystr);
1340 };
1341
1342 var float numkey = 0;
1343 void(void) CONTROL_KEY =
1344 {
1345         entity key1, key2, desc;
1346         entity temp_desc, temp_key;
1347
1348         temp_desc = menu_getitem("control_desc_template");
1349         temp_key = menu_getitem("control_key_template");
1350
1351         desc = spawn();
1352         copyentity(temp_desc, desc);
1353
1354         key1 = spawn();
1355         copyentity(temp_key, key1);
1356
1357         key2 = spawn();
1358         copyentity(temp_key, key2);
1359
1360         desc.name = self.text;
1361         key1.name = strzone(strcat(self.text, " key1"));
1362         key2.name = strzone(strcat(self.text, " key2"));
1363
1364         desc.pos_y = key1.pos_y = key2.pos_y = temp_desc.pos_y * numkey;
1365         key2.pos_x = 2 * key2.pos_x;
1366
1367         desc.text = self.text;
1368         desc.link = self.link;
1369
1370         key1.text = strzone("-");
1371         key2.text = strzone("-");
1372
1373         desc.alignment = 0;
1374
1375         // set the parents
1376         desc.parent = "options_control";
1377         desc._parent = menu_getitem("options_control");
1378
1379         key1.parent = key2.parent = desc.name;
1380         key1._parent = key2._parent = desc;
1381
1382         //eprint(key1);
1383         //eprint(key2);
1384         //eprint(desc);
1385
1386         numkey = numkey + 1;
1387 };
1388
1389 ////////////////////////////////////////////////////
1390 // Test Stuff
1391 ///
1392 void(void) initbrightness =
1393 {
1394         self.value = cvar("scr_conbrightness");
1395 };
1396
1397 void(void) setbrightness =
1398 {
1399         cvar_set("scr_conbrightness",ftos(self.value));
1400 };
1401
1402 void(void)  nex_main_exit =
1403 {
1404         entity e;
1405         e = menu_getitem("MAIN_MENU");
1406         e.flag = FLAG_NOSELECT + FLAG_CHILDDRAWONLY;
1407         e = menu_getitem("MAIN_EXIT_MENU");
1408         e.flag = FLAG_NOSELECT;
1409         menu_jumptowindow(e, false);
1410 };
1411
1412 void(void) nex_main_exit_no =
1413 {
1414         entity e;
1415         e = menu_getitem("MAIN_EXIT_MENU");
1416         e.flag = FLAG_NOSELECT + FLAG_HIDDEN;
1417         e = menu_getitem("MAIN_MENU");
1418         e.flag = FLAG_NOSELECT;
1419         menu_selectup();
1420 };
1421
1422 void(void) nex_main_exit_yes =
1423 {
1424         cmd("quit\n");
1425 };
1426
1427 float(float keynr, float ascii) nex_main_exit_key =
1428 {
1429         if(keynr == K_ESCAPE)
1430         {
1431                 nex_main_exit_no();
1432                 return true;
1433         }
1434         return false;
1435 }
1436
1437 void(void)  dorestart =
1438 {
1439         cmd("menu_restart\n");
1440 };
1441
1442 void(void) nex_text_cur_x =
1443 {
1444         self.text = ftos(rint(cursor_x));
1445 };
1446
1447 void(void) nex_text_cur_y =
1448 {
1449         self.text = ftos(rint(cursor_y));
1450 };