Skip to content

Commit

Permalink
Fix drag slot equality check
Browse files Browse the repository at this point in the history
prevents deleting party slots if a slot is dragged into its original
slot (X->X); Equals check only checked reference
  • Loading branch information
kwsch committed Nov 24, 2019
1 parent 64d9490 commit 32d8225
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs
@@ -1,10 +1,12 @@
using System;

namespace PKHeX.Core
{
/// <summary>
/// Tuple containing data for a <see cref="Slot"/> and the originating <see cref="View"/>
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class SlotViewInfo<T>
public sealed class SlotViewInfo<T> : IEquatable<T>
{
public readonly ISlotInfo Slot;
public readonly ISlotViewer<T> View;
Expand All @@ -18,5 +20,20 @@ public SlotViewInfo(ISlotInfo slot, ISlotViewer<T> view)
Slot = slot;
View = view;
}

private bool Equals(SlotViewInfo<T> other)
{
if (other.View.SAV != View.SAV)
return false;
if (other.View.ViewIndex != View.ViewIndex)
return false;
if (other.Slot.Slot != Slot.Slot)
return false;
return other.GetType() == GetType();
}

public override bool Equals(object obj) => ReferenceEquals(this, obj) || (obj is SlotViewInfo<T> other && Equals(other));
public override int GetHashCode() => ((Slot?.GetHashCode() ?? 0) * 397) ^ (View?.GetHashCode() ?? 0);
bool IEquatable<T>.Equals(T other) => other != null && Equals(other);
}
}
2 changes: 1 addition & 1 deletion PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs
Expand Up @@ -194,7 +194,7 @@ private bool TryMakeDragDropPKM(PictureBox pb, byte[] data, string newfile)
Drag.Info.CurrentPath = newfile;
var result = pb.DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
var external = Drag.Info.Destination == null || result != DragDropEffects.Link;
if (external || Drag.Info.Source.Equals(Drag.Info.Destination)) // not dropped to another box slot, restore img
if (external || Drag.Info.SameLocation) // not dropped to another box slot, restore img
{
pb.Image = img;
pb.BackgroundImage = LastSlot.OriginalBackground;
Expand Down

0 comments on commit 32d8225

Please sign in to comment.