Make credits window inherit from dcx::window

This commit is contained in:
Kp 2020-08-28 00:18:45 +00:00
parent 955c7d9542
commit c038805a9b

View file

@ -75,25 +75,42 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#define ALLOWED_CHAR (!Current_mission ? 'R' : (is_SHAREWARE ? 'S' : 'R'))
#endif
namespace dcx {
namespace {
struct credits : ignore_window_pointer_t
struct credits_window : window
{
RAIIPHYSFS_File file;
int have_bin_file;
std::array<PHYSFSX_gets_line_t<80>, NUM_LINES> buffer;
int buffer_line;
int first_line_offset;
int extra_inc;
int done;
int row;
grs_main_bitmap backdrop;
const uint8_t have_bin_file;
std::array<PHYSFSX_gets_line_t<80>, NUM_LINES> buffer = {};
int buffer_line = 0;
int first_line_offset = 0;
int extra_inc = 0;
int done = 0;
int row = 0;
grs_main_bitmap backdrop = {};
credits_window(grs_canvas &src, int x, int y, int w, int h, RAIIPHYSFS_File f, const uint8_t bin_file) :
window(src, x, y, w, h), file(std::move(f)), have_bin_file(bin_file)
{
}
};
}
}
namespace dsx {
static window_event_result credits_handler(window *, const d_event &event, credits *cr)
namespace {
struct credits_window : ::dcx::credits_window
{
using ::dcx::credits_window::credits_window;
virtual window_event_result event_handler(const d_event &) override;
};
window_event_result credits_window::event_handler(const d_event &event)
{
int l, y;
window_event_result result;
@ -119,7 +136,7 @@ static window_event_result credits_handler(window *, const d_event &event, credi
return window_event_result::close;
case EVENT_IDLE:
if (cr->done>NUM_LINES)
if (done > NUM_LINES)
{
return window_event_result::close;
}
@ -133,22 +150,23 @@ static window_event_result credits_handler(window *, const d_event &event, credi
timer_delay(F1_0/28);
#endif
if (cr->row == 0)
if (row == 0)
{
do {
cr->buffer_line = (cr->buffer_line+1) % NUM_LINES;
buffer_line = (buffer_line + 1) % NUM_LINES;
#if defined(DXX_BUILD_DESCENT_II)
get_line:;
#endif
if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], cr->file )) {
if (PHYSFSX_fgets(buffer[buffer_line], file))
{
char *p;
if (cr->have_bin_file) // is this a binary tbl file
decode_text_line (cr->buffer[cr->buffer_line]);
if (have_bin_file) // is this a binary tbl file
decode_text_line (buffer[buffer_line]);
#if defined(DXX_BUILD_DESCENT_I)
p = strchr(&cr->buffer[cr->buffer_line][0],'\n');
p = strchr(&buffer[buffer_line][0],'\n');
if (p) *p = '\0';
#elif defined(DXX_BUILD_DESCENT_II)
p = cr->buffer[cr->buffer_line];
p = buffer[buffer_line];
if (p[0] == ';')
goto get_line;
@ -165,33 +183,34 @@ static window_event_result credits_handler(window *, const d_event &event, credi
#endif
} else {
//fseek( file, 0, SEEK_SET);
cr->buffer[cr->buffer_line][0] = 0;
cr->done++;
buffer[buffer_line][0] = 0;
done++;
}
} while (cr->extra_inc--);
cr->extra_inc = 0;
} while (extra_inc--);
extra_inc = 0;
}
// cheap but effective: towards end of credits sequence, fade out the music volume
if (cr->done >= NUM_LINES-16)
if (done >= NUM_LINES-16)
{
static int curvol = -10;
if (curvol == -10)
curvol = GameCfg.MusicVolume;
if (curvol > (NUM_LINES-cr->done)/2)
const auto limitvol = (NUM_LINES - done) / 2;
if (curvol > limitvol)
{
curvol = (NUM_LINES-cr->done)/2;
curvol = limitvol;
songs_set_volume(curvol);
}
}
y = cr->first_line_offset - cr->row;
y = first_line_offset - row;
auto &canvas = *grd_curcanv;
show_fullscr(canvas, cr->backdrop);
show_fullscr(canvas, backdrop);
for (uint_fast32_t j=0; j != NUM_LINES; ++j, y += ROW_SPACING)
{
l = (cr->buffer_line + j + 1 ) % NUM_LINES;
const char *s = cr->buffer[l];
l = (buffer_line + j + 1 ) % NUM_LINES;
const char *s = buffer[l];
if (!s)
continue;
@ -217,39 +236,31 @@ static window_event_result credits_handler(window *, const d_event &event, credi
}
}
cr->row += SHEIGHT/200;
if (cr->row >= ROW_SPACING)
cr->row = 0;
row += SHEIGHT / 200;
if (row >= ROW_SPACING)
row = 0;
break;
}
case EVENT_WINDOW_CLOSE:
songs_set_volume(GameCfg.MusicVolume);
songs_play_song( SONG_TITLE, 1 );
std::default_delete<credits>()(cr);
break;
default:
break;
}
return window_event_result::ignored;
}
}
namespace dsx {
static void credits_show_common(RAIIPHYSFS_File file, const int have_bin_file)
{
palette_array_t backdrop_palette;
auto cr = std::make_unique<credits>();
*cr = {};
cr->file = std::move(file);
cr->have_bin_file = have_bin_file;
auto cr = std::make_unique<credits_window>(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, std::move(file), have_bin_file);
set_screen_mode(SCREEN_MENU);
#if defined(DXX_BUILD_DESCENT_II)
gr_use_palette_table( "credits.256" );
#endif
cr->backdrop.bm_data=NULL;
const auto pcx_error = pcx_read_bitmap(STARS_BACKGROUND, cr->backdrop,backdrop_palette);
if (pcx_error != pcx_result::SUCCESS)
@ -266,17 +277,11 @@ static void credits_show_common(RAIIPHYSFS_File file, const int have_bin_file)
gr_palette_load( gr_palette );
key_flush();
credits *pcr = cr.get();
const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, credits_handler, cr.release());
if (!wind)
{
d_event event = { EVENT_WINDOW_CLOSE };
credits_handler(NULL, event, pcr);
return;
}
cr->send_creation_events(nullptr);
event_process_all();
cr.release();
}
}
void credits_show(const char *const filename)