2017-05-23 04:55:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-07-02 02:43:51 +00:00
|
|
|
|
using System.Diagnostics;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
2018-09-16 19:44:00 +00:00
|
|
|
|
using System.Linq;
|
2018-05-11 23:58:29 +00:00
|
|
|
|
using System.Media;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using PKHeX.WinForms.Properties;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-09-03 02:30:58 +00:00
|
|
|
|
/// Orchestrates the movement of slots within the GUI.
|
2017-05-23 04:55:05 +00:00
|
|
|
|
/// </summary>
|
2017-12-16 22:11:41 +00:00
|
|
|
|
public sealed class SlotChangeManager : IDisposable
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
public readonly SAVEditor SE;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
public readonly SlotTrackerImage LastSlot = new SlotTrackerImage();
|
|
|
|
|
public readonly DragManager Drag = new DragManager();
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public SaveDataEditor<PictureBox> Env { get; set; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public readonly List<BoxEditor> Boxes = new List<BoxEditor>();
|
2019-08-21 02:50:28 +00:00
|
|
|
|
public readonly SlotHoverHandler Hover = new SlotHoverHandler();
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
public SlotChangeManager(SAVEditor se) => SE = se;
|
2018-05-11 23:38:09 +00:00
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
public void Reset()
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
Drag.Initialize();
|
2019-08-21 02:50:28 +00:00
|
|
|
|
LastSlot.Reset();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public void MouseEnter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var pb = (PictureBox)sender;
|
|
|
|
|
if (pb.Image == null)
|
|
|
|
|
return;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Hover.Start(pb, LastSlot);
|
2018-05-13 15:14:46 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-05-13 15:14:46 +00:00
|
|
|
|
public void MouseLeave(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Hover.Stop();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public void MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
if (!Drag.Info.DragDropInProgress)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SE.ClickSlot(sender, e);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public void MouseUp(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.Info.LeftMouseIsDown = false;
|
2019-09-04 02:54:41 +00:00
|
|
|
|
Drag.Info.Source = null;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public void MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
2018-05-11 23:38:09 +00:00
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.Info.LeftMouseIsDown = true;
|
|
|
|
|
Drag.MouseDownPosition = Cursor.Position;
|
2018-05-11 23:38:09 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public void QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Action != DragAction.Cancel && e.Action != DragAction.Drop)
|
|
|
|
|
return;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.Info.LeftMouseIsDown = false;
|
|
|
|
|
Drag.Info.DragDropInProgress = false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public void DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
2019-09-04 02:54:41 +00:00
|
|
|
|
if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) // external file
|
2017-05-23 04:55:05 +00:00
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
else if (e.Data != null) // within
|
|
|
|
|
e.Effect = DragDropEffects.Move;
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
if (Drag.Info.DragDropInProgress)
|
|
|
|
|
Drag.SetCursor(((Control)sender).FindForm(), Drag.Info.Cursor);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-09-04 02:54:41 +00:00
|
|
|
|
private static SlotViewInfo<T> GetSlotInfo<T>(T pb) where T : Control
|
|
|
|
|
{
|
|
|
|
|
var view = WinFormsUtil.FindFirstControlOfType<ISlotViewer<T>>(pb);
|
|
|
|
|
var src = view.GetSlotData(pb);
|
|
|
|
|
return new SlotViewInfo<T> { Slot = src, View = view };
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-11 23:38:09 +00:00
|
|
|
|
public void MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
if (!Drag.CanStartDrag)
|
2018-05-11 23:38:09 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Abort if there is no Pokemon in the given slot.
|
|
|
|
|
PictureBox pb = (PictureBox)sender;
|
|
|
|
|
if (pb.Image == null)
|
|
|
|
|
return;
|
2019-09-04 02:54:41 +00:00
|
|
|
|
var src = GetSlotInfo(pb);
|
|
|
|
|
if (!src.CanWriteTo())
|
2018-05-11 23:38:09 +00:00
|
|
|
|
return;
|
|
|
|
|
bool encrypt = Control.ModifierKeys == Keys.Control;
|
2018-05-12 15:41:23 +00:00
|
|
|
|
HandleMovePKM(pb, encrypt);
|
2018-05-11 23:38:09 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-05-11 23:38:09 +00:00
|
|
|
|
public void DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
PictureBox pb = (PictureBox)sender;
|
2019-09-04 02:54:41 +00:00
|
|
|
|
var info = GetSlotInfo(pb);
|
|
|
|
|
if (!info.CanWriteTo())
|
2018-05-11 23:38:09 +00:00
|
|
|
|
{
|
2018-05-11 23:58:29 +00:00
|
|
|
|
SystemSounds.Asterisk.Play();
|
2018-05-11 23:38:09 +00:00
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.Reset();
|
2018-05-11 23:38:09 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
var mod = SlotUtil.GetDropModifier();
|
2019-09-04 02:54:41 +00:00
|
|
|
|
Drag.Info.Destination = info;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
HandleDropPKM(pb, e, mod);
|
2018-05-11 23:58:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
private void HandleMovePKM(PictureBox pb, bool encrypt)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
// Create a temporary PKM file to perform a drag drop operation.
|
|
|
|
|
|
|
|
|
|
// Set flag to prevent re-entering.
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.Info.DragDropInProgress = true;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// Prepare Data
|
2019-09-04 02:54:41 +00:00
|
|
|
|
Drag.Info.Source = GetSlotInfo(pb);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// Make a new file name based off the PID
|
2018-05-12 15:41:23 +00:00
|
|
|
|
string newfile = CreateDragDropPKM(pb, encrypt, out bool external);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
|
|
|
|
// drop finished, clean up
|
2019-09-04 02:54:41 +00:00
|
|
|
|
Drag.Info.Source = null;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.Reset();
|
|
|
|
|
Drag.ResetCursor(pb.FindForm());
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// Browser apps need time to load data since the file isn't moved to a location on the user's local storage.
|
|
|
|
|
// Tested 10ms -> too quick, 100ms was fine. 500ms should be safe?
|
2018-12-17 19:17:19 +00:00
|
|
|
|
// Keep it to 10 seconds; Discord upload only stores the file path until you click Upload.
|
|
|
|
|
int delay = external ? 10_000 : 0;
|
2017-07-02 02:43:51 +00:00
|
|
|
|
DeleteAsync(newfile, delay);
|
2019-09-04 02:54:41 +00:00
|
|
|
|
if (Drag.Info.DragIsParty)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SE.SetParty();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-07-02 02:43:51 +00:00
|
|
|
|
private async void DeleteAsync(string path, int delay)
|
|
|
|
|
{
|
2018-05-25 04:22:44 +00:00
|
|
|
|
await Task.Delay(delay).ConfigureAwait(true);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
if (File.Exists(path) && Drag.Info.CurrentPath == null)
|
2017-07-02 02:43:51 +00:00
|
|
|
|
File.Delete(path);
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-05-12 15:41:23 +00:00
|
|
|
|
private string CreateDragDropPKM(PictureBox pb, bool encrypt, out bool external)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
// Make File
|
2019-09-04 02:54:41 +00:00
|
|
|
|
PKM pk = Drag.Info.Source.ReadCurrent();
|
2019-02-15 19:46:46 +00:00
|
|
|
|
string newfile = FileUtil.GetPKMTempFileName(pk, encrypt);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
var data = encrypt ? pk.EncryptedBoxData : pk.DecryptedBoxData;
|
|
|
|
|
external = TryMakeDragDropPKM(pb, data, newfile);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception x)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Error("Drag & Drop Error", x);
|
|
|
|
|
external = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newfile;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
private bool TryMakeDragDropPKM(PictureBox pb, byte[] data, string newfile)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
File.WriteAllBytes(newfile, data);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
var img = (Bitmap)pb.Image;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.SetCursor(pb.FindForm(), new Cursor(img.GetHicon()));
|
|
|
|
|
Hover.Stop();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
pb.Image = null;
|
|
|
|
|
pb.BackgroundImage = Resources.slotDrag;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Thread Blocks on DoDragDrop
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.Info.CurrentPath = newfile;
|
|
|
|
|
var result = pb.DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var external = Drag.Info.Source == null || result != DragDropEffects.Link;
|
|
|
|
|
if (external || Drag.Info.Source.Equals(Drag.Info.Destination)) // not dropped to another box slot, restore img
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
pb.Image = img;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
pb.BackgroundImage = LastSlot.OriginalBackground;
|
|
|
|
|
Drag.ResetCursor(pb.FindForm());
|
|
|
|
|
return external;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result == DragDropEffects.Copy) // viewed in tabs or cloned
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (Drag.Info.Destination == null) // apply 'view' highlight
|
2019-09-04 02:54:41 +00:00
|
|
|
|
Env.Slots.Get(Drag.Info.Source.Slot);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return true;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
private void HandleDropPKM(PictureBox pb, DragEventArgs e, DropModifier mod)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
|
|
|
if (Directory.Exists(files[0])) // folder
|
|
|
|
|
{
|
|
|
|
|
SE.LoadBoxes(out string _, files[0]);
|
2019-09-23 22:13:22 +00:00
|
|
|
|
Drag.Reset();
|
2019-08-21 02:50:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Effect = mod == DropModifier.Clone ? DragDropEffects.Copy : DragDropEffects.Link;
|
|
|
|
|
|
|
|
|
|
// file
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (Drag.Info.SameLocation)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Link;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
|
|
|
|
var dest = Drag.Info.Destination;
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (Drag.Info.Source == null) // external source
|
2017-05-24 01:35:32 +00:00
|
|
|
|
{
|
2019-09-04 02:54:41 +00:00
|
|
|
|
bool badDest = !dest.CanWriteTo();
|
2019-08-21 02:50:28 +00:00
|
|
|
|
if (!TryLoadFiles(files, e, badDest))
|
2019-09-03 02:30:58 +00:00
|
|
|
|
WinFormsUtil.Alert(MessageStrings.MsgSaveSlotBadData);
|
2017-06-22 03:24:42 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
else if (!TrySetPKMDestination(pb, mod))
|
2017-06-22 03:24:42 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
WinFormsUtil.Alert(MessageStrings.MsgSaveSlotEmpty);
|
2017-05-24 01:35:32 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
Drag.Reset();
|
2017-06-22 03:24:42 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tries to load the input <see cref="files"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="files">Files to load</param>
|
|
|
|
|
/// <param name="e">Args</param>
|
|
|
|
|
/// <param name="badDest">Destination slot disallows eggs/blanks</param>
|
|
|
|
|
/// <returns>True if loaded</returns>
|
|
|
|
|
private bool TryLoadFiles(IReadOnlyList<string> files, DragEventArgs e, bool badDest)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2018-09-16 19:44:00 +00:00
|
|
|
|
if (files.Count == 0)
|
2017-07-11 01:57:03 +00:00
|
|
|
|
return false;
|
2018-09-16 19:44:00 +00:00
|
|
|
|
|
2019-09-04 02:54:41 +00:00
|
|
|
|
var sav = Drag.Info.Destination.View.SAV;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
var path = files[0];
|
|
|
|
|
var temp = FileUtil.GetSingleFromPath(path, sav);
|
2018-09-16 19:44:00 +00:00
|
|
|
|
if (temp == null)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.RequestDD(this, e); // pass thru
|
2018-05-25 02:05:13 +00:00
|
|
|
|
return true; // treat as handled
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
PKM pk = PKMConverter.ConvertToType(temp, sav.PKMType, out string c);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (pk == null)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Error(c);
|
2017-07-02 02:43:51 +00:00
|
|
|
|
Debug.WriteLine(c);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
if (badDest && (pk.Species == 0 || pk.IsEgg))
|
2017-06-22 03:24:42 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(pk.Format, il.Japanese, pk.Japanese))
|
2018-07-24 22:49:00 +00:00
|
|
|
|
{
|
2019-07-14 22:06:45 +00:00
|
|
|
|
c = PKMConverter.GetIncompatibleGBMessage(pk, il.Japanese);
|
2018-07-24 22:49:00 +00:00
|
|
|
|
WinFormsUtil.Error(c);
|
|
|
|
|
Debug.WriteLine(c);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
var errata = sav.IsPKMCompatible(pk);
|
2018-07-21 04:32:33 +00:00
|
|
|
|
if (errata.Count > 0)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
string concat = string.Join(Environment.NewLine, errata);
|
2018-12-17 19:17:19 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, concat, MessageStrings.MsgContinue))
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2017-07-02 02:43:51 +00:00
|
|
|
|
Debug.WriteLine(c);
|
|
|
|
|
Debug.WriteLine(concat);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return false;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 02:54:41 +00:00
|
|
|
|
Env.Slots.Set(Drag.Info.Destination.Slot, pk);
|
2017-07-02 02:43:51 +00:00
|
|
|
|
Debug.WriteLine(c);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return true;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private bool TrySetPKMDestination(PictureBox pb, DropModifier mod)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-09-04 02:54:41 +00:00
|
|
|
|
PKM pk = Drag.Info.Source.ReadCurrent();
|
|
|
|
|
var msg = Drag.Info.Destination.CanWriteTo(pk);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (msg != WriteBlockedMessage.None)
|
2017-06-22 03:24:42 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (Drag.Info.Source != null)
|
2019-08-21 02:50:28 +00:00
|
|
|
|
TrySetPKMSource(pb, mod);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
|
|
|
|
// Copy from temp to destination slot.
|
2019-09-04 02:54:41 +00:00
|
|
|
|
Env.Slots.Set(Drag.Info.Destination.Slot, pk);
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Drag.ResetCursor(pb.FindForm());
|
2017-06-22 03:24:42 +00:00
|
|
|
|
return true;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-08-21 02:50:28 +00:00
|
|
|
|
private bool TrySetPKMSource(PictureBox sender, DropModifier mod)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (Drag.Info.Destination == null || mod == DropModifier.Clone)
|
2019-08-21 02:50:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (sender.Image == null || mod == DropModifier.Overwrite)
|
2017-05-23 04:55:05 +00:00
|
|
|
|
{
|
2019-09-04 02:54:41 +00:00
|
|
|
|
Env.Slots.Delete(Drag.Info.Source.Slot);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return true;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 02:54:41 +00:00
|
|
|
|
var pk = Drag.Info.Destination.ReadCurrent();
|
|
|
|
|
Env.Slots.Set(Drag.Info.Source.Slot, pk);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return true;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 06:37:55 +00:00
|
|
|
|
// Utility
|
2019-09-04 02:54:41 +00:00
|
|
|
|
public void SwapBoxes(int index, int other, SaveFile SAV)
|
2018-01-24 06:37:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (index == other)
|
|
|
|
|
return;
|
|
|
|
|
SAV.SwapBox(index, other);
|
2018-09-16 19:44:00 +00:00
|
|
|
|
UpdateBoxViewAtBoxIndexes(index, other);
|
2018-01-24 06:37:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2019-08-21 02:50:28 +00:00
|
|
|
|
Hover.Dispose();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SE?.Dispose();
|
2019-08-21 02:50:28 +00:00
|
|
|
|
LastSlot.OriginalBackground?.Dispose();
|
|
|
|
|
LastSlot.CurrentBackground?.Dispose();
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
2018-09-16 19:44:00 +00:00
|
|
|
|
|
|
|
|
|
private void UpdateBoxViewAtBoxIndexes(params int[] boxIndexes)
|
|
|
|
|
{
|
|
|
|
|
foreach (var box in Boxes)
|
|
|
|
|
{
|
|
|
|
|
var current = box.CurrentBox;
|
|
|
|
|
if (!boxIndexes.Contains(current))
|
|
|
|
|
continue;
|
|
|
|
|
box.ResetSlots();
|
|
|
|
|
box.ResetBoxNames(current);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|