Skip to content

Commit

Permalink
Merge pull request scp-fs2open#6424 from Goober5000/credits_substitut…
Browse files Browse the repository at this point in the history
…e_music

add $Substitute Music: for credits.tbl
  • Loading branch information
Goober5000 authored Dec 16, 2024
2 parents b7c6761 + b412d93 commit 91b54c7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
23 changes: 19 additions & 4 deletions code/menuui/credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ static credits_screen_buttons Buttons[NUM_BUTTONS][GR_NUM_RESOLUTIONS] = {
};

char Credits_music_name[NAME_LENGTH] = "Cinema";
char Credits_substitute_music_name[NAME_LENGTH] = "";

static int Credits_music_handle = -1;
static UI_TIMESTAMP Credits_music_begin_timestamp;

Expand Down Expand Up @@ -319,6 +321,10 @@ void credits_parse_table(const char* filename)
{
stuff_string(Credits_music_name, F_NAME, NAME_LENGTH);
}
if (optional_string("$Substitute Music:"))
{
stuff_string(Credits_substitute_music_name, F_NAME, NAME_LENGTH);
}
if (optional_string("$Number of Images:"))
{
int temp;
Expand Down Expand Up @@ -499,12 +505,21 @@ void credits_init()
Credits_artwork_index = Random::next(Credits_num_images);
}

auto credits_wavfile_name = credits_get_music_filename(Credits_music_name);
if (credits_wavfile_name != nullptr) {
const char *credits_wavfile_name = nullptr;

// try substitute music first
if (*Credits_substitute_music_name)
credits_wavfile_name = credits_get_music_filename(Credits_substitute_music_name);

// fall back to regular music
if (!credits_wavfile_name)
credits_wavfile_name = credits_get_music_filename(Credits_music_name);

// if we have something, play it
if (credits_wavfile_name)
credits_load_music(credits_wavfile_name);
}

// Use this id to trigger the start of music playing on the briefing screen
// Use this id to trigger the start of music playing on the credits screen
Credits_music_begin_timestamp = ui_timestamp(Credits_music_delay);

Credits_frametime = 0;
Expand Down
3 changes: 2 additions & 1 deletion code/menuui/credits.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#ifndef __CREDITS_H__
#define __CREDITS_H__

extern char Credits_music_name[NAME_LENGTH];
extern char Credits_music_name[];
extern char Credits_substitute_music_name[];
extern int Credits_num_images;
extern int Credits_artwork_index;
extern float Credits_scroll_rate;
Expand Down
12 changes: 11 additions & 1 deletion code/scripting/api/libs/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,17 @@ ADE_VIRTVAR(Music, l_UserInterface_Credits, nullptr, "The credits music filename
LuaError(L, "This property is read only.");
}

return ade_set_args(L, "s", credits_get_music_filename(Credits_music_name));
const char *credits_wavfile_name = nullptr;

// try substitute music first
if (*Credits_substitute_music_name)
credits_wavfile_name = credits_get_music_filename(Credits_substitute_music_name);

// fall back to regular music
if (!credits_wavfile_name)
credits_wavfile_name = credits_get_music_filename(Credits_music_name);

return ade_set_args(L, "s", credits_wavfile_name);
}

ADE_VIRTVAR(NumImages, l_UserInterface_Credits, nullptr, "The total number of credits images", "number", "The number of images")
Expand Down

0 comments on commit 91b54c7

Please sign in to comment.