2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
29 #if !defined(_MSC_VER) && !defined(macintosh)
55 #define MAXDISPLAYABLEITEMS 15
57 #define LHX(x) ((x)*(MenuHires?2:1))
58 #define LHY(y) ((y)*(MenuHires?2.4:1))
60 #define TITLE_FONT HUGE_FONT
61 #define NORMAL_FONT MEDIUM1_FONT // normal, non-highlighted item
62 #define SELECTED_FONT MEDIUM2_FONT // highlighted item
63 #define SUBTITLE_FONT MEDIUM3_FONT
65 #define NORMAL_CHECK_BOX "\x81" // 129
66 #define CHECKED_CHECK_BOX "\x82" // 130
68 #define NORMAL_RADIO_BOX "\x7f" // 127
69 #define CHECKED_RADIO_BOX "\x80" // 128
70 #define CURSOR_STRING "_"
71 #define SLIDER_LEFT "\x83" // 131
72 #define SLIDER_RIGHT "\x84" // 132
73 #define SLIDER_MIDDLE "\x85" // 133
74 #define SLIDER_MARKER "\x86" // 134
75 #define UP_ARROW_MARKER "\x87" // 135
76 #define DOWN_ARROW_MARKER "\x88" // 136
78 int newmenu_do4( char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int citem, char *filename, int width, int height, int TinyMode );
79 void show_extra_netgame_info(int choice);
81 int Newmenu_first_time = 1;
82 //--unused-- int Newmenu_fade_in = 1;
85 grs_canvas *menu_canvas;
86 grs_bitmap *saved; // The background under the menu.
87 grs_bitmap *background;
90 grs_bitmap nm_background,nm_background_save;
92 #define MESSAGEBOX_TEXT_SIZE 2176 // How many characters in messagebox (changed form 300 (fixes crash from show_game_score and friends) - 2000/01/18 Matt Mueller)
93 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
95 ubyte MenuReordering = 0;
97 char Pauseable_menu = 0;
98 char already_showing_info = 0;
101 void newmenu_close(void)
103 if ( nm_background.bm_data )
104 d_free(nm_background.bm_data);
106 if ( nm_background_save.bm_data )
107 d_free(nm_background_save.bm_data);
108 Newmenu_first_time = 1;
112 ubyte background_palette[768];
115 //should be called whenever the palette changes
116 void nm_remap_background(void)
118 if (!Newmenu_first_time) {
119 if (!nm_background.bm_data)
120 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
122 memcpy(nm_background.bm_data,nm_background_save.bm_data, nm_background.bm_w * nm_background.bm_h);
124 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
129 extern char last_palette_loaded[];
132 void nm_draw_background1(char *filename)
139 //@@//I think this only gets called to fill the whole screen
140 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
141 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
143 pcx_error = pcx_get_dimensions(filename, &width, &height);
144 if (pcx_error != PCX_ERROR_NONE)
145 Error("Could not open pcx file <%s>\n", filename);
147 bmp = gr_create_bitmap(width, height);
149 pcx_error = pcx_read_bitmap(filename, bmp, bmp->bm_type, pal);
150 Assert(pcx_error == PCX_ERROR_NONE);
152 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
154 { // remap stuff. this code is kindof a hack
156 // now, before we bring up the menu, we need to
157 // do some stuff to make sure the palette is ok. First, we need to
158 // get our current palette into the 2d's array, so the remapping will
159 // work. Second, we need to remap the fonts. Third, we need to fill
160 // in part of the fade tables so the darkening of the menu edges works
162 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
164 gr_palette_load(gr_palette);
166 remap_fonts_and_menus(1);
170 gr_bitmap_fullscr(bmp);
174 strcpy(last_palette_loaded,""); // force palette load next time
178 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
179 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
180 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
182 int Background_hires;
183 int No_darkening = 0;
186 void nm_draw_background(int x1, int y1, int x2, int y2 )
190 if (Newmenu_first_time || MenuHires!=Background_hires) {
193 if (Newmenu_first_time) {
194 atexit( newmenu_close );
195 Newmenu_first_time = 0;
196 nm_background_save.bm_data = NULL;
198 if (nm_background_save.bm_data)
199 d_free(nm_background_save.bm_data);
200 if (nm_background.bm_data)
201 d_free(nm_background.bm_data);
204 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP, &nm_background_save, BM_LINEAR, background_palette);
205 Assert(pcx_error == PCX_ERROR_NONE);
207 nm_background = nm_background_save;
208 nm_background.bm_data = NULL;
209 nm_remap_background();
211 Background_hires = MenuHires;
214 if ( x1 < 0 ) x1 = 0;
215 if ( y1 < 0 ) y1 = 0;
220 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
221 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
227 gr_bm_bitblt( w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
229 if ( GWIDTH > nm_background.bm_w || GHEIGHT > nm_background.bm_h ) {
230 // Resize background to fit. Resize so that the original aspect is preserved. -MPM
231 grs_canvas *tmp, *old;
235 tmp = gr_create_sub_canvas(old, x1, y1, w, h);
236 gr_init_sub_bitmap(&bg, &nm_background, 0, 0, w*(nm_background.bm_w)/GWIDTH, h*(nm_background.bm_h)/GHEIGHT); // note that we haven't replaced current_canvas yet, so these macros are still ok.
237 gr_set_current_canvas(tmp);
238 gr_bitmap_fullscr( &bg );
239 gr_set_current_canvas(old);
240 gr_free_sub_canvas(tmp);
242 gr_bm_bitblt( w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
246 Gr_scanline_darkening_level = 2*7;
248 gr_setcolor( BM_XRGB(0,0,0) );
249 gr_urect( x2-5, y1+5, x2-5, y2-5 );
250 gr_urect( x2-4, y1+4, x2-4, y2-5 );
251 gr_urect( x2-3, y1+3, x2-3, y2-5 );
252 gr_urect( x2-2, y1+2, x2-2, y2-5 );
253 gr_urect( x2-1, y1+1, x2-1, y2-5 );
254 gr_urect( x2+0, y1+0, x2-0, y2-5 );
256 gr_urect( x1+5, y2-5, x2, y2-5 );
257 gr_urect( x1+4, y2-4, x2, y2-4 );
258 gr_urect( x1+3, y2-3, x2, y2-3 );
259 gr_urect( x1+2, y2-2, x2, y2-2 );
260 gr_urect( x1+1, y2-1, x2, y2-1 );
261 gr_urect( x1+0, y2, x2, y2-0 );
264 Gr_scanline_darkening_level = GR_FADE_LEVELS;
268 void nm_restore_background( int x, int y, int w, int h )
275 if ( x1 < 0 ) x1 = 0;
276 if ( y1 < 0 ) y1 = 0;
278 if ( x2 >= GWIDTH ) x2 = GWIDTH - 1;
279 if ( y2 >= GHEIGHT ) y2 = GHEIGHT - 1;
284 if (GWIDTH > nm_background.bm_w || GHEIGHT > nm_background.bm_h) {
286 grs_canvas *tmp, *old;
289 tmp = gr_create_sub_canvas(old, x1, y1, w, h);
290 gr_init_sub_bitmap(&sbg, &nm_background, x1*(nm_background.bm_w)/GWIDTH, y1*(nm_background.bm_h)/GHEIGHT, w*(nm_background.bm_w)/GWIDTH, h*(nm_background.bm_h)/GHEIGHT); // use the correctly resized portion of the background. -MPM
291 gr_set_current_canvas(tmp);
292 gr_bitmap_fullscr( &sbg );
293 gr_set_current_canvas(old);
294 gr_free_sub_canvas(tmp);
296 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap));
300 // Draw a left justfied string
301 void nm_string( bkg *b, int w1,int x, int y, char *s )
303 int w, h, aw, tx = 0, t = 0, i;
304 char *p, *s1, *s2, measure[2];
305 int XTabs[] = { 15, 87, 124, 162, 228, 253 };
310 for (i = 0; i < 6; i++) {
311 XTabs[i] = (LHX(XTabs[i]));
318 p = strchr( s2, '\t' );
319 if (p && (w1 > 0) ) {
325 gr_get_string_size( s2, &w, &h, &aw );
331 gr_bm_bitblt( b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
332 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
335 for (i = 0; i < strlen(s2); i++) {
336 if (s2[i] == '\t' && SurfingNet) {
342 gr_get_string_size(measure, &tx, &h, &aw);
343 gr_string(x, y, measure);
349 if (!SurfingNet && p && (w1 > 0) ) {
350 gr_get_string_size( s1, &w, &h, &aw );
352 gr_string( x+w1-w, y, s1 );
360 // Draw a slider and it's string
361 void nm_string_slider( bkg *b, int w1, int x, int y, char *s )
368 p = strchr( s, '\t' );
374 gr_get_string_size( s, &w, &h, &aw );
377 gr_bm_bitblt( b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
378 //gr_bm_bitblt( w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
380 gr_string( x, y, s );
383 gr_get_string_size( s1, &w, &h, &aw );
386 gr_bm_bitblt( w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
388 gr_bm_bitblt( w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
390 gr_string( x+w1-w, y, s1 );
397 // Draw a left justfied string with black background.
398 void nm_string_black( bkg *b, int w1, int x, int y, char *s )
402 gr_get_string_size( s, &w, &h, &aw );
405 gr_setcolor( BM_XRGB(2,2,2) );
406 gr_rect( x-1, y-1, x-1, y+h-1 );
407 gr_rect( x-1, y-1, x+w1-1, y-1 );
409 gr_setcolor( BM_XRGB(5,5,5) );
410 gr_rect( x, y+h, x+w1, y+h);
411 gr_rect( x+w1, y-1, x+w1, y+h );
413 gr_setcolor( BM_XRGB(0,0,0) );
414 gr_rect( x, y, x+w1-1, y+h-1 );
416 gr_string( x+1, y+1, s );
420 // Draw a right justfied string
421 void nm_rstring( bkg *b, int w1, int x, int y, char *s )
425 gr_get_string_size( s, &w, &h, &aw );
430 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
433 gr_bm_bitblt( w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
434 gr_string( x-w, y, s );
438 // for text items, constantly redraw cursor (to achieve flash)
439 void update_cursor( newmenu_item *item )
442 fix time = timer_get_approx_seconds();
444 char *text = item->text;
446 Assert(item->type == NM_TYPE_INPUT_MENU || item->type == NM_TYPE_INPUT);
449 gr_get_string_size( text, &w, &h, &aw );
450 if ( w > item->w-10 )
457 x = item->x+w; y = item->y;
460 gr_string( x, y, CURSOR_STRING );
462 gr_setcolor( BM_XRGB(0,0,0) );
463 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
468 void nm_string_inputbox( bkg *b, int w, int x, int y, char *text, int current )
473 gr_get_string_size( text, &w1, &h1, &aw );
482 nm_string_black( b, w, x, y, text );
485 gr_string( x+w1+1, y, CURSOR_STRING );
489 void draw_item( bkg *b, newmenu_item *item, int is_current, int tiny )
493 gr_set_fontcolor(gr_find_closest_color_current(57,49,20), -1);
495 gr_set_fontcolor(gr_find_closest_color_current(29,29,47), -1);
497 if (item->text[0]=='\t')
498 gr_set_fontcolor (gr_find_closest_color_current(63,63,63), -1);
501 grd_curcanv->cv_font = SELECTED_FONT;
503 grd_curcanv->cv_font = NORMAL_FONT;
506 if (is_current && item->type == NM_TYPE_TEXT)
507 grd_curcanv->cv_font = NORMAL_FONT;
511 switch( item->type ) {
513 //grd_curcanv->cv_font=TEXT_FONT;
514 // fall through on purpose
516 nm_string( b, item->w, item->x, item->y, item->text );
518 case NM_TYPE_SLIDER: {
521 if (item->value < item->min_value) item->value = item->min_value;
522 if (item->value > item->max_value) item->value = item->max_value;
523 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
524 for (j = 0; j < (item->max_value-item->min_value+1); j++ )
525 strncat( item->saved_text, SLIDER_MIDDLE, sizeof(item->saved_text)-strlen(item->saved_text)-1 );
526 strncat( item->saved_text, SLIDER_RIGHT, sizeof(item->saved_text)-strlen(item->saved_text)-1 );
528 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
530 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
533 case NM_TYPE_INPUT_MENU:
534 if ( item->group == 0 )
535 nm_string( b, item->w, item->x, item->y, item->text );
537 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
540 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
543 nm_string( b, item->w, item->x, item->y, item->text );
545 nm_rstring( b, item->right_offset, item->x, item->y, CHECKED_CHECK_BOX );
547 nm_rstring( b, item->right_offset, item->x, item->y, NORMAL_CHECK_BOX );
550 nm_string( b, item->w, item->x, item->y, item->text );
552 nm_rstring( b, item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
554 nm_rstring( b, item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
556 case NM_TYPE_NUMBER: {
559 if (item->value < item->min_value) item->value = item->min_value;
560 if (item->value > item->max_value) item->value = item->max_value;
561 nm_string( b, item->w, item->x, item->y, item->text );
562 sprintf( text, "%d", item->value );
563 nm_rstring( b,item->right_offset,item->x, item->y, text );
570 const char *Newmenu_allowed_chars=NULL;
573 // returns true if char is allowed
574 int char_allowed(char c)
576 const char *p = Newmenu_allowed_chars;
584 if (c >= p[0] && c <= p[1])
594 void strip_end_whitespace( char *text )
598 l = (int)strlen( text );
599 for ( i = l-1; i >= 0; i-- ) {
600 if ( isspace(text[i]) )
608 int newmenu_do( char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem) )
610 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
614 int newmenu_dotiny( char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem) )
616 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
620 int newmenu_dotiny2( char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem) )
622 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
626 int newmenu_do1( char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int citem )
628 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
632 int newmenu_do2( char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int citem, char *filename )
634 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
638 int newmenu_do3( char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int citem, char *filename, int width, int height )
640 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height, 0 );
644 int newmenu_do_fixedfont( char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int citem, char *filename, int width, int height )
646 set_screen_mode(SCREEN_MENU); // hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
647 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width, height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT );
648 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height, 0);
652 // use menu with joystick
653 int newmenu_inkey(void)
659 if ( !Config_control_joystick.intval || key < KEY_JB1 || key > 255 ) // not using joystick, not a joystick button, or modifier pressed
662 if ( strlen(key_text[key]) > 5 && key_text[key][0] == 'J' && key_text[key][2] == 'H' ) // joystick hat
663 switch (key_text[key][4]) {
664 case 'U': key = KEY_UP; break;
665 case 'R': key = KEY_RIGHT; break;
666 case 'D': key = KEY_DOWN; break;
667 case 'L': key = KEY_LEFT; break;
669 else if ( strlen(key_text[key]) > 3 && key_text[key][0] == 'J' && key_text[key][2] == 'B' ) // joystick button
670 switch (key_text[key][3]) {
671 case '1': key = KEY_SPACEBAR; break;
672 case '2': key = KEY_ENTER; break;
673 case '3': key = KEY_ESC; break;
679 int newmenu_getch(void)
681 while (!key_checkch())
684 return newmenu_inkey();
688 extern int network_request_player_names(int);
689 extern int RestoringMenu;
692 ubyte Hack_DblClick_MenuMode = 0;
696 extern ubyte joydefs_calibrating;
698 # define joydefs_calibrating 0
701 #define CLOSE_X (MenuHires?15:7)
702 #define CLOSE_Y (MenuHires?15:7)
703 #define CLOSE_SIZE (MenuHires?10:5)
706 void draw_close_box(int x, int y)
708 gr_setcolor( BM_XRGB(0, 0, 0) );
709 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
710 gr_setcolor( BM_XRGB(21, 21, 21) );
711 gr_rect(x + CLOSE_X + LHX(1), y + CLOSE_Y + LHX(1), x + CLOSE_X + CLOSE_SIZE - LHX(1), y + CLOSE_Y + CLOSE_SIZE - LHX(1));
715 extern int Num_bitmap_files;
718 int newmenu_do4( char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int citem, char *filename, int width, int height, int TinyMode )
720 int old_keyd_repeat, done;
721 int choice, old_choice, i, j, x, y, w, h, aw, tw, th, twidth, fm, right_offset;
722 int k, nmenus, nothers, ScrollOffset = 0, LastScrollCheck = -1, MaxDisplayable, sx, sy;
724 int string_width, string_height = 0, average_width;
727 int all_text = 0; // set true if all text items
728 int sound_stopped = 0, time_stopped = 0;
729 int TopChoice, IsScrollBox = 0; // Is this a scrolling box? Set to false at init
731 int dont_restore = 0;
732 int MaxOnMenu = MAXDISPLAYABLEITEMS;
733 grs_canvas *save_canvas;
735 int mouse_state, omouse_state, dblclick_flag = 0;
736 int mx = 0, my = 0, x1 = 0, x2, y1, y2;
740 EventRecord event; // looking for disk inserted events for CD mounts
743 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
744 newmenu_hide_cursor();
749 MaxDisplayable = nitems;
751 //set_screen_mode(SCREEN_MENU);
754 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
755 digi_pause_digi_sounds();
759 if ( !((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) ) {
768 save_canvas = grd_curcanv;
770 gr_set_current_canvas(NULL);
772 save_font = grd_curcanv->cv_font;
777 grd_curcanv->cv_font = TITLE_FONT;
778 gr_get_string_size( title, &string_width, &string_height, &average_width );
783 grd_curcanv->cv_font = SUBTITLE_FONT;
784 gr_get_string_size( subtitle, &string_width, &string_height, &average_width );
785 if (string_width > tw )
790 th += LHY(8); // put some space between titles & body
793 grd_curcanv->cv_font = SMALL_FONT;
795 grd_curcanv->cv_font = NORMAL_FONT;
799 nmenus = nothers = 0;
801 // Find menu height & width (store in w,h)
802 for (i = 0; i < nitems; i++ ) {
805 gr_get_string_size( item[i].text, &string_width, &string_height, &average_width );
806 item[i].right_offset = 0;
809 string_height += LHY(3);
811 item[i].saved_text[0] = '\0';
813 if ( item[i].type == NM_TYPE_SLIDER ) {
817 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
818 for (j = 0; j < (item[i].max_value-item[i].min_value+1); j++ )
819 strncat( item[i].saved_text, SLIDER_MIDDLE, sizeof(item[i].saved_text)-strlen(item[i].saved_text)-1 );
820 strncat( item[i].saved_text, SLIDER_RIGHT, sizeof(item[i].saved_text)-strlen(item[i].saved_text)-1 );
821 gr_get_string_size( item[i].saved_text, &w1, &h1, &aw1 );
822 string_width += w1 + aw;
825 if ( item[i].type == NM_TYPE_MENU )
828 if ( item[i].type == NM_TYPE_CHECK ) {
832 gr_get_string_size( NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
833 item[i].right_offset = w1;
834 gr_get_string_size( CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
835 if (w1 > item[i].right_offset)
836 item[i].right_offset = w1;
839 if (item[i].type == NM_TYPE_RADIO ) {
843 gr_get_string_size( NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
844 item[i].right_offset = w1;
845 gr_get_string_size( CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
846 if (w1 > item[i].right_offset)
847 item[i].right_offset = w1;
850 if (item[i].type == NM_TYPE_NUMBER ) {
855 sprintf( test_text, "%d", item[i].max_value );
856 gr_get_string_size( test_text, &w1, &h1, &aw1 );
857 item[i].right_offset = w1;
858 sprintf( test_text, "%d", item[i].min_value );
859 gr_get_string_size( test_text, &w1, &h1, &aw1 );
860 if ( w1 > item[i].right_offset)
861 item[i].right_offset = w1;
864 if ( item[i].type == NM_TYPE_INPUT ) {
865 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
866 strcpy( item[i].saved_text, item[i].text );
868 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
869 if ( string_width > MAX_TEXT_WIDTH )
870 string_width = MAX_TEXT_WIDTH;
874 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
875 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
876 strcpy( item[i].saved_text, item[i].text );
878 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
883 item[i].w = string_width;
884 item[i].h = string_height;
886 if ( string_width > w )
887 w = string_width; // Save maximum width
888 if ( average_width > aw )
890 h += string_height+1; // Find the height of all strings
893 // Big hack for allowing the netgame options menu to spill over
895 MaxOnMenu = MAXDISPLAYABLEITEMS;
896 if (ExtGameStatus == GAMESTAT_NETGAME_OPTIONS || ExtGameStatus == GAMESTAT_MORE_NETGAME_OPTIONS)
899 if (!TinyMode && (h > ((MaxOnMenu+1)*(string_height+1))+(LHY(8))) ) {
901 h = (MaxOnMenu*(string_height+1)+LHY(8));
902 MaxDisplayable = MaxOnMenu;
903 mprintf((0, "Hey, this is a scroll box!\n"));
915 for (i = 0; i < nitems; i++ ) {
917 if (item[i].right_offset > right_offset )
918 right_offset = item[i].right_offset;
920 if (right_offset > 0 )
923 //gr_get_string_size( "", &string_width, &string_height, &average_width );
929 twidth = ( tw - w )/2;
938 mprintf(( 0, "Right offset = %d\n", right_offset ));
941 // Find min point of menu border
942 // x = (grd_curscreen->sc_w-w)/2;
943 // y = (grd_curscreen->sc_h-h)/2;
945 w += MenuHires?60:30;
946 h += MenuHires?60:30;
948 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
949 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
951 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
952 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
957 if ( filename != NULL ) {
958 nm_draw_background1( filename );
959 gr_palette_load(gr_palette);
962 // Save the background of the display
963 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h );
964 gr_set_current_canvas(bg.menu_canvas);
966 if ( filename == NULL ) {
967 // Save the background under the menu...
973 bg.saved = gr_create_bitmap( w, h );
974 Assert( bg.saved != NULL );
976 gr_bm_bitblt( w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
978 gr_set_current_canvas( NULL );
980 nm_draw_background(x, y, x+w-1, y+h-1);
982 gr_set_current_canvas( bg.menu_canvas );
984 bg.background = gr_create_sub_bitmap(&nm_background, 0, 0, w, h);
988 bg.background = gr_create_bitmap( w, h );
989 Assert( bg.background != NULL );
991 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
994 // ty = 15 + (yborder/4);
996 ty = MenuHires?30:15;
999 grd_curcanv->cv_font = TITLE_FONT;
1000 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1001 gr_get_string_size(title, &string_width, &string_height, &average_width );
1004 gr_printf( 0x8000, ty, title );
1009 grd_curcanv->cv_font = SUBTITLE_FONT;
1010 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1011 gr_get_string_size(subtitle, &string_width, &string_height, &average_width );
1014 gr_printf( 0x8000, ty, subtitle );
1019 grd_curcanv->cv_font = SMALL_FONT;
1021 grd_curcanv->cv_font = NORMAL_FONT;
1023 // Update all item's x & y values.
1024 for (i = 0; i < nitems; i++ ) {
1025 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1026 item[i].y += (MenuHires?30:15);
1027 if ( item[i].type == NM_TYPE_RADIO ) {
1028 fm = -1; // find first marked one
1029 for ( j = 0; j < nitems; j++ ) {
1030 if ( item[j].type == NM_TYPE_RADIO && item[j].group == item[i].group ) {
1031 if (fm == -1 && item[j].value)
1043 old_keyd_repeat = keyd_repeat;
1049 if (citem < 0 ) citem = 0;
1050 if (citem > nitems-1 ) citem = nitems-1;
1053 #ifdef NEWMENU_MOUSE
1057 while ( item[choice].type == NM_TYPE_TEXT ) {
1059 if (choice >= nitems ) {
1062 if (choice == citem ) {
1073 // Clear mouse, joystick to clear button presses.
1074 game_flush_inputs();
1076 #ifdef NEWMENU_MOUSE
1077 mouse_state = omouse_state = 0;
1078 if (filename == NULL && !MenuReordering) {
1079 //draw_close_box(0, 0);
1083 if (!MenuReordering && !joydefs_calibrating) {
1084 newmenu_show_cursor();
1086 SetCursor(LoadCursor(NULL, IDC_ARROW));
1091 mprintf((0, "Set to true!\n"));
1094 #ifdef NEWMENU_MOUSE
1095 if (!joydefs_calibrating)
1096 newmenu_show_cursor(); // possibly hidden
1097 omouse_state = mouse_state;
1098 if (!MenuReordering)
1099 mouse_state = mouse_button_state(0);
1100 //@@ mprintf((0, "mouse state:%d\n", mouse_state));
1103 // see if redbook song needs to be restarted
1104 songs_check_redbook_repeat();
1108 k = newmenu_inkey();
1111 (*subfunction)(nitems, item, &k, choice);
1114 if (!time_stopped) {
1115 // Save current menu box
1116 if (multi_menu_poll() == -1)
1122 dont_restore = (k == -3); // -3 means don't restore
1128 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
1129 if (Config_control_mouse.intval)
1130 for ( i = 0; i < 3; i++ )
1131 if (mouse_button_down_count(i) > 0)
1135 // if ( (nmenus < 2) && (k > 0) && (nothers == 0) )
1138 old_choice = choice;
1140 // More versatile menu navigation
1143 switch (item[choice].type) {
1145 case NM_TYPE_INPUT_MENU:
1155 switch (item[choice].type) {
1159 case NM_TYPE_INPUT_MENU:
1170 if (SurfingNet && !already_showing_info)
1171 show_extra_netgame_info(choice-2);
1172 if (SurfingNet && already_showing_info) {
1178 if (SurfingNet && !already_showing_info)
1179 network_request_player_names(choice-2);
1180 if (SurfingNet && already_showing_info) {
1187 if (Pauseable_menu) {
1193 case KEY_TAB + KEY_SHIFTED:
1202 LastScrollCheck = -1;
1203 mprintf((0, "Scrolling! Choice=%d\n", choice));
1205 if (choice < TopChoice) {
1210 if (choice < ScrollOffset) {
1211 for (i = 0; i < nitems; i++)
1214 mprintf((0, "ScrollOffset=%d\n", ScrollOffset));
1217 if (choice >= nitems )
1222 } while ( item[choice].type == NM_TYPE_TEXT );
1223 if ((item[choice].type == NM_TYPE_INPUT) && (choice != old_choice))
1224 item[choice].value = -1;
1225 if ((old_choice > -1) && (item[old_choice].type == NM_TYPE_INPUT_MENU) && (old_choice != choice)) {
1226 item[old_choice].group = 0;
1227 strcpy(item[old_choice].text, item[old_choice].saved_text );
1228 item[old_choice].value = -1;
1230 if (old_choice > -1)
1231 item[old_choice].redraw = 1;
1232 item[choice].redraw = 1;
1237 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1244 LastScrollCheck = -1;
1245 mprintf((0, "Scrolling! Choice=%d\n", choice));
1247 if (choice == nitems) {
1252 if (choice >= MaxOnMenu+ScrollOffset) {
1253 for (i = 0; i < nitems; i++)
1256 mprintf((0, "ScrollOffset=%d\n", ScrollOffset));
1261 if (choice >= nitems )
1265 } while ( item[choice].type == NM_TYPE_TEXT );
1267 if ((item[choice].type == NM_TYPE_INPUT) && (choice != old_choice))
1268 item[choice].value = -1;
1269 if ( (old_choice > -1) && (item[old_choice].type == NM_TYPE_INPUT_MENU) && (old_choice != choice) ) {
1270 item[old_choice].group = 0;
1271 strcpy( item[old_choice].text, item[old_choice].saved_text );
1272 item[old_choice].value = -1;
1274 if (old_choice > -1)
1275 item[old_choice].redraw = 1;
1276 item[choice].redraw = 1;
1279 if ( choice > -1 ) {
1280 switch( item[choice].type ) {
1283 case NM_TYPE_INPUT_MENU:
1286 if ( item[choice].value )
1287 item[choice].value = 0;
1289 item[choice].value = 1;
1290 mprintf((0, "ISB=%d MDI=%d SO=%d choice=%d\n", IsScrollBox, MAXDISPLAYABLEITEMS, ScrollOffset, choice));
1292 if (choice == (MaxOnMenu+ScrollOffset-1) || choice == ScrollOffset) {
1293 mprintf((0, "Special redraw!\n"));
1294 LastScrollCheck = -1;
1298 item[choice].redraw = 1;
1301 for ( i = 0; i < nitems; i++ ) {
1302 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1307 item[choice].value = 1;
1308 item[choice].redraw = 1;
1314 case KEY_SHIFTED+KEY_UP:
1315 if (MenuReordering && choice != TopChoice) {
1316 Temp = item[choice].text;
1317 TempVal = item[choice].value;
1318 item[choice].text = item[choice-1].text;
1319 item[choice].value = item[choice-1].value;
1320 item[choice-1].text = Temp;
1321 item[choice-1].value = TempVal;
1322 item[choice].redraw = 1;
1323 item[choice-1].redraw = 1;
1327 case KEY_SHIFTED+KEY_DOWN:
1328 if (MenuReordering && choice != (nitems-1)) {
1329 Temp = item[choice].text;
1330 TempVal = item[choice].value;
1331 item[choice].text = item[choice+1].text;
1332 item[choice].value = item[choice+1].value;
1333 item[choice+1].text = Temp;
1334 item[choice+1].value = TempVal;
1335 item[choice].redraw = 1;
1336 item[choice+1].redraw = 1;
1342 if ( (choice > -1) && (item[choice].type == NM_TYPE_INPUT_MENU) && (item[choice].group == 0)) {
1343 item[choice].group = 1;
1344 item[choice].redraw = 1;
1345 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1346 item[choice].text[0] = 0;
1347 item[choice].value = -1;
1349 strip_end_whitespace(item[choice].text);
1355 if ( (choice > -1) && (item[choice].type == NM_TYPE_INPUT_MENU) && (item[choice].group == 1)) {
1356 item[choice].group = 0;
1357 strcpy( item[choice].text, item[choice].saved_text );
1358 item[choice].redraw = 1;
1359 item[choice].value = -1;
1366 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
1367 case KEY_PRINT_SCREEN:
1368 MAC(newmenu_hide_cursor());
1369 save_screen_shot(0);
1370 for (i = 0; i < nitems; i++)
1373 MAC(newmenu_show_cursor());
1378 case KEY_COMMAND+KEY_RIGHT:
1379 songs_goto_next_song();
1381 case KEY_COMMAND+KEY_LEFT:
1382 songs_goto_prev_song();
1384 case KEY_COMMAND+KEY_UP:
1385 songs_play_level_song(1);
1387 case KEY_COMMAND+KEY_DOWN:
1388 songs_stop_redbook();
1391 case KEY_COMMAND+KEY_M:
1393 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1396 key_close(); // no processing of keys with keyboard handler.. jeez
1398 newmenu_hide_cursor();
1399 show_boxed_message("Mounting CD\nESC to quit");
1400 RBAMountDisk(); // OS has totaly control of the CD.
1401 if (Function_mode == FMODE_MENU)
1402 songs_play_song(SONG_TITLE, 1);
1403 else if (Function_mode == FMODE_GAME)
1404 songs_play_level_song( Current_level_num );
1405 clear_boxed_message();
1406 newmenu_show_cursor();
1412 case KEY_COMMAND+KEY_E:
1413 songs_stop_redbook();
1415 k = -1; // force key not to register
1419 case KEY_COMMAND+KEY_Q:
1420 if ( !(Game_mode & GM_MULTI) )
1422 if (!joydefs_calibrating)
1423 newmenu_show_cursor();
1424 k = -1; // force key not to register
1429 if ( (choice > -1) && (item[choice].type != NM_TYPE_INPUT) && (item[choice].type != NM_TYPE_INPUT_MENU))
1434 case KEY_SHIFTED + KEY_B:
1437 grs_canvas *canv_save = grd_curcanv;
1438 grs_canvas *temp_canv;
1441 ubyte pal_save[768];
1443 memcpy(pal_save, gr_palette, 768);
1444 gr_use_palette_table(DEFAULT_LEVEL_PALETTE);
1445 memcpy(bm_pal, gr_palette, 768);
1446 gr_copy_palette(gr_palette, pal_save, 768);
1448 if (k & KEY_SHIFTED)
1454 n = Num_bitmap_files - 1;
1455 n %= Num_bitmap_files;
1456 bm = &GameBitmaps[n];
1457 PIGGY_PAGE_IN( *(bitmap_index *)&n );
1458 con_printf(CON_DEBUG, "showing bitmap %d of %d: %s\n", n, Num_bitmap_files, piggy_game_bitmap_name(bm));
1460 temp_canv = gr_create_canvas(bm->bm_w, bm->bm_h);
1461 gr_set_current_canvas(temp_canv);
1462 gr_bitmap(0, 0, bm);
1463 gr_set_current_canvas(&grd_curscreen->sc_canvas);
1464 gr_remap_bitmap_good(&temp_canv->cv_bitmap, bm_pal, -1, -1);
1465 gr_bitmap(0, 0, &temp_canv->cv_bitmap);
1466 gr_free_canvas(temp_canv);
1467 gr_set_current_canvas(canv_save);
1472 case KEY_SHIFTED + KEY_P:
1474 char *palettes[] = {
1484 static unsigned int palnum = 0;
1486 if (k & KEY_SHIFTED)
1491 palnum %= sizeof(palettes)/sizeof(char *);
1492 load_palette(palettes[palnum], 0, 0);
1499 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1500 if ( !done && mouse_state && !omouse_state && !all_text ) {
1501 mouse_get_pos(&mx, &my);
1502 for (i = 0; i < nitems; i++ ) {
1503 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1504 x2 = x1 + item[i].w;
1505 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1506 y2 = y1 + item[i].h;
1507 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1508 if (i+ScrollOffset != choice) {
1509 if (Hack_DblClick_MenuMode)
1513 choice = i + ScrollOffset;
1515 switch( item[choice].type ) {
1517 if ( item[choice].value )
1518 item[choice].value = 0;
1520 item[choice].value = 1;
1521 item[choice].redraw = 1;
1524 LastScrollCheck = -1;
1527 if (choice == (MaxOnMenu+ScrollOffset-1) || choice == ScrollOffset) {
1528 mprintf((0, "Special redraw!\n"));
1529 LastScrollCheck = -1;
1535 for ( i = 0; i < nitems; i++ ) {
1536 if ((i != choice) && (item[i].type == NM_TYPE_RADIO) && (item[i].group == item[choice].group) && (item[i].value) ) {
1541 item[choice].value = 1;
1542 item[choice].redraw = 1;
1545 item[old_choice].redraw = 1;
1551 if (mouse_state && all_text)
1554 if ( !done && mouse_state && !all_text ) {
1555 mouse_get_pos(&mx, &my);
1557 // check possible scrollbar stuff first
1559 int arrow_width, arrow_height, aw;
1561 if (ScrollOffset != 0) {
1562 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1563 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1564 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1565 x1 = x1 - arrow_width;
1566 y2 = y1 + arrow_height;
1567 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1569 LastScrollCheck = -1;
1570 mprintf((0, "Scrolling! Choice=%d\n", choice));
1572 if (choice < ScrollOffset) {
1573 for (i = 0; i < nitems; i++)
1576 mprintf((0, "ScrollOffset=%d\n", ScrollOffset));
1580 if (ScrollOffset+MaxDisplayable < nitems) {
1581 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1582 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1583 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1584 x1 = x1 - arrow_width;
1585 y2 = y1 + arrow_height;
1586 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1588 LastScrollCheck = -1;
1589 mprintf((0, "Scrolling! Choice=%d\n", choice));
1591 if (choice >= MaxOnMenu+ScrollOffset) {
1592 for (i = 0; i < nitems; i++)
1595 mprintf((0, "ScrollOffset=%d\n", ScrollOffset));
1601 for ( i = 0; i < nitems; i++ ) {
1602 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1603 x2 = x1 + item[i].w;
1604 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1605 y2 = y1 + item[i].h;
1606 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1607 if (i+ScrollOffset != choice) {
1608 if (Hack_DblClick_MenuMode)
1612 choice = i + ScrollOffset;
1614 if ( item[choice].type == NM_TYPE_SLIDER ) {
1615 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1 = NULL;
1616 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1618 strcpy(slider_text, item[choice].saved_text);
1619 p = strchr(slider_text, '\t');
1625 gr_get_string_size(s1, &slider_width, &height, &aw);
1626 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1627 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1628 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1630 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1631 x2 = x1 + slider_width + sright_width;
1632 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1633 item[choice].value = item[choice].min_value;
1634 item[choice].redraw = 2;
1635 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1636 item[choice].value = item[choice].max_value;
1637 item[choice].redraw = 2;
1638 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1639 int num_values, value_width, new_value;
1641 num_values = item[choice].max_value - item[choice].min_value + 1;
1642 value_width = (slider_width - sleft_width - sright_width) / num_values;
1643 new_value = (mx - x1 - sleft_width) / value_width;
1644 if ( item[choice].value != new_value ) {
1645 item[choice].value = new_value;
1646 item[choice].redraw = 2;
1652 if (choice == old_choice)
1654 if ((item[choice].type == NM_TYPE_INPUT) && (choice != old_choice))
1655 item[choice].value = -1;
1656 if ((old_choice > -1) && (item[old_choice].type == NM_TYPE_INPUT_MENU) && (old_choice != choice)) {
1657 item[old_choice].group = 0;
1658 strcpy( item[old_choice].text, item[old_choice].saved_text );
1659 item[old_choice].value = -1;
1661 if (old_choice > -1)
1662 item[old_choice].redraw = 1;
1663 item[choice].redraw = 1;
1669 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1670 mouse_get_pos(&mx, &my);
1671 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1672 x2 = x1 + item[choice].w;
1673 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1674 y2 = y1 + item[choice].h;
1675 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1676 if (Hack_DblClick_MenuMode) {
1687 if ( !done && !mouse_state && omouse_state && (choice > -1) && (item[choice].type == NM_TYPE_INPUT_MENU) && (item[choice].group == 0)) {
1688 item[choice].group = 1;
1689 item[choice].redraw = 1;
1690 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1691 item[choice].text[0] = 0;
1692 item[choice].value = -1;
1694 strip_end_whitespace(item[choice].text);
1697 if ( !done && !mouse_state && omouse_state && close_box ) {
1698 mouse_get_pos(&mx, &my);
1699 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1700 x2 = x1 + CLOSE_SIZE;
1701 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1702 y2 = y1 + CLOSE_SIZE;
1703 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1709 // HACK! Don't redraw loadgame preview
1712 #endif // NEWMENU_MOUSE
1714 if ( choice > -1 ) {
1717 if ( ((item[choice].type == NM_TYPE_INPUT) || ((item[choice].type == NM_TYPE_INPUT_MENU) && (item[choice].group == 1)) ) && (old_choice == choice) ) {
1718 if ( k == KEY_LEFT || k == KEY_BACKSP || k == KEY_PAD4 ) {
1719 if (item[choice].value == -1)
1720 item[choice].value = (int)strlen(item[choice].text);
1721 if (item[choice].value > 0)
1722 item[choice].value--;
1723 item[choice].text[item[choice].value] = 0;
1724 item[choice].redraw = 1;
1726 ascii = key_to_ascii(k);
1727 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len )) {
1730 if (item[choice].value == -1)
1731 item[choice].value = 0;
1733 allowed = char_allowed(ascii);
1735 if (!allowed && (ascii == ' ') && char_allowed('_')) {
1741 item[choice].text[item[choice].value++] = ascii;
1742 item[choice].text[item[choice].value] = 0;
1743 item[choice].redraw = 1;
1747 } else if ( (item[choice].type != NM_TYPE_INPUT) && (item[choice].type != NM_TYPE_INPUT_MENU) ) {
1748 ascii = key_to_ascii(k);
1750 int choice1 = choice;
1752 ascii = toupper(ascii);
1757 if (choice1 >= nitems )
1759 for (i = 0; (ch = item[choice1].text[i]) != 0 && ch == ' '; i++);
1760 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1761 (item[choice1].type==NM_TYPE_CHECK) ||
1762 (item[choice1].type==NM_TYPE_RADIO) ||
1763 (item[choice1].type==NM_TYPE_NUMBER) ||
1764 (item[choice1].type==NM_TYPE_SLIDER) ) &&
1765 (ascii == toupper(ch)) ) {
1768 if (old_choice > -1)
1769 item[old_choice].redraw = 1;
1770 item[choice].redraw = 1;
1772 } while (choice1 != choice );
1776 if ( (item[choice].type == NM_TYPE_NUMBER) || (item[choice].type == NM_TYPE_SLIDER)) {
1777 int ov = item[choice].value;
1783 case KEY_MINUS+KEY_SHIFTED:
1785 item[choice].value -= 1;
1790 case KEY_EQUAL+KEY_SHIFTED:
1792 item[choice].value++;
1797 item[choice].value += 10;
1802 item[choice].value -= 10;
1805 if (ov != item[choice].value)
1806 item[choice].redraw = 1;
1810 gr_set_current_canvas(bg.menu_canvas);
1812 // Redraw everything...
1813 for (i = ScrollOffset; i < MaxDisplayable+ScrollOffset; i++ ) {
1814 if (item[i].redraw) { // warning! ugly hack below
1815 item[i].y -= ((string_height+1)*ScrollOffset);
1816 newmenu_hide_cursor();
1817 draw_item( &bg, &item[i], (i == choice && !all_text), TinyMode );
1819 #ifdef NEWMENU_MOUSE
1820 if (!MenuReordering && !joydefs_calibrating)
1821 newmenu_show_cursor();
1823 item[i].y += ((string_height+1)*ScrollOffset);
1825 if ((i == choice) && (item[i].type == NM_TYPE_INPUT || (item[i].type == NM_TYPE_INPUT_MENU && item[i].group)))
1826 update_cursor( &item[i] );
1831 //grd_curcanv->cv_font = NORMAL_FONT;
1833 if (LastScrollCheck != ScrollOffset) {
1834 LastScrollCheck = ScrollOffset;
1835 grd_curcanv->cv_font = SELECTED_FONT;
1837 sy = item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1838 sx = item[ScrollOffset].x-(MenuHires?24:12);
1840 if (ScrollOffset != 0)
1841 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1843 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1845 sy = item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1846 sx = item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1848 if (ScrollOffset+MaxDisplayable < nitems)
1849 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1851 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1856 if ( !dont_restore && gr_palette_faded_out )
1857 gr_palette_fade_in( gr_palette, 32, 0 );
1860 newmenu_hide_cursor();
1862 // Restore everything...
1864 gr_set_current_canvas(bg.menu_canvas);
1866 if ( filename == NULL ) {
1867 // Save the background under the menu...
1868 gr_bitmap(0, 0, bg.saved);
1869 gr_free_bitmap(bg.saved);
1870 d_free( bg.background );
1872 if (!dont_restore) // info passed back from subfunction
1873 gr_bitmap(0, 0, bg.background);
1874 gr_free_bitmap(bg.background);
1877 gr_free_sub_canvas( bg.menu_canvas );
1879 gr_set_current_canvas(save_canvas);
1880 grd_curcanv->cv_font = save_font;
1881 keyd_repeat = old_keyd_repeat;
1883 game_flush_inputs();
1893 if ( sound_stopped )
1894 digi_resume_digi_sounds();
1900 int nm_messagebox1( char *title, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int nchoices, ... )
1906 char nm_text[MESSAGEBOX_TEXT_SIZE];
1907 newmenu_item nm_message_items[5];
1909 va_start( args, nchoices );
1911 Assert( nchoices <= 5 );
1913 for ( i = 0; i < nchoices; i++ ) {
1914 s = va_arg( args, char * );
1915 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1917 format = va_arg( args, char * );
1918 strcpy( nm_text, "" );
1919 vsprintf(nm_text,format,args);
1922 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1924 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1928 int nm_messagebox( char *title, int nchoices, ... )
1934 char nm_text[MESSAGEBOX_TEXT_SIZE];
1935 newmenu_item nm_message_items[5];
1937 va_start(args, nchoices );
1939 Assert( nchoices <= 5 );
1941 for ( i = 0; i < nchoices; i++ ) {
1942 s = va_arg( args, char * );
1943 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1945 format = va_arg( args, char * );
1946 strcpy( nm_text, "" );
1947 vsprintf(nm_text, format, args);
1950 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1952 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1956 void newmenu_file_sort( int n, char *list )
1963 for (i = incr; i < n; i++ ) {
1966 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1967 memcpy( t, &list[j*14], FILENAME_LEN );
1968 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1969 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1979 void delete_player_saved_games(char *name)
1984 for (i = 0; i < 10; i++) {
1985 sprintf( filename, PLAYER_DIR "%s.sg%d", name, i );
1986 PHYSFS_delete(filename);
1991 #define MAX_FILES 300
1994 // FIXME: should maybe put globbing ability back?
1995 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
2001 int NumFiles=0, key,done, citem, ocitem;
2002 char *filenames = NULL;
2003 int NumFiles_displayed = 8;
2004 int first_item = -1, ofirst_item;
2005 int old_keyd_repeat = keyd_repeat;
2006 int player_mode = 0;
2008 int demos_deleted = 0;
2009 int initialized = 0;
2011 int w_x, w_y, w_w, w_h, title_height;
2012 int box_x, box_y, box_w, box_h;
2013 bkg bg = { NULL, NULL, NULL}; // background under listbox
2014 #ifdef NEWMENU_MOUSE
2015 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2016 int mouse2_state, omouse2_state;
2017 int dblclick_flag = 0;
2020 int show_up_arrow = 0, show_down_arrow = 0;
2024 w_x = w_y = w_w = w_h = title_height = 0;
2025 box_x = box_y = box_w = box_h = 0;
2027 filenames = d_malloc( MAX_FILES * 14 );
2028 if (filenames == NULL)
2034 if (!stricmp(type, "plr"))
2036 else if (!stricmp(type, "dem"))
2043 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2045 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2050 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
2051 for (f = find; *f != NULL; f++) {
2053 ext = strrchr(*f, '.');
2054 if (!ext || strnicmp(ext, ".plr", 4))
2057 if (NumFiles < MAX_FILES) {
2058 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
2062 p = strchr(&filenames[NumFiles*14], '.');
2071 PHYSFS_freeList(find);
2073 if ( (NumFiles < 1) && demos_deleted ) {
2077 if ( (NumFiles < 1) && demo_mode ) {
2078 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE );
2084 if ( (NumFiles < 2) && player_mode ) {
2086 goto ExitFileMenuEarly;
2090 if ( NumFiles < 1 ) {
2092 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND );
2099 // set_screen_mode(SCREEN_MENU);
2102 gr_set_current_canvas(NULL);
2104 grd_curcanv->cv_font = SUBTITLE_FONT;
2109 for ( i = 0; i < NumFiles; i++ ) {
2112 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2119 gr_get_string_size( title, &w, &h, &aw );
2122 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2126 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2128 w_w += (grd_curfont->ft_w * 4);
2129 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2131 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2132 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2134 w_x = (grd_curcanv->cv_w-w_w)/2;
2135 w_y = (grd_curcanv->cv_h-w_h)/2;
2137 if ( w_x < 0 ) w_x = 0;
2138 if ( w_y < 0 ) w_y = 0;
2140 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2141 box_y = w_y + title_height;
2143 // save the screen behind the menu.
2147 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2148 bg.background = &VR_offscreen_buffer->cv_bitmap;
2150 bg.background = gr_create_bitmap( w_w, w_h );
2152 Assert( bg.background != NULL );
2154 gr_bm_bitblt( w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2157 gr_bm_bitblt( grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2160 nm_draw_background( w_x, w_y, w_x+w_w-1, w_y+w_h-1 );
2162 gr_string( 0x8000, w_y+10, title );
2168 newmenu_file_sort( NumFiles, filenames );
2170 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2171 newmenu_file_sort( NumFiles, filenames );
2173 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2175 for ( i = 0; i < NumFiles; i++ ) {
2176 if ( !stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2177 #ifdef NEWMENU_MOUSE
2185 #ifdef NEWMENU_MOUSE
2186 mouse_state = omouse_state = 0;
2187 mouse2_state = omouse2_state = 0;
2188 //draw_close_box(w_x, w_y);
2189 newmenu_show_cursor();
2194 ofirst_item = first_item;
2197 #ifdef NEWMENU_MOUSE
2198 omouse_state = mouse_state;
2199 omouse2_state = mouse2_state;
2200 mouse_state = mouse_button_state(0);
2201 mouse2_state = mouse_button_state(1);
2204 // see if redbook song needs to be restarted
2205 songs_check_redbook_repeat();
2207 key = newmenu_inkey();
2210 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2211 case KEY_PRINT_SCREEN:
2212 MAC(newmenu_hide_cursor());
2213 save_screen_shot(0);
2215 MAC(newmenu_show_cursor());
2219 case KEY_CTRLED+KEY_D:
2220 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2224 if ( (player_mode && (citem > 0)) || (demo_mode && (citem >= 0)) ) {
2227 newmenu_hide_cursor();
2229 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2231 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2232 newmenu_show_cursor();
2236 char name[PATH_MAX];
2238 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2242 strcpy(name, demo_mode?DEMO_DIR:"");
2243 strcat(name, &filenames[citem*14]);
2250 if ( !strncmp(name, ".\\", 2) )
2251 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2252 name[i] = name[i+1];
2253 while ( (p = strchr(name, '\\')) )
2258 ret = !PHYSFS_delete(name);
2262 if ((!ret) && player_mode)
2263 delete_player_saved_games( &filenames[citem*14] );
2267 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2269 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2270 } else if (demo_mode)
2295 citem += NumFiles_displayed;
2299 citem -= NumFiles_displayed;
2303 if (allow_abort_flag) {
2313 case KEY_COMMAND+KEY_Q:
2314 if ( !(Game_mode & GM_MULTI) ) {
2318 newmenu_show_cursor();
2323 int ascii = key_to_ascii(key);
2325 if ( ascii < 255 ) {
2328 if (cc1 < 0 ) cc1 = 0;
2329 if (cc1 >= NumFiles ) cc1 = 0;
2331 if ( cc < 0 ) cc = 0;
2332 if ( cc >= NumFiles ) cc = 0;
2333 if ( citem == cc ) break;
2335 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2350 if (citem >= NumFiles)
2353 if (citem < first_item)
2356 if (citem >= (first_item+NumFiles_displayed))
2357 first_item = citem-NumFiles_displayed+1;
2360 if (NumFiles > first_item+NumFiles_displayed)
2361 show_down_arrow = 1;
2363 show_down_arrow = 0;
2371 if (NumFiles <= NumFiles_displayed)
2374 if (first_item > NumFiles-NumFiles_displayed)
2375 first_item = NumFiles-NumFiles_displayed;
2377 if (first_item < 0 )
2380 #ifdef NEWMENU_MOUSE
2381 if (mouse_state || mouse2_state) {
2384 mouse_get_pos(&mx, &my);
2385 for ( i = first_item; i < first_item+NumFiles_displayed; i++ ) {
2386 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2388 x2 = box_x + box_w - 1;
2389 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2391 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2392 if (i == citem && !mouse2_state)
2401 if (!mouse_state && omouse_state) {
2404 gr_get_string_size( &filenames[citem*14], &w, &h, &aw );
2405 mouse_get_pos(&mx, &my);
2407 x2 = box_x + box_w - 1;
2408 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2410 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2418 if ( !mouse_state && omouse_state ) {
2419 mouse_get_pos(&mx, &my);
2420 x1 = w_x + CLOSE_X + 2;
2421 x2 = x1 + CLOSE_SIZE - 2;
2422 y1 = w_y + CLOSE_Y + 2;
2423 y2 = y1 + CLOSE_SIZE - 2;
2424 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2433 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2435 y1 = box_y+box_h-LHY(7);
2437 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2443 gr_setcolor( BM_XRGB(2,2,2) );
2444 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2445 gr_setcolor( BM_XRGB( 0,0,0) );
2447 if (ofirst_item != first_item) {
2448 newmenu_hide_cursor();
2449 gr_setcolor( BM_XRGB( 0,0,0) );
2450 for (i = first_item; i < first_item+NumFiles_displayed; i++ ) {
2453 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2455 if ( i >= NumFiles ) {
2456 gr_setcolor( BM_XRGB(5,5,5) );
2457 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1 );
2458 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2 );
2460 gr_setcolor( BM_XRGB(2,2,2) );
2461 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2463 gr_setcolor( BM_XRGB(0,0,0) );
2464 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1 );
2468 grd_curcanv->cv_font = SELECTED_FONT;
2470 grd_curcanv->cv_font = NORMAL_FONT;
2471 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2473 gr_setcolor( BM_XRGB(5,5,5) );
2474 //gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2 );
2475 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1 );
2477 gr_setcolor( BM_XRGB(2,2,2) );
2478 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1 );
2479 gr_setcolor( BM_XRGB(0,0,0) );
2481 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2482 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2485 newmenu_show_cursor();
2486 } else if ( citem != ocitem ) {
2489 newmenu_hide_cursor();
2491 if ( (i >= 0) && (i < NumFiles) ) {
2492 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2494 grd_curcanv->cv_font = SELECTED_FONT;
2496 grd_curcanv->cv_font = NORMAL_FONT;
2497 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2498 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2499 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2502 if ( (i>=0) && (i<NumFiles) ) {
2503 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2505 grd_curcanv->cv_font = SELECTED_FONT;
2507 grd_curcanv->cv_font = NORMAL_FONT;
2508 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2509 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2510 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2512 newmenu_show_cursor();
2516 grd_curcanv->cv_font = NORMAL_FONT;
2518 gr_string( box_x-LHX(10), box_y, UP_ARROW_MARKER );
2521 nm_draw_background(box_x-LHX(10), box_y, box_x-2, box_y+LHY(7));
2525 if (show_down_arrow)
2526 gr_string( box_x-LHX(10), box_y+box_h-LHY(7), DOWN_ARROW_MARKER );
2529 nm_draw_background(box_x-LHX(10), box_y+box_h-LHY(7), box_x-2, box_y+box_h);
2536 MAC(newmenu_hide_cursor());
2538 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2544 keyd_repeat = old_keyd_repeat;
2546 if ( initialized ) {
2547 if (Newdemo_state != ND_STATE_PLAYBACK) // horrible hack to prevent restore when screen has been cleared
2548 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2549 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2550 gr_free_bitmap(bg.background);
2552 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2563 // Example listbox callback function...
2564 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2568 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2569 // if ( *nitems > 1 ) {
2570 // PHYSFS_delete(items[*citem]); // Delete the file
2571 // for ( i = *citem; i < *nitems-1; i++ ) {
2572 // items[i] = items[i+1];
2574 // *nitems = *nitems - 1;
2575 // d_free( items[*nitems] );
2576 // items[*nitems] = NULL;
2577 // return 1; // redraw;
2585 #define LB_ITEMS_ON_SCREEN 8
2588 int newmenu_listbox( char *title, int nitems, char *items[], int allow_abort_flag, int (*listbox_callback)( int *citem, int *nitems, char *items[], int *keypress ) )
2590 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2594 int newmenu_listbox1( char *title, int nitems, char *items[], int allow_abort_flag, int default_item, int (*listbox_callback)( int *citem, int *nitems, char *items[], int *keypress ) )
2597 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2598 int old_keyd_repeat = keyd_repeat;
2599 int width, height, wx, wy, title_height, border_size;
2600 int total_width, total_height;
2602 #ifdef NEWMENU_MOUSE
2603 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2604 int close_x, close_y;
2606 int simukey = 0, show_up_arrow = 0, show_down_arrow = 0;
2612 // set_screen_mode(SCREEN_MENU);
2615 gr_set_current_canvas(NULL);
2617 grd_curcanv->cv_font = SUBTITLE_FONT;
2620 for ( i = 0; i < nitems; i++ ) {
2623 gr_get_string_size( items[i], &w, &h, &aw );
2627 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2631 gr_get_string_size( title, &w, &h, &aw );
2634 title_height = h + 5;
2637 border_size = grd_curfont->ft_w;
2638 WIN(border_size = grd_curfont->ft_w*2);
2640 width += (grd_curfont->ft_w);
2641 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2642 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2644 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2645 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2646 if ( wy < title_height )
2649 total_width = width+2*border_size;
2650 total_height = height+2*border_size+title_height;
2654 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2655 bg.background = &VR_offscreen_buffer->cv_bitmap;
2657 //bg.background = gr_create_bitmap( width, (height + title_height) );
2658 bg.background = gr_create_bitmap(total_width, total_height);
2659 Assert( bg.background != NULL );
2661 //gr_bm_bitblt( wx+width+border_size, wy+height+border_size, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2662 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2665 gr_bm_bitblt( grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2668 nm_draw_background( wx-border_size, wy-title_height-border_size, wx+width+border_size-1, wy+height+border_size-1 );
2670 gr_string( 0x8000, wy - title_height, title );
2673 citem = default_item;
2674 if ( citem < 0 ) citem = 0;
2675 if ( citem >= nitems ) citem = 0;
2679 #ifdef NEWMENU_MOUSE
2680 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2681 close_x = wx-border_size;
2682 close_y = wy-title_height-border_size;
2683 //draw_close_box(close_x, close_y);
2684 newmenu_show_cursor();
2689 ofirst_item = first_item;
2690 #ifdef NEWMENU_MOUSE
2691 omouse_state = mouse_state;
2692 mouse_state = mouse_button_state(0);
2694 // see if redbook song needs to be restarted
2695 songs_check_redbook_repeat();
2697 key = newmenu_inkey();
2699 if ( listbox_callback )
2700 redraw = (*listbox_callback)( &citem, &nitems, items, &key );
2713 else if (simukey == 1)
2719 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2720 case KEY_PRINT_SCREEN:
2721 MAC(newmenu_hide_cursor());
2722 save_screen_shot(0);
2723 MAC(newmenu_show_cursor());
2744 citem += LB_ITEMS_ON_SCREEN;
2748 citem -= LB_ITEMS_ON_SCREEN;
2752 if (allow_abort_flag) {
2762 case KEY_COMMAND+KEY_Q:
2763 if ( !(Game_mode & GM_MULTI) )
2765 newmenu_show_cursor();
2771 int ascii = key_to_ascii(key);
2773 if ( ascii < 255 ) {
2776 if (cc1 < 0 ) cc1 = 0;
2777 if (cc1 >= nitems ) cc1 = 0;
2779 if ( cc < 0 ) cc = 0;
2780 if ( cc >= nitems ) cc = 0;
2781 if ( citem == cc ) break;
2783 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2798 if (citem >= nitems)
2801 if (citem < first_item)
2804 if (citem >= (first_item+LB_ITEMS_ON_SCREEN))
2805 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2807 if (nitems <= LB_ITEMS_ON_SCREEN)
2810 if (first_item > nitems-LB_ITEMS_ON_SCREEN)
2811 first_item = nitems-LB_ITEMS_ON_SCREEN;
2812 if (first_item < 0 )
2816 if (nitems > first_item+LB_ITEMS_ON_SCREEN)
2817 show_down_arrow = 1;
2819 show_down_arrow = 0;
2826 #ifdef NEWMENU_MOUSE
2830 mouse_get_pos(&mx, &my);
2831 for (i = first_item; i < first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2834 gr_get_string_size( items[i], &w, &h, &aw );
2837 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2839 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2851 // no double-click stuff for listbox
2852 //@@if (!mouse_state && omouse_state) {
2855 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
2856 //@@ mouse_get_pos(&mx, &my);
2858 //@@ x2 = wx + width;
2859 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
2861 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2862 //@@ if (dblclick_flag) done = 1;
2866 // check for close box clicked
2867 if ( !mouse_state && omouse_state ) {
2868 mouse_get_pos(&mx, &my);
2869 x1 = close_x + CLOSE_X + 2;
2870 x2 = x1 + CLOSE_SIZE - 2;
2871 y1 = close_y + CLOSE_Y + 2;
2872 y2 = y1 + CLOSE_SIZE - 2;
2873 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2883 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2885 y1 = total_height-LHY(7);
2887 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
2893 if ( (ofirst_item != first_item) || redraw ) {
2894 newmenu_hide_cursor();
2896 gr_setcolor( BM_XRGB(0,0,0) );
2897 for ( i = first_item; i < first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2899 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2900 if ( i >= nitems ) {
2901 gr_setcolor( BM_XRGB(0,0,0) );
2902 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
2905 grd_curcanv->cv_font = SELECTED_FONT;
2907 grd_curcanv->cv_font = NORMAL_FONT;
2908 gr_get_string_size( items[i], &w, &h, &aw );
2909 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2910 gr_string( wx+5, y, items[i] );
2914 // If Win95 port, draw up/down arrows on left side of menu
2916 grd_curcanv->cv_font = NORMAL_FONT;
2918 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
2921 nm_draw_background(wx-LHX(10), wy, wx-2, wy+LHY(7));
2925 if (show_down_arrow)
2926 gr_string( wx-LHX(10), wy+total_height-LHY(7), DOWN_ARROW_MARKER );
2929 nm_draw_background(wx-LHX(10), wy+total_height-LHY(7), wx-2, wy+total_height);
2934 newmenu_show_cursor();
2936 } else if ( citem != ocitem ) {
2939 newmenu_hide_cursor();
2942 if ( (i >= 0) && (i < nitems) ) {
2943 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2945 grd_curcanv->cv_font = SELECTED_FONT;
2947 grd_curcanv->cv_font = NORMAL_FONT;
2948 gr_get_string_size( items[i], &w, &h, &aw );
2949 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2950 gr_string( wx+5, y, items[i] );
2953 if ( (i >= 0) && (i < nitems) ) {
2954 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2956 grd_curcanv->cv_font = SELECTED_FONT;
2958 grd_curcanv->cv_font = NORMAL_FONT;
2959 gr_get_string_size( items[i], &w, &h, &aw );
2960 gr_rect( wx, y-1, wx+width-1, y+h );
2961 gr_string( wx+5, y, items[i] );
2964 newmenu_show_cursor();
2968 newmenu_hide_cursor();
2970 keyd_repeat = old_keyd_repeat;
2972 gr_bm_bitblt( total_width, total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2974 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2975 gr_free_bitmap(bg.background);
2978 gr_bm_bitblt( grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) );
2986 int newmenu_filelist( char *title, char *filespec, char *filename )
2989 char *Filenames[MAX_FILES];
2990 char FilenameText[MAX_FILES][14];
2991 FILEFINDSTRUCT find;
2994 if ( !FileFindFirst( filespec, &find ) ) {
2996 if (NumFiles<MAX_FILES) {
2997 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN );
2998 Filenames[NumFiles] = FilenameText[NumFiles];
3002 } while( !FileFindNext( &find ) );
3006 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3008 strcpy( filename, Filenames[i] );
3016 // added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3017 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3023 char nm_text[MESSAGEBOX_TEXT_SIZE];
3024 newmenu_item nm_message_items[5];
3026 va_start( args, nchoices );
3028 Assert( nchoices <= 5 );
3030 for ( i = 0; i < nchoices; i++ ) {
3031 s = va_arg( args, char * );
3032 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3034 format = va_arg( args, char * );
3035 //sprintf( nm_text, "" ); // adb: ?
3036 vsprintf(nm_text, format, args);
3039 Assert( strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3041 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3046 extern netgame_info Active_games[];
3047 extern int NumActiveNetgames;
3050 void show_extra_netgame_info(int choice)
3056 if (choice >= NumActiveNetgames)
3059 for (i = 0; i < 5; i++) {
3060 m[i].text = (char *)&mtext[i];
3061 m[i].type = NM_TYPE_TEXT;
3064 sprintf(mtext[num], "Game: %s", Active_games[choice].game_name); num++;
3065 sprintf(mtext[num], "Mission: %s", Active_games[choice].mission_title); num++;
3066 sprintf(mtext[num], "Current Level: %d", Active_games[choice].levelnum); num++;
3067 sprintf(mtext[num], "Difficulty: %s", MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3069 already_showing_info = 1;
3070 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL );
3071 already_showing_info = 0;
3076 /* Spiffy word wrap string formatting function */
3077 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3083 tbuf = (char *)d_malloc((unsigned int)strlen(sbuf) + 1);
3086 wordptr = strtok(tbuf, " ");
3087 if (!wordptr) return;
3092 col = col + (int)strlen(wordptr) + 1;
3093 if (col >=line_length) {
3095 strncat(dbuf, "\n", sizeof(dbuf)-strlen(dbuf)-1);
3097 strncat(dbuf, wordptr, sizeof(dbuf)-strlen(dbuf)-1);
3098 wordptr = strtok(NULL, " ");