mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-09 23:06:13 -05:00
Show preview for encounter database slots on hover
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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<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 @@ 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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user