Show lock capsule slot in mystery gift editor

Closes #3487

editor getting hacky, but it works
This commit is contained in:
Kurt 2022-05-05 21:21:03 -07:00
parent 4c73f1c592
commit 75874b6b81
4 changed files with 58 additions and 15 deletions

View file

@ -57,6 +57,8 @@ namespace PKHeX.Core
public override bool IsPokémon { get => Gift.IsPokémon; set => Gift.IsPokémon = value; } public override bool IsPokémon { get => Gift.IsPokémon; set => Gift.IsPokémon = value; }
public override bool IsItem { get => Gift.IsItem; set => Gift.IsItem = value; } public override bool IsItem { get => Gift.IsItem; set => Gift.IsItem = value; }
public override int ItemID { get => Gift.ItemID; set => Gift.ItemID = value; } public override int ItemID { get => Gift.ItemID; set => Gift.ItemID = value; }
public bool IsLockCapsule => IsItem && ItemID == 533; // 0x215
public bool CanConvertToPGT => !IsLockCapsule;
public override int CardID public override int CardID
{ {

View file

@ -393,11 +393,14 @@ namespace PKHeX.Core
{ {
get get
{ {
DataMysteryGift[] cards = new DataMysteryGift[8 + 3]; int pcd = this is SAV4HGSS ? 4 : 3;
DataMysteryGift[] cards = new DataMysteryGift[8 + pcd];
for (int i = 0; i < 8; i++) // 8 PGT for (int i = 0; i < 8; i++) // 8 PGT
cards[i] = new PGT(General.Slice(WondercardData + (i * PGT.Size), PGT.Size)); cards[i] = new PGT(General.Slice(WondercardData + (i * PGT.Size), PGT.Size));
for (int i = 8; i < 11; i++) // 3 PCD for (int i = 8; i < 11; i++) // 3 PCD
cards[i] = new PCD(General.Slice(WondercardData + (8 * PGT.Size) + ((i-8) * PCD.Size), PCD.Size)); cards[i] = new PCD(General.Slice(WondercardData + (8 * PGT.Size) + ((i-8) * PCD.Size), PCD.Size));
if (this is SAV4HGSS hgss)
cards[^1] = hgss.LockCapsuleSlot;
return cards; return cards;
} }
set set
@ -416,6 +419,8 @@ namespace PKHeX.Core
if (value[i] is PCD) if (value[i] is PCD)
SetData(General, value[i].Data, WondercardData + (8 *PGT.Size) + ((i - 8)*PCD.Size)); SetData(General, value[i].Data, WondercardData + (8 *PGT.Size) + ((i - 8)*PCD.Size));
} }
if (this is SAV4HGSS hgss && value.Length >= 11 && value[^1] is PCD capsule)
hgss.LockCapsuleSlot = capsule;
} }
} }

View file

@ -58,6 +58,14 @@ namespace PKHeX.Core
Box = 0; Box = 0;
} }
private Span<byte> LockCapsuleSpan => General.AsSpan(0xB064, PCD.Size);
public PCD LockCapsuleSlot
{
get => new(LockCapsuleSpan.ToArray());
set => value.Data.CopyTo(LockCapsuleSpan);
}
#region Storage #region Storage
// box{pk4[30}[18] // box{pk4[30}[18]
// u32 currentBox // u32 currentBox

View file

