mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-14 00:07:15 +00:00
Show preview for encounter database slots on hover
This commit is contained in:
parent
30cbe117dc
commit
a2d5d7d769
3 changed files with 55 additions and 3 deletions
|
@ -15,7 +15,7 @@
|
|||
: 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)
|
||||
|
|
|
@ -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 @@ namespace PKHeX.WinForms.Controls
|
|||
ShowSet.SetToolTip(pb, text);
|
||||
}
|
||||
|
||||
public void Show(Control pb, IEncounterInfo enc)
|
||||
{
|
||||
if (enc.Species == 0)
|
||||
{
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = new List<string>();
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ namespace PKHeX.WinForms
|
|||
{
|
||||
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 @@ namespace PKHeX.WinForms
|
|||
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 @@ namespace PKHeX.WinForms
|
|||
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 @@ namespace PKHeX.WinForms
|
|||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue