Make the scores menu into a window

This commit is contained in:
kreatordxx 2010-02-07 06:00:10 +00:00
parent afa0d75fb6
commit ff1c8547f3
2 changed files with 120 additions and 91 deletions

View file

@ -3,6 +3,7 @@ D2X-Rebirth Changelog
20100207 20100207
-------- --------
main/game.c, main/gameseq.c, main/inferno.c, main/inferno.h, main/menu.c, main/newdemo.c: Create the main event loop and use it for the game and main menu main/game.c, main/gameseq.c, main/inferno.c, main/inferno.h, main/menu.c, main/newdemo.c: Create the main event loop and use it for the game and main menu
main/scores.c: Make the scores menu into a window
20100206 20100206
-------- --------

View file

@ -25,6 +25,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "scores.h" #include "scores.h"
#include "error.h" #include "error.h"
#include "pstypes.h" #include "pstypes.h"
#include "window.h"
#include "gr.h" #include "gr.h"
#include "key.h" #include "key.h"
#include "palette.h" #include "palette.h"
@ -327,107 +328,134 @@ void scores_draw_item( int i, stats_info * stats )
} }
} }
void scores_view(int citem) typedef struct scores_menu
{ {
int citem;
fix t1; fix t1;
int i,done,looper; int looper;
} scores_menu;
int scores_handler(window *wind, d_event *event, scores_menu *menu)
{
int i;
int k; int k;
sbyte fades[64] = { 1,1,1,2,2,3,4,4,5,6,8,9,10,12,13,15,16,17,19,20,22,23,24,26,27,28,28,29,30,30,31,31,31,31,31,30,30,29,28,28,27,26,24,23,22,20,19,17,16,15,13,12,10,9,8,6,5,4,4,3,2,2,1,1 }; sbyte fades[64] = { 1,1,1,2,2,3,4,4,5,6,8,9,10,12,13,15,16,17,19,20,22,23,24,26,27,28,28,29,30,30,31,31,31,31,31,30,30,29,28,28,27,26,24,23,22,20,19,17,16,15,13,12,10,9,8,6,5,4,4,3,2,2,1,1 };
grs_canvas canvas;
int w = FSPACX(290), h = FSPACY(170); int w = FSPACX(290), h = FSPACY(170);
gr_palette_load( gr_palette ); switch (event->type)
{
case EVENT_KEY_COMMAND:
k = ((d_event_keycommand *)event)->keycode;
switch( k ) {
case KEY_CTRLED+KEY_R:
if ( menu->citem < 0 ) {
// Reset scores...
if ( nm_messagebox( NULL, 2, TXT_NO, TXT_YES, TXT_RESET_HIGH_SCORES )==1 ) {
PHYSFS_delete(get_scores_filename());
scores_view(menu->citem); // create new scores window
window_close(wind); // then remove the old one
}
}
break;
case KEY_BACKSP: Int3(); k = 0; break;
case KEY_PRINT_SCREEN: save_screen_shot(0); k = 0; break;
case KEY_ENTER:
case KEY_SPACEBAR:
case KEY_ESC:
window_close(wind);
break;
}
break;
case EVENT_IDLE:
timer_delay2(50);
//see if redbook song needs to be restarted
RBACheckFinishedHook();
break;
case EVENT_WINDOW_DRAW:
gr_set_current_canvas(NULL);
#ifdef OGL
nm_draw_background1(Menu_pcx_name);
#endif
nm_draw_background(((SWIDTH-w)/2)-BORDERX,((SHEIGHT-h)/2)-BORDERY,((SWIDTH-w)/2)+w+BORDERX,((SHEIGHT-h)/2)+h+BORDERY);
gr_set_current_canvas(window_get_canvas(wind));
grd_curcanv->cv_font = MEDIUM3_FONT;
gr_string( 0x8000, FSPACY(15), TXT_HIGH_SCORES );
grd_curcanv->cv_font = GAME_FONT;
gr_set_fontcolor( BM_XRGB(31,26,5), -1 );
gr_string( FSPACX( 71), FSPACY(50), TXT_NAME );
gr_string( FSPACX(122), FSPACY(50), TXT_SCORE );
gr_string( FSPACX(167), FSPACY(50), TXT_SKILL );
gr_string( FSPACX(210), FSPACY(50), TXT_LEVELS );
gr_string( FSPACX(253), FSPACY(50), TXT_TIME );
if ( menu->citem < 0 )
gr_string( 0x8000, FSPACY(175), TXT_PRESS_CTRL_R );
gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
gr_printf( 0x8000, FSPACY(31), "%c%s%c - %s", 34, Scores.cool_saying, 34, Scores.stats[0].name );
for (i=0; i<MAX_HIGH_SCORES; i++ ) {
gr_set_fontcolor( BM_XRGB(28-i*2,28-i*2,28-i*2), -1 );
scores_draw_item( i, &Scores.stats[i] );
}
if ( menu->citem > -1 ) {
gr_set_fontcolor( BM_XRGB(7+fades[menu->looper],7+fades[menu->looper],7+fades[menu->looper]), -1 );
if (timer_get_fixed_seconds() >= menu->t1+F1_0/128)
{
menu->t1 = timer_get_fixed_seconds();
menu->looper++;
if (menu->looper>63) menu->looper=0;
}
if ( menu->citem == MAX_HIGH_SCORES )
scores_draw_item( MAX_HIGH_SCORES, &Last_game );
else
scores_draw_item( menu->citem, &Scores.stats[menu->citem] );
}
gr_set_current_canvas(NULL);
break;
case EVENT_WINDOW_CLOSE:
d_free(menu);
break;
default:
break;
}
return 0;
}
void scores_view(int citem)
{
scores_menu *menu;
MALLOC(menu, scores_menu, 1);
if (!menu)
return;
menu->citem = citem;
menu->t1 = timer_get_fixed_seconds();
menu->looper = 0;
newmenu_close(); newmenu_close();
ReshowScores:
scores_read(); scores_read();
set_screen_mode(SCREEN_MENU); set_screen_mode(SCREEN_MENU);
gr_set_current_canvas(NULL);
gr_init_sub_canvas(&canvas, &grd_curscreen->sc_canvas, (SWIDTH - FSPACX(320))/2, (SHEIGHT - FSPACY(200))/2, FSPACX(320), FSPACY(200)); window_create(&grd_curscreen->sc_canvas, (SWIDTH - FSPACX(320))/2, (SHEIGHT - FSPACY(200))/2, FSPACX(320), FSPACY(200),
(int (*)(window *, d_event *, void *))scores_handler, menu);
game_flush_inputs();
done = 0;
looper = 0;
while(!done) {
timer_delay2(50);
gr_set_current_canvas(NULL);
gr_flip();
#ifdef OGL
nm_draw_background1(Menu_pcx_name);
#endif
nm_draw_background(((SWIDTH-w)/2)-BORDERX,((SHEIGHT-h)/2)-BORDERY,((SWIDTH-w)/2)+w+BORDERX,((SHEIGHT-h)/2)+h+BORDERY);
gr_set_current_canvas(&canvas);
grd_curcanv->cv_font = MEDIUM3_FONT;
gr_string( 0x8000, FSPACY(15), TXT_HIGH_SCORES );
grd_curcanv->cv_font = GAME_FONT;
gr_set_fontcolor( BM_XRGB(31,26,5), -1 );
gr_string( FSPACX( 71), FSPACY(50), TXT_NAME );
gr_string( FSPACX(122), FSPACY(50), TXT_SCORE );
gr_string( FSPACX(167), FSPACY(50), TXT_SKILL );
gr_string( FSPACX(210), FSPACY(50), TXT_LEVELS );
gr_string( FSPACX(253), FSPACY(50), TXT_TIME );
if ( citem < 0 )
gr_string( 0x8000, FSPACY(175), TXT_PRESS_CTRL_R );
gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
gr_printf( 0x8000, FSPACY(31), "%c%s%c - %s", 34, Scores.cool_saying, 34, Scores.stats[0].name );
for (i=0; i<MAX_HIGH_SCORES; i++ ) {
gr_set_fontcolor( BM_XRGB(28-i*2,28-i*2,28-i*2), -1 );
scores_draw_item( i, &Scores.stats[i] );
}
if ( citem > -1 ) {
t1 = timer_get_fixed_seconds();
while ( timer_get_fixed_seconds() < t1+F1_0/128 );
gr_set_fontcolor( BM_XRGB(7+fades[looper],7+fades[looper],7+fades[looper]), -1 );
looper++;
if (looper>63) looper=0;
if ( citem == MAX_HIGH_SCORES )
scores_draw_item( MAX_HIGH_SCORES, &Last_game );
else
scores_draw_item( citem, &Scores.stats[citem] );
}
//see if redbook song needs to be restarted
RBACheckFinishedHook();
k = key_inkey();
switch( k ) {
case KEY_CTRLED+KEY_R:
if ( citem < 0 ) {
// Reset scores...
if ( nm_messagebox( NULL, 2, TXT_NO, TXT_YES, TXT_RESET_HIGH_SCORES )==1 ) {
PHYSFS_delete(get_scores_filename());
goto ReshowScores;
}
}
break;
case KEY_BACKSP: Int3(); k = 0; break;
case KEY_PRINT_SCREEN: save_screen_shot(0); k = 0; break;
case KEY_ENTER:
case KEY_SPACEBAR:
case KEY_ESC:
done=1;
break;
}
}
gr_set_current_canvas(NULL);
game_flush_inputs();
} }