PKHeX/PKHeX.WinForms/Controls/Slots/CryPlayer.cs
Kurt 0d45075d4b
Rewrite settings handling; enhance some user experiences (#3193)
- Settings now stored as json next to exe
- Settings now exposes all legality checking setttings that can be changed
- Slot hovering now can play cries in MGDB/PKMDB/etc, not just the main boxes.
- Enhanced hover text for mystery gifts and encounters that have movesets
- Show recently loaded save files in ctrl-f browser
- Toggle auto-load savefile setting to be none/detect-latest/last-loaded
- Custom extensions & extra backup paths can now be configured directly in the json settings
- Settings editor now uses propertygrid & tabs.
2021-04-11 18:09:54 -07:00

51 lines
1.7 KiB
C#

using System.Diagnostics;
using System.IO;
using System.Media;
using PKHeX.Core;
using PKHeX.Drawing;
namespace PKHeX.WinForms.Controls
{
public sealed class CryPlayer
{
private readonly SoundPlayer Sounds = new();
public void PlayCry(ISpeciesForm pk, int format)
{
if (pk.Species == 0)
return;
string path = GetCryPath(pk, Main.CryPath, format);
if (!File.Exists(path))
return;
Sounds.SoundLocation = path;
try { Sounds.Play(); }
#pragma warning disable CA1031 // Do not catch general exception types
catch { Debug.WriteLine("Failed to play sound."); }
#pragma warning restore CA1031 // Do not catch general exception types
}
public void Stop() => Sounds.Stop();
private static string GetCryPath(ISpeciesForm pk, string cryFolder, int format)
{
var name = GetCryFileName(pk, format);
var path = Path.Combine(cryFolder, $"{name}.wav");
if (!File.Exists(path))
path = Path.Combine(cryFolder, $"{pk.Species}.wav");
return path;
}
private static string GetCryFileName(ISpeciesForm pk, int format)
{
if (pk.Species == (int)Species.Urshifu && pk.Form == 1) // same sprite for both forms, but different cries
return "892-1";
// don't grab sprite of pkm, no gender specific cries
var res = SpriteName.GetResourceStringSprite(pk.Species, pk.Form, 0, 0, format);
return res.Replace('_', '-') // people like - instead of _ file names ;)
.Substring(1); // skip leading underscore
}
}
}