2020-06-28 04:36:53 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
using System.Media;
|
|
|
|
|
using PKHeX.Core;
|
2019-10-04 01:23:40 +00:00
|
|
|
|
using PKHeX.Drawing;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
|
|
|
{
|
2019-10-04 02:09:02 +00:00
|
|
|
|
public sealed class CryPlayer
|
2019-08-21 02:50:28 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly SoundPlayer Sounds = new SoundPlayer();
|
|
|
|
|
|
|
|
|
|
public void PlayCry(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
if (pk.Species == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
string path = GetCryPath(pk, Main.CryPath);
|
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Sounds.SoundLocation = path;
|
|
|
|
|
try { Sounds.Play(); }
|
2020-09-19 05:11:13 +00:00
|
|
|
|
#pragma warning disable CA1031 // Do not catch general exception types
|
2020-06-28 04:36:53 +00:00
|
|
|
|
catch { Debug.WriteLine("Failed to play sound."); }
|
2020-09-19 05:11:13 +00:00
|
|
|
|
#pragma warning restore CA1031 // Do not catch general exception types
|
2019-08-21 02:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop() => Sounds.Stop();
|
|
|
|
|
|
|
|
|
|
private static string GetCryPath(PKM pk, string cryFolder)
|
|
|
|
|
{
|
2019-10-04 01:35:33 +00:00
|
|
|
|
var name = GetCryFileName(pk);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
var path = Path.Combine(cryFolder, $"{name}.wav");
|
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
path = Path.Combine(cryFolder, $"{pk.Species}.wav");
|
|
|
|
|
return path;
|
|
|
|
|
}
|
2019-10-04 01:35:33 +00:00
|
|
|
|
|
|
|
|
|
private static string GetCryFileName(PKM pk)
|
|
|
|
|
{
|
2020-06-19 23:51:15 +00:00
|
|
|
|
if (pk.Species == (int)Species.Urshifu && pk.AltForm == 1) // same sprite for both forms, but different cries
|
|
|
|
|
return "892-1";
|
|
|
|
|
|
2019-10-04 01:35:33 +00:00
|
|
|
|
// don't grab sprite of pkm, no gender specific cries
|
2020-03-04 04:22:57 +00:00
|
|
|
|
var res = SpriteName.GetResourceStringSprite(pk.Species, pk.AltForm, 0, 0, pk.Format);
|
2019-10-04 01:35:33 +00:00
|
|
|
|
return res.Replace('_', '-') // people like - instead of _ file names ;)
|
|
|
|
|
.Substring(1); // skip leading underscore
|
|
|
|
|
}
|
2019-08-21 02:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|