Fixed save menu for SaveAnywhere. Also added in suport for .mp3 files via NAudio.

This commit is contained in:
Joshua Navarro 2018-12-10 01:33:10 -08:00
parent 0529e9eebb
commit 67d77701b3
8 changed files with 107 additions and 24 deletions

View File

@ -9,8 +9,9 @@ using System.Text;
namespace Omegasis.SaveAnywhere.Framework
{
/// <summary>A marker subclass to detect when a custom save is in progress.</summary>
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;
}

View File

@ -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);
}
/// <summary>Clear saved data.</summary>
@ -93,8 +92,6 @@ namespace Omegasis.SaveAnywhere.Framework
/// <summary>Initiate a game save.</summary>
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);
}
/// <summary>

View File

@ -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;
}
}
/// <summary>The method invoked after a menu is opened or changed.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event data.</param>
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
{
this.IsCustomSaving = e.NewMenu != null && (e.NewMenu is NewSaveGameMenu || e.NewMenu is NewShippingMenu);
}
/// <summary>The method invoked when the game updates (roughly 60 times per second).</summary>
/// <param name="sender">The event sender.</param>
@ -225,7 +221,9 @@ namespace Omegasis.SaveAnywhere
return;
}
// save
this.IsCustomSaving = true;
this.SaveManager.BeginSaveData();
}
else

View File

@ -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)

View File

@ -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
/// </summary>
public class WavMusicPack : MusicPack
{
/// <summary>
/// The refererence to the information for the current song.
/// </summary>
public Song currentSong;
/// <summary>
/// The directory where all of the songs are stored.
/// </summary>
public string songsDirectory;
/// <summary>
/// The currently playing sound.
/// </summary>
public SoundEffectInstance sound;
bool loop;
/// <summary>
/// The name of the music pack/
/// </summary>
public string Name
{
get
{
return musicPackInformation.name;
}
}
public Dictionary<string,SoundEffectInstance> sounds;
/// <summary>
@ -98,22 +120,76 @@ namespace StardewSymphonyRemastered.Framework
/// </summary>
public override void loadMusicFiles()
{
string[] wavFiles = Directory.GetFiles(this.songsDirectory, "*.wav");
List<string> wavFiles = Directory.GetFiles(this.songsDirectory, "*.wav").ToList();
wavFiles.AddRange(Directory.GetFiles(this.songsDirectory, "*.mp3"));
List<Song> listOfSongs = new List<Song>();
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());
}
/// <summary>

View File

@ -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
/// </summary>
public void createBlankWAVTemplate()
{
string path = Path.Combine(TemplateMusicDirectory, "WAV");
string pathSongs = Path.Combine(path, "Songs");
if (!Directory.Exists(path))

View File

@ -68,6 +68,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="NAudio">
<HintPath>..\..\..\..\..\..\..\..\Desktop\NAudio.dll</HintPath>
</Reference>
<Reference Include="StardustCore">
<HintPath>..\..\StardustCore\bin\Release\StardustCore.dll</HintPath>
</Reference>

View File

@ -31,6 +31,11 @@ namespace StardustCore.Animations
public NetFields NetFields { get; } = new NetFields();
public Animation()
{
sourceRectangle = new Rectangle();
frameDuration = -1;
}
/// <summary>
/// Constructor that causes the animation frame count to be set to -1; This forces it to never change.