2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2019-08-21 02:50:28 +00:00
|
|
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms.Controls;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +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>
|
|
|
|
public sealed class SlotHoverHandler : IDisposable
|
|
|
|
{
|
|
|
|
public DrawConfig Draw { private get; set; } = new();
|
|
|
|
public bool GlowHover { private get; set; } = true;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static readonly CryPlayer CryPlayer = new();
|
|
|
|
public static readonly SummaryPreviewer Preview = new();
|
|
|
|
private static Bitmap Hover => SpriteUtil.Spriter.Hover;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly BitmapAnimator HoverWorker = new();
|
2019-08-21 02:50:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private PictureBox? Slot;
|
|
|
|
private SlotTrackerImage? LastSlot;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void Start(PictureBox pb, SlotTrackerImage lastSlot)
|
|
|
|
{
|
|
|
|
var view = WinFormsUtil.FindFirstControlOfType<ISlotViewer<PictureBox>>(pb);
|
|
|
|
if (view == null)
|
|
|
|
throw new InvalidCastException(nameof(view));
|
|
|
|
var data = view.GetSlotData(pb);
|
|
|
|
var pk = data.Read(view.SAV);
|
|
|
|
Slot = pb;
|
|
|
|
LastSlot = lastSlot;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var orig = LastSlot.OriginalBackground = pb.BackgroundImage;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Bitmap bg;
|
|
|
|
if (GlowHover)
|
|
|
|
{
|
|
|
|
HoverWorker.Stop();
|
|
|
|
var hover = Hover;
|
2023-01-22 04:02:33 +00:00
|
|
|
var glow = Draw.GlowInitial;
|
|
|
|
SpriteUtil.GetSpriteGlow(pk, glow.B, glow.G, glow.R, out var glowdata, out var imgGlowBase);
|
|
|
|
bg = ImageUtil.LayerImage(imgGlowBase, hover, 0, 0);
|
2022-06-18 18:04:24 +00:00
|
|
|
HoverWorker.GlowToColor = Draw.GlowFinal;
|
|
|
|
HoverWorker.GlowFromColor = Draw.GlowInitial;
|
2023-01-22 04:02:33 +00:00
|
|
|
HoverWorker.Start(pb, imgGlowBase, glowdata, orig, hover);
|
2019-08-21 02:50:28 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2019-08-21 02:50:28 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
bg = Hover;
|
2019-08-21 02:50:28 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (orig != null)
|
|
|
|
bg = ImageUtil.LayerImage(orig, bg, 0, 0);
|
|
|
|
pb.BackgroundImage = LastSlot.CurrentBackground = bg;
|
|
|
|
|
|
|
|
Preview.Show(pb, pk);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
{
|
|
|
|
if (Slot != null)
|
2019-08-21 02:50:28 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (HoverWorker.Enabled)
|
|
|
|
HoverWorker.Stop();
|
|
|
|
else
|
|
|
|
Slot.BackgroundImage = LastSlot?.OriginalBackground;
|
2020-10-18 18:02:39 +00:00
|
|
|
Slot = null;
|
2022-06-18 18:04:24 +00:00
|
|
|
LastSlot = null;
|
2019-08-21 02:50:28 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
Preview.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
HoverWorker.Dispose();
|
|
|
|
Slot = null;
|
|
|
|
Draw.Dispose();
|
2019-08-21 02:50:28 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|