From dae3beac2d71c73d5f18d6308af2ad15d8c755ea Mon Sep 17 00:00:00 2001 From: Date: Sat, 1 Sep 2018 01:55:51 -0700 Subject: [PATCH] Reenabled Stardew Music and fixed glitch where menus with no music cues would stop all music. --- .../StardewSymphonyRemastered/Config.cs | 5 ++ .../Framework/Menus/MusicManagerMenu.cs | 6 +- .../Framework/Music/MusicManager.cs | 62 ++++++++++++++++++- .../StardewSymphony.cs | 32 +++++++--- .../StardewSymphonyRemastered/manifest.json | 2 +- 5 files changed, 94 insertions(+), 13 deletions(-) diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Config.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Config.cs index c52d7469..1e1c81ba 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Config.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Config.cs @@ -35,5 +35,10 @@ namespace StardewSymphonyRemastered /// Used to write a .json file for every possible option for a music pack. Use at your own risk! /// public bool writeAllConfigMusicOptions { get; set; } = false; + + /// + /// Used to completely disable the Stardew Valley OST. + /// + public bool disableStardewMusic { get; set; } = false; } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs index 771ccee8..e4118a5f 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs @@ -2167,7 +2167,11 @@ namespace StardewSymphonyRemastered.Framework.Menus { if (this.drawMode == DrawMode.WeatherSelection || this.drawMode == DrawMode.TimeSelection || this.drawMode == DrawMode.LocationSelection || this.drawMode == DrawMode.DaySelection || this.drawMode == DrawMode.NothingElseToDisplay) { - if (this.selectedJustLocation==false) + if (this.drawMode == DrawMode.LocationSelection && this.selectedJustLocation == true) + { + + } + else { if (!doesPackContainMusic()) { diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicManager.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicManager.cs index 572780c1..4f5f51fd 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicManager.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicManager.cs @@ -72,12 +72,32 @@ namespace StardewSymphonyRemastered.Framework { if (this.currentMusicPack == null) return; - if (this.currentMusicPack.isPlaying()) + if (StardewSymphonyRemastered.StardewSymphony.Config.disableStardewMusic==true) { - return; + if (this.currentMusicPack.isPlaying()) + { + return; + } } else { + try + { + string songName = Game1.currentSong.Name.ToLower(); + + if (this.currentMusicPack.isPlaying() || (Game1.currentSong.IsPlaying && !songName.Contains("ambient")) ) + { + return; + } + } + catch (Exception err) + { + if (this.currentMusicPack.isPlaying()) + { + return; + } + } + } if (timer == null) { Random r = new Random(Game1.random.Next()); @@ -92,7 +112,7 @@ namespace StardewSymphonyRemastered.Framework timer.Enabled = true; timer.Elapsed += onTimerFinished; } - } + } @@ -112,6 +132,9 @@ namespace StardewSymphonyRemastered.Framework //StardewSymphony.ModMonitor.Log("AHH THE TIMER FINISHED!"); timer.Enabled = false; timer.Elapsed -= onTimerFinished; + + + selectMusic(SongSpecifics.getCurrentConditionalString()); timer = null; } @@ -292,6 +315,39 @@ namespace StardewSymphonyRemastered.Framework return listOfValidDictionaries; } + + + public void selectMenuMusic(string songListKey) + { + //Nullify the timer when new music is selected. + if (this.timer != null) + { + this.timer = null; + } + + var listOfValidMusicPacks = getListOfApplicableMusicPacks(songListKey); + + if (listOfValidMusicPacks.Count == 0) return; + + + int randInt = packSelector.Next(0, listOfValidMusicPacks.Count - 1); + + var musicPackPair = listOfValidMusicPacks.ElementAt(randInt); + + + //used to swap the music packs and stop the last playing song. + this.swapMusicPacks(musicPackPair.Key.musicPackInformation.name); + + int randInt2 = songSelector.Next(0, musicPackPair.Value.Count); + + + var songName = musicPackPair.Value.ElementAt(randInt2); + + this.currentMusicPack.playSong(songName.name); + + StardewSymphony.menuChangedMusic = true; + + } /// /// Selects the actual song to be played right now based off of the selector key. The selector key should be called when the player's location changes. /// diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs index dd239ed5..e4420b6a 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs @@ -66,13 +66,13 @@ namespace StardewSymphonyRemastered /// public override void Entry(IModHelper helper) { - Config = helper.ReadConfig(); + DefaultSoundBank = Game1.soundBank; DefaultWaveBank = Game1.waveBank; ModHelper = helper; ModMonitor = Monitor; Manifest = ModManifest; - + Config = helper.ReadConfig(); StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; // StardewModdingAPI.Events.EventArgsLocationsChanged += LocationEvents_CurrentLocationChanged; @@ -199,7 +199,8 @@ namespace StardewSymphonyRemastered /// private void MenuEvents_MenuChanged(object sender, StardewModdingAPI.Events.EventArgsClickableMenuChanged e) { - musicManager.selectMusic(SongSpecifics.getCurrentConditionalString()); + //var ok = musicManager.currentMusicPack.getNameOfCurrentSong(); + musicManager.selectMenuMusic(SongSpecifics.getCurrentConditionalString()); } private void SaveEvents_BeforeSave(object sender, EventArgs e) @@ -233,12 +234,27 @@ namespace StardewSymphonyRemastered /// private void GameEvents_UpdateTick(object sender, EventArgs e) { - if (Game1.currentSong != null) + if (musicManager == null) return; + + if (Config.disableStardewMusic==true) { - //ModMonitor.Log("STOP THE MUSIC!!!"); - Game1.currentSong.Stop(AudioStopOptions.Immediate); //stop the normal songs from playing over the new songs - Game1.currentSong.Stop(AudioStopOptions.AsAuthored); - Game1.nextMusicTrack = ""; //same as above line + if (Game1.currentSong != null) + { + Game1.currentSong.Stop(AudioStopOptions.Immediate); //stop the normal songs from playing over the new songs + Game1.currentSong.Stop(AudioStopOptions.AsAuthored); + Game1.nextMusicTrack = ""; //same as above line + } + } + else + { + if (musicManager.currentMusicPack == null) return; + if (Game1.currentSong != null && musicManager.currentMusicPack.isPlaying()) + { + //ModMonitor.Log("STOP THE MUSIC!!!"); + Game1.currentSong.Stop(AudioStopOptions.Immediate); //stop the normal songs from playing over the new songs + Game1.currentSong.Stop(AudioStopOptions.AsAuthored); + //Game1.nextMusicTrack = ""; //same as above line + } } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json index 74efdc77..8a0c53a7 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/manifest.json @@ -1,7 +1,7 @@ { "Name": "Stardew Symphony Remastered", "Author": "Alpha_Omegasis", - "Version": "2.1.6", + "Version": "2.1.7", "Description": "Adding more music to the game one beep at a time. Now with streaming!", "UniqueID": "Omegasis.StardewSymphonyRemastered", "EntryDll": "StardewSymphonyRemastered.dll",