Don't set dex on slot swap within save

Closes #3411
This commit is contained in:
Kurt 2022-02-07 15:03:26 -08:00
parent 17495fafca
commit b20fb39d77
4 changed files with 24 additions and 11 deletions

View file

@ -38,6 +38,11 @@ namespace PKHeX.Core
/// <param name="setting">Setting to use when importing the <see cref="pkm"/> data</param>
/// <returns>Returns false if it did not succeed.</returns>
bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault);
/// <summary>
/// Reads a <see cref="PKM"/> from the <see cref="sav"/>.
/// </summary>
/// <param name="sav">Save file to read from.</param>
PKM Read(SaveFile sav);
}
}

View file

@ -36,14 +36,15 @@
/// </summary>
/// <param name="slot">Slot to be set to.</param>
/// <param name="pkm">Data to set.</param>
/// <param name="type">Type of slot action</param>
/// <returns>Operation succeeded or not via enum value.</returns>
public SlotTouchResult Set(ISlotInfo slot, PKM pkm)
public SlotTouchResult Set(ISlotInfo slot, PKM pkm, SlotTouchType type = SlotTouchType.Set)
{
if (!slot.CanWriteTo(SAV))
return SlotTouchResult.FailWrite;
WriteSlot(slot, pkm);
NotifySlotChanged(slot, SlotTouchType.Set, pkm);
WriteSlot(slot, pkm, type);
NotifySlotChanged(slot, type, pkm);
return SlotTouchResult.Success;
}
@ -86,7 +87,8 @@
private void WriteSlot(ISlotInfo slot, PKM pkm, SlotTouchType type = SlotTouchType.Set)
{
Changelog.AddNewChange(slot);
var result = slot.WriteTo(SAV, pkm);
var setDetail = type is SlotTouchType.Swap ? PKMImportSetting.Skip : PKMImportSetting.UseDefault;
var result = slot.WriteTo(SAV, pkm, setDetail);
if (result)
NotifySlotChanged(slot, type, pkm);
}

View file

@ -325,7 +325,8 @@ namespace PKHeX.WinForms.Controls
private bool TrySetPKMDestination(PictureBox pb, DropModifier mod)
{
var pk = Drag.Info.Source!.ReadCurrent();
var info = Drag.Info;
var pk = info.Source!.ReadCurrent();
var msg = Drag.Info.Destination!.CanWriteTo(pk);
if (msg != WriteBlockedMessage.None)
return false;
@ -334,24 +335,27 @@ namespace PKHeX.WinForms.Controls
TrySetPKMSource(pb, mod);
// Copy from temp to destination slot.
Env.Slots.Set(Drag.Info.Destination!.Slot, pk);
var type = info.DragIsSwap ? SlotTouchType.Swap : SlotTouchType.Set;
Env.Slots.Set(info.Destination!.Slot, pk, type);
Drag.ResetCursor(pb.FindForm());
return true;
}
private bool TrySetPKMSource(PictureBox sender, DropModifier mod)
{
if (Drag.Info.Destination == null || mod == DropModifier.Clone)
var info = Drag.Info;
if (info.Destination == null || mod == DropModifier.Clone)
return false;
if (sender.Image == null || mod == DropModifier.Overwrite)
{
Env.Slots.Delete(Drag.Info.Source!.Slot);
Env.Slots.Delete(info.Source!.Slot);
return true;
}
var pk = Drag.Info.Destination.ReadCurrent();
Env.Slots.Set(Drag.Info.Source!.Slot, pk);
var type = info.DragIsSwap ? SlotTouchType.Swap : SlotTouchType.Set;
var pk = info.Destination.ReadCurrent();
Env.Slots.Set(Drag.Info.Source!.Slot, pk, type);
return true;
}

View file

@ -29,5 +29,7 @@ namespace PKHeX.WinForms.Controls
/// Used to indicate if the changes will alter the player's party data state.
/// </summary>
public bool DragIsParty => SourceIsParty || DestinationIsParty;
public bool DragIsSwap => Source is not null && Destination is not null;
}
}
}