mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-17 05:48:44 +00:00
A little bit cleaner when the logic is separated Keep an abstraction of BoxEdit to cache the current box contents. Already fetched to show sprites; any future fetches (for preview text / hover sprite) can reuse the already fetched pkm data. Should probably rewrite this stuff completely, but effort better spent elsewhere
36 lines
No EOL
986 B
C#
36 lines
No EOL
986 B
C#
using System.IO;
|
|
using System.Media;
|
|
using PKHeX.Core;
|
|
|
|
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)
|
|
{
|
|
var name = PKX.GetResourceStringSprite(pk.Species, pk.AltForm, pk.Gender, pk.Format).Replace('_', '-').Substring(1);
|
|
var path = Path.Combine(cryFolder, $"{name}.wav");
|
|
if (!File.Exists(path))
|
|
path = Path.Combine(cryFolder, $"{pk.Species}.wav");
|
|
return path;
|
|
}
|
|
}
|
|
} |