From 7bc3613f5bcfcebd7b48f8e186d993d1e4ae27db Mon Sep 17 00:00:00 2001 From: SabreML <57483089+SabreML@users.noreply.github.com> Date: Sat, 18 Mar 2023 17:46:42 +0000 Subject: [PATCH] Pause menu text in Arena mode And a fix for the music sprite sometimes overlapping with the 'Paused' text. (Atomic commits, what are those?) --- MusicAnnouncements/modinfo.json | 2 +- src/MusicAnnouncementsMod.cs | 45 ++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/MusicAnnouncements/modinfo.json b/MusicAnnouncements/modinfo.json index 4c08ddb..ff61fde 100644 --- a/MusicAnnouncements/modinfo.json +++ b/MusicAnnouncements/modinfo.json @@ -1,7 +1,7 @@ { "id": "sabreml.musicannouncements", "name": "Music Announcements", - "version": "1.2.0", + "version": "1.2.2", "target_game_version": "v1.9.06", "authors": "SabreML", "description": "Shows the name of the currently playing music track in-game.", diff --git a/src/MusicAnnouncementsMod.cs b/src/MusicAnnouncementsMod.cs index cb7de80..10a12e6 100644 --- a/src/MusicAnnouncementsMod.cs +++ b/src/MusicAnnouncementsMod.cs @@ -1,4 +1,5 @@ using BepInEx; +using HUD; using Music; using System.Security.Permissions; using System.Text.RegularExpressions; @@ -10,7 +11,7 @@ namespace MusicAnnouncements { - [BepInPlugin("sabreml.musicannouncements", "MusicAnnouncements", "1.2.0")] + [BepInPlugin("sabreml.musicannouncements", "MusicAnnouncements", "1.2.2")] public class MusicAnnouncementsMod : BaseUnityPlugin { // The current mod version. (Stored here as a variable so that I don't have to update it in as many places.) @@ -22,6 +23,7 @@ public class MusicAnnouncementsMod : BaseUnityPlugin // The number of attempts to make to try and announce the music. public static int AnnounceAttempts; + public void OnEnable() { // Take the version number that was given to `BepInPlugin()` above. @@ -33,6 +35,7 @@ public void OnEnable() On.Music.Song.ctor += SongHK; On.Music.MusicPiece.StopAndDestroy += MusicPiece_StopAndDestroyHK; On.Music.MusicPlayer.Update += MusicPlayer_UpdateHK; + On.HUD.TextPrompt.Draw += TextPrompt_DrawHK; // Pause menu hooks. PauseMenuText.SetupHooks(); @@ -50,7 +53,7 @@ private void RainWorld_OnModsInitHK(On.RainWorld.orig_OnModsInit orig, RainWorld private void SongHK(On.Music.Song.orig_ctor orig, Song self, MusicPlayer musicPlayer, string name, MusicPlayer.MusicContext context) { orig(self, musicPlayer, name, context); - if (context != MusicPlayer.MusicContext.StoryMode) // Ingame music only. + if (context == MusicPlayer.MusicContext.Menu) // Ingame music only. { return; } @@ -65,12 +68,19 @@ private void SongHK(On.Music.Song.orig_ctor orig, Song self, MusicPlayer musicPl // The full `name` will be something like "RW_24 - Kayava". We want the part after the dash. SongToAnnounce = Regex.Split(name, " - ")[1]; - + + // Arena mode announces the song name in the bottom left by itself already, so there's no need to do it here with `AnnounceAttempts`. + // (`SongToAnnounce` is still set though so that the pause menu text is shown.) + if (context == MusicPlayer.MusicContext.Arena) + { + return; + } + if (MusicAnnouncementsConfig.IngameText.Value) // Gameplay announcements are enabled. { AnnounceAttempts = 500; // 500 attempts } - else + else // Gameplay announcements are disabled. { Debug.Log("(MusicAnnouncements) Skipping gameplay announcement due to config"); } @@ -82,7 +92,9 @@ private void MusicPiece_StopAndDestroyHK(On.Music.MusicPiece.orig_StopAndDestroy orig(self); if (self.GetType() == typeof(Song)) { + // Reset everything back to default. SongToAnnounce = null; + AnnounceAttempts = 0; } } @@ -111,13 +123,34 @@ private void MusicPlayer_UpdateHK(On.Music.MusicPlayer.orig_Update orig, MusicPl // Exactly the same as `HUD.TextPrompt.AddMusicMessage()`, but with the `hideHud` argument set to `true`. // Without this it can look pretty weird if the HUD is up. - private void AddMusicMessage_HideHUD(HUD.TextPrompt self, string text, int time) + private void AddMusicMessage_HideHUD(TextPrompt self, string text, int time) { - self.messages.Add(new HUD.TextPrompt.MusicMessage(" ~ " + text, 0, time, false, true)); + self.messages.Add(new TextPrompt.MusicMessage(" ~ " + text, 0, time, false, true)); if (self.messages.Count == 1) { self.InitNextMessage(); } } + + // This is here mainly to hide the little quaver/quarter note 'music sprite' if there isn't currently a music announcement on the screen. + // Without this, if another message of a higher priority overrides it (Pause menu, game over, etc.), the music sprite will still be visible overlapping with the new text. + private void TextPrompt_DrawHK(On.HUD.TextPrompt.orig_Draw orig, TextPrompt self, float timeStacker) + { + orig(self, timeStacker); + // If the current message is a music announcement, but it's being overridden by another type of `TextPrompt`. + if ((self.musicSprite != null && self.messages.Count > 0 && self.messages[0] is TextPrompt.MusicMessage) && self.currentlyShowing != TextPrompt.InfoID.Message) + { + // Force the music sprite to be invisible. + self.musicSprite.alpha = 0f; + + // Also, if the message override was caused by the pause menu being opened, force the black letterbox border at the top to be visible. + // It only seems to disappear in Arena mode for whatever reason, but it happens consistently and the pause menu text looks weird without it. + if (self.currentlyShowing == TextPrompt.InfoID.Paused) + { + float currentAlpha = Mathf.Lerp(self.lastShow, self.show, timeStacker); + self.sprites[0].y = self.hud.rainWorld.screenSize.y - (30f + self.hud.rainWorld.options.SafeScreenOffset.y) * RWCustom.Custom.SCurve(Mathf.InverseLerp(0f, 0.5f, currentAlpha), 0.5f); + } + } + } } }