Play the opposite type music (Digital/MIDI) when toggling between them in menu

* S_MusicInfo method to retrieve name, flags, and looping
This commit is contained in:
mazmazz 2018-08-23 16:46:40 -04:00
parent 4aa100aa57
commit f6ec93198f
3 changed files with 60 additions and 5 deletions

View file

@ -9485,7 +9485,24 @@ static void M_ToggleDigital(INT32 choice)
{
digital_disabled = true;
if (S_MusicType() != MU_MID)
S_StopMusic();
{
if (midi_disabled)
S_StopMusic();
else
{
char mmusic[7];
UINT16 mflags;
boolean looping;
if (S_MusicInfo(mmusic, &mflags, &looping) && S_MIDIExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
else
S_StopMusic();
}
}
//M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING);
}
}
@ -9504,6 +9521,12 @@ static void M_ToggleMIDI(INT32 choice)
itemOn--;
return;
case KEY_LEFTARROW:
case KEY_RIGHTARROW:
if (S_MusicType() != MU_MID && S_MusicType() != MU_NONE)
S_StartSound(NULL, sfx_menu1);
break;
case KEY_ESCAPE:
if (currentMenu->prevMenu)
M_SetupNextMenu(currentMenu->prevMenu);
@ -9529,7 +9552,24 @@ static void M_ToggleMIDI(INT32 choice)
{
midi_disabled = true;
if (S_MusicType() == MU_MID)
S_StopMusic();
{
if (digital_disabled)
S_StopMusic();
else
{
char mmusic[7];
UINT16 mflags;
boolean looping;
if (S_MusicInfo(mmusic, &mflags, &looping) && S_DigExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
else
S_StopMusic();
}
}
//M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING);
}
}

View file

@ -1347,6 +1347,8 @@ const char *compat_special_music_slots[16] =
#endif
static char music_name[7]; // up to 6-character name
static UINT16 music_flags;
static boolean music_looping;
/// ------------------------
/// Music Status
@ -1382,9 +1384,17 @@ musictype_t S_MusicType(void)
return I_GetMusicType();
}
const char *S_MusicName(void)
boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping)
{
return music_name;
if (!I_MusicPlaying())
return false;
strncpy(mname, music_name, 7);
mname[6] = 0;
*mflags = music_flags;
*looping = music_looping;
return (boolean)mname[0];
}
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi)
@ -1453,6 +1463,8 @@ static void S_UnloadMusic(void)
{
I_UnloadSong();
music_name[0] = 0;
music_flags = 0;
music_looping = false;
}
static boolean S_PlayMusic(boolean looping)
@ -1489,6 +1501,9 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
if (!S_LoadMusic(mmusic))
return;
music_flags = mflags;
music_looping = looping;
if (!S_PlayMusic(looping))
{
CONS_Alert(CONS_ERROR, "Music cannot be played!\n");

View file

@ -136,7 +136,7 @@ boolean S_MusicDisabled(void);
boolean S_MusicPlaying(void);
boolean S_MusicPaused(void);
musictype_t S_MusicType(void);
const char *S_MusicName(void);
boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping);
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi);
#define S_DigExists(a) S_MusicExists(a, false, true)
#define S_MIDIExists(a) S_MusicExists(a, true, false)