Fixed save menu for SaveAnywhere. Also added in suport for .mp3 files via NAudio.
This commit is contained in:
parent
0529e9eebb
commit
67d77701b3
|
@ -9,8 +9,9 @@ using System.Text;
|
||||||
|
|
||||||
namespace Omegasis.SaveAnywhere.Framework
|
namespace Omegasis.SaveAnywhere.Framework
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>A marker subclass to detect when a custom save is in progress.</summary>
|
/// <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;
|
public event EventHandler SaveComplete;
|
||||||
|
|
||||||
|
@ -33,7 +34,8 @@ namespace Omegasis.SaveAnywhere.Framework
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void complete()
|
|
||||||
|
public new void complete()
|
||||||
{
|
{
|
||||||
Game1.playSound("money");
|
Game1.playSound("money");
|
||||||
this.completePause = 1500;
|
this.completePause = 1500;
|
||||||
|
@ -47,7 +49,7 @@ namespace Omegasis.SaveAnywhere.Framework
|
||||||
{
|
{
|
||||||
if (this.quit)
|
if (this.quit)
|
||||||
return;
|
return;
|
||||||
base.update(time);
|
//base.update(time);
|
||||||
if (Game1.client != null && Game1.client.timedOut)
|
if (Game1.client != null && Game1.client.timedOut)
|
||||||
{
|
{
|
||||||
this.quit = true;
|
this.quit = true;
|
||||||
|
@ -164,7 +166,7 @@ namespace Omegasis.SaveAnywhere.Framework
|
||||||
this.hasDrawn = true;
|
this.hasDrawn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public new void Dispose()
|
||||||
{
|
{
|
||||||
Game1.game1.IsSaving = false;
|
Game1.game1.IsSaving = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,6 @@ namespace Omegasis.SaveAnywhere.Framework
|
||||||
currentSaveMenu.SaveComplete -= CurrentSaveMenu_SaveComplete;
|
currentSaveMenu.SaveComplete -= CurrentSaveMenu_SaveComplete;
|
||||||
currentSaveMenu = null;
|
currentSaveMenu = null;
|
||||||
//AfterSave.Invoke(this, EventArgs.Empty);
|
//AfterSave.Invoke(this, EventArgs.Empty);
|
||||||
UnifiedSaveCore.UnifiedSaveCore.SaveEvents_AfterSave(this, EventArgs.Empty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Clear saved data.</summary>
|
/// <summary>Clear saved data.</summary>
|
||||||
|
@ -93,8 +92,6 @@ namespace Omegasis.SaveAnywhere.Framework
|
||||||
/// <summary>Initiate a game save.</summary>
|
/// <summary>Initiate a game save.</summary>
|
||||||
public void BeginSaveData()
|
public void BeginSaveData()
|
||||||
{
|
{
|
||||||
SaveAnywhere.ModMonitor.Log("SVE ANYWHERE WHAT YOU DOING???");
|
|
||||||
UnifiedSaveCore.UnifiedSaveCore.SaveEvents_BeforeSave(this, EventArgs.Empty);
|
|
||||||
|
|
||||||
// save game data
|
// save game data
|
||||||
Farm farm = Game1.getFarm();
|
Farm farm = Game1.getFarm();
|
||||||
|
@ -147,7 +144,6 @@ namespace Omegasis.SaveAnywhere.Framework
|
||||||
|
|
||||||
// Notify other mods that load is complete
|
// Notify other mods that load is complete
|
||||||
//AfterLoad.Invoke(this, EventArgs.Empty);
|
//AfterLoad.Invoke(this, EventArgs.Empty);
|
||||||
UnifiedSaveCore.UnifiedSaveCore.SaveEvents_AfterLoad(this, EventArgs.Empty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -58,7 +58,6 @@ namespace Omegasis.SaveAnywhere
|
||||||
|
|
||||||
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
|
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
|
||||||
SaveEvents.AfterSave += this.SaveEvents_AfterSave;
|
SaveEvents.AfterSave += this.SaveEvents_AfterSave;
|
||||||
MenuEvents.MenuChanged += this.MenuEvents_MenuChanged;
|
|
||||||
ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;
|
ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;
|
||||||
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
|
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
|
||||||
TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted;
|
TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted;
|
||||||
|
@ -98,15 +97,12 @@ namespace Omegasis.SaveAnywhere
|
||||||
// clear custom data after a normal save (to avoid restoring old state)
|
// clear custom data after a normal save (to avoid restoring old state)
|
||||||
if (!this.IsCustomSaving)
|
if (!this.IsCustomSaving)
|
||||||
this.SaveManager.ClearData();
|
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>
|
/// <summary>The method invoked when the game updates (roughly 60 times per second).</summary>
|
||||||
/// <param name="sender">The event sender.</param>
|
/// <param name="sender">The event sender.</param>
|
||||||
|
@ -225,7 +221,9 @@ namespace Omegasis.SaveAnywhere
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// save
|
// save
|
||||||
|
this.IsCustomSaving = true;
|
||||||
this.SaveManager.BeginSaveData();
|
this.SaveManager.BeginSaveData();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -70,12 +70,12 @@ namespace StardewSymphonyRemastered.Framework
|
||||||
{
|
{
|
||||||
try
|
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)
|
catch(Exception errr)
|
||||||
{
|
{
|
||||||
errr.ToString();
|
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)
|
catch(Exception err)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Audio;
|
using Microsoft.Xna.Framework.Audio;
|
||||||
|
using NAudio.Wave;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -15,13 +16,34 @@ namespace StardewSymphonyRemastered.Framework
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WavMusicPack : MusicPack
|
public class WavMusicPack : MusicPack
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The refererence to the information for the current song.
|
||||||
|
/// </summary>
|
||||||
public Song currentSong;
|
public Song currentSong;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The directory where all of the songs are stored.
|
||||||
|
/// </summary>
|
||||||
public string songsDirectory;
|
public string songsDirectory;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The currently playing sound.
|
||||||
|
/// </summary>
|
||||||
public SoundEffectInstance sound;
|
public SoundEffectInstance sound;
|
||||||
|
|
||||||
|
|
||||||
bool loop;
|
bool loop;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name of the music pack/
|
||||||
|
/// </summary>
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return musicPackInformation.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Dictionary<string,SoundEffectInstance> sounds;
|
public Dictionary<string,SoundEffectInstance> sounds;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -98,22 +120,76 @@ namespace StardewSymphonyRemastered.Framework
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void loadMusicFiles()
|
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>();
|
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);
|
MemoryStream memoryStream = new MemoryStream();
|
||||||
SoundEffect eff = SoundEffect.FromStream(waveFileStream);
|
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();
|
SoundEffectInstance instance = eff.CreateInstance();
|
||||||
|
|
||||||
|
|
||||||
string name = Path.GetFileNameWithoutExtension(wav);
|
string name = Path.GetFileNameWithoutExtension(wav);
|
||||||
|
if (this.sounds.ContainsKey(name))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this.sounds.Add(name, instance);
|
this.sounds.Add(name, instance);
|
||||||
|
|
||||||
waveFileStream.Dispose();
|
//waveFileStream.Dispose();
|
||||||
Song song = new Song(wav);
|
Song song = new Song(wav);
|
||||||
this.songInformation.listOfSongsWithoutTriggers.Add(song);
|
this.songInformation.listOfSongsWithoutTriggers.Add(song);
|
||||||
//listOfSongs.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>
|
/// <summary>
|
||||||
|
|
|
@ -10,6 +10,7 @@ using StardewValley;
|
||||||
using StardewSymphonyRemastered.Framework;
|
using StardewSymphonyRemastered.Framework;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using StardustCore.UIUtilities;
|
using StardustCore.UIUtilities;
|
||||||
|
using NAudio.Wave;
|
||||||
|
|
||||||
namespace StardewSymphonyRemastered
|
namespace StardewSymphonyRemastered
|
||||||
{
|
{
|
||||||
|
@ -405,6 +406,8 @@ namespace StardewSymphonyRemastered
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void createBlankWAVTemplate()
|
public void createBlankWAVTemplate()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
string path = Path.Combine(TemplateMusicDirectory, "WAV");
|
string path = Path.Combine(TemplateMusicDirectory, "WAV");
|
||||||
string pathSongs = Path.Combine(path, "Songs");
|
string pathSongs = Path.Combine(path, "Songs");
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
|
|
|
@ -68,6 +68,9 @@
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="NAudio">
|
||||||
|
<HintPath>..\..\..\..\..\..\..\..\Desktop\NAudio.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="StardustCore">
|
<Reference Include="StardustCore">
|
||||||
<HintPath>..\..\StardustCore\bin\Release\StardustCore.dll</HintPath>
|
<HintPath>..\..\StardustCore\bin\Release\StardustCore.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
|
@ -31,6 +31,11 @@ namespace StardustCore.Animations
|
||||||
public NetFields NetFields { get; } = new NetFields();
|
public NetFields NetFields { get; } = new NetFields();
|
||||||
|
|
||||||
|
|
||||||
|
public Animation()
|
||||||
|
{
|
||||||
|
sourceRectangle = new Rectangle();
|
||||||
|
frameDuration = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor that causes the animation frame count to be set to -1; This forces it to never change.
|
/// Constructor that causes the animation frame count to be set to -1; This forces it to never change.
|
||||||
|
|
Loading…
Reference in New Issue