2019-08-21 02:50:28 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
2019-09-29 16:47:06 +00:00
|
|
|
|
using PKHeX.Drawing;
|
2021-11-27 23:48:08 +00:00
|
|
|
|
using PKHeX.Drawing.PokeSprite;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles Hovering operations for an editor, where only one (1) slot can be animated at a given time when hovering over it.
|
|
|
|
|
/// </summary>
|
2019-10-04 02:09:02 +00:00
|
|
|
|
public sealed class SlotHoverHandler : IDisposable
|
2019-08-21 02:50:28 +00:00
|
|
|
|
{
|
2020-12-22 07:37:07 +00:00
|
|
|
|
public DrawConfig Draw { private get; set; } = new();
|
2019-08-21 02:50:28 +00:00
|
|
|
|
public bool GlowHover { private get; set; } = true;
|
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
public static readonly CryPlayer CryPlayer = new();
|
|
|
|
|
public static readonly SummaryPreviewer Preview = new();
|
2019-11-16 01:34:18 +00:00
|
|
|
|
private static Bitmap Hover => SpriteUtil.Spriter.Hover;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
private readonly BitmapAnimator HoverWorker = new();
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private PictureBox? Slot;
|
|
|
|
|
private SlotTrackerImage? LastSlot;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
2020-01-04 03:46:04 +00:00
|
|
|
|
public void Start(PictureBox pb, SlotTrackerImage lastSlot)
|
2019-08-21 02:50:28 +00:00
|
|
|
|
{
|
|
|
|
|
var view = WinFormsUtil.FindFirstControlOfType<ISlotViewer<PictureBox>>(pb);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (view == null)
|
2020-11-14 16:20:48 +00:00
|
|
|
|
throw new InvalidCastException(nameof(view));
|
2019-08-21 02:50:28 +00:00
|
|
|
|
var data = view.GetSlotData(pb);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var pk = data.Read(view.SAV);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Slot = pb;
|
2020-01-04 03:46:04 +00:00
|
|
|
|
LastSlot = lastSlot;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
|
|
|
|
var orig = LastSlot.OriginalBackground = pb.BackgroundImage;
|
|
|
|
|
|
|
|
|
|
Bitmap bg;
|
|
|
|
|
if (GlowHover)
|
|
|
|
|
{
|
|
|
|
|
HoverWorker.Stop();
|
2019-11-16 01:34:18 +00:00
|
|
|
|
var hover = Hover;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
SpriteUtil.GetSpriteGlow(pk, Draw.GlowInitial.B, Draw.GlowInitial.G, Draw.GlowInitial.R, out var glowdata, out var GlowBase);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
bg = ImageUtil.LayerImage(GlowBase, hover, 0, 0);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
HoverWorker.GlowToColor = Draw.GlowFinal;
|
|
|
|
|
HoverWorker.GlowFromColor = Draw.GlowInitial;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
HoverWorker.Start(pb, GlowBase, glowdata, orig, hover);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
bg = Hover;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (orig != null)
|
|
|
|
|
bg = ImageUtil.LayerImage(orig, bg, 0, 0);
|
|
|
|
|
pb.BackgroundImage = LastSlot.CurrentBackground = bg;
|
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
Preview.Show(pb, pk);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
if (Slot != null)
|
|
|
|
|
{
|
2020-01-04 03:46:04 +00:00
|
|
|
|
if (HoverWorker.Enabled)
|
|
|
|
|
HoverWorker.Stop();
|
|
|
|
|
else
|
2020-10-18 18:02:39 +00:00
|
|
|
|
Slot.BackgroundImage = LastSlot?.OriginalBackground;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Slot = null;
|
2020-01-04 03:46:04 +00:00
|
|
|
|
LastSlot = null;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
Preview.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
HoverWorker.Dispose();
|
|
|
|
|
Slot = null;
|
|
|
|
|
Draw.Dispose();
|
2019-08-21 02:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|