@ -192,10 +192,12 @@ namespace PKHeX.WinForms
int lastUnfilled = GetLastUnfilledByType(gift, mga); int lastUnfilled = GetLastUnfilledByType(gift, mga);
if (lastUnfilled > -1 && lastUnfilled < index) if (lastUnfilled > -1 && lastUnfilled < index)
index = lastUnfilled; index = lastUnfilled;
if (gift is PCD { IsLockCapsule: true })
index = 11;
var gifts = mga.Gifts; var gifts = mga.Gifts;
var other = gifts[index]; var other = gifts[index];
if (gift is PCD pcd && other is PGT) if (gift is PCD { CanConvertToPGT: true } pcd && other is PGT)
{ {
gift = pcd.Gift; gift = pcd.Gift;
} }
@ -204,6 +206,11 @@ namespace PKHeX.WinForms
WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{gift.Type} != {other.Type}"); WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{gift.Type} != {other.Type}");
return; return;
} }
else if (gift is PCD { IsLockCapsule: true } != (index == 11))
{
WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{GameInfo.Strings.Item[533]} slot not valid.");
return;
}
gifts[index] = (DataMysteryGift)gift.Clone(); gifts[index] = (DataMysteryGift)gift.Clone();
SetBackground(index, Drawing.PokeSprite.Properties.Resources.slotSet); SetBackground(index, Drawing.PokeSprite.Properties.Resources.slotSet);
SetGiftBoxes(); SetGiftBoxes();
@ -454,6 +461,8 @@ namespace PKHeX.WinForms
int lastUnfilled = GetLastUnfilledByType(mg, mga); int lastUnfilled = GetLastUnfilledByType(mg, mga);
if (lastUnfilled > -1 && lastUnfilled < index && mga.Gifts[lastUnfilled].Type == mga.Gifts[index].Type) if (lastUnfilled > -1 && lastUnfilled < index && mga.Gifts[lastUnfilled].Type == mga.Gifts[index].Type)
index = lastUnfilled; index = lastUnfilled;
if (mg is PCD { IsLockCapsule: true })
index = 11;
if (wc_slot == -1) // dropped if (wc_slot == -1) // dropped
{ {
@ -470,20 +479,21 @@ namespace PKHeX.WinForms
if (gift == null) if (gift == null)
{ WinFormsUtil.Alert(MsgFileUnsupported, first); return; } { WinFormsUtil.Alert(MsgFileUnsupported, first); return; }
if (gift is PCD pcd && mga.Gifts[index] is PGT) ref var dest = ref mga.Gifts[index];
if (gift is PCD { CanConvertToPGT: true } pcd && dest is PGT)
{ {
gift = pcd.Gift; gift = pcd.Gift;
} }
else if (gift.Type != mga.Gifts[index].Type) else if (gift.Type != dest.Type)
{ {
WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{gift.Type} != {mga.Gifts[index].Type}"); WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{gift.Type} != {dest.Type}");
return; return;
} }
SetBackground(index, Drawing.PokeSprite.Properties.Resources.slotSet); SetBackground(index, Drawing.PokeSprite.Properties.Resources.slotSet);
mga.Gifts[index] = (DataMysteryGift)gift.Clone(); dest = (DataMysteryGift)gift.Clone();
SetCardID(mga.Gifts[index].CardID); SetCardID(dest.CardID);
ViewGiftData(mga.Gifts[index]); ViewGiftData(dest);
} }
else // Swap Data else // Swap Data
{ {
@ -504,7 +514,7 @@ namespace PKHeX.WinForms
// Double check compatibility of slots // Double check compatibility of slots
if (s1.Type != s2.Type) if (s1.Type != s2.Type)
{ {
if (s2 is PCD && s1 is PGT) if (s2 is PCD { CanConvertToPGT: true } && s1 is PGT)
{ {
// Get first empty slot // Get first empty slot
var firstEmpty = Array.FindIndex(gifts, z => z.Empty); var firstEmpty = Array.FindIndex(gifts, z => z.Empty);
@ -523,12 +533,17 @@ namespace PKHeX.WinForms
return -1; return -1;
} }
if ((s1 is PCD && dest == 11) || (s2 is PCD && src == 11))
{
WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{GameInfo.Strings.Item[533]} swap not valid.");
return -1;
}
// If data is present in both slots, just swap. // If data is present in both slots, just swap.
if (!gifts[dest].Empty) if (!s1.Empty)
{ {
// Swap // Swap
gifts[src] = s1; (gifts[src], gifts[dest]) = (s1, s2);
gifts[dest] = s2;
return dest; return dest;
} }
@ -579,7 +594,7 @@ namespace PKHeX.WinForms
} }
// Row 3 // Row 3
var f3 = GetFlowLayoutPanel(); var f3 = GetFlowLayoutPanel();
f3.Margin = new Padding(0, f3.Height, 0, 0); f3.Margin = new Padding(0, 12, 0, 0);
f3.Controls.Add(GetLabel($"{nameof(PCD)} 1-3")); f3.Controls.Add(GetLabel($"{nameof(PCD)} 1-3"));
for (int i = 8; i < 11; i++) for (int i = 8; i < 11; i++)
{ {
@ -591,6 +606,19 @@ namespace PKHeX.WinForms
FLP_Gifts.Controls.Add(f1); FLP_Gifts.Controls.Add(f1);
FLP_Gifts.Controls.Add(f2); FLP_Gifts.Controls.Add(f2);
FLP_Gifts.Controls.Add(f3); FLP_Gifts.Controls.Add(f3);
if (mga.Gifts.Length == 12) // lock capsule
{
// Row 4
var f4 = GetFlowLayoutPanel();
f4.Controls.Add(GetLabel(GameInfo.Strings.Item[533])); // Lock Capsule
{
var p = GetPictureBox(spriter.Width, spriter.Height);
f4.Controls.Add(p);
pb.Add(p);
}
FLP_Gifts.Controls.Add(f4);
}
return pb; return pb;
} }
@ -623,7 +651,7 @@ namespace PKHeX.WinForms
private static FlowLayoutPanel GetFlowLayoutPanel() => new() private static FlowLayoutPanel GetFlowLayoutPanel() => new()
{ {
Width = 480, Width = 490,
Height = 60, Height = 60,
Padding = new Padding(0), Padding = new Padding(0),
Margin = new Padding(0), Margin = new Padding(0),
@ -631,7 +659,7 @@ namespace PKHeX.WinForms
private static Label GetLabel(string text) => new() private static Label GetLabel(string text) => new()
{ {
Size = new Size(40, 60), Size = new Size(50, 60),
AutoSize = false, AutoSize = false,
TextAlign = ContentAlignment.MiddleRight, TextAlign = ContentAlignment.MiddleRight,
Text = text, Text = text,