2019-08-21 02:50:28 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
public class CryPlayer
|
|
|
|
|
{
|
|
|
|
|
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(); }
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop() => Sounds.Stop();
|
|
|
|
|
|
|
|
|
|
private static string GetCryPath(PKM pk, string cryFolder)
|
|
|
|
|
{
|
2019-10-04 01:23:40 +00:00
|
|
|
|
var name = SpriteName.GetResourceStringSprite(pk.Species, pk.AltForm, pk.Gender, pk.Format).Replace('_', '-').Substring(1);
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|