From a2d5d7d769094a60b38ffa0626b44c6412ef92be Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 6 Feb 2021 22:33:13 -0800 Subject: [PATCH] Show preview for encounter database slots on hover --- PKHeX.Core/Legality/Structures/ILocation.cs | 2 +- .../Controls/Slots/SummaryPreviewer.cs | 35 +++++++++++++++++-- PKHeX.WinForms/Subforms/SAV_Encounters.cs | 21 +++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/PKHeX.Core/Legality/Structures/ILocation.cs b/PKHeX.Core/Legality/Structures/ILocation.cs index c580374ac..610e9ea96 100644 --- a/PKHeX.Core/Legality/Structures/ILocation.cs +++ b/PKHeX.Core/Legality/Structures/ILocation.cs @@ -15,7 +15,7 @@ public static int GetLocation(this ILocation encounter) : encounter.EggLocation; } - internal static string? GetEncounterLocation(this ILocation Encounter, int gen, int version = -1) + public static string? GetEncounterLocation(this ILocation Encounter, int gen, int version = -1) { int loc = Encounter.GetLocation(); if (loc < 0) diff --git a/PKHeX.WinForms/Controls/Slots/SummaryPreviewer.cs b/PKHeX.WinForms/Controls/Slots/SummaryPreviewer.cs index 098b1ac6b..3c6f63872 100644 --- a/PKHeX.WinForms/Controls/Slots/SummaryPreviewer.cs +++ b/PKHeX.WinForms/Controls/Slots/SummaryPreviewer.cs @@ -1,7 +1,11 @@ -using System.Windows.Forms; +using System; +using System.Collections.Generic; +using System.Windows.Forms; using PKHeX.Core; using PKHeX.WinForms.Properties; +using static PKHeX.Core.LegalityCheckStrings; + namespace PKHeX.WinForms.Controls { public sealed class SummaryPreviewer @@ -19,6 +23,33 @@ public void Show(Control pb, PKM pk) ShowSet.SetToolTip(pb, text); } + public void Show(Control pb, IEncounterInfo enc) + { + if (enc.Species == 0) + { + Clear(); + return; + } + + var lines = new List(); + var str = GameInfo.Strings.Species; + var name = (uint)enc.Species < str.Count ? str[enc.Species] : enc.Species.ToString(); + var EncounterName = $"{(enc is IEncounterable ie ? ie.LongName : "Special")} ({name})"; + lines.Add(string.Format(L_FEncounterType_0, EncounterName)); + + var el = enc as ILocation; + var loc = el?.GetEncounterLocation(enc.Generation, (int)enc.Version); + if (!string.IsNullOrEmpty(loc)) + lines.Add(string.Format(L_F0_1, "Location", loc)); + lines.Add(string.Format(L_F0_1, nameof(GameVersion), enc.Version)); + lines.Add(enc.LevelMin == enc.LevelMax + ? $"Level: {enc.LevelMin}" + : $"Level: {enc.LevelMin}-{enc.LevelMax}"); + + var text = string.Join(Environment.NewLine, lines); + ShowSet.SetToolTip(pb, text); + } + public void Clear() => ShowSet.RemoveAll(); } -} \ No newline at end of file +} diff --git a/PKHeX.WinForms/Subforms/SAV_Encounters.cs b/PKHeX.WinForms/Subforms/SAV_Encounters.cs index c9b84c067..e7ae9c348 100644 --- a/PKHeX.WinForms/Subforms/SAV_Encounters.cs +++ b/PKHeX.WinForms/Subforms/SAV_Encounters.cs @@ -18,6 +18,7 @@ public partial class SAV_Encounters : Form { private readonly PKMEditor PKME_Tabs; private SaveFile SAV => PKME_Tabs.RequestSaveFile; + private readonly SummaryPreviewer ShowSet = new(); public SAV_Encounters(PKMEditor f1) { @@ -53,6 +54,8 @@ public SAV_Encounters(PKMEditor f1) ClickView(sender, e); }; slot.ContextMenuStrip = mnu; + if (Settings.Default.HoverSlotShowText) + slot.MouseEnter += (o, args) => ShowHoverTextForSlot(slot, args); } Counter = L_Count.Text; @@ -102,6 +105,14 @@ private EncounterOrder[] GetTypes() private const int RES_MIN = 6; private readonly string Counter; + private bool GetShiftedIndex(ref int index) + { + if (index >= RES_MAX) + return false; + index += SCR_Box.Value * RES_MIN; + return index < Results.Count; + } + // Important Events private void ClickView(object sender, EventArgs e) { @@ -330,5 +341,15 @@ protected override void OnMouseWheel(MouseEventArgs e) if (newval >= SCR_Box.Minimum && SCR_Box.Maximum >= newval) FillPKXBoxes(SCR_Box.Value = newval); } + + private void ShowHoverTextForSlot(object sender, EventArgs e) + { + var pb = (PictureBox)sender; + int index = Array.IndexOf(PKXBOXES, pb); + if (!GetShiftedIndex(ref index)) + return; + + ShowSet.Show(pb, Results[index]); + } } }