]> icculus.org git repositories - taylor/freespace2.git/blob - src/menuui/credits.cpp
Various 64-bit platform fixes
[taylor/freespace2.git] / src / menuui / credits.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/MenuUI/Credits.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * C source file for displaying game credits
16  *
17  * $Log$
18  * Revision 1.9  2005/03/29 02:18:47  taylor
19  * Various 64-bit platform fixes
20  * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too
21  * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions)
22  * Streaming audio support (big thanks to Pierre Willenbrock!!)
23  * Removed dependance on strings.tbl for FS1 since we don't actually need it now
24  *
25  * Revision 1.8  2004/09/20 01:31:44  theoddone33
26  * GCC 3.4 fixes.
27  *
28  * Revision 1.7  2003/08/03 16:10:29  taylor
29  * cleanup; compile warning fixes
30  *
31  * Revision 1.6  2003/06/11 18:30:32  taylor
32  * plug memory leaks
33  *
34  * Revision 1.5  2003/05/25 02:30:42  taylor
35  * Freespace 1 support
36  *
37  * Revision 1.4  2002/06/09 04:41:22  relnev
38  * added copyright header
39  *
40  * Revision 1.3  2002/05/27 22:43:02  theoddone33
41  * Fix more glide symbols
42  *
43  * Revision 1.2  2002/05/07 03:16:46  theoddone33
44  * The Great Newline Fix
45  *
46  * Revision 1.1.1.1  2002/05/03 03:28:09  root
47  * Initial import.
48  *
49  * 
50  * 20    9/14/99 5:14a Dave
51  * Fixed credits drawing in Glide.
52  * 
53  * 19    9/13/99 1:53p Dave
54  * Fixed completely brain dead code in credits_init().
55  * 
56  * 18    9/09/99 10:55a Jefff
57  * 
58  * 17    9/03/99 11:45a Jefff
59  * 
60  * 16    9/01/99 5:28p Jefff
61  * hi res art shows up now
62  * 
63  * 15    9/01/99 4:20p Jefff
64  * mo' pictures
65  * 
66  * 14    9/01/99 12:19p Jefff
67  * text splitting for long lines
68  * 
69  * 13    7/19/99 2:13p Dave
70  * Added some new strings for Heiko.
71  * 
72  * 12    2/03/99 6:06p Dave
73  * Groundwork for FS2 PXO usertracker support.  Gametracker support next.
74  * 
75  * 11    2/03/99 11:44a Dave
76  * Fixed d3d transparent textures.
77  * 
78  * 10    2/01/99 5:55p Dave
79  * Removed the idea of explicit bitmaps for buttons. Fixed text
80  * highlighting for disabled gadgets.
81  * 
82  * 9     1/30/99 9:01p Dave
83  * Coord fixes.
84  * 
85  * 8     1/30/99 5:08p Dave
86  * More new hi-res stuff.Support for nice D3D textures.
87  * 
88  * 7     1/29/99 12:47a Dave
89  * Put in sounds for beam weapon. A bunch of interface screens (tech
90  * database stuff).
91  * 
92  * 6     1/28/99 1:46a Dave
93  * Updated coords and bitmaps.
94  * 
95  * 5     1/14/99 5:15p Neilk
96  * changed credits, command debrief interfaces to high resolution support
97  * 
98  * 4     11/20/98 4:08p Dave
99  * Fixed flak effect in multiplayer.
100  * 
101  * 3     10/13/98 9:28a Dave
102  * Started neatening up freespace.h. Many variables renamed and
103  * reorganized. Added AlphaColors.[h,cpp]
104  * 
105  * 2     10/07/98 10:53a Dave
106  * Initial checkin.
107  * 
108  * 1     10/07/98 10:49a Dave
109  * 
110  * 18    6/19/98 3:51p Lawrance
111  * deal with foreign chars in the credits
112  * 
113  * 17    6/01/98 11:43a John
114  * JAS & MK:  Classified all strings for localization.
115  * 
116  * 16    5/24/98 9:01p Lawrance
117  * Add commit sounds when accept is pressed
118  * 
119  * 15    5/20/98 1:04p Hoffoss
120  * Made credits screen use new artwork and removed rating field usage from
121  * Fred (a goal struct member).
122  * 
123  * 14    5/12/98 4:17p Hoffoss
124  * Make ctrl-arrows (up/down) switch between tech room screens.
125  * 
126  * 13    5/12/98 11:21a Hoffoss
127  * Disabled cutscene screen and simulator room.
128  * 
129  * 12    5/11/98 8:04p Hoffoss
130  * Fixed minor bugs.
131  * 
132  * 11    4/22/98 3:35p John
133  * String externalization marking
134  * 
135  * 10    4/22/98 10:46a Hoffoss
136  * Added images to credits screen.
137  * 
138  * 9     4/21/98 7:07p Hoffoss
139  * Fixed problem where when switching screens flashes old tab hilight once
140  * before switching to new state.
141  * 
142  * 8     4/17/98 3:28p Hoffoss
143  * Added new credits screen code.
144  * 
145  * 7     3/05/98 11:15p Hoffoss
146  * Changed non-game key checking to use game_check_key() instead of
147  * game_poll().
148  * 
149  * 6     2/22/98 12:19p John
150  * Externalized some strings
151  * 
152  * 5     1/05/98 2:30p John
153  * made credits.tbl display
154  * 
155  * 4     9/19/97 5:14p Lawrance
156  * use new naming convention for spooled music
157  * 
158  * 3     8/31/97 6:38p Lawrance
159  * pass in frametime to do_frame loop
160  * 
161  * 2     4/22/97 11:06a Lawrance
162  * credits music playing, credits screen is a separate state
163  *
164  * $NoKeywords: $
165  */
166
167 #include <stdlib.h>
168
169 #include "gamesequence.h"
170 #include "font.h"
171 #include "key.h"
172 #include "bmpman.h"
173 #include "2d.h"
174 #include "timer.h"
175 #include "gamesnd.h"
176 #include "audiostr.h"
177 #include "eventmusic.h" /* for Master_event_music_volume */
178 #include "cfile.h"
179 #include "ui.h"
180 #include "missionscreencommon.h"
181 #include "player.h"
182 #include "freespace.h"
183 #include "alphacolors.h"
184 #include "localize.h"
185
186 #define CREDITS_MUSIC_DELAY     2000
187 #define CREDITS_SCROLL_RATE     15.0f
188 #define CREDITS_ARTWORK_DISPLAY_TIME    9.0f
189 #define CREDITS_ARTWORK_FADE_TIME               1.0f
190
191 #define NUM_BUTTONS                             5
192 #define NUM_IMAGES                              46
193
194 #define TECH_DATABASE_BUTTON    0
195 #define SIMULATOR_BUTTON                1
196 #define CUTSCENES_BUTTON                2
197 #define CREDITS_BUTTON                  3
198 #define EXIT_BUTTON                             4
199
200 // inidicies for coordinates
201 #define CREDITS_X_COORD 0
202 #define CREDITS_Y_COORD 1
203 #define CREDITS_W_COORD 2
204 #define CREDITS_H_COORD 3
205
206 static char* Credits_bitmap_fname[GR_NUM_RESOLUTIONS] = {
207         "Credits",                      // GR_640
208         "2_Credits"
209 };
210
211 static char* Credits_bitmap_mask_fname[GR_NUM_RESOLUTIONS] = {
212         "Credits-M",                    // GR_640
213         "2_Credits-M"
214 };
215
216 int Credits_image_coords[GR_NUM_RESOLUTIONS][4] = {
217         {
218 #ifdef MAKE_FS1
219                 225, 15, 400, 292
220 #else
221                 219, 15, 394, 286                       // GR_640
222 #endif
223         },
224         {
225                 351, 25, 629, 455                       // GR_1024
226         }
227 };
228
229 // x, y, w, h
230 int Credits_text_coords[GR_NUM_RESOLUTIONS][4] = {
231         {
232 #ifdef MAKE_FS1
233                 46, 321, 450, 134
234 #else
235                 26, 316, 482, 157                       // GR_640
236 #endif
237         },
238         {
239                 144, 507, 568, 249                      // GR_640
240         }
241 };
242
243 struct credits_screen_buttons {
244         char *filename;
245         int x, y, xt, yt;
246         int hotspot;
247         UI_BUTTON button;  // because we have a class inside this struct, we need the constructor below..
248
249         credits_screen_buttons(char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
250 };
251
252 static int Background_bitmap;
253 #ifdef MAKE_FS1
254 static int CreditsWin01 = -1;
255 static int CreditsWin02 = -1;
256 static int CreditsWin03 = -1;
257 static int CreditsWin04 = -1;
258 #endif
259
260 static UI_WINDOW Ui_window;
261
262 static credits_screen_buttons Buttons[NUM_BUTTONS][GR_NUM_RESOLUTIONS] = {
263 //XSTR:OFF
264 #ifdef MAKE_FS1
265     {
266                         credits_screen_buttons("TDB_00", 0, 0, -1, -1, 0),              // GR_640
267                         credits_screen_buttons("2_TDB_00", 12, 5, 59, 12, 0)            // GR_1024
268     },
269     {
270                         credits_screen_buttons("TDB_01", 0, 19, -1, -1, 1),             // GR_640
271                         credits_screen_buttons("2_TDB_01", 12, 31, 59, 37, 1)           // GR_1024
272     },
273     {
274                         credits_screen_buttons("TDB_02", 0, 35, -1, -1, 2),             // GR_640
275                         credits_screen_buttons("2_TDB_02", 12, 56, 59, 62, 2)           // GR_1024
276     },
277     {
278                         credits_screen_buttons("TDB_03", 0, 56, -1, -1, 3),             // GR_640
279                         credits_screen_buttons("2_TDB_03", 12, 81, 59, 88, 3)           // GR_1024
280     },
281     {
282                         credits_screen_buttons("CRB_04", 561, 411, -1, -1, 4),  // GR_640
283                         credits_screen_buttons("2_CRB_04", 914, 681, 953, 68, 4)        // GR_1024
284     }
285 #else
286         {
287                         credits_screen_buttons("TDB_00", 7, 3, 37, 7, 0),                       // GR_640
288                         credits_screen_buttons("2_TDB_00", 12, 5, 59, 12, 0)                    // GR_1024
289         },
290         {
291                         credits_screen_buttons("TDB_01", 7, 18, 37, 23, 1),             // GR_640
292                         credits_screen_buttons("2_TDB_01", 12, 31, 59, 37, 1)           // GR_1024
293         },
294         {
295                         credits_screen_buttons("TDB_02", 7, 34, 37, 38, 2),             // GR_640
296                         credits_screen_buttons("2_TDB_02", 12, 56, 59, 62, 2)           // GR_1024
297         },
298         {
299                         credits_screen_buttons("TDB_03", 7, 49, 37, 54, 3),             // GR_640
300                         credits_screen_buttons("2_TDB_03", 12, 81, 59, 88, 3)           // GR_1024
301         },
302         {
303                         credits_screen_buttons("CRB_04", 571, 425, 588, 413, 4),        // GR_640
304                         credits_screen_buttons("2_CRB_04", 914, 681, 953, 668, 4)       // GR_1024
305         }
306 #endif
307 //XSTR:ON
308 };
309
310 static int      Credits_music_handle = -1;
311 static int      Credits_music_begin_timestamp;
312
313 static int      Credits_frametime;              // frametime of credits_do_frame() loop in ms
314 static int      Credits_last_time;              // timestamp used to calc frametime (in ms)
315 static float Credits_counter;
316 static int Credits_artwork_index;
317 static int Credits_bmps[NUM_IMAGES];
318
319 char *Credit_text = NULL;
320 int Credit_text_malloced = 0;                   // TRUE if credit_text was malloced
321
322 // Positions for credits...
323 float Credit_start_pos, Credit_stop_pos, Credit_position = 0.0f;
324
325 void credits_stop_music()
326 {
327         if ( Credits_music_handle != -1 ) {
328                 audiostream_close_file(Credits_music_handle);
329                 Credits_music_handle = -1;
330         }
331 }
332
333 void credits_load_music(char* fname)
334 {
335         if ( Credits_music_handle != -1 ){
336                 return;
337         }
338
339         if ( fname ){
340                 Credits_music_handle = audiostream_open( fname, ASF_EVENTMUSIC );
341         }
342 }
343
344 void credits_start_music()
345 {
346         if (Credits_music_handle != -1) {
347                 if ( !audiostream_is_playing(Credits_music_handle) ){
348                         audiostream_play(Credits_music_handle, Master_event_music_volume);
349                 }
350         } else {
351                 nprintf(("Warning", "Cannot play credits music\n"));
352         }
353 }
354
355 int credits_screen_button_pressed(int n)
356 {
357         switch (n) {
358         case TECH_DATABASE_BUTTON:
359                 gamesnd_play_iface(SND_SWITCH_SCREENS);
360                 gameseq_post_event(GS_EVENT_TECH_MENU);
361                 return 1;
362
363         case SIMULATOR_BUTTON:
364                 gamesnd_play_iface(SND_SWITCH_SCREENS);
365                 gameseq_post_event(GS_EVENT_SIMULATOR_ROOM);
366                 return 1;
367
368         case CUTSCENES_BUTTON:
369                 gamesnd_play_iface(SND_SWITCH_SCREENS);
370                 gameseq_post_event(GS_EVENT_GOTO_VIEW_CUTSCENES_SCREEN);
371                 return 1;
372
373         case EXIT_BUTTON:
374                 gamesnd_play_iface(SND_COMMIT_PRESSED);
375                 gameseq_post_event(GS_EVENT_MAIN_MENU);
376                 game_flush();
377                 break;
378         }
379
380         return 0;
381 }
382
383 void credits_init()
384 {
385         int i, w, h;
386         credits_screen_buttons *b;
387         char line[512] = "";    
388         char *linep1, *linep2;  
389
390         int credits_spooled_music_index = event_music_get_spooled_music_index("Cinema");        
391         if(credits_spooled_music_index != -1){
392                 char *credits_wavfile_name = Spooled_music[credits_spooled_music_index].filename;               
393                 if(credits_wavfile_name != NULL){
394                         credits_load_music(credits_wavfile_name);
395                 }
396         }
397
398         // Use this id to trigger the start of music playing on the briefing screen
399         Credits_music_begin_timestamp = timestamp(CREDITS_MUSIC_DELAY);
400
401         Credits_frametime = 0;
402         Credits_last_time = timer_get_milliseconds();
403
404         Credit_text = NULL;
405         Credit_text_malloced = 0;
406
407         // allocate enough space for credits text
408         CFILE *fp = cfopen( NOX("credits.tbl"), "rb" );
409         if(fp != NULL){
410                 int size;
411                 size = cfilelength(fp);
412                 Credit_text = (char *) malloc(size + 200);
413                 Credit_text_malloced = 1;
414                 cfclose(fp);
415
416                 // open localization and parse
417                 lcl_ext_open();
418                 read_file_text("credits.tbl");
419                 reset_parse();
420
421                 // keep reading everything in
422                 strcpy(Credit_text,"");         
423 #ifndef MAKE_FS1
424                 while(!check_for_string_raw("#end")){
425 #else
426                 char *ugh = Mp;
427                 char ch;
428                 int line_count = 0;
429
430                 // get the line count, probably a crappy way to do it but it's the best way i've
431                 // found to step through the credits without crashing problems since there's no
432                 // definite end line in FS1
433                 while (*ugh && *ugh != EOF_CHAR) {
434                         ch = *ugh;
435
436                         if (ch == '\n'){
437                                 line_count++;
438                         }
439                         ugh++;
440                 }
441
442                 while(line_count > 0){
443                         line_count--;
444 #endif
445                         stuff_string_line(line, 511);
446                         linep1 = line;
447
448                         do {
449                                 linep2 = split_str_once(linep1, Credits_text_coords[gr_screen.res][2]);
450                                 strcat(Credit_text, linep1);
451                                 strcat(Credit_text, "\n");                      
452                                 linep1 = linep2;
453                         } while (linep2 != NULL);
454                 }               
455
456                 // close localization
457                 lcl_ext_close();        
458         } else {
459                 Credit_text = NOX("No credits available.\n");
460         }       
461
462         int ch;
463         for ( i = 0; Credit_text[i]; i++ ) {
464                         ch = Credit_text[i];
465                         switch (ch) {
466                         case -4:
467                                 ch = 129;
468                                 break;
469
470                         case -28:
471                                 ch = 132;
472                                 break;
473
474                         case -10:
475                                 ch = 148;
476                                 break;
477
478                         case -23:
479                                 ch = 130;
480                                 break;
481
482                         case -30:
483                                 ch = 131;
484                                 break;
485
486                         case -25:
487                                 ch = 135;
488                                 break;
489
490                         case -21:
491                                 ch = 137;
492                                 break;
493
494                         case -24:
495                                 ch = 138;
496                                 break;
497
498                         case -17:
499                                 ch = 139;
500                                 break;
501
502                         case -18:
503                                 ch = 140;
504                                 break;
505
506                         case -60:
507                                 ch = 142;
508                                 break;
509
510                         case -55:
511                                 ch = 144;
512                                 break;
513
514                         case -12:
515                                 ch = 147;
516                                 break;
517
518                         case -14:
519                                 ch = 149;
520                                 break;
521
522                         case -5:
523                                 ch = 150;
524                                 break;
525
526                         case -7:
527                                 ch = 151;
528                                 break;
529
530                         case -42:
531                                 ch = 153;
532                                 break;
533
534                         case -36:
535                                 ch = 154;
536                                 break;
537
538                         case -31:
539                                 ch = 160;
540                                 break;
541
542                         case -19:
543                                 ch = 161;
544                                 break;
545
546                         case -13:
547                                 ch = 162;
548                                 break;
549
550                         case -6:
551                                 ch = 163;
552                                 break;
553
554                         case -32:
555                                 ch = 133;
556                                 break;
557
558                         case -22:
559                                 ch = 136;
560                                 break;
561
562                         case -20:
563                                 ch = 141;
564                                 break;
565                         }
566                         Credit_text[i] = (char)ch;
567         }
568
569         gr_get_string_size(&w, &h, Credit_text);
570
571         Credit_start_pos = i2fl(Credits_text_coords[gr_screen.res][CREDITS_H_COORD]);
572         Credit_stop_pos = -i2fl(h);
573         Credit_position = Credit_start_pos;
574
575         Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
576         Ui_window.set_mask_bmap(Credits_bitmap_mask_fname[gr_screen.res]);
577         common_set_interface_palette("InterfacePalette");  // set the interface palette
578
579         for (i=0; i<NUM_BUTTONS; i++) {
580                 b = &Buttons[i][gr_screen.res];
581
582                 b->button.create(&Ui_window, "", b->x, b->y, 60, 30, (i < 2), 1);
583                 // set up callback for when a mouse first goes over a button
584                 b->button.set_highlight_action(common_play_highlight_sound);
585                 b->button.set_bmaps(b->filename);
586                 b->button.link_hotspot(b->hotspot);
587         }
588
589 #ifndef MAKE_FS1
590         // add some text
591         Ui_window.add_XSTR("Technical Database", 1055, Buttons[TECH_DATABASE_BUTTON][gr_screen.res].xt,  Buttons[TECH_DATABASE_BUTTON][gr_screen.res].yt, &Buttons[TECH_DATABASE_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_GREEN);
592         Ui_window.add_XSTR("Mission Simulator", 1056, Buttons[SIMULATOR_BUTTON][gr_screen.res].xt,  Buttons[SIMULATOR_BUTTON][gr_screen.res].yt, &Buttons[SIMULATOR_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_GREEN);
593         Ui_window.add_XSTR("Cutscenes", 1057, Buttons[CUTSCENES_BUTTON][gr_screen.res].xt,  Buttons[CUTSCENES_BUTTON][gr_screen.res].yt, &Buttons[CUTSCENES_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_GREEN);
594         Ui_window.add_XSTR("Credits", 1058, Buttons[CREDITS_BUTTON][gr_screen.res].xt,  Buttons[CREDITS_BUTTON][gr_screen.res].yt, &Buttons[CREDITS_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_GREEN);
595         Ui_window.add_XSTR("Exit", 1420, Buttons[EXIT_BUTTON][gr_screen.res].xt,  Buttons[EXIT_BUTTON][gr_screen.res].yt, &Buttons[EXIT_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_PINK);
596 #endif
597
598         if (Player->flags & PLAYER_FLAGS_IS_MULTI) {
599                 Buttons[SIMULATOR_BUTTON][gr_screen.res].button.disable();
600                 Buttons[CUTSCENES_BUTTON][gr_screen.res].button.disable();
601         }
602
603         Buttons[EXIT_BUTTON][gr_screen.res].button.set_hotkey(KEY_CTRLED | KEY_ENTER);
604
605         Background_bitmap = bm_load(Credits_bitmap_fname[gr_screen.res]);
606         Credits_artwork_index = rand() % NUM_IMAGES;
607         for (i=0; i<NUM_IMAGES; i++){
608                 Credits_bmps[i] = -1;
609         }
610
611 #ifdef MAKE_FS1
612         CreditsWin01 = bm_load(NOX("CreditsWin01"));
613         CreditsWin02 = bm_load(NOX("CreditsWin02"));
614         CreditsWin03 = bm_load(NOX("CreditsWin03"));
615         CreditsWin04 = bm_load(NOX("CreditsWin04"));
616 #endif
617 }
618
619 void credits_close()
620 {       
621         int i;
622
623 #ifdef MAKE_FS1
624         if (CreditsWin01 != -1){
625                 bm_unload(CreditsWin01);
626                 CreditsWin01 = -1;
627         }
628         if (CreditsWin02 != -1){
629                 bm_unload(CreditsWin02);
630                 CreditsWin02 = -1;
631         }
632         if (CreditsWin03 != -1){
633                 bm_unload(CreditsWin03);
634                 CreditsWin03 = -1;
635         }
636         if (CreditsWin04 != -1){
637                 bm_unload(CreditsWin04);
638                 CreditsWin04 = -1;
639         }
640 #endif
641
642         for (i=0; i<NUM_IMAGES; i++){
643                 if (Credits_bmps[i] >= 0){
644                         bm_unload(Credits_bmps[i]);
645                         Credits_bmps[i] = -1;
646                 }
647         }       
648
649         credits_stop_music();
650
651         if (Credit_text) {
652                 if (Credit_text_malloced){
653                         free(Credit_text);
654                 }
655
656                 Credit_text = NULL;
657         }
658
659         if (Background_bitmap){
660                 bm_unload(Background_bitmap);
661         }
662
663         Ui_window.destroy();
664         common_free_interface_palette();                // restore game palette
665 }
666
667 void credits_do_frame(float frametime)
668 {
669         int i, k, next, percent, bm1, bm2;
670         int bx1, by1, bw1, bh1;
671         int bx2, by2, bw2, bh2;
672
673         // Use this id to trigger the start of music playing on the credits screen
674         if ( timestamp_elapsed(Credits_music_begin_timestamp) ) {
675                 Credits_music_begin_timestamp = 0;
676                 credits_start_music();
677         }
678
679         k = Ui_window.process();
680         switch (k) {
681         case KEY_ESC:
682                 gameseq_post_event(GS_EVENT_MAIN_MENU);
683                 key_flush();
684                 break;
685
686         case KEY_CTRLED | KEY_UP:
687         case KEY_SHIFTED | KEY_TAB:
688                 if ( !(Player->flags & PLAYER_FLAGS_IS_MULTI) ) {
689                         credits_screen_button_pressed(CUTSCENES_BUTTON);
690                         break;
691                 }
692                 // else, react like tab key.
693
694         case KEY_CTRLED | KEY_DOWN:
695         case KEY_TAB:
696                 credits_screen_button_pressed(TECH_DATABASE_BUTTON);
697                 break;
698
699         default:
700                 break;
701         } // end switch
702
703         for (i=0; i<NUM_BUTTONS; i++){
704                 if (Buttons[i][gr_screen.res].button.pressed()){
705                         if (credits_screen_button_pressed(i)){
706                                 return;
707                         }
708                 }
709         }
710
711         gr_reset_clip();        
712         GR_MAYBE_CLEAR_RES(Background_bitmap);
713         if (Background_bitmap >= 0) {
714                 gr_set_bitmap(Background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
715                 gr_bitmap(0, 0);
716         } 
717
718         percent = (int) (100.0f - (CREDITS_ARTWORK_DISPLAY_TIME - Credits_counter) * 100.0f / CREDITS_ARTWORK_FADE_TIME);
719         if (percent < 0){
720                 percent = 0;
721         }
722
723         next = Credits_artwork_index + 1;
724         if (next >= NUM_IMAGES){
725                 next = 0;
726         }
727
728         if (Credits_bmps[Credits_artwork_index] < 0) {
729                 char buf[40];
730
731                 if (gr_screen.res == GR_1024) {
732                         sprintf(buf, NOX("2_CrIm%.2d"), Credits_artwork_index);
733                 } else {
734                         sprintf(buf, NOX("CrIm%.2d"), Credits_artwork_index);
735                 }
736                 Credits_bmps[Credits_artwork_index] = bm_load(buf);
737         }
738
739         if (Credits_bmps[next] < 0) {
740                 char buf[40];
741
742                 if (gr_screen.res == GR_1024) {
743                         sprintf(buf, NOX("2_CrIm%.2d"), Credits_artwork_index);
744                 } else {
745                         sprintf(buf, NOX("CrIm%.2d"), next);
746                 }
747                 Credits_bmps[next] = bm_load(buf);
748         }
749
750         bm1 = Credits_bmps[Credits_artwork_index];
751         bm2 = Credits_bmps[next];
752
753         if((bm1 != -1) && (bm2 != -1)){
754                 Assert(percent >= 0 && percent <= 100);
755
756                 // get width and height
757                 bm_get_info(bm1, &bw1, &bh1, NULL, NULL, NULL); 
758                 bm_get_info(bm2, &bw2, &bh2, NULL, NULL, NULL); 
759         
760                 // determine where to draw the coords
761                 bx1 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw1)/2);
762                 by1 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh1)/2);
763                 bx2 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw2)/2);
764                 by2 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh2)/2);
765
766                 gr_cross_fade(bm1, bm2, bx1, by1, bx2, by2, (float)percent / 100.0f);
767         }
768
769 #ifdef MAKE_FS1
770         if (CreditsWin01 != -1) {
771                 gr_set_bitmap(CreditsWin01, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
772                 gr_bitmap(233, 5);
773         }
774
775         if (CreditsWin02 != -1) {
776                 gr_set_bitmap(CreditsWin02, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
777                 gr_bitmap(616, 8);
778         }
779
780         if (CreditsWin03 != -1) {
781                 gr_set_bitmap(CreditsWin03, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
782                 gr_bitmap(233, 299);
783         }
784
785         if (CreditsWin04 != -1) {
786                 gr_set_bitmap(CreditsWin04, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
787                 gr_bitmap(215, 8);
788         }
789 #endif
790
791         Ui_window.draw();
792
793         for (i=TECH_DATABASE_BUTTON; i<=CREDITS_BUTTON; i++){
794                 if (Buttons[i][gr_screen.res].button.button_down()){
795                         break;
796                 }
797         }
798
799         if (i > CREDITS_BUTTON){
800                 Buttons[CREDITS_BUTTON][gr_screen.res].button.draw_forced(2);
801         }
802
803         gr_set_clip(Credits_text_coords[gr_screen.res][CREDITS_X_COORD], Credits_text_coords[gr_screen.res][CREDITS_Y_COORD], Credits_text_coords[gr_screen.res][CREDITS_W_COORD], Credits_text_coords[gr_screen.res][CREDITS_H_COORD]);
804         gr_set_font(FONT1);
805         gr_set_color_fast(&Color_normal);
806
807         int sy;
808         if ( Credit_position > 0 ) {
809                 sy = fl2i(Credit_position+0.5f);
810         } else {
811                 sy = fl2i(Credit_position-0.5f);
812         }
813
814         // HACK - I don't want to change the string code, so we'll just use a special version here
815         if(gr_screen.mode == GR_GLIDE){
816 #ifndef PLAT_UNIX
817                 extern void gr_glide_string_hack(int sx, int sy, char *s);
818                 gr_glide_string_hack(0x8000, sy, Credit_text);
819 #endif
820         } else {
821                 gr_string(0x8000, sy, Credit_text);
822         }
823
824         int temp_time;
825         temp_time = timer_get_milliseconds();
826
827         Credits_frametime = temp_time - Credits_last_time;
828         Credits_last_time = temp_time;
829         timestamp_inc(Credits_frametime / 1000.0f);
830
831         float fl_frametime = i2fl(Credits_frametime) / 1000.f;
832         if (keyd_pressed[KEY_LSHIFT]) {
833                 Credit_position -= fl_frametime * CREDITS_SCROLL_RATE * 4.0f;
834         } else {
835                 Credit_position -= fl_frametime * CREDITS_SCROLL_RATE;
836         }
837
838         if (Credit_position < Credit_stop_pos){
839                 Credit_position = Credit_start_pos;
840         }
841
842         Credits_counter += fl_frametime;
843         while (Credits_counter >= CREDITS_ARTWORK_DISPLAY_TIME) {
844                 Credits_counter -= CREDITS_ARTWORK_DISPLAY_TIME;
845                 Credits_artwork_index = next;
846         }
847
848         gr_flip();
849 }
850