From 618d40882ac13d36d0d8a4e2625d7e753d9fa06e Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 10 Mar 2024 15:03:37 +0000 Subject: [PATCH] Add the ability to play SECRET_ALTMUSIC music on the Challenges screen Supports both standard play and "E Side", if it exists (justification for Encore using the same CD) --- src/k_menudraw.c | 84 +++++++++++++++++++++++++++++++++++ src/menus/extras-challenges.c | 82 +++++++++++++++++++++++++++++++--- src/music.cpp | 8 ++++ 3 files changed, 167 insertions(+), 7 deletions(-) diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 45cf02c7a..b7a193879 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -7089,6 +7089,90 @@ static void M_DrawChallengePreview(INT32 x, INT32 y) break; } + case SECRET_ALTMUSIC: + { + UINT16 map = M_UnlockableMapNum(ref); + if (map >= nummapheaders + || !mapheaderinfo[map]) + { + return; + } + + UINT8 musicid; + for (musicid = 1; musicid < MAXMUSNAMES; musicid++) + { + if (mapheaderinfo[map]->cache_muslock[musicid - 1] == challengesmenu.currentunlock) + break; + } + + if (musicid == MAXMUSNAMES) + { + return; + } + + spritedef_t *sprdef = &sprites[SPR_ALTM]; + spriteframe_t *sprframe; + patch_t *patch; + UINT32 addflags = 0; + + x -= 10; + y += 15; + + if (sprdef->numframes) + { + sprframe = &sprdef->spriteframes[0]; + patch = W_CachePatchNum(sprframe->lumppat[0], PU_CACHE); + + if (sprframe->flip & 1) // Only for first sprite + { + addflags ^= V_FLIP; // This sprite is left/right flipped! + } + + V_DrawFixedPatch(x*FRACUNIT, (y+2)*FRACUNIT, FRACUNIT/2, addflags, patch, NULL); + } + + x = 8; + y = BASEVIDHEIGHT-16; + + const boolean thismusplaying = Music_Playing("challenge_altmusic"); + boolean pushed = false; + const char *song = NULL; + + if (M_SecretUnlocked(SECRET_ENCORE, true) + && musicid < mapheaderinfo[map]->encoremusname_size) + { + if (thismusplaying) + { + song = Music_Song("challenge_altmusic"); + pushed = strcmp(song, mapheaderinfo[map]->encoremusname[musicid]) == 0; + } + + K_drawButton(x&FRACUNIT, y*FRACUNIT, 0, kp_button_l, pushed); + x += SHORT(kp_button_l[0]->width); + V_DrawThinString(x, y + 1, (pushed ? V_GRAYMAP : highlightflags), "E Side"); + + x = 8; + y -= 10; + } + + if (musicid < mapheaderinfo[map]->musname_size) + { + if (pushed || !thismusplaying) + { + pushed = false; + } + else + { + if (!song) + song = Music_Song("challenge_altmusic"); + pushed = strcmp(song, mapheaderinfo[map]->musname[musicid]) == 0; + } + + K_drawButton(x*FRACUNIT, y*FRACUNIT, 0, kp_button_a[1], pushed); + x += SHORT(kp_button_a[1][0]->width); + V_DrawThinString(x, y + 1, (pushed ? V_GRAYMAP : highlightflags), "Play CD"); + } + } default: { break; diff --git a/src/menus/extras-challenges.c b/src/menus/extras-challenges.c index b6b71957e..1d6b9704e 100644 --- a/src/menus/extras-challenges.c +++ b/src/menus/extras-challenges.c @@ -834,6 +834,8 @@ boolean M_ChallengesInputs(INT32 ch) { if (M_MenuBackPressed(pid) || start) { + Music_Stop("challenge_altmusic"); + currentMenu->prevMenu = M_SpecificMenuRestore(currentMenu->prevMenu); M_GoBack(0); @@ -1021,17 +1023,83 @@ boolean M_ChallengesInputs(INT32 ch) return true; } - if (M_MenuConfirmPressed(pid) - && challengesmenu.currentunlock < MAXUNLOCKABLES + if (challengesmenu.currentunlock < MAXUNLOCKABLES && gamedata->unlocked[challengesmenu.currentunlock]) { switch (unlockables[challengesmenu.currentunlock].type) { - case SECRET_ALTTITLE: { - extern consvar_t cv_alttitle; - CV_AddValue(&cv_alttitle, 1); - S_StartSound(NULL, sfx_s3kc3s); - M_SetMenuDelay(pid); + case SECRET_ALTTITLE: + { + if (M_MenuConfirmPressed(pid)) + { + extern consvar_t cv_alttitle; + CV_AddValue(&cv_alttitle, 1); + S_StartSound(NULL, sfx_s3kc3s); + M_SetMenuDelay(pid); + } + break; + } + case SECRET_ALTMUSIC: + { + UINT8 trymus = 0, musicid = MAXMUSNAMES; + + if (M_MenuConfirmPressed(pid)) + { + trymus = 1; + } + else if (M_MenuButtonPressed(pid, MBT_L)) + { + trymus = 2; + } + + if (trymus) + { + const char *trymusname = NULL; + + UINT16 map = M_UnlockableMapNum(&unlockables[challengesmenu.currentunlock]); + if (map >= nummapheaders + || !mapheaderinfo[map]) + { + ; + } + else for (musicid = 1; musicid < MAXMUSNAMES; musicid++) + { + if (mapheaderinfo[map]->cache_muslock[musicid - 1] == challengesmenu.currentunlock) + break; + } + + if (trymus == 1) + { + if (musicid < mapheaderinfo[map]->musname_size) + { + trymusname = mapheaderinfo[map]->musname[musicid]; + } + } + else + { + if (musicid < mapheaderinfo[map]->encoremusname_size) + { + trymusname = mapheaderinfo[map]->encoremusname[musicid]; + } + } + + if (trymusname) + { + if (!Music_Playing("challenge_altmusic") + || strcmp(Music_Song("challenge_altmusic"), trymusname)) + { + Music_Remap("challenge_altmusic", trymusname); + Music_Play("challenge_altmusic"); + } + else + { + Music_Stop("challenge_altmusic"); + } + + M_SetMenuDelay(pid); + } + } + break; } default: diff --git a/src/music.cpp b/src/music.cpp index 9b0de56e9..0f5c31e71 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -195,6 +195,14 @@ void Music_Init(void) tune.fade_out = 5000; tune.fade_out_inclusive = false; } + + { + Tune& tune = g_tunes.insert("challenge_altmusic"); + + tune.priority = 100; + tune.resist = true; + tune.credit = true; + } } void Music_Tick(void)