2014-06-28 21:22:05 +00:00
|
|
|
|
using System;
|
2016-10-27 01:49:40 +00:00
|
|
|
|
using System.Collections.Generic;
|
2015-03-11 04:18:35 +00:00
|
|
|
|
using System.Drawing;
|
2015-03-11 01:44:51 +00:00
|
|
|
|
using System.IO;
|
2015-03-11 04:18:35 +00:00
|
|
|
|
using System.Linq;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
using PKHeX.Core;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class SAV_Wondercard : Form
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private readonly SaveFile Origin;
|
|
|
|
|
private readonly SaveFile SAV;
|
|
|
|
|
public SAV_Wondercard(SaveFile sav, MysteryGift g = null)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
SAV = (Origin = sav).Clone();
|
2014-06-28 21:22:05 +00:00
|
|
|
|
InitializeComponent();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
mga = SAV.GiftAlbum;
|
2016-10-27 01:49:40 +00:00
|
|
|
|
|
|
|
|
|
switch (SAV.Generation)
|
2015-12-18 05:15:40 +00:00
|
|
|
|
{
|
2016-10-27 01:49:40 +00:00
|
|
|
|
case 4:
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pba = PopulateViewGiftsG4().ToArray();
|
2016-10-27 01:49:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
case 6:
|
|
|
|
|
case 7:
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pba = PopulateViewGiftsG567().ToArray();
|
2016-10-27 01:49:40 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentException("Game not supported.");
|
|
|
|
|
}
|
2015-12-18 05:15:40 +00:00
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
foreach (PictureBox pb in pba)
|
|
|
|
|
{
|
|
|
|
|
pb.AllowDrop = true;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pb.DragDrop += BoxSlot_DragDrop;
|
|
|
|
|
pb.DragEnter += BoxSlot_DragEnter;
|
|
|
|
|
pb.MouseDown += BoxSlot_MouseDown;
|
2016-10-27 01:49:40 +00:00
|
|
|
|
pb.ContextMenuStrip = mnuVSD;
|
2016-07-06 02:12:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetGiftBoxes();
|
|
|
|
|
GetReceivedFlags();
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
2014-06-28 21:22:05 +00:00
|
|
|
|
if (LB_Received.Items.Count > 0)
|
2014-12-10 23:24:34 +00:00
|
|
|
|
LB_Received.SelectedIndex = 0;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
DragEnter += Main_DragEnter;
|
|
|
|
|
DragDrop += Main_DragDrop;
|
2015-04-01 00:58:23 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (g == null)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ClickView(pba[0], null);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
else
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ViewGiftData(g);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
private MysteryGiftAlbum mga;
|
|
|
|
|
private MysteryGift mg;
|
2016-01-17 21:27:24 +00:00
|
|
|
|
private readonly PictureBox[] pba;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
|
|
|
|
// Repopulation Functions
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void SetBackground(int index, Image bg)
|
2015-12-19 04:48:47 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 0; i < mga.Gifts.Length; i++)
|
2015-12-19 04:48:47 +00:00
|
|
|
|
pba[i].BackgroundImage = index == i ? bg : null;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void SetGiftBoxes()
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 0; i < mga.Gifts.Length; i++)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
MysteryGift m = mga.Gifts[i];
|
2017-05-23 04:55:05 +00:00
|
|
|
|
pba[i].Image = m.Sprite(SAV);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ViewGiftData(MysteryGift g)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2014-12-11 06:50:40 +00:00
|
|
|
|
try
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-07-24 22:44:44 +00:00
|
|
|
|
// only check if the form is visible (not opening)
|
|
|
|
|
if (Visible && g.GiftUsed && DialogResult.Yes ==
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Prompt(MessageBoxButtons.YesNo,
|
2015-12-18 05:15:40 +00:00
|
|
|
|
"Wonder Card is marked as USED and will not be able to be picked up in-game.",
|
2015-09-13 04:32:30 +00:00
|
|
|
|
"Do you want to remove the USED flag so that it is UNUSED?"))
|
2016-06-20 04:22:43 +00:00
|
|
|
|
g.GiftUsed = false;
|
2016-01-24 18:19:30 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
RTB.Text = GetDescription(g, SAV);
|
2017-05-23 04:55:05 +00:00
|
|
|
|
PB_Preview.Image = g.Sprite(SAV);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
mg = g;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2015-01-11 07:31:51 +00:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Error("Loading of data failed... is this really a Wonder Card?", e);
|
2015-01-11 07:31:51 +00:00
|
|
|
|
RTB.Clear();
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void GetReceivedFlags()
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
|
|
|
|
LB_Received.Items.Clear();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 1; i < mga.Flags.Length; i++)
|
|
|
|
|
if (mga.Flags[i])
|
2014-06-28 21:22:05 +00:00
|
|
|
|
LB_Received.Items.Add(i.ToString("0000"));
|
2016-04-22 02:16:55 +00:00
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
if (LB_Received.Items.Count > 0)
|
|
|
|
|
LB_Received.SelectedIndex = 0;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void SetCardID(int cardID)
|
2015-12-19 06:04:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (cardID <= 0 || cardID >= 0x100 * 8) return;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
string card = cardID.ToString("0000");
|
|
|
|
|
if (!LB_Received.Items.Contains(card))
|
|
|
|
|
LB_Received.Items.Add(card);
|
|
|
|
|
LB_Received.SelectedIndex = LB_Received.Items.IndexOf(card);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 03:48:02 +00:00
|
|
|
|
// Mystery Gift IO (.file<->window)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
private void B_Import_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
OpenFileDialog import = new OpenFileDialog {Filter = WinFormsUtil.GetMysterGiftFilter(SAV.Generation)};
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (import.ShowDialog() != DialogResult.OK) return;
|
2015-03-12 04:44:12 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
string path = import.FileName;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
MysteryGift g = MysteryGift.GetMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (g == null)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Error("File is not a Mystery Gift:", path);
|
2015-03-12 04:44:12 +00:00
|
|
|
|
return;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ViewGiftData(g);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
private void B_Output_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-05-19 01:10:58 +00:00
|
|
|
|
WinFormsUtil.SaveMGDialog(mg);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static int GetLastUnfilledByType(MysteryGift Gift, MysteryGiftAlbum Album)
|
2016-08-16 03:48:02 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < Album.Gifts.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!Album.Gifts[i].Empty)
|
|
|
|
|
continue;
|
|
|
|
|
if (Album.Gifts[i].Type != Gift.Type)
|
|
|
|
|
continue;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// Mystery Gift RW (window<->sav)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickView(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
|
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-20 00:25:32 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetBackground(index, Properties.Resources.slotView);
|
|
|
|
|
ViewGiftData(mga.Gifts[index]);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickSet(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!IsSpecialWonderCard(mg))
|
2016-03-31 01:28:28 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2016-02-01 07:15:54 +00:00
|
|
|
|
sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
|
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-20 00:25:32 +00:00
|
|
|
|
|
|
|
|
|
// Hijack to the latest unfilled slot if index creates interstitial empty slots.
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int lastUnfilled = GetLastUnfilledByType(mg, mga);
|
2016-03-31 01:28:28 +00:00
|
|
|
|
if (lastUnfilled > -1 && lastUnfilled < index)
|
2015-12-20 00:25:32 +00:00
|
|
|
|
index = lastUnfilled;
|
2017-01-20 16:43:41 +00:00
|
|
|
|
|
|
|
|
|
if (mg is PCD && mga.Gifts[index] is PGT)
|
|
|
|
|
mg = (mg as PCD).Gift;
|
|
|
|
|
else if (mg.Type != mga.Gifts[index].Type)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Alert("Can't set slot here.", $"{mg.Type} != {mga.Gifts[index].Type}");
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetBackground(index, Properties.Resources.slotSet);
|
2016-08-16 03:48:02 +00:00
|
|
|
|
mga.Gifts[index] = mg.Clone();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetGiftBoxes();
|
|
|
|
|
SetCardID(mg.CardID);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickDelete(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
|
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
mga.Gifts[index].Data = new byte[mga.Gifts[index].Data.Length];
|
2016-08-16 03:48:02 +00:00
|
|
|
|
|
|
|
|
|
// Shuffle blank card down
|
|
|
|
|
int i = index;
|
|
|
|
|
while (i < mga.Gifts.Length - 1)
|
|
|
|
|
{
|
|
|
|
|
if (mga.Gifts[i+1].Empty)
|
|
|
|
|
break;
|
|
|
|
|
if (mga.Gifts[i+1].Type != mga.Gifts[i].Type)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
var mg1 = mga.Gifts[i];
|
|
|
|
|
var mg2 = mga.Gifts[i-1];
|
|
|
|
|
|
|
|
|
|
mga.Gifts[i-1] = mg1;
|
|
|
|
|
mga.Gifts[i] = mg2;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetBackground(i, Properties.Resources.slotDel);
|
|
|
|
|
SetGiftBoxes();
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close Window
|
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Make sure all of the Received Flags are flipped!
|
2016-06-20 04:22:43 +00:00
|
|
|
|
bool[] flags = new bool[mga.Flags.Length];
|
2016-04-22 02:16:55 +00:00
|
|
|
|
foreach (var o in LB_Received.Items)
|
|
|
|
|
flags[Util.ToUInt32(o.ToString())] = true;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
mga.Flags = flags;
|
|
|
|
|
SAV.GiftAlbum = mga;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Origin.SetData(SAV.Data, 0);
|
2014-06-28 21:22:05 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 03:48:02 +00:00
|
|
|
|
// Delete Received Flag
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClearRecievedFlag(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
if (LB_Received.SelectedIndex < 0) return;
|
2015-03-12 04:44:12 +00:00
|
|
|
|
|
|
|
|
|
if (LB_Received.Items.Count > 0)
|
|
|
|
|
LB_Received.Items.Remove(LB_Received.Items[LB_Received.SelectedIndex]);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
if (LB_Received.Items.Count > 0)
|
|
|
|
|
LB_Received.SelectedIndex = 0;
|
2014-06-28 21:22:05 +00:00
|
|
|
|
}
|
2014-12-10 23:24:34 +00:00
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
|
// Drag & Drop Wonder Cards
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void Main_DragEnter(object sender, DragEventArgs e)
|
2014-12-10 23:24:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void Main_DragDrop(object sender, DragEventArgs e)
|
2014-12-10 23:24:34 +00:00
|
|
|
|
{
|
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
2015-01-11 07:31:51 +00:00
|
|
|
|
|
2015-01-31 23:59:23 +00:00
|
|
|
|
// Check for multiple wondercards
|
2016-03-19 22:50:01 +00:00
|
|
|
|
if (Directory.Exists(files[0]))
|
|
|
|
|
files = Directory.GetFiles(files[0], "*", SearchOption.AllDirectories);
|
|
|
|
|
if (files.Length == 1 && !Directory.Exists(files[0]))
|
2014-12-10 23:24:34 +00:00
|
|
|
|
{
|
2015-01-31 23:59:23 +00:00
|
|
|
|
string path = files[0]; // open first D&D
|
2016-03-19 22:50:01 +00:00
|
|
|
|
long len = new FileInfo(path).Length;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (len > 0x1000) // arbitrary
|
2015-01-31 23:59:23 +00:00
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Alert("File is not a Mystery Gift.", path);
|
2015-01-31 23:59:23 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
MysteryGift g = MysteryGift.GetMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (g == null)
|
2016-03-31 01:28:28 +00:00
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Error("File is not a Mystery Gift:", path);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
2016-03-31 01:28:28 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ViewGiftData(g);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
2016-03-19 22:50:01 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetGiftBoxes();
|
2014-12-10 23:24:34 +00:00
|
|
|
|
}
|
2015-03-11 04:18:35 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private bool IsSpecialWonderCard(MysteryGift g)
|
2016-03-31 01:28:28 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (SAV.Generation != 6)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (g is WC6)
|
2016-03-31 01:28:28 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (g.CardID == 2048 && g.ItemID == 726) // Eon Ticket (OR/AS)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
if (!SAV.ORAS || ((SAV6)SAV).EonTicket < 0)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
goto reject;
|
|
|
|
|
BitConverter.GetBytes(WC6.EonTicketConst).CopyTo(SAV.Data, ((SAV6)SAV).EonTicket);
|
|
|
|
|
}
|
2016-03-31 01:28:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
reject: WinFormsUtil.Alert("Unable to insert the Mystery Gift.", "Does this Mystery Gift really belong to this game?");
|
2016-03-31 01:28:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-04-22 02:16:55 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickQR(object sender, EventArgs e)
|
2015-03-11 04:18:35 +00:00
|
|
|
|
{
|
|
|
|
|
if (ModifierKeys == Keys.Alt)
|
2017-07-03 04:27:22 +00:00
|
|
|
|
{
|
|
|
|
|
string url = Clipboard.GetText();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(url))
|
|
|
|
|
{
|
|
|
|
|
ImportQRToView(url);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ExportQRFromView();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
}
|
|
|
|
|
private void ExportQRFromView()
|
|
|
|
|
{
|
|
|
|
|
if (mg.Data.SequenceEqual(new byte[mg.Data.Length]))
|
2015-03-11 04:18:35 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
WinFormsUtil.Alert("No wondercard data found in loaded slot!");
|
|
|
|
|
return;
|
2015-03-11 04:18:35 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (SAV.Generation == 6 && mg.ItemID == 726 && mg.IsItem)
|
2015-03-11 04:18:35 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
WinFormsUtil.Alert("Eon Ticket Wonder Cards will not function properly", "Inject to the save file instead.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
const string server = "http://lunarcookies.github.io/wc.html#";
|
|
|
|
|
Image qr = QR.GetQRImage(mg.Data, server);
|
|
|
|
|
if (qr == null)
|
|
|
|
|
return;
|
2015-03-11 04:18:35 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
string desc = $"({mg.Type}) {GetDescription(mg, SAV)}";
|
2015-03-11 04:18:35 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
new QR(qr, PB_Preview.Image, null, desc + "PKHeX Wonder Card @ ProjectPokemon.org").ShowDialog();
|
|
|
|
|
}
|
2017-07-03 04:27:22 +00:00
|
|
|
|
private void ImportQRToView(string url)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
{
|
2017-07-03 04:27:22 +00:00
|
|
|
|
byte[] data = QR.GetQRData(url);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (data == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
string[] types = mga.Gifts.Select(g => g.Type).Distinct().ToArray();
|
|
|
|
|
MysteryGift gift = MysteryGift.GetMysteryGift(data);
|
|
|
|
|
string giftType = gift.Type;
|
|
|
|
|
|
|
|
|
|
if (mga.Gifts.All(card => card.Data.Length != data.Length))
|
|
|
|
|
WinFormsUtil.Alert("Decoded data not valid for loaded save file.", $"QR Data Size: 0x{data.Length:X}");
|
|
|
|
|
else if (types.All(type => type != giftType))
|
|
|
|
|
WinFormsUtil.Alert("Gift type is not compatible with the save file.",
|
|
|
|
|
$"QR Gift Type: {gift.Type}" + Environment.NewLine + $"Expected Types: {string.Join(", ", types)}");
|
|
|
|
|
else if (gift.Species > SAV.MaxSpeciesID || gift.Moves.Any(move => move > SAV.MaxMoveID) ||
|
|
|
|
|
gift.HeldItem > SAV.MaxItemID)
|
|
|
|
|
WinFormsUtil.Alert("Gift Details are not compatible with the save file.");
|
|
|
|
|
else
|
|
|
|
|
ViewGiftData(gift);
|
2015-03-11 04:18:35 +00:00
|
|
|
|
}
|
2015-12-18 05:15:40 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void BoxSlot_MouseDown(object sender, MouseEventArgs e)
|
2015-12-18 05:15:40 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
switch (ModifierKeys)
|
2015-12-18 05:15:40 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
case Keys.Control: ClickView(sender, e); return;
|
|
|
|
|
case Keys.Shift: ClickSet(sender, e); return;
|
|
|
|
|
case Keys.Alt: ClickDelete(sender, e); return;
|
2015-12-18 05:15:40 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
PictureBox pb = sender as PictureBox;
|
|
|
|
|
if (pb?.Image == null)
|
2015-12-19 06:04:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (e.Button != MouseButtons.Left || e.Clicks != 1) return;
|
|
|
|
|
|
2016-02-01 07:15:54 +00:00
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-19 06:17:01 +00:00
|
|
|
|
wc_slot = index;
|
2015-12-19 06:04:01 +00:00
|
|
|
|
// Create Temp File to Drag
|
|
|
|
|
Cursor.Current = Cursors.Hand;
|
|
|
|
|
|
|
|
|
|
// Prepare Data
|
2016-06-20 04:22:43 +00:00
|
|
|
|
MysteryGift card = mga.Gifts[index];
|
2017-01-20 07:48:31 +00:00
|
|
|
|
string filename = Util.CleanFileName($"{card.CardID:0000} - {card.CardTitle}.{card.Extension}");
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
|
|
|
|
// Make File
|
|
|
|
|
string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename));
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-04-22 02:16:55 +00:00
|
|
|
|
File.WriteAllBytes(newfile, card.Data);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
|
|
|
|
|
}
|
2016-08-26 03:59:29 +00:00
|
|
|
|
catch (Exception x)
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{ WinFormsUtil.Error("Drag & Drop Error", x); }
|
2015-12-19 06:04:01 +00:00
|
|
|
|
File.Delete(newfile);
|
2015-12-19 06:17:01 +00:00
|
|
|
|
wc_slot = -1;
|
2015-12-18 05:15:40 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void BoxSlot_DragDrop(object sender, DragEventArgs e)
|
2015-12-18 05:15:40 +00:00
|
|
|
|
{
|
2016-02-01 07:15:54 +00:00
|
|
|
|
int index = Array.IndexOf(pba, sender);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
|
|
|
|
// Hijack to the latest unfilled slot if index creates interstitial empty slots.
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int lastUnfilled = GetLastUnfilledByType(mg, mga);
|
2017-01-21 03:35:56 +00:00
|
|
|
|
if (lastUnfilled > -1 && lastUnfilled < index && mga.Gifts[lastUnfilled].Type == mga.Gifts[index].Type)
|
2015-12-19 06:04:01 +00:00
|
|
|
|
index = lastUnfilled;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
if (wc_slot == -1) // dropped
|
2015-12-19 06:17:01 +00:00
|
|
|
|
{
|
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (files.Length < 1)
|
2015-12-19 06:17:01 +00:00
|
|
|
|
return;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (PCD.Size < (int)new FileInfo(files[0]).Length)
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert("Data size invalid.", files[0]); return; }
|
2016-04-22 02:16:55 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
byte[] data = File.ReadAllBytes(files[0]);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
MysteryGift gift = MysteryGift.GetMysteryGift(data, new FileInfo(files[0]).Extension);
|
2017-01-20 16:43:41 +00:00
|
|
|
|
|
2017-01-21 03:35:56 +00:00
|
|
|
|
if (gift is PCD && mga.Gifts[index] is PGT)
|
|
|
|
|
gift = (gift as PCD).Gift;
|
|
|
|
|
else if (gift.Type != mga.Gifts[index].Type)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-01-21 03:35:56 +00:00
|
|
|
|
WinFormsUtil.Alert("Can't set slot here.", $"{gift.Type} != {mga.Gifts[index].Type}");
|
2016-08-16 03:48:02 +00:00
|
|
|
|
return;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetBackground(index, Properties.Resources.slotSet);
|
2017-01-21 03:35:56 +00:00
|
|
|
|
mga.Gifts[index] = gift.Clone();
|
2017-01-20 16:43:41 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetCardID(mga.Gifts[index].CardID);
|
|
|
|
|
ViewGiftData(mga.Gifts[index]);
|
2015-12-19 06:17:01 +00:00
|
|
|
|
}
|
|
|
|
|
else // Swap Data
|
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
MysteryGift s1 = mga.Gifts[index];
|
|
|
|
|
MysteryGift s2 = mga.Gifts[wc_slot];
|
|
|
|
|
|
2017-01-21 03:35:56 +00:00
|
|
|
|
if (s2 is PCD && s1 is PGT)
|
|
|
|
|
{
|
|
|
|
|
// set the PGT to the PGT slot instead
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ViewGiftData(s2);
|
|
|
|
|
ClickSet(pba[index], null);
|
2017-01-21 03:35:56 +00:00
|
|
|
|
{ WinFormsUtil.Alert($"Set {s2.Type} gift to {s1.Type} slot."); return; }
|
|
|
|
|
}
|
2016-08-16 03:48:02 +00:00
|
|
|
|
if (s1.Type != s2.Type)
|
2017-01-21 03:35:56 +00:00
|
|
|
|
{ WinFormsUtil.Alert($"Can't swap {s2.Type} with {s1.Type}."); return; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
mga.Gifts[wc_slot] = s1;
|
|
|
|
|
mga.Gifts[index] = s2;
|
2016-08-16 03:48:02 +00:00
|
|
|
|
|
|
|
|
|
if (mga.Gifts[wc_slot].Empty) // empty slot created, slide down
|
|
|
|
|
{
|
|
|
|
|
int i = wc_slot;
|
|
|
|
|
while (i < index)
|
|
|
|
|
{
|
|
|
|
|
if (mga.Gifts[i + 1].Empty)
|
|
|
|
|
break;
|
|
|
|
|
if (mga.Gifts[i + 1].Type != mga.Gifts[i].Type)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
var mg1 = mga.Gifts[i];
|
|
|
|
|
var mg2 = mga.Gifts[i - 1];
|
|
|
|
|
|
|
|
|
|
mga.Gifts[i - 1] = mg1;
|
|
|
|
|
mga.Gifts[i] = mg2;
|
|
|
|
|
}
|
|
|
|
|
index = i-1;
|
|
|
|
|
}
|
2015-12-19 06:17:01 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetBackground(index, Properties.Resources.slotView);
|
|
|
|
|
SetGiftBoxes();
|
2015-12-18 05:15:40 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static void BoxSlot_DragEnter(object sender, DragEventArgs e)
|
2015-12-18 05:15:40 +00:00
|
|
|
|
{
|
2015-12-19 06:04:01 +00:00
|
|
|
|
if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
else if (e.Data != null) // within
|
|
|
|
|
e.Effect = DragDropEffects.Move;
|
2015-12-18 05:15:40 +00:00
|
|
|
|
}
|
2015-12-19 06:17:01 +00:00
|
|
|
|
private int wc_slot = -1;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static string GetDescription(MysteryGift gift, SaveFile SAV)
|
2016-04-22 02:16:55 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (gift.Empty)
|
|
|
|
|
return "Empty Slot. No data!";
|
2016-04-22 02:16:55 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
string s = gift.CardHeader + Environment.NewLine;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (gift.IsItem)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
s += $"Item: {GameInfo.Strings.itemlist[gift.ItemID]} (Quantity: {gift.Quantity})" + Environment.NewLine;
|
2017-02-21 05:46:25 +00:00
|
|
|
|
if (gift is WC7)
|
|
|
|
|
{
|
|
|
|
|
var ind = 1;
|
|
|
|
|
var wc7 = (WC7) gift;
|
|
|
|
|
while (wc7.GetItem(ind) != 0)
|
|
|
|
|
{
|
|
|
|
|
s += $"Item: {GameInfo.Strings.itemlist[wc7.GetItem(ind)]} (Quantity: {wc7.GetQuantity(ind)})" + Environment.NewLine;
|
|
|
|
|
ind++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-01-05 22:45:53 +00:00
|
|
|
|
else if (gift.IsPokémon)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKM pk = gift.ConvertToPKM(SAV);
|
2016-04-22 02:16:55 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
try
|
2016-04-22 02:16:55 +00:00
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
s += $"{GameInfo.Strings.specieslist[pk.Species]} @ {GameInfo.Strings.itemlist[pk.HeldItem]} --- ";
|
|
|
|
|
s += (pk.IsEgg ? GameInfo.Strings.eggname : $"{pk.OT_Name} - {pk.TID:00000}/{pk.SID:00000}") + Environment.NewLine;
|
|
|
|
|
s += $"{GameInfo.Strings.movelist[pk.Move1]} / {GameInfo.Strings.movelist[pk.Move2]} / {GameInfo.Strings.movelist[pk.Move3]} / {GameInfo.Strings.movelist[pk.Move4]}" + Environment.NewLine;
|
2016-11-20 23:04:28 +00:00
|
|
|
|
if (gift is WC7)
|
|
|
|
|
{
|
|
|
|
|
var addItem = ((WC7) gift).AdditionalItem;
|
|
|
|
|
if (addItem != 0)
|
2017-01-27 17:09:28 +00:00
|
|
|
|
s += $"+ {GameInfo.Strings.itemlist[addItem]}" + Environment.NewLine;
|
2016-11-20 23:04:28 +00:00
|
|
|
|
}
|
2016-04-22 02:16:55 +00:00
|
|
|
|
}
|
2017-01-05 22:45:53 +00:00
|
|
|
|
catch { s += "Unable to create gift description." + Environment.NewLine; }
|
|
|
|
|
}
|
2017-01-27 17:09:28 +00:00
|
|
|
|
else if (gift.IsBP)
|
|
|
|
|
{
|
|
|
|
|
s += "BP: " + gift.BP + Environment.NewLine;
|
|
|
|
|
}
|
|
|
|
|
else if (gift.IsBean)
|
|
|
|
|
{
|
|
|
|
|
s += "Bean ID: " + gift.Bean + Environment.NewLine + "Quantity: " + gift.Quantity + Environment.NewLine;
|
|
|
|
|
}
|
2017-01-05 22:45:53 +00:00
|
|
|
|
else { s += "Unknown Wonder Card Type!" + Environment.NewLine; }
|
|
|
|
|
if (gift is WC7)
|
|
|
|
|
{
|
|
|
|
|
var wc7 = (WC7) gift;
|
|
|
|
|
s += $"Repeatable: {wc7.GiftRepeatable}" + Environment.NewLine;
|
|
|
|
|
s += $"Collected: {wc7.GiftUsed}" + Environment.NewLine;
|
|
|
|
|
s += $"Once Per Day: {wc7.GiftOncePerDay}" + Environment.NewLine;
|
2016-04-22 02:16:55 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return s;
|
2016-04-22 02:16:55 +00:00
|
|
|
|
}
|
2016-10-27 01:49:40 +00:00
|
|
|
|
|
|
|
|
|
// UI Generation
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private List<PictureBox> PopulateViewGiftsG4()
|
2016-10-27 01:49:40 +00:00
|
|
|
|
{
|
|
|
|
|
List<PictureBox> pb = new List<PictureBox>();
|
|
|
|
|
|
|
|
|
|
// Row 1
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var f1 = GetFlowLayoutPanel();
|
|
|
|
|
f1.Controls.Add(GetLabel("PGT 1-6"));
|
2016-10-27 01:49:40 +00:00
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var p = GetPictureBox();
|
2016-10-27 01:49:40 +00:00
|
|
|
|
f1.Controls.Add(p);
|
|
|
|
|
pb.Add(p);
|
|
|
|
|
}
|
|
|
|
|
// Row 2
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var f2 = GetFlowLayoutPanel();
|
|
|
|
|
f2.Controls.Add(GetLabel("PGT 7-8"));
|
2016-10-27 01:49:40 +00:00
|
|
|
|
for (int i = 6; i < 8; i++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var p = GetPictureBox();
|
2016-10-27 01:49:40 +00:00
|
|
|
|
f2.Controls.Add(p);
|
|
|
|
|
pb.Add(p);
|
|
|
|
|
}
|
|
|
|
|
// Row 3
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var f3 = GetFlowLayoutPanel();
|
2016-10-27 01:49:40 +00:00
|
|
|
|
f3.Margin = new Padding(0, f3.Height, 0, 0);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
f3.Controls.Add(GetLabel("PCD 1-3"));
|
2016-10-27 01:49:40 +00:00
|
|
|
|
for (int i = 8; i < 11; i++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var p = GetPictureBox();
|
2016-10-27 01:49:40 +00:00
|
|
|
|
f3.Controls.Add(p);
|
|
|
|
|
pb.Add(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FLP_Gifts.Controls.Add(f1);
|
|
|
|
|
FLP_Gifts.Controls.Add(f2);
|
|
|
|
|
FLP_Gifts.Controls.Add(f3);
|
|
|
|
|
return pb;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private List<PictureBox> PopulateViewGiftsG567()
|
2016-10-27 01:49:40 +00:00
|
|
|
|
{
|
|
|
|
|
List<PictureBox> pb = new List<PictureBox>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < mga.Gifts.Length / 6; i++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var flp = GetFlowLayoutPanel();
|
|
|
|
|
flp.Controls.Add(GetLabel($"{i * 6 + 1}-{i * 6 + 6}"));
|
2016-10-27 01:49:40 +00:00
|
|
|
|
for (int j = 0; j < 6; j++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var p = GetPictureBox();
|
2016-10-27 01:49:40 +00:00
|
|
|
|
flp.Controls.Add(p);
|
|
|
|
|
pb.Add(p);
|
|
|
|
|
}
|
|
|
|
|
FLP_Gifts.Controls.Add(flp);
|
|
|
|
|
}
|
|
|
|
|
return pb;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static FlowLayoutPanel GetFlowLayoutPanel()
|
2016-10-27 01:49:40 +00:00
|
|
|
|
{
|
|
|
|
|
return new FlowLayoutPanel
|
|
|
|
|
{
|
|
|
|
|
Width = 305,
|
|
|
|
|
Height = 34,
|
|
|
|
|
Padding = new Padding(0),
|
|
|
|
|
Margin = new Padding(0),
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static Label GetLabel(string text)
|
2016-10-27 01:49:40 +00:00
|
|
|
|
{
|
|
|
|
|
return new Label
|
|
|
|
|
{
|
|
|
|
|
Size = new Size(40, 34),
|
|
|
|
|
AutoSize = false,
|
|
|
|
|
TextAlign = ContentAlignment.MiddleRight,
|
|
|
|
|
Text = text,
|
|
|
|
|
Padding = new Padding(0),
|
|
|
|
|
Margin = new Padding(0),
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static PictureBox GetPictureBox()
|
2016-10-27 01:49:40 +00:00
|
|
|
|
{
|
|
|
|
|
return new PictureBox
|
|
|
|
|
{
|
|
|
|
|
Size = new Size(42, 32),
|
|
|
|
|
SizeMode = PictureBoxSizeMode.CenterImage,
|
|
|
|
|
BorderStyle = BorderStyle.FixedSingle,
|
|
|
|
|
BackColor = Color.Transparent,
|
|
|
|
|
Padding = new Padding(0),
|
|
|
|
|
Margin = new Padding(1),
|
|
|
|
|
};
|
|
|
|
|
}
|
2016-04-22 02:16:55 +00:00
|
|
|
|
}
|
2014-12-15 00:50:15 +00:00
|
|
|
|
}
|