PKHeX/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs
Kurt bf6c25eca7 Break up SlotChangeManager logic
A little bit cleaner when the logic is separated
Keep an abstraction of BoxEdit to cache the current box contents.
Already fetched to show sprites; any future fetches (for preview text /
hover sprite) can reuse the already fetched pkm data.

Should probably rewrite this stuff completely, but effort better spent
elsewhere
2019-08-20 19:50:28 -07:00

62 lines
2 KiB
C#

using System;
using System.Windows.Forms;
using PKHeX.Core;
using PKHeX.WinForms.Controls;
namespace PKHeX.WinForms
{
public sealed partial class SAV_BoxViewer : Form
{
private readonly SAVEditor parent;
public SAV_BoxViewer(SAVEditor p, SlotChangeManager m)
{
parent = p;
InitializeComponent();
Box.Editor = new BoxEdit(m.SE.SAV);
Box.Setup(m);
Box.Reset();
CenterToParent();
AllowDrop = true;
GiveFeedback += (sender, e) => e.UseDefaultCursors = false;
DragEnter += Main_DragEnter;
DragDrop += (sender, e) =>
{
Cursor = DefaultCursor;
System.Media.SystemSounds.Asterisk.Play();
};
Owner = p.ParentForm;
MouseWheel += (s, e) =>
{
if (parent.menu.mnuVSD.Visible)
return;
Box.CurrentBox = e.Delta > 1 ? Box.Editor.MoveLeft() : Box.Editor.MoveRight();
};
foreach (PictureBox pb in Box.SlotPictureBoxes)
pb.ContextMenuStrip = parent.SlotPictureBoxes[0].ContextMenuStrip;
Box.ResetBoxNames(); // fix box names
Box.ResetSlots(); // refresh box background
}
public int CurrentBox => Box.CurrentBox;
private void PB_BoxSwap_Click(object sender, EventArgs e) => Box.CurrentBox = parent.SwapBoxesViewer(Box.CurrentBox);
public void SetPKMBoxes() => Box.ResetSlots();
private static void Main_DragEnter(object sender, DragEventArgs e)
{
if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file
e.Effect = DragDropEffects.Copy;
else if (e.Data != null) // within
e.Effect = DragDropEffects.Move;
}
private void SAV_BoxViewer_FormClosing(object sender, FormClosingEventArgs e)
{
// Remove viewer from manager list
Box.M.Boxes.Remove(Box);
}
}
}