2016-09-04 17:38:53 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2017-09-05 05:22:02 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
using PKHeX.Core;
|
2019-09-29 16:47:06 +00:00
|
|
|
|
using PKHeX.Drawing;
|
|
|
|
|
using PKHeX.WinForms.Properties;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
using PKHeX.WinForms.Controls;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class SAV_MysteryGiftDB : Form
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private readonly PKMEditor PKME_Tabs;
|
|
|
|
|
private readonly SaveFile SAV;
|
2018-02-02 01:29:07 +00:00
|
|
|
|
private readonly SAVEditor BoxView;
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public SAV_MysteryGiftDB(PKMEditor tabs, SAVEditor sav)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
2018-04-03 03:36:13 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
SAV = sav.SAV;
|
2018-02-02 01:29:07 +00:00
|
|
|
|
BoxView = sav;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
PKME_Tabs = tabs;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
|
|
|
|
// Preset Filters to only show PKM available for loaded save
|
|
|
|
|
CB_FormatComparator.SelectedIndex = 3; // <=
|
|
|
|
|
|
2019-11-16 23:56:30 +00:00
|
|
|
|
var grid = MysteryPokeGrid;
|
|
|
|
|
var smallWidth = grid.Width;
|
|
|
|
|
var smallHeight = grid.Height;
|
|
|
|
|
grid.InitializeGrid(6, 11, SpriteUtil.Spriter);
|
|
|
|
|
grid.SetBackground(Resources.box_wp_clean);
|
|
|
|
|
var newWidth = grid.Width;
|
|
|
|
|
var newHeight = grid.Height;
|
|
|
|
|
var wdelta = newWidth - smallWidth;
|
|
|
|
|
if (wdelta != 0)
|
|
|
|
|
Width += wdelta;
|
|
|
|
|
var hdelta = newHeight - smallHeight;
|
|
|
|
|
if (hdelta != 0)
|
|
|
|
|
Height += hdelta;
|
|
|
|
|
|
|
|
|
|
PKXBOXES = grid.Entries.ToArray();
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
|
|
|
|
// Enable Scrolling when hovered over
|
|
|
|
|
foreach (var slot in PKXBOXES)
|
|
|
|
|
{
|
|
|
|
|
// Enable Click
|
2017-07-06 01:39:53 +00:00
|
|
|
|
slot.MouseClick += (sender, e) =>
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (ModifierKeys == Keys.Control)
|
2017-07-06 01:39:53 +00:00
|
|
|
|
ClickView(sender, e);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
};
|
2019-10-28 03:39:07 +00:00
|
|
|
|
|
|
|
|
|
slot.ContextMenuStrip = mnu;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-09-04 17:38:53 +00:00
|
|
|
|
Counter = L_Count.Text;
|
|
|
|
|
Viewed = L_Viewed.Text;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
L_Viewed.Text = string.Empty; // invis for now
|
2017-07-06 01:39:53 +00:00
|
|
|
|
L_Viewed.MouseEnter += (sender, e) => hover.SetToolTip(L_Viewed, L_Viewed.Text);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
|
|
|
|
// Load Data
|
2017-09-05 05:22:02 +00:00
|
|
|
|
B_Search.Enabled = false;
|
|
|
|
|
L_Count.Text = "Loading...";
|
|
|
|
|
new Task(LoadDatabase).Start();
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
2018-04-07 04:23:09 +00:00
|
|
|
|
CB_Format.Items[0] = MsgAny;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
CenterToParent();
|
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2016-09-04 17:38:53 +00:00
|
|
|
|
private readonly PictureBox[] PKXBOXES;
|
2016-11-13 21:11:53 +00:00
|
|
|
|
private readonly string DatabasePath = Main.MGDatabasePath;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
private List<MysteryGift> Results;
|
2017-09-05 05:22:02 +00:00
|
|
|
|
private List<MysteryGift> RawDB;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
private int slotSelected = -1; // = null;
|
|
|
|
|
private Image slotColor;
|
|
|
|
|
private const int RES_MAX = 66;
|
|
|
|
|
private const int RES_MIN = 6;
|
|
|
|
|
private readonly string Counter;
|
|
|
|
|
private readonly string Viewed;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
private const int MAXFORMAT = PKX.Generation;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
|
|
|
|
// Important Events
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickView(object sender, EventArgs e)
|
2017-05-19 01:10:58 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int index = GetSenderIndex(sender);
|
2017-07-15 05:50:12 +00:00
|
|
|
|
if (index < 0)
|
|
|
|
|
return;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PKME_Tabs.PopulateFields(Results[index].ConvertToPKM(SAV), false);
|
2017-05-19 01:10:58 +00:00
|
|
|
|
slotSelected = index;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
slotColor = SpriteUtil.Spriter.View;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
UpdateSlotColor(SCR_Box.Value);
|
2017-05-19 01:10:58 +00:00
|
|
|
|
L_Viewed.Text = string.Format(Viewed, Results[index].FileName);
|
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickSavePK(object sender, EventArgs e)
|
2017-05-19 01:10:58 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int index = GetSenderIndex(sender);
|
2017-07-15 05:50:12 +00:00
|
|
|
|
if (index < 0)
|
|
|
|
|
return;
|
2017-05-19 01:10:58 +00:00
|
|
|
|
var gift = Results[index];
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var pk = gift.ConvertToPKM(SAV);
|
2017-05-19 01:10:58 +00:00
|
|
|
|
WinFormsUtil.SavePKMDialog(pk);
|
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickSaveMG(object sender, EventArgs e)
|
2017-05-19 01:10:58 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int index = GetSenderIndex(sender);
|
2017-07-15 05:50:12 +00:00
|
|
|
|
if (index < 0)
|
|
|
|
|
return;
|
2017-05-19 01:10:58 +00:00
|
|
|
|
var gift = Results[index];
|
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 (!(gift is DataMysteryGift g)) // e.g. WC3
|
2017-07-16 01:36:55 +00:00
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgExportWC3DataFail);
|
2017-07-16 01:36:55 +00:00
|
|
|
|
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
|
|
|
|
WinFormsUtil.ExportMGDialog(g, SAV.Version);
|
2017-05-19 01:10:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private int GetSenderIndex(object sender)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
2019-09-25 01:14:15 +00:00
|
|
|
|
var pb = WinFormsUtil.GetUnderlyingControl<PictureBox>(sender);
|
|
|
|
|
int index = Array.IndexOf(PKXBOXES, pb);
|
2017-04-19 10:15:50 +00:00
|
|
|
|
if (index >= RES_MAX)
|
|
|
|
|
{
|
2016-09-04 17:38:53 +00:00
|
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
2017-05-19 01:10:58 +00:00
|
|
|
|
return -1;
|
2017-04-19 10:15:50 +00:00
|
|
|
|
}
|
|
|
|
|
index += SCR_Box.Value*RES_MIN;
|
|
|
|
|
if (index >= Results.Count)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
2017-04-19 10:15:50 +00:00
|
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
2017-05-19 01:10:58 +00:00
|
|
|
|
return -1;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
2017-05-19 01:10:58 +00:00
|
|
|
|
return index;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void PopulateComboBoxes()
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
|
|
|
|
// Set the Text
|
2018-07-14 23:00:28 +00:00
|
|
|
|
CB_HeldItem.InitializeBinding();
|
|
|
|
|
CB_Species.InitializeBinding();
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
2019-06-02 02:12:41 +00:00
|
|
|
|
var Any = new ComboItem(MsgAny, -1);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
2016-10-29 22:41:55 +00:00
|
|
|
|
var DS_Species = new List<ComboItem>(GameInfo.SpeciesDataSource);
|
2016-09-18 05:31:47 +00:00
|
|
|
|
DS_Species.RemoveAt(0);
|
|
|
|
|
var filteredSpecies = DS_Species.Where(spec => RawDB.Any(mg => mg.Species == spec.Value)).ToList();
|
|
|
|
|
filteredSpecies.Insert(0, Any);
|
|
|
|
|
CB_Species.DataSource = filteredSpecies;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
2016-10-29 22:41:55 +00:00
|
|
|
|
var DS_Item = new List<ComboItem>(GameInfo.ItemDataSource);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
DS_Item.Insert(0, Any); CB_HeldItem.DataSource = DS_Item;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-09-04 17:38:53 +00:00
|
|
|
|
// Set the Move ComboBoxes too..
|
2016-10-29 22:41:55 +00:00
|
|
|
|
var DS_Move = new List<ComboItem>(GameInfo.MoveDataSource);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
DS_Move.RemoveAt(0); DS_Move.Insert(0, Any);
|
|
|
|
|
{
|
|
|
|
|
foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 })
|
|
|
|
|
{
|
2018-07-14 23:00:28 +00:00
|
|
|
|
cb.InitializeBinding();
|
2016-09-04 17:38:53 +00:00
|
|
|
|
cb.DataSource = new BindingSource(DS_Move, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Trigger a Reset
|
2019-02-02 18:19:41 +00:00
|
|
|
|
ResetFilters(null, EventArgs.Empty);
|
2017-09-05 05:54:16 +00:00
|
|
|
|
B_Search.Enabled = true;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ResetFilters(object sender, EventArgs e)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
|
|
|
|
CHK_Shiny.Checked = CHK_IsEgg.Checked = true;
|
|
|
|
|
CHK_Shiny.CheckState = CHK_IsEgg.CheckState = CheckState.Indeterminate;
|
|
|
|
|
CB_HeldItem.SelectedIndex = 0;
|
|
|
|
|
CB_Species.SelectedIndex = 0;
|
|
|
|
|
|
|
|
|
|
CB_Move1.SelectedIndex = CB_Move2.SelectedIndex = CB_Move3.SelectedIndex = CB_Move4.SelectedIndex = 0;
|
|
|
|
|
RTB_Instructions.Clear();
|
|
|
|
|
|
|
|
|
|
if (sender != null)
|
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2017-09-05 05:22:02 +00:00
|
|
|
|
private void LoadDatabase()
|
|
|
|
|
{
|
2019-11-17 05:55:38 +00:00
|
|
|
|
var db = EncounterEvent.GetAllEvents();
|
|
|
|
|
|
2020-02-12 04:23:59 +00:00
|
|
|
|
// when all sprites in new size are available, remove this filter
|
|
|
|
|
db = SAV is SAV8SWSH ? db.Where(z => ((PersonalInfoSWSH)PersonalTable.SWSH.GetFormeEntry(z.Species, z.Form)).IsPresentInGame) : db.Where(z => !(z is WC8));
|
2019-11-17 05:55:38 +00:00
|
|
|
|
|
|
|
|
|
RawDB = new List<MysteryGift>(db);
|
2017-09-05 05:22:02 +00:00
|
|
|
|
foreach (var mg in RawDB)
|
|
|
|
|
mg.GiftUsed = false;
|
2020-03-14 21:58:36 +00:00
|
|
|
|
|
|
|
|
|
try
|
2017-09-05 05:22:02 +00:00
|
|
|
|
{
|
2020-03-14 21:58:36 +00:00
|
|
|
|
while (!IsHandleCreated) { }
|
|
|
|
|
BeginInvoke(new MethodInvoker(delegate
|
|
|
|
|
{
|
|
|
|
|
SetResults(RawDB);
|
|
|
|
|
PopulateComboBoxes();
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
catch { /* Window Closed? */ }
|
2017-09-05 05:22:02 +00:00
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
|
|
|
|
// IO Usage
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void OpenDB(object sender, EventArgs e)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(DatabasePath))
|
|
|
|
|
Process.Start("explorer.exe", DatabasePath);
|
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2016-09-04 17:38:53 +00:00
|
|
|
|
private void Menu_Export_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Results == null || Results.Count == 0)
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgDBCreateReportFail); return; }
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
2018-04-07 04:23:09 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDBExportResultsPrompt))
|
2016-09-04 17:38:53 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var fbd = new FolderBrowserDialog();
|
2016-09-04 17:38:53 +00:00
|
|
|
|
if (DialogResult.OK != fbd.ShowDialog())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
string path = fbd.SelectedPath;
|
2017-10-03 06:13:40 +00:00
|
|
|
|
Directory.CreateDirectory(path);
|
2016-09-04 17:38:53 +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
|
|
|
|
foreach (var gift in Results.OfType<DataMysteryGift>()) // WC3 have no data
|
2019-12-25 07:24:28 +00:00
|
|
|
|
File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(gift.FileName)), gift.Write());
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// View Updates
|
|
|
|
|
private void B_Search_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Populate Search Query Result
|
|
|
|
|
IEnumerable<MysteryGift> res = RawDB;
|
|
|
|
|
|
|
|
|
|
int format = MAXFORMAT + 1 - CB_Format.SelectedIndex;
|
|
|
|
|
|
|
|
|
|
switch (CB_FormatComparator.SelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0: /* Do nothing */ break;
|
|
|
|
|
case 1: res = res.Where(mg => mg.Format >= format); break;
|
|
|
|
|
case 2: res = res.Where(mg => mg.Format == format); break;
|
|
|
|
|
case 3: res = res.Where(mg => mg.Format <= format); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Primary Searchables
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int species = WinFormsUtil.GetIndex(CB_Species);
|
|
|
|
|
int item = WinFormsUtil.GetIndex(CB_HeldItem);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
if (species != -1) res = res.Where(pk => pk.Species == species);
|
|
|
|
|
if (item != -1) res = res.Where(pk => pk.HeldItem == item);
|
|
|
|
|
|
|
|
|
|
// Secondary Searchables
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int move1 = WinFormsUtil.GetIndex(CB_Move1);
|
|
|
|
|
int move2 = WinFormsUtil.GetIndex(CB_Move2);
|
|
|
|
|
int move3 = WinFormsUtil.GetIndex(CB_Move3);
|
|
|
|
|
int move4 = WinFormsUtil.GetIndex(CB_Move4);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
if (move1 != -1) res = res.Where(pk => pk.Moves.Contains(move1));
|
|
|
|
|
if (move2 != -1) res = res.Where(pk => pk.Moves.Contains(move2));
|
|
|
|
|
if (move3 != -1) res = res.Where(pk => pk.Moves.Contains(move3));
|
|
|
|
|
if (move4 != -1) res = res.Where(pk => pk.Moves.Contains(move4));
|
|
|
|
|
if (CHK_Shiny.CheckState == CheckState.Checked) res = res.Where(pk => pk.IsShiny);
|
|
|
|
|
if (CHK_Shiny.CheckState == CheckState.Unchecked) res = res.Where(pk => !pk.IsShiny);
|
|
|
|
|
if (CHK_IsEgg.CheckState == CheckState.Checked) res = res.Where(pk => pk.IsEgg);
|
|
|
|
|
if (CHK_IsEgg.CheckState == CheckState.Unchecked) res = res.Where(pk => !pk.IsEgg);
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-09-04 17:38:53 +00:00
|
|
|
|
slotSelected = -1; // reset the slot last viewed
|
|
|
|
|
|
|
|
|
|
if (RTB_Instructions.Lines.Any(line => line.Length > 0))
|
|
|
|
|
{
|
2018-05-18 05:43:07 +00:00
|
|
|
|
var filters = StringInstruction.GetFilters(RTB_Instructions.Lines).ToArray();
|
|
|
|
|
BatchEditing.ScreenStrings(filters);
|
2018-06-01 02:59:05 +00:00
|
|
|
|
res = res.Where(pkm => BatchEditing.IsFilterMatch(filters, pkm)); // Compare across all filters
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var results = res.ToArray();
|
|
|
|
|
if (results.Length == 0)
|
2018-04-07 04:23:09 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgDBSearchNone);
|
2017-08-25 01:49:09 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetResults(new List<MysteryGift>(results)); // updates Count Label as well.
|
2016-09-04 17:38:53 +00:00
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
|
|
|
}
|
2018-05-18 05:43:07 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void UpdateScroll(object sender, ScrollEventArgs e)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (e.OldValue != e.NewValue)
|
|
|
|
|
FillPKXBoxes(e.NewValue);
|
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void SetResults(List<MysteryGift> res)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
|
|
|
|
Results = new List<MysteryGift>(res);
|
|
|
|
|
|
|
|
|
|
SCR_Box.Maximum = (int)Math.Ceiling((decimal)Results.Count / RES_MIN);
|
2018-05-13 02:07:32 +00:00
|
|
|
|
if (SCR_Box.Maximum > 0) SCR_Box.Maximum--;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
|
|
|
|
SCR_Box.Value = 0;
|
|
|
|
|
FillPKXBoxes(0);
|
|
|
|
|
|
|
|
|
|
L_Count.Text = string.Format(Counter, Results.Count);
|
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2016-09-04 17:38:53 +00:00
|
|
|
|
private void FillPKXBoxes(int start)
|
|
|
|
|
{
|
|
|
|
|
if (Results == null)
|
2016-09-04 18:02:27 +00:00
|
|
|
|
{
|
2016-09-04 17:38:53 +00:00
|
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
|
|
|
|
PKXBOXES[i].Image = null;
|
2016-09-04 18:02:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-04-21 03:52:08 +00:00
|
|
|
|
int begin = start * RES_MIN;
|
2018-09-27 01:56:29 +00:00
|
|
|
|
int end = Math.Min(RES_MAX, Results.Count - (start * RES_MIN));
|
2017-04-21 03:52:08 +00:00
|
|
|
|
for (int i = 0; i < end; i++)
|
2017-11-18 19:34:23 +00:00
|
|
|
|
PKXBOXES[i].Image = Results[i + begin].Sprite();
|
2017-04-21 03:52:08 +00:00
|
|
|
|
for (int i = end; i < RES_MAX; i++)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
PKXBOXES[i].Image = null;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
UpdateSlotColor(start);
|
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2017-07-16 01:36:55 +00:00
|
|
|
|
private void UpdateSlotColor(int start)
|
|
|
|
|
{
|
2016-09-04 17:38:53 +00:00
|
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
2019-11-16 01:34:18 +00:00
|
|
|
|
PKXBOXES[i].BackgroundImage = SpriteUtil.Spriter.Transparent;
|
2018-09-27 01:56:29 +00:00
|
|
|
|
if (slotSelected != -1 && slotSelected >= RES_MIN * start && slotSelected < (RES_MIN * start) + RES_MAX)
|
2019-11-16 01:34:18 +00:00
|
|
|
|
PKXBOXES[slotSelected - (start * RES_MIN)].BackgroundImage = slotColor ?? SpriteUtil.Spriter.View;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 01:29:07 +00:00
|
|
|
|
private void Menu_Import_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-12-29 01:58:13 +00:00
|
|
|
|
if (!BoxView.GetBulkImportSettings(out var clearAll, out var overwrite, out var noSetb))
|
2018-02-02 01:29:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int box = BoxView.Box.CurrentBox;
|
2019-02-23 22:37:06 +00:00
|
|
|
|
int ctr = SAV.LoadBoxes(Results, out var result, box, clearAll, overwrite, noSetb);
|
|
|
|
|
if (ctr <= 0)
|
2018-02-02 01:29:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
BoxView.SetPKMBoxes();
|
|
|
|
|
BoxView.UpdateBoxViewers();
|
|
|
|
|
WinFormsUtil.Alert(result);
|
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
|
|
|
|
private void Menu_Exit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
|
2016-09-04 17:38:53 +00:00
|
|
|
|
protected override void OnMouseWheel(MouseEventArgs e)
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (!MysteryPokeGrid.RectangleToScreen(MysteryPokeGrid.ClientRectangle).Contains(MousePosition))
|
2016-09-04 17:38:53 +00:00
|
|
|
|
return;
|
|
|
|
|
int oldval = SCR_Box.Value;
|
|
|
|
|
int newval = oldval + (e.Delta < 0 ? 1 : -1);
|
|
|
|
|
if (newval >= SCR_Box.Minimum && SCR_Box.Maximum >= newval)
|
|
|
|
|
FillPKXBoxes(SCR_Box.Value = newval);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeFormatFilter(object sender, EventArgs e)
|
2016-09-04 17:38:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (CB_FormatComparator.SelectedIndex == 0)
|
|
|
|
|
{
|
|
|
|
|
CB_Format.Visible = false; // !any
|
|
|
|
|
CB_Format.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CB_Format.Visible = true;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
int index = MAXFORMAT - SAV.Generation + 1;
|
2016-09-05 01:17:13 +00:00
|
|
|
|
CB_Format.SelectedIndex = index < CB_Format.Items.Count ? index : 0; // SAV generation (offset by 1 for "Any")
|
2016-09-04 17:38:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|