PKHeX/PKHeX.WinForms/Controls/Slots/SummaryPreviewer.cs
Kurt c73264d4f3 Minor minor perf
Small changes to reduce some allocations
2023-04-15 01:58:37 -07:00

58 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls;
public sealed class SummaryPreviewer
{
private readonly ToolTip ShowSet = new() { InitialDelay = 200, IsBalloon = false, AutoPopDelay = 32_767 };
private readonly CryPlayer Cry = new();
public void Show(Control pb, PKM pk)
{
if (pk.Species == 0)
{
Clear();
return;
}
if (Main.Settings.Hover.HoverSlotShowText)
{
var text = ShowdownParsing.GetLocalizedPreviewText(pk, Main.Settings.Startup.Language);
var la = new LegalityAnalysis(pk);
var result = new List<string> { text, string.Empty };
LegalityFormatting.AddEncounterInfo(la, result);
ShowSet.SetToolTip(pb, string.Join(Environment.NewLine, result));
}
if (Main.Settings.Hover.HoverSlotPlayCry)
Cry.PlayCry(pk, pk.Context);
}
public void Show(Control pb, IEncounterInfo enc)
{
if (enc.Species == 0)
{
Clear();
return;
}
if (Main.Settings.Hover.HoverSlotShowText)
{
var lines = enc.GetTextLines(GameInfo.Strings);
var text = string.Join(Environment.NewLine, lines);
ShowSet.SetToolTip(pb, text);
}
if (Main.Settings.Hover.HoverSlotPlayCry)
Cry.PlayCry(enc, enc.Context);
}
public void Clear()
{
ShowSet.RemoveAll();
Cry.Stop();
}
}