Skip to content

Commit

Permalink
Change OpenTTD#6684: Force theme song on title screen
Browse files Browse the repository at this point in the history
Theme song is whatever song is in the "theme" slot in the baseset music definition.
If the baseset doesn't define a theme song, this change should keep playing from
the playlist as usual, but that's untested. All known music sets have a theme.
  • Loading branch information
nielsmh committed Apr 27, 2018
1 parent 1e5eaae commit 31a6504
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/base_media_base.h
Expand Up @@ -308,6 +308,7 @@ struct MusicSet : BaseSet<MusicSet, NUM_SONGS_AVAILABLE, false> {
/** The name of the different songs. */
MusicSongInfo songinfo[NUM_SONGS_AVAILABLE];
byte num_available;
bool has_theme;

bool FillSetDetails(struct IniFile *ini, const char *path, const char *full_filename);
};
Expand Down
2 changes: 2 additions & 0 deletions src/music.cpp
Expand Up @@ -123,6 +123,8 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f
bool ret = this->BaseSet<MusicSet, NUM_SONGS_AVAILABLE, false>::FillSetDetails(ini, path, full_filename);
if (ret) {
this->num_available = 0;
this->has_theme = !StrEmpty(this->files[0].filename);

IniGroup *names = ini->GetGroup("names");
IniGroup *catindex = ini->GetGroup("catindex");
for (uint i = 0, j = 1; i < lengthof(this->songinfo); i++) {
Expand Down
29 changes: 25 additions & 4 deletions src/music_gui.cpp
Expand Up @@ -245,6 +245,16 @@ static void StopMusic()

static void PlayPlaylistSong()
{
if (_game_mode == GM_MENU && BaseMusic::GetUsedSet()->has_theme) {
/* force first song (theme) on the main menu.
* this is guaranteed to exist, otherwise
* has_theme would not be set. */
_music_wnd_cursong = 1;
DoPlaySong();
_song_is_active = true;
return;
}

if (_cur_playlist[0] == 0) {
SelectSongToPlay();
/* if there is not songs in the playlist, it may indicate
Expand All @@ -270,8 +280,19 @@ void ResetMusic()
DoPlaySong();
}

/**
* Check music playback status and start/stop/song-finished
* Called from main loop.
*/
void MusicLoop()
{
static GameMode _last_game_mode = GM_BOOTSTRAP;
bool force_restart = false;
if (_game_mode != _last_game_mode) {
force_restart = true;
_last_game_mode = _game_mode;
}

if (!_settings_client.music.playing && _song_is_active) {
StopMusic();
} else if (_settings_client.music.playing && !_song_is_active) {
Expand All @@ -280,13 +301,13 @@ void MusicLoop()

if (!_song_is_active) return;

if (!MusicDriver::GetInstance()->IsSongPlaying()) {
if (_game_mode != GM_MENU) {
if (force_restart || !MusicDriver::GetInstance()->IsSongPlaying()) {
if (_game_mode == GM_MENU && BaseMusic::GetUsedSet()->has_theme) {
ResetMusic();
} else {
StopMusic();
SkipToNextSong();
PlayPlaylistSong();
} else {
ResetMusic();
}
}
}
Expand Down

0 comments on commit 31a6504

Please sign in to comment.