From 67d77701b31237c36fccbfc89fe160849435804e Mon Sep 17 00:00:00 2001 From: Joshua Navarro Date: Mon, 10 Dec 2018 01:33:10 -0800 Subject: [PATCH] Fixed save menu for SaveAnywhere. Also added in suport for .mp3 files via NAudio. --- .../SaveAnywhere/Framework/NewSaveGameMenu.cs | 12 +-- .../SaveAnywhere/Framework/SaveManager.cs | 4 - GeneralMods/SaveAnywhere/SaveAnywhere.cs | 14 ++- .../Framework/Music/MusicPackMetaData.cs | 4 +- .../Framework/Music/WavMusicPack.cs | 86 +++++++++++++++++-- .../StardewSymphony.cs | 3 + .../StardewSymphonyRemastered.csproj | 3 + .../StardustCore/Animations/Animation.cs | 5 ++ 8 files changed, 107 insertions(+), 24 deletions(-) diff --git a/GeneralMods/SaveAnywhere/Framework/NewSaveGameMenu.cs b/GeneralMods/SaveAnywhere/Framework/NewSaveGameMenu.cs index 509529cd..b3917895 100644 --- a/GeneralMods/SaveAnywhere/Framework/NewSaveGameMenu.cs +++ b/GeneralMods/SaveAnywhere/Framework/NewSaveGameMenu.cs @@ -9,8 +9,9 @@ using System.Text; namespace Omegasis.SaveAnywhere.Framework { + /// A marker subclass to detect when a custom save is in progress. - internal class NewSaveGameMenu : IClickableMenu { + internal class NewSaveGameMenu : SaveGameMenu { public event EventHandler SaveComplete; @@ -23,7 +24,7 @@ namespace Omegasis.SaveAnywhere.Framework public bool hasDrawn; private SparklingText saveText; private int _ellipsisCount; - + public NewSaveGameMenu() { this.saveText = new SparklingText(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:SaveGameMenu.cs.11378"), Color.LimeGreen, new Color((int)(Color.Black.R * (1.0 / 1000.0)),(int)( Color.Black.G * (1.0 / 1000.0)),(int)( Color.Black.B * (1.0 / 1000.0)),255), false, 0.1, 1500, 32, 500); @@ -33,7 +34,8 @@ namespace Omegasis.SaveAnywhere.Framework { } - public void complete() + + public new void complete() { Game1.playSound("money"); this.completePause = 1500; @@ -47,7 +49,7 @@ namespace Omegasis.SaveAnywhere.Framework { if (this.quit) return; - base.update(time); + //base.update(time); if (Game1.client != null && Game1.client.timedOut) { this.quit = true; @@ -164,7 +166,7 @@ namespace Omegasis.SaveAnywhere.Framework this.hasDrawn = true; } - public void Dispose() + public new void Dispose() { Game1.game1.IsSaving = false; } diff --git a/GeneralMods/SaveAnywhere/Framework/SaveManager.cs b/GeneralMods/SaveAnywhere/Framework/SaveManager.cs index 0fd358c0..16eb42b1 100644 --- a/GeneralMods/SaveAnywhere/Framework/SaveManager.cs +++ b/GeneralMods/SaveAnywhere/Framework/SaveManager.cs @@ -80,7 +80,6 @@ namespace Omegasis.SaveAnywhere.Framework currentSaveMenu.SaveComplete -= CurrentSaveMenu_SaveComplete; currentSaveMenu = null; //AfterSave.Invoke(this, EventArgs.Empty); - UnifiedSaveCore.UnifiedSaveCore.SaveEvents_AfterSave(this, EventArgs.Empty); } /// Clear saved data. @@ -93,8 +92,6 @@ namespace Omegasis.SaveAnywhere.Framework /// Initiate a game save. public void BeginSaveData() { - SaveAnywhere.ModMonitor.Log("SVE ANYWHERE WHAT YOU DOING???"); - UnifiedSaveCore.UnifiedSaveCore.SaveEvents_BeforeSave(this, EventArgs.Empty); // save game data Farm farm = Game1.getFarm(); @@ -147,7 +144,6 @@ namespace Omegasis.SaveAnywhere.Framework // Notify other mods that load is complete //AfterLoad.Invoke(this, EventArgs.Empty); - UnifiedSaveCore.UnifiedSaveCore.SaveEvents_AfterLoad(this, EventArgs.Empty); } /// diff --git a/GeneralMods/SaveAnywhere/SaveAnywhere.cs b/GeneralMods/SaveAnywhere/SaveAnywhere.cs index 0c4a0d8f..ee824935 100644 --- a/GeneralMods/SaveAnywhere/SaveAnywhere.cs +++ b/GeneralMods/SaveAnywhere/SaveAnywhere.cs @@ -58,7 +58,6 @@ namespace Omegasis.SaveAnywhere SaveEvents.AfterLoad += this.SaveEvents_AfterLoad; SaveEvents.AfterSave += this.SaveEvents_AfterSave; - MenuEvents.MenuChanged += this.MenuEvents_MenuChanged; ControlEvents.KeyPressed += this.ControlEvents_KeyPressed; GameEvents.UpdateTick += this.GameEvents_UpdateTick; TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted; @@ -98,15 +97,12 @@ namespace Omegasis.SaveAnywhere // clear custom data after a normal save (to avoid restoring old state) if (!this.IsCustomSaving) this.SaveManager.ClearData(); + else + { + IsCustomSaving = false; + } } - /// The method invoked after a menu is opened or changed. - /// The event sender. - /// The event data. - private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) - { - this.IsCustomSaving = e.NewMenu != null && (e.NewMenu is NewSaveGameMenu || e.NewMenu is NewShippingMenu); - } /// The method invoked when the game updates (roughly 60 times per second). /// The event sender. @@ -225,7 +221,9 @@ namespace Omegasis.SaveAnywhere return; } + // save + this.IsCustomSaving = true; this.SaveManager.BeginSaveData(); } else diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs index 8c06798f..fdb742d9 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/MusicPackMetaData.cs @@ -70,12 +70,12 @@ namespace StardewSymphonyRemastered.Framework { try { - meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest, Path.Combine(pathParse[1], meta.pathToMusicPackIcon + ".png")); + meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest, Path.Combine(pathParse[1].Remove(0,1), meta.pathToMusicPackIcon + ".png")); } catch(Exception errr) { errr.ToString(); - meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest ,Path.Combine(pathParse[1], meta.pathToMusicPackIcon)); + meta.Icon = new Texture2DExtended(StardewSymphony.ModHelper,StardewSymphony.Manifest ,Path.Combine(pathParse[1].Remove(0,1), meta.pathToMusicPackIcon)); } } catch(Exception err) diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs index 6f240133..d1a6a8b0 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Music/WavMusicPack.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; +using NAudio.Wave; using StardewValley; using System; using System.Collections.Generic; @@ -15,13 +16,34 @@ namespace StardewSymphonyRemastered.Framework /// public class WavMusicPack : MusicPack { + /// + /// The refererence to the information for the current song. + /// public Song currentSong; + + /// + /// The directory where all of the songs are stored. + /// public string songsDirectory; + /// + /// The currently playing sound. + /// public SoundEffectInstance sound; + bool loop; + /// + /// The name of the music pack/ + /// + public string Name + { + get + { + return musicPackInformation.name; + } + } public Dictionary sounds; /// @@ -98,22 +120,76 @@ namespace StardewSymphonyRemastered.Framework /// public override void loadMusicFiles() { - string[] wavFiles = Directory.GetFiles(this.songsDirectory, "*.wav"); + List wavFiles = Directory.GetFiles(this.songsDirectory, "*.wav").ToList(); + wavFiles.AddRange(Directory.GetFiles(this.songsDirectory, "*.mp3")); + List listOfSongs = new List(); - foreach(var wav in wavFiles) + + DateTime span = DateTime.Now; + + foreach (var wav in wavFiles) { - System.IO.Stream waveFileStream = File.OpenRead(wav); //TitleContainer.OpenStream(file); - SoundEffect eff = SoundEffect.FromStream(waveFileStream); + MemoryStream memoryStream = new MemoryStream(); + AudioFileReader fileReader = new AudioFileReader(wav); + fileReader.CopyTo(memoryStream); + byte[] wavData=memoryStream.ToArray(); + + SoundEffect eff = null; + + System.IO.Stream waveFileStream= waveFileStream = File.OpenRead(wav); //TitleContainer.OpenStream(file); + + if (wav.Contains(".wav")) + { + eff = SoundEffect.FromStream(waveFileStream); + } + else if (wav.Contains(".mp3")) + { + /* + Mp3FileReader mp3 = new Mp3FileReader(waveFileStream); + mp3.CopyTo(memoryStream); ; + wavData = memoryStream.ToArray(); + eff = new SoundEffect(wavData, mp3.Mp3WaveFormat.SampleRate, AudioChannels.Mono); + */ + + using (Mp3FileReader reader = new Mp3FileReader(waveFileStream)) + { + using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader)) + { + StardewSymphony.ModMonitor.Log("MP3 CONVERT! "+ Path.GetFileNameWithoutExtension(wav) + ".wav"); + WaveFileWriter.CreateWaveFile(Path.Combine(this.songsDirectory,(Path.GetFileNameWithoutExtension(wav)+".wav")), pcmStream); + + waveFileStream = File.OpenRead((Path.GetFileNameWithoutExtension(wav) + ".wav")); //TitleContainer.OpenStream(file); + eff = SoundEffect.FromStream(waveFileStream); + + File.Delete(Path.Combine(this.songsDirectory, (Path.GetFileNameWithoutExtension(wav) + ".wav"))); + } + } + } + + + + + //SoundEffect eff = new SoundEffect(wavData, 48000 , AudioChannels.Mono); + + if (eff == null) continue; SoundEffectInstance instance = eff.CreateInstance(); + + string name = Path.GetFileNameWithoutExtension(wav); + if (this.sounds.ContainsKey(name)) + { + continue; + } this.sounds.Add(name, instance); - waveFileStream.Dispose(); + //waveFileStream.Dispose(); Song song = new Song(wav); this.songInformation.listOfSongsWithoutTriggers.Add(song); //listOfSongs.Add(song); } + if(StardewSymphony.Config.EnableDebugLog) StardewSymphony.ModMonitor.Log("Time to load WAV music pack: "+this.musicPackInformation.name+span.Subtract(DateTime.Now).ToString()); + } /// diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs index e4420b6a..61daae38 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphony.cs @@ -10,6 +10,7 @@ using StardewValley; using StardewSymphonyRemastered.Framework; using System.IO; using StardustCore.UIUtilities; +using NAudio.Wave; namespace StardewSymphonyRemastered { @@ -405,6 +406,8 @@ namespace StardewSymphonyRemastered /// public void createBlankWAVTemplate() { + + string path = Path.Combine(TemplateMusicDirectory, "WAV"); string pathSongs = Path.Combine(path, "Songs"); if (!Directory.Exists(path)) diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj index a1f248ba..1aaf0659 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/StardewSymphonyRemastered.csproj @@ -68,6 +68,9 @@ MinimumRecommendedRules.ruleset + + ..\..\..\..\..\..\..\..\Desktop\NAudio.dll + ..\..\StardustCore\bin\Release\StardustCore.dll diff --git a/GeneralMods/StardustCore/Animations/Animation.cs b/GeneralMods/StardustCore/Animations/Animation.cs index 04f2561e..6ef5fca3 100644 --- a/GeneralMods/StardustCore/Animations/Animation.cs +++ b/GeneralMods/StardustCore/Animations/Animation.cs @@ -31,6 +31,11 @@ namespace StardustCore.Animations public NetFields NetFields { get; } = new NetFields(); + public Animation() + { + sourceRectangle = new Rectangle(); + frameDuration = -1; + } /// /// Constructor that causes the animation frame count to be set to -1; This forces it to never change.