2020-01-26 19:19:58 +00:00
|
|
|
using PKHeX.Core;
|
2018-07-29 23:39:15 +00:00
|
|
|
using System;
|
2016-10-27 01:49:40 +00:00
|
|
|
using System.Collections.Generic;
|
2022-03-23 06:02:46 +00:00
|
|
|
using System.Diagnostics;
|
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;
|
2022-03-23 06:02:46 +00:00
|
|
|
using System.Threading.Tasks;
|
2014-06-28 21:22:05 +00:00
|
|
|
using System.Windows.Forms;
|
2021-11-27 23:48:08 +00:00
|
|
|
using PKHeX.Drawing.Misc;
|
2022-03-26 22:52:17 +00:00
|
|
|
using PKHeX.Drawing.PokeSprite;
|
2021-04-09 23:37:32 +00:00
|
|
|
using PKHeX.WinForms.Controls;
|
2018-04-07 04:23:09 +00:00
|
|
|
using static PKHeX.Core.MessageStrings;
|
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;
|
2021-04-09 23:37:32 +00:00
|
|
|
private readonly SummaryPreviewer Summary = new();
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
public SAV_Wondercard(SaveFile sav, DataMysteryGift? g = null)
|
2014-06-28 21:22:05 +00:00
|
|
|
{
|
|
|
|
InitializeComponent();
|
2017-06-18 01:37:19 +00:00
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2018-04-03 03:36:13 +00:00
|
|
|
SAV = (Origin = sav).Clone();
|
2017-05-23 04:55:05 +00:00
|
|
|
mga = SAV.GiftAlbum;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2020-12-24 01:14:38 +00:00
|
|
|
pba = SAV.Generation switch
|
2015-12-18 05:15:40 +00:00
|
|
|
{
|
2020-12-24 01:14:38 +00:00
|
|
|
4 => PopulateViewGiftsG4().ToArray(),
|
|
|
|
5 or 6 or 7 => PopulateViewGiftsG567().ToArray(),
|
2021-08-21 23:51:50 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(SAV.Generation), "Game not supported."),
|
2020-12-24 01:14:38 +00:00
|
|
|
};
|
2021-04-09 23:37:32 +00:00
|
|
|
foreach (var pb in pba)
|
2015-12-19 06:04:01 +00:00
|
|
|
{
|
|
|
|
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;
|
2021-04-09 23:37:32 +00:00
|
|
|
pb.MouseHover += (_, _) => Summary.Show(pb, mga.Gifts[pba.IndexOf(pb)]);
|
2016-07-06 02:12:18 +00:00
|
|
|
}
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
SetGiftBoxes();
|
|
|
|
GetReceivedFlags();
|
2018-05-12 15:13:39 +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;
|
|
|
|
|
2021-09-16 20:45:41 +00:00
|
|
|
if (mga.Gifts[0] is WR7) // giftused is not a valid prop
|
|
|
|
B_UnusedAll.Visible = B_UsedAll.Visible = L_QR.Visible = false;
|
|
|
|
|
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)
|
2020-10-18 18:02:39 +00:00
|
|
|
ClickView(pba[0], EventArgs.Empty);
|
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
|
|
|
|
2018-07-29 23:39:15 +00:00
|
|
|
private readonly MysteryGiftAlbum mga;
|
2020-10-18 18:02:39 +00:00
|
|
|
private DataMysteryGift? mg;
|
2020-12-24 01:14:38 +00:00
|
|
|
private readonly IList<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;
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
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-11-18 19:34:23 +00:00
|
|
|
pba[i].Image = m.Sprite();
|
2014-06-28 21:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
private void ViewGiftData(DataMysteryGift 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)
|
2018-04-07 04:23:09 +00:00
|
|
|
if (Visible && g.GiftUsed && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgMsyteryGiftUsedAlert, MsgMysteryGiftUsedFix))
|
2016-06-20 04:22:43 +00:00
|
|
|
g.GiftUsed = false;
|
2016-01-24 18:19:30 +00:00
|
|
|
|
2018-04-21 16:55:27 +00:00
|
|
|
RTB.Lines = g.GetDescription().ToArray();
|
2017-11-18 19:34:23 +00:00
|
|
|
PB_Preview.Image = g.Sprite();
|
2016-06-20 04:22:43 +00:00
|
|
|
mg = g;
|
2014-06-28 21:22:05 +00:00
|
|
|
}
|
2020-09-09 19:47:24 +00:00
|
|
|
// Some user input mystery gifts can have out-of-bounds values. Just swallow any exception.
|
2015-01-11 07:31:51 +00:00
|
|
|
catch (Exception e)
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
WinFormsUtil.Error(MsgMysteryGiftParseTypeUnknown, e);
|
2015-01-11 07:31:51 +00:00
|
|
|
RTB.Clear();
|
2014-06-28 21:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 23:39:15 +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++)
|
2018-07-29 23:39:15 +00:00
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
if (mga.Flags[i])
|
2014-06-28 21:22:05 +00:00
|
|
|
LB_Received.Items.Add(i.ToString("0000"));
|
2018-07-29 23:39:15 +00:00
|
|
|
}
|
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
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
private void SetCardID(int cardID)
|
2015-12-19 06:04:01 +00:00
|
|
|
{
|
2020-12-25 20:30:26 +00:00
|
|
|
if (cardID is <= 0 or >= 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)
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
using var import = new OpenFileDialog {Filter = WinFormsUtil.GetMysterGiftFilter(SAV.Generation, SAV.Version) };
|
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;
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
var 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
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
WinFormsUtil.Error(MsgMysteryGiftInvalid, 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
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2014-06-28 21:22:05 +00:00
|
|
|
private void B_Output_Click(object sender, EventArgs e)
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
if (mg == null)
|
|
|
|
return;
|
2019-07-14 22:06:45 +00:00
|
|
|
WinFormsUtil.ExportMGDialog(mg, SAV.Version);
|
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
|
|
|
{
|
2019-09-25 01:14:15 +00:00
|
|
|
var pb = WinFormsUtil.GetUnderlyingControl<PictureBox>(sender);
|
2020-12-24 01:14:38 +00:00
|
|
|
if (pb == null)
|
|
|
|
return;
|
|
|
|
int index = pba.IndexOf(pb);
|
2015-12-20 00:25:32 +00:00
|
|
|
|
2021-11-27 23:48:08 +00:00
|
|
|
SetBackground(index, Drawing.PokeSprite.Properties.Resources.slotView);
|
2017-06-18 01:37:19 +00:00
|
|
|
ViewGiftData(mga.Gifts[index]);
|
2014-06-28 21:22:05 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +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
|
|
|
{
|
2022-02-15 05:32:52 +00:00
|
|
|
if (mg is not { } gift)
|
2020-10-18 18:02:39 +00:00
|
|
|
return;
|
|
|
|
|
2022-02-15 05:32:52 +00:00
|
|
|
if (!gift.IsCardCompatible(SAV, out var msg))
|
2018-04-21 16:55:27 +00:00
|
|
|
{
|
|
|
|
WinFormsUtil.Alert(MsgMysteryGiftSlotFail, msg);
|
2016-03-31 01:28:28 +00:00
|
|
|
return;
|
2018-04-21 16:55:27 +00:00
|
|
|
}
|
2016-03-31 01:28:28 +00:00
|
|
|
|
2019-09-25 01:14:15 +00:00
|
|
|
var pb = WinFormsUtil.GetUnderlyingControl<PictureBox>(sender);
|
2020-12-24 01:14:38 +00:00
|
|
|
if (pb == null)
|
|
|
|
return;
|
|
|
|
int index = pba.IndexOf(pb);
|
2015-12-20 00:25:32 +00:00
|
|
|
|
|
|
|
// Hijack to the latest unfilled slot if index creates interstitial empty slots.
|
2022-02-15 05:32:52 +00:00
|
|
|
int lastUnfilled = GetLastUnfilledByType(gift, 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
|
|
|
|
2022-03-26 22:52:17 +00:00
|
|
|
var gifts = mga.Gifts;
|
|
|
|
var other = gifts[index];
|
|
|
|
if (gift is PCD pcd && other is PGT)
|
2018-07-29 23:39:15 +00:00
|
|
|
{
|
2022-02-15 05:32:52 +00:00
|
|
|
gift = pcd.Gift;
|
2018-07-29 23:39:15 +00:00
|
|
|
}
|
2022-03-26 22:52:17 +00:00
|
|
|
else if (gift.Type != other.Type)
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-03-26 22:52:17 +00:00
|
|
|
WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{gift.Type} != {other.Type}");
|
2016-06-20 04:22:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-03-26 22:52:17 +00:00
|
|
|
gifts[index] = (DataMysteryGift)gift.Clone();
|
2021-11-27 23:48:08 +00:00
|
|
|
SetBackground(index, Drawing.PokeSprite.Properties.Resources.slotSet);
|
2017-06-18 01:37:19 +00:00
|
|
|
SetGiftBoxes();
|
2022-02-15 05:32:52 +00:00
|
|
|
SetCardID(gift.CardID);
|
2014-06-28 21:22:05 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +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
|
|
|
{
|
2019-09-25 01:14:15 +00:00
|
|
|
var pb = WinFormsUtil.GetUnderlyingControl<PictureBox>(sender);
|
2020-12-24 01:14:38 +00:00
|
|
|
if (pb == null)
|
|
|
|
return;
|
|
|
|
int index = pba.IndexOf(pb);
|
2015-12-19 06:04:01 +00:00
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
var arr = mga.Gifts[index].Data;
|
|
|
|
Array.Clear(arr, 0, arr.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;
|
|
|
|
}
|
2021-11-27 23:48:08 +00:00
|
|
|
SetBackground(i, Drawing.PokeSprite.Properties.Resources.slotDel);
|
2017-06-18 01:37:19 +00:00
|
|
|
SetGiftBoxes();
|
2014-06-28 21:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close Window
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2014-06-28 21:22:05 +00:00
|
|
|
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)
|
2020-10-18 18:02:39 +00:00
|
|
|
{
|
|
|
|
var value = o?.ToString();
|
|
|
|
if (value == null)
|
|
|
|
continue;
|
|
|
|
var flag = Util.ToUInt32(value);
|
|
|
|
flags[flag] = true;
|
|
|
|
}
|
2014-06-28 21:22:05 +00:00
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
flags.CopyTo(mga.Flags, 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
SAV.GiftAlbum = mga;
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
Origin.CopyChangesFrom(SAV);
|
2014-06-28 21:22:05 +00:00
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2016-08-16 03:48:02 +00:00
|
|
|
// Delete Received Flag
|
2020-03-12 22:05:34 +00:00
|
|
|
private void ClearReceivedFlag(object sender, EventArgs e)
|
2014-06-28 21:22:05 +00:00
|
|
|
{
|
2019-09-12 05:17:16 +00:00
|
|
|
if (LB_Received.SelectedIndex < 0)
|
|
|
|
return;
|
2015-03-12 04:44:12 +00:00
|
|
|
|
2021-03-14 23:16:55 +00:00
|
|
|
if (LB_Received.SelectedIndices.Count > 1)
|
|
|
|
{
|
|
|
|
for (int i = LB_Received.SelectedIndices.Count - 1; i >= 0; i--)
|
2020-01-26 19:19:58 +00:00
|
|
|
LB_Received.Items.RemoveAt(LB_Received.SelectedIndices[i]);
|
|
|
|
}
|
2021-03-14 23:16:55 +00:00
|
|
|
else if (LB_Received.SelectedIndices.Count == 1)
|
|
|
|
{
|
2020-01-26 19:19:58 +00:00
|
|
|
int lastIndex = LB_Received.SelectedIndex;
|
2021-03-14 23:16:55 +00:00
|
|
|
LB_Received.Items.RemoveAt(lastIndex);
|
|
|
|
if (LB_Received.Items.Count == 0)
|
|
|
|
return;
|
|
|
|
if (lastIndex == LB_Received.Items.Count)
|
|
|
|
lastIndex--;
|
|
|
|
LB_Received.SelectedIndex = lastIndex;
|
2020-01-26 19:19:58 +00:00
|
|
|
}
|
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
|
2021-12-05 06:29:51 +00:00
|
|
|
private static void Main_DragEnter(object? sender, DragEventArgs? e)
|
2014-12-10 23:24:34 +00:00
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
if (e?.Data is null)
|
|
|
|
return;
|
2020-01-06 02:46:30 +00:00
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
2019-12-25 07:24:28 +00:00
|
|
|
e.Effect = DragDropEffects.Copy;
|
2014-12-10 23:24:34 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2021-12-05 06:29:51 +00:00
|
|
|
private void Main_DragDrop(object? sender, DragEventArgs? e)
|
2014-12-10 23:24:34 +00:00
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] { Length: not 0 } files)
|
|
|
|
return;
|
2015-01-11 07:31:51 +00:00
|
|
|
|
2021-12-05 06:29:51 +00:00
|
|
|
var first = files[0];
|
2015-01-31 23:59:23 +00:00
|
|
|
// Check for multiple wondercards
|
2021-12-05 06:29:51 +00:00
|
|
|
if (Directory.Exists(first))
|
|
|
|
files = Directory.GetFiles(first, "*", SearchOption.AllDirectories);
|
|
|
|
|
2016-03-19 22:50:01 +00:00
|
|
|
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
|
2018-07-29 23:39:15 +00:00
|
|
|
if (!MysteryGift.IsMysteryGift(new FileInfo(path).Length)) // arbitrary
|
2015-01-31 23:59:23 +00:00
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
WinFormsUtil.Alert(MsgMysteryGiftInvalid, path);
|
2015-01-31 23:59:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
var gift = MysteryGift.GetMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path));
|
|
|
|
if (gift == null)
|
2016-03-31 01:28:28 +00:00
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
WinFormsUtil.Error(MsgMysteryGiftInvalid, path);
|
2016-06-20 04:22:43 +00:00
|
|
|
return;
|
2016-03-31 01:28:28 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
ViewGiftData(gift);
|
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
|
|
|
}
|
2018-05-12 15:13:39 +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
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
private void ExportQRFromView()
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
if (mg == null)
|
|
|
|
return;
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
if (mg.Empty)
|
2015-03-11 04:18:35 +00:00
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
WinFormsUtil.Alert(MsgMysteryGiftSlotNone);
|
2017-06-18 01:37:19 +00:00
|
|
|
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
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
WinFormsUtil.Alert(MsgMysteryGiftQREonTicket, MsgMysteryGiftQREonTicketAdvice);
|
2017-06-18 01:37:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2019-09-29 16:47:06 +00:00
|
|
|
Image qr = QREncode.GenerateQRCode(mg);
|
2015-03-11 04:18:35 +00:00
|
|
|
|
2018-04-21 16:55:27 +00:00
|
|
|
string desc = $"({mg.Type}) {string.Join(Environment.NewLine, mg.GetDescription())}";
|
2015-03-11 04:18:35 +00:00
|
|
|
|
2019-10-08 01:40:09 +00:00
|
|
|
using var form = new QR(qr, PB_Preview.Image, desc + Environment.NewLine + "PKHeX Wonder Card @ ProjectPokemon.org");
|
|
|
|
form.ShowDialog();
|
2017-06-18 01:37:19 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2017-07-03 04:27:22 +00:00
|
|
|
private void ImportQRToView(string url)
|
2017-06-18 01:37:19 +00:00
|
|
|
{
|
2019-09-29 16:47:06 +00:00
|
|
|
var msg = QRDecode.GetQRData(url, out var data);
|
|
|
|
if (msg != 0)
|
|
|
|
{
|
|
|
|
WinFormsUtil.Alert(msg.ConvertMsg());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-02 07:08:03 +00:00
|
|
|
if (data.Length == 0)
|
2017-06-18 01:37:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
string[] types = mga.Gifts.Select(g => g.Type).Distinct().ToArray();
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
var gift = MysteryGift.GetMysteryGift(data);
|
2020-10-18 18:02:39 +00:00
|
|
|
if (gift == null)
|
|
|
|
return;
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
string giftType = gift.Type;
|
|
|
|
|
|
|
|
if (mga.Gifts.All(card => card.Data.Length != data.Length))
|
2018-05-12 13:57:11 +00:00
|
|
|
WinFormsUtil.Alert(MsgMysteryGiftQRTypeLength, string.Format(MsgQRDecodeSize, $"0x{data.Length:X}"));
|
2017-06-18 01:37:19 +00:00
|
|
|
else if (types.All(type => type != giftType))
|
2020-03-12 22:05:34 +00:00
|
|
|
WinFormsUtil.Alert(MsgMysteryGiftTypeIncompatible, $"{MsgMysteryGiftQRReceived} {gift.Type}{Environment.NewLine}{MsgMysteryGiftTypeUnexpected} {string.Join(", ", types)}");
|
|
|
|
else if (!SAV.CanReceiveGift(gift))
|
2018-04-07 04:23:09 +00:00
|
|
|
WinFormsUtil.Alert(MsgMysteryGiftTypeDetails);
|
2017-06-18 01:37:19 +00:00
|
|
|
else
|
|
|
|
ViewGiftData(gift);
|
2015-03-11 04:18:35 +00:00
|
|
|
}
|
2015-12-18 05:15:40 +00:00
|
|
|
|
2022-03-23 06:02:46 +00:00
|
|
|
private async void BoxSlot_MouseDown(object? sender, MouseEventArgs e)
|
2015-12-18 05:15:40 +00:00
|
|
|
{
|
2020-11-14 16:20:48 +00:00
|
|
|
if (sender == null)
|
|
|
|
return;
|
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
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
var pb = sender as PictureBox;
|
2016-06-20 04:22:43 +00:00
|
|
|
if (pb?.Image == null)
|
2015-12-19 06:04:01 +00:00
|
|
|
return;
|
|
|
|
|
2022-03-26 22:52:17 +00:00
|
|
|
if (e.Button != MouseButtons.Left || e.Clicks != 1)
|
|
|
|
return;
|
2015-12-19 06:04:01 +00:00
|
|
|
|
2020-12-24 01:14:38 +00:00
|
|
|
int index = pba.IndexOf(pb);
|
2022-03-26 22:52:17 +00:00
|
|
|
var gift = mga.Gifts[index];
|
|
|
|
if (gift.Empty)
|
|
|
|
return;
|
|
|
|
|
2015-12-19 06:04:01 +00:00
|
|
|
// Create Temp File to Drag
|
2022-03-26 22:52:17 +00:00
|
|
|
wc_slot = index;
|
2015-12-19 06:04:01 +00:00
|
|
|
Cursor.Current = Cursors.Hand;
|
2018-07-29 23:39:15 +00:00
|
|
|
string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(gift.FileName));
|
2015-12-19 06:04:01 +00:00
|
|
|
try
|
|
|
|
{
|
2019-12-25 07:24:28 +00:00
|
|
|
File.WriteAllBytes(newfile, gift.Write());
|
2022-03-26 22:52:17 +00:00
|
|
|
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy | DragDropEffects.Move);
|
2015-12-19 06:04:01 +00:00
|
|
|
}
|
2020-09-09 19:47:24 +00:00
|
|
|
// Sometimes the drag-drop is canceled or ends up at a bad location. Don't bother recovering from an exception; just display a safe error message.
|
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:17:01 +00:00
|
|
|
wc_slot = -1;
|
2022-03-23 06:02:46 +00:00
|
|
|
await DeleteAsync(newfile, 20_000).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static async Task DeleteAsync(string path, int delay)
|
|
|
|
{
|
|
|
|
await Task.Delay(delay).ConfigureAwait(true);
|
|
|
|
if (!File.Exists(path))
|
|
|
|
return;
|
|
|
|
|
|
|
|
try { File.Delete(path); }
|
|
|
|
catch (Exception ex) { Debug.WriteLine(ex.Message); }
|
2015-12-18 05:15:40 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2021-12-05 06:29:51 +00:00
|
|
|
private void BoxSlot_DragDrop(object? sender, DragEventArgs? e)
|
2015-12-18 05:15:40 +00:00
|
|
|
{
|
2020-12-24 01:14:38 +00:00
|
|
|
if (mg == null || sender is not PictureBox pb)
|
2020-10-18 18:02:39 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-24 01:14:38 +00:00
|
|
|
int index = pba.IndexOf(pb);
|
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;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
if (wc_slot == -1) // dropped
|
2015-12-19 06:17:01 +00:00
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] {Length: not 0} files)
|
2015-12-19 06:17:01 +00:00
|
|
|
return;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2020-09-09 19:47:24 +00:00
|
|
|
var first = files[0];
|
|
|
|
var fi = new FileInfo(first);
|
|
|
|
if (!MysteryGift.IsMysteryGift(fi.Length))
|
|
|
|
{ WinFormsUtil.Alert(MsgFileUnsupported, first); return; }
|
|
|
|
|
|
|
|
byte[] data = File.ReadAllBytes(first);
|
|
|
|
var gift = MysteryGift.GetMysteryGift(data, fi.Extension);
|
|
|
|
if (gift == null)
|
|
|
|
{ WinFormsUtil.Alert(MsgFileUnsupported, first); return; }
|
2017-01-20 16:43:41 +00:00
|
|
|
|
2018-05-13 02:07:32 +00:00
|
|
|
if (gift is PCD pcd && mga.Gifts[index] is PGT)
|
2018-07-29 23:39:15 +00:00
|
|
|
{
|
2018-05-13 02:07:32 +00:00
|
|
|
gift = pcd.Gift;
|
2018-07-29 23:39:15 +00:00
|
|
|
}
|
2017-01-21 03:35:56 +00:00
|
|
|
else if (gift.Type != mga.Gifts[index].Type)
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
WinFormsUtil.Alert(MsgMysteryGiftSlotFail, $"{gift.Type} != {mga.Gifts[index].Type}");
|
2016-08-16 03:48:02 +00:00
|
|
|
return;
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2021-11-27 23:48:08 +00:00
|
|
|
SetBackground(index, Drawing.PokeSprite.Properties.Resources.slotSet);
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
mga.Gifts[index] = (DataMysteryGift)gift.Clone();
|
2018-05-12 15:13:39 +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
|
|
|
|
{
|
2022-03-26 22:52:17 +00:00
|
|
|
index = SwapSlots(index, wc_slot);
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetBackground(index, Drawing.PokeSprite.Properties.Resources.slotView);
|
|
|
|
SetGiftBoxes();
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2022-03-26 22:52:17 +00:00
|
|
|
private int SwapSlots(int dest, int src)
|
|
|
|
{
|
|
|
|
var gifts = mga.Gifts;
|
|
|
|
var s1 = gifts[dest];
|
|
|
|
var s2 = gifts[src];
|
|
|
|
|
|
|
|
// Double check compatibility of slots
|
|
|
|
if (s1.Type != s2.Type)
|
|
|
|
{
|
2017-01-21 03:35:56 +00:00
|
|
|
if (s2 is PCD && s1 is PGT)
|
|
|
|
{
|
2022-03-26 22:52:17 +00:00
|
|
|
// Get first empty slot
|
|
|
|
var firstEmpty = Array.FindIndex(gifts, z => z.Empty);
|
|
|
|
if ((uint)firstEmpty < dest)
|
|
|
|
dest = firstEmpty;
|
|
|
|
|
|
|
|
// set the PGT to the destination PGT slot instead
|
2017-06-18 01:37:19 +00:00
|
|
|
ViewGiftData(s2);
|
2022-03-26 22:52:17 +00:00
|
|
|
ClickSet(pba[dest], EventArgs.Empty);
|
|
|
|
WinFormsUtil.Alert(string.Format(MsgMysteryGiftSlotAlternate, s2.Type, s1.Type));
|
2017-01-21 03:35:56 +00:00
|
|
|
}
|
2022-03-26 22:52:17 +00:00
|
|
|
else
|
2016-08-16 03:48:02 +00:00
|
|
|
{
|
2022-03-26 22:52:17 +00:00
|
|
|
WinFormsUtil.Alert(string.Format(MsgMysteryGiftSlotFailSwap, s2.Type, s1.Type));
|
2016-08-16 03:48:02 +00:00
|
|
|
}
|
2022-03-26 22:52:17 +00:00
|
|
|
return -1;
|
2015-12-19 06:17:01 +00:00
|
|
|
}
|
2022-03-26 22:52:17 +00:00
|
|
|
|
|
|
|
// If data is present in both slots, just swap.
|
|
|
|
if (!gifts[dest].Empty)
|
|
|
|
{
|
|
|
|
// Swap
|
|
|
|
gifts[src] = s1;
|
|
|
|
gifts[dest] = s2;
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
// empty slot created, bubble this slot to the end of its list
|
|
|
|
for (int i = src; i != dest; i++)
|
|
|
|
{
|
|
|
|
if (gifts[i + 1].Empty)
|
|
|
|
return i; // done bubbling
|
|
|
|
(gifts[i + 1], gifts[i]) = (gifts[i], gifts[i + 1]);
|
|
|
|
}
|
|
|
|
throw new InvalidOperationException(); // shouldn't ever hit here.
|
2015-12-18 05:15:40 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2021-12-05 06:29:51 +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;
|
2022-03-26 22:52:17 +00:00
|
|
|
Debug.WriteLine(e.Effect);
|
2015-12-18 05:15:40 +00:00
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2015-12-19 06:17:01 +00:00
|
|
|
private int wc_slot = -1;
|
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
|
|
|
{
|
2020-12-22 07:37:07 +00:00
|
|
|
List<PictureBox> pb = new();
|
2022-03-26 22:52:17 +00:00
|
|
|
var spriter = SpriteUtil.Spriter;
|
2016-10-27 01:49:40 +00:00
|
|
|
|
|
|
|
// Row 1
|
2017-06-18 01:37:19 +00:00
|
|
|
var f1 = GetFlowLayoutPanel();
|
2017-11-18 19:34:23 +00:00
|
|
|
f1.Controls.Add(GetLabel($"{nameof(PGT)} 1-6"));
|
2016-10-27 01:49:40 +00:00
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
2022-03-26 22:52:17 +00:00
|
|
|
var p = GetPictureBox(spriter.Width, spriter.Height);
|
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();
|
2017-11-18 19:34:23 +00:00
|
|
|
f2.Controls.Add(GetLabel($"{nameof(PGT)} 7-8"));
|
2016-10-27 01:49:40 +00:00
|
|
|
for (int i = 6; i < 8; i++)
|
|
|
|
{
|
2022-03-26 22:52:17 +00:00
|
|
|
var p = GetPictureBox(spriter.Width, spriter.Height);
|
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-11-18 19:34:23 +00:00
|
|
|
f3.Controls.Add(GetLabel($"{nameof(PCD)} 1-3"));
|
2016-10-27 01:49:40 +00:00
|
|
|
for (int i = 8; i < 11; i++)
|
|
|
|
{
|
2022-03-26 22:52:17 +00:00
|
|
|
var p = GetPictureBox(spriter.Width, spriter.Height);
|
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;
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
private List<PictureBox> PopulateViewGiftsG567()
|
2016-10-27 01:49:40 +00:00
|
|
|
{
|
2018-07-29 23:39:15 +00:00
|
|
|
var pb = new List<PictureBox>();
|
2016-10-27 01:49:40 +00:00
|
|
|
|
2018-12-30 06:00:17 +00:00
|
|
|
const int cellsPerRow = 6;
|
|
|
|
int rows = (int)Math.Ceiling(mga.Gifts.Length / (decimal)cellsPerRow);
|
|
|
|
int countRemaining = mga.Gifts.Length;
|
2022-03-26 22:52:17 +00:00
|
|
|
var spriter = SpriteUtil.Spriter;
|
2018-12-30 06:00:17 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < rows; i++)
|
2016-10-27 01:49:40 +00:00
|
|
|
{
|
2018-12-30 06:00:17 +00:00
|
|
|
var row = GetFlowLayoutPanel();
|
|
|
|
int count = cellsPerRow >= countRemaining ? countRemaining : cellsPerRow;
|
|
|
|
countRemaining -= count;
|
|
|
|
int start = (i * cellsPerRow) + 1;
|
|
|
|
row.Controls.Add(GetLabel($"{start}-{start + count - 1}"));
|
|
|
|
for (int j = 0; j < count; j++)
|
2016-10-27 01:49:40 +00:00
|
|
|
{
|
2022-03-26 22:52:17 +00:00
|
|
|
var p = GetPictureBox(spriter.Width, spriter.Height);
|
2018-12-30 06:00:17 +00:00
|
|
|
row.Controls.Add(p);
|
2016-10-27 01:49:40 +00:00
|
|
|
pb.Add(p);
|
|
|
|
}
|
2018-12-30 06:00:17 +00:00
|
|
|
FLP_Gifts.Controls.Add(row);
|
2016-10-27 01:49:40 +00:00
|
|
|
}
|
|
|
|
return pb;
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2021-12-05 01:56:56 +00:00
|
|
|
private static FlowLayoutPanel GetFlowLayoutPanel() => new()
|
2016-10-27 01:49:40 +00:00
|
|
|
{
|
2021-12-05 01:56:56 +00:00
|
|
|
Width = 480,
|
|
|
|
Height = 60,
|
|
|
|
Padding = new Padding(0),
|
|
|
|
Margin = new Padding(0),
|
|
|
|
};
|
2018-07-29 23:39:15 +00:00
|
|
|
|
2021-12-05 01:56:56 +00:00
|
|
|
private static Label GetLabel(string text) => new()
|
2016-10-27 01:49:40 +00:00
|
|
|
{
|
2021-12-05 01:56:56 +00:00
|
|
|
Size = new Size(40, 60),
|
|
|
|
AutoSize = false,
|
|
|
|
TextAlign = ContentAlignment.MiddleRight,
|
|
|
|
Text = text,
|
|
|
|
Padding = new Padding(0),
|
|
|
|
Margin = new Padding(0),
|
|
|
|
};
|
|
|
|
|
2022-03-26 22:52:17 +00:00
|
|
|
private static PictureBox GetPictureBox(int width, int height) => new()
|
2016-10-27 01:49:40 +00:00
|
|
|
{
|
2022-03-26 22:52:17 +00:00
|
|
|
Size = new Size(width + 2, height + 2), // +1 to each side for the FixedSingle border
|
2021-12-05 01:56:56 +00:00
|
|
|
SizeMode = PictureBoxSizeMode.CenterImage,
|
|
|
|
BorderStyle = BorderStyle.FixedSingle,
|
2022-03-26 22:52:17 +00:00
|
|
|
BackColor = SlotUtil.GoodDataColor,
|
2021-12-05 01:56:56 +00:00
|
|
|
Padding = new Padding(0),
|
|
|
|
Margin = new Padding(1),
|
|
|
|
};
|
2017-10-01 01:25:21 +00:00
|
|
|
|
|
|
|
private void B_ModifyAll_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
foreach (var g in mga.Gifts)
|
|
|
|
g.GiftUsed = sender == B_UsedAll;
|
|
|
|
SetGiftBoxes();
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
|
|
}
|
2020-01-26 19:19:58 +00:00
|
|
|
|
|
|
|
private void LB_Received_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
{
|
2021-03-14 23:16:55 +00:00
|
|
|
if (e.KeyCode == Keys.Delete)
|
|
|
|
{
|
|
|
|
if (LB_Received.SelectedIndices.Count > 1)
|
|
|
|
{
|
|
|
|
for (int i = LB_Received.SelectedIndices.Count - 1; i >= 0; i--)
|
2020-01-26 19:19:58 +00:00
|
|
|
LB_Received.Items.RemoveAt(LB_Received.SelectedIndices[i]);
|
|
|
|
}
|
2021-03-14 23:16:55 +00:00
|
|
|
else if (LB_Received.SelectedIndices.Count == 1)
|
|
|
|
{
|
2020-01-26 19:19:58 +00:00
|
|
|
int lastIndex = LB_Received.SelectedIndex;
|
2021-03-14 23:16:55 +00:00
|
|
|
LB_Received.Items.RemoveAt(lastIndex);
|
|
|
|
if (LB_Received.Items.Count == 0)
|
|
|
|
return;
|
|
|
|
if (lastIndex == LB_Received.Items.Count)
|
|
|
|
lastIndex--;
|
|
|
|
LB_Received.SelectedIndex = lastIndex;
|
2020-01-26 19:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 02:16:55 +00:00
|
|
|
}
|
2014-12-15 00:50:15 +00:00
|
|
|
}
|