2022-06-28 02:59:36 +00:00
|
|
|
using System;
|
2016-09-04 17:38:53 +00:00
|
|
|
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;
|
2021-11-27 23:48:08 +00:00
|
|
|
using PKHeX.Drawing.PokeSprite;
|
2019-09-29 16:47:06 +00:00
|
|
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms;
|
|
|
|
|
|
|
|
public partial class SAV_MysteryGiftDB : Form
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly PKMEditor PKME_Tabs;
|
|
|
|
private readonly SaveFile SAV;
|
|
|
|
private readonly SAVEditor BoxView;
|
|
|
|
private readonly SummaryPreviewer ShowSet = new();
|
2022-09-17 09:00:06 +00:00
|
|
|
private readonly EntityInstructionBuilder UC_Builder;
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV_MysteryGiftDB(PKMEditor tabs, SAVEditor sav)
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
2022-08-20 17:43:04 +00:00
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2022-09-17 09:00:06 +00:00
|
|
|
UC_Builder = new EntityInstructionBuilder(() => tabs.PreparePKM())
|
2022-06-28 02:59:36 +00:00
|
|
|
{
|
|
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
|
|
|
|
Width = Tab_Advanced.Width,
|
|
|
|
Dock = DockStyle.Top,
|
|
|
|
ReadOnly = true,
|
|
|
|
};
|
|
|
|
Tab_Advanced.Controls.Add(UC_Builder);
|
2022-09-17 09:00:06 +00:00
|
|
|
UC_Builder.SendToBack();
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
SAV = sav.SAV;
|
|
|
|
BoxView = sav;
|
|
|
|
PKME_Tabs = tabs;
|
|
|
|
|
|
|
|
// Preset Filters to only show PKM available for loaded save
|
|
|
|
CB_FormatComparator.SelectedIndex = 3; // <=
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Enable Scrolling when hovered over
|
|
|
|
foreach (var slot in PKXBOXES)
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Enable Click
|
|
|
|
slot.MouseClick += (sender, e) =>
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (ModifierKeys == Keys.Control)
|
|
|
|
ClickView(sender!, e);
|
|
|
|
};
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
slot.ContextMenuStrip = mnu;
|
|
|
|
slot.MouseEnter += (o, args) => ShowHoverTextForSlot(slot, args);
|
2023-02-05 08:42:37 +00:00
|
|
|
slot.Enter += (sender, e) =>
|
|
|
|
{
|
|
|
|
if (sender is not PictureBox pb)
|
|
|
|
return;
|
|
|
|
var index = Array.IndexOf(PKXBOXES, sender);
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
|
|
|
index += (SCR_Box.Value * RES_MIN);
|
|
|
|
if (index >= Results.Count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var enc = Results[index];
|
2023-04-15 08:58:37 +00:00
|
|
|
pb.AccessibleDescription = string.Join(Environment.NewLine, enc.GetTextLines());
|
2023-02-05 08:42:37 +00:00
|
|
|
};
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Counter = L_Count.Text;
|
|
|
|
Viewed = L_Viewed.Text;
|
|
|
|
L_Viewed.Text = string.Empty; // invis for now
|
|
|
|
L_Viewed.MouseEnter += (sender, e) => hover.SetToolTip(L_Viewed, L_Viewed.Text);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Load Data
|
|
|
|
B_Search.Enabled = false;
|
|
|
|
L_Count.Text = "Loading...";
|
|
|
|
new Task(LoadDatabase).Start();
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_Format.Items[0] = MsgAny;
|
|
|
|
CenterToParent();
|
|
|
|
}
|
2021-02-07 16:32:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly PictureBox[] PKXBOXES;
|
|
|
|
private readonly string DatabasePath = Main.MGDatabasePath;
|
|
|
|
private List<MysteryGift> Results = new();
|
|
|
|
private List<MysteryGift> RawDB = new();
|
|
|
|
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;
|
|
|
|
private const int MAXFORMAT = PKX.Generation;
|
|
|
|
|
|
|
|
private bool GetShiftedIndex(ref int index)
|
|
|
|
{
|
|
|
|
if (index >= RES_MAX)
|
|
|
|
return false;
|
|
|
|
index += SCR_Box.Value * RES_MIN;
|
|
|
|
return index < Results.Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Important Events
|
|
|
|
private void ClickView(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int index = GetSenderIndex(sender);
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
|
|
|
var temp = Results[index].ConvertToPKM(SAV);
|
|
|
|
var pk = EntityConverter.ConvertToType(temp, SAV.PKMType, out var c);
|
|
|
|
if (pk == null)
|
2017-05-19 01:10:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Error(c.GetDisplayString(temp, SAV.PKMType));
|
|
|
|
return;
|
2017-05-19 01:10:58 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
SAV.AdaptPKM(pk);
|
|
|
|
PKME_Tabs.PopulateFields(pk, false);
|
|
|
|
slotSelected = index;
|
|
|
|
slotColor = SpriteUtil.Spriter.View;
|
|
|
|
UpdateSlotColor(SCR_Box.Value);
|
|
|
|
L_Viewed.Text = string.Format(Viewed, Results[index].FileName);
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ClickSavePK(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int index = GetSenderIndex(sender);
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
|
|
|
var gift = Results[index];
|
|
|
|
var pk = gift.ConvertToPKM(SAV);
|
|
|
|
WinFormsUtil.SavePKMDialog(pk);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ClickSaveMG(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int index = GetSenderIndex(sender);
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
|
|
|
var gift = Results[index];
|
|
|
|
if (gift is not DataMysteryGift g) // e.g. WC3
|
2017-05-19 01:10:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.Alert(MsgExportWC3DataFail);
|
|
|
|
return;
|
2017-05-19 01:10:58 +00:00
|
|
|
}
|
2022-11-25 01:42:17 +00:00
|
|
|
WinFormsUtil.ExportMGDialog(g);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private int GetSenderIndex(object sender)
|
|
|
|
{
|
|
|
|
var pb = WinFormsUtil.GetUnderlyingControl<PictureBox>(sender);
|
|
|
|
int index = Array.IndexOf(PKXBOXES, pb);
|
|
|
|
if (index >= RES_MAX)
|
2017-05-19 01:10:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
|
|
|
return -1;
|
2017-05-19 01:10:58 +00:00
|
|
|
}
|
2023-04-22 03:47:04 +00:00
|
|
|
index += SCR_Box.Value * RES_MIN;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (index >= Results.Count)
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
|
|
|
return -1;
|
2016-09-04 17:38:53 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return index;
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void PopulateComboBoxes()
|
|
|
|
{
|
|
|
|
// Set the Text
|
|
|
|
CB_HeldItem.InitializeBinding();
|
|
|
|
CB_Species.InitializeBinding();
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-08-31 04:15:07 +00:00
|
|
|
var comboAny = new ComboItem(MsgAny, -1);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var species = new List<ComboItem>(GameInfo.SpeciesDataSource);
|
|
|
|
species.RemoveAt(0);
|
|
|
|
var filteredSpecies = species.Where(z => RawDB.Any(mg => mg.Species == z.Value)).ToList();
|
|
|
|
filteredSpecies.Insert(0, comboAny);
|
|
|
|
CB_Species.DataSource = filteredSpecies;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var items = new List<ComboItem>(GameInfo.ItemDataSource);
|
|
|
|
items.Insert(0, comboAny); CB_HeldItem.DataSource = items;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Set the Move ComboBoxes too..
|
|
|
|
var moves = new List<ComboItem>(GameInfo.MoveDataSource);
|
|
|
|
moves.RemoveAt(0); moves.Insert(0, comboAny);
|
|
|
|
{
|
|
|
|
var arr = new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 };
|
|
|
|
foreach (var cb in arr)
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
cb.InitializeBinding();
|
|
|
|
cb.DataSource = new BindingSource(moves, null);
|
2016-09-04 17:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Trigger a Reset
|
|
|
|
ResetFilters(this, EventArgs.Empty);
|
|
|
|
B_Search.Enabled = true;
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ResetFilters(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
CHK_Shiny.Checked = CHK_IsEgg.Checked = true;
|
|
|
|
CHK_Shiny.CheckState = CHK_IsEgg.CheckState = CheckState.Indeterminate;
|
|
|
|
CB_HeldItem.SelectedIndex = 0;
|
|
|
|
CB_Species.SelectedIndex = 0;
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_Move1.SelectedIndex = CB_Move2.SelectedIndex = CB_Move3.SelectedIndex = CB_Move4.SelectedIndex = 0;
|
|
|
|
RTB_Instructions.Clear();
|
2019-11-17 05:55:38 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sender != this)
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
|
|
}
|
2019-11-17 05:55:38 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void LoadDatabase()
|
|
|
|
{
|
|
|
|
var db = EncounterEvent.GetAllEvents();
|
2020-03-14 21:58:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Main.Settings.MysteryDb.FilterUnavailableSpecies)
|
|
|
|
{
|
2023-04-22 03:47:04 +00:00
|
|
|
static bool IsPresentInGameSV(ISpeciesForm pk) => PersonalTable.SV.IsPresentInGame(pk.Species, pk.Form);
|
2022-06-18 18:04:24 +00:00
|
|
|
static bool IsPresentInGameSWSH(ISpeciesForm pk) => PersonalTable.SWSH.IsPresentInGame(pk.Species, pk.Form);
|
|
|
|
static bool IsPresentInGameBDSP(ISpeciesForm pk) => PersonalTable.BDSP.IsPresentInGame(pk.Species, pk.Form);
|
2023-04-22 03:47:04 +00:00
|
|
|
static bool IsPresentInGameLA(ISpeciesForm pk) => PersonalTable.LA.IsPresentInGame(pk.Species, pk.Form);
|
2022-06-18 18:04:24 +00:00
|
|
|
db = SAV switch
|
2017-09-05 05:22:02 +00:00
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
SAV9SV => db.Where(IsPresentInGameSV),
|
2022-06-18 18:04:24 +00:00
|
|
|
SAV8SWSH => db.Where(IsPresentInGameSWSH),
|
|
|
|
SAV8BS => db.Where(IsPresentInGameBDSP),
|
|
|
|
SAV8LA => db.Where(IsPresentInGameLA),
|
|
|
|
SAV7b => db.Where(z => z is WB7),
|
|
|
|
SAV7 => db.Where(z => z.Generation < 7 || z is WC7),
|
|
|
|
_ => db.Where(z => z.Generation <= SAV.Generation),
|
|
|
|
};
|
2017-09-05 05:22:02 +00:00
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
RawDB = new List<MysteryGift>(db);
|
|
|
|
foreach (var mg in RawDB)
|
|
|
|
mg.GiftUsed = false;
|
|
|
|
|
|
|
|
try
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
while (!IsHandleCreated) { }
|
|
|
|
BeginInvoke(new MethodInvoker(delegate
|
|
|
|
{
|
|
|
|
SetResults(RawDB);
|
|
|
|
PopulateComboBoxes();
|
|
|
|
}));
|
2016-09-04 17:38:53 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
catch { /* Window Closed? */ }
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// IO Usage
|
|
|
|
private void OpenDB(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Directory.Exists(DatabasePath))
|
|
|
|
Process.Start("explorer.exe", DatabasePath);
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Menu_Export_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (Results.Count == 0)
|
|
|
|
{ WinFormsUtil.Alert(MsgDBCreateReportFail); return; }
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDBExportResultsPrompt))
|
|
|
|
return;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
using var fbd = new FolderBrowserDialog();
|
|
|
|
if (DialogResult.OK != fbd.ShowDialog())
|
|
|
|
return;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
string folder = fbd.SelectedPath;
|
|
|
|
Directory.CreateDirectory(folder);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
foreach (var gift in Results.OfType<DataMysteryGift>()) // WC3 have no data
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var fileName = Util.CleanFileName(gift.FileName);
|
|
|
|
var path = Path.Combine(folder, fileName);
|
|
|
|
var data = gift.Write();
|
|
|
|
File.WriteAllBytes(path, data);
|
|
|
|
}
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// View Updates
|
|
|
|
private void B_Search_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Populate Search Query Result
|
|
|
|
IEnumerable<MysteryGift> res = RawDB;
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int format = MAXFORMAT + 1 - CB_Format.SelectedIndex;
|
2017-08-25 01:49:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
switch (CB_FormatComparator.SelectedIndex)
|
|
|
|
{
|
|
|
|
case 0: /* Do nothing */ break;
|
|
|
|
case 1: res = res.Where(mg => mg.Generation >= format); break;
|
|
|
|
case 2: res = res.Where(mg => mg.Generation == format); break;
|
|
|
|
case 3: res = res.Where(mg => mg.Generation <= format); break;
|
2016-09-04 17:38:53 +00:00
|
|
|
}
|
2018-05-18 05:43:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Primary Searchables
|
2022-08-31 04:15:07 +00:00
|
|
|
var species = WinFormsUtil.GetIndex(CB_Species);
|
2022-06-18 18:04:24 +00:00
|
|
|
int item = WinFormsUtil.GetIndex(CB_HeldItem);
|
2022-08-31 04:15:07 +00:00
|
|
|
if (species != -1) res = res.Where(pk => pk.Species == species);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (item != -1) res = res.Where(pk => pk.HeldItem == item);
|
|
|
|
|
|
|
|
// Secondary Searchables
|
|
|
|
int move1 = WinFormsUtil.GetIndex(CB_Move1);
|
|
|
|
int move2 = WinFormsUtil.GetIndex(CB_Move2);
|
|
|
|
int move3 = WinFormsUtil.GetIndex(CB_Move3);
|
|
|
|
int move4 = WinFormsUtil.GetIndex(CB_Move4);
|
2022-08-27 06:43:36 +00:00
|
|
|
if (move1 != -1) res = res.Where(mg => mg.HasMove((ushort)move1));
|
|
|
|
if (move2 != -1) res = res.Where(mg => mg.HasMove((ushort)move2));
|
|
|
|
if (move3 != -1) res = res.Where(mg => mg.HasMove((ushort)move3));
|
|
|
|
if (move4 != -1) res = res.Where(mg => mg.HasMove((ushort)move4));
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
var shiny = CHK_Shiny.CheckState;
|
|
|
|
if (shiny == CheckState.Checked) res = res.Where(pk => pk.IsShiny);
|
|
|
|
else if (shiny == CheckState.Unchecked) res = res.Where(pk => !pk.IsShiny);
|
|
|
|
|
|
|
|
var egg = CHK_IsEgg.CheckState;
|
|
|
|
if (egg == CheckState.Checked) res = res.Where(pk => pk.IsEgg);
|
|
|
|
else if (egg == CheckState.Unchecked) res = res.Where(pk => !pk.IsEgg);
|
|
|
|
|
|
|
|
slotSelected = -1; // reset the slot last viewed
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
ReadOnlySpan<char> batchText = RTB_Instructions.Text;
|
|
|
|
if (batchText.Length > 0 && !StringInstructionSet.HasEmptyLine(batchText))
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var filters = StringInstruction.GetFilters(batchText);
|
2022-06-18 18:04:24 +00:00
|
|
|
BatchEditing.ScreenStrings(filters);
|
|
|
|
res = res.Where(pk => BatchEditing.IsFilterMatch(filters, pk)); // Compare across all filters
|
2016-09-04 17:38:53 +00:00
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var results = res.ToArray();
|
|
|
|
if (results.Length == 0)
|
|
|
|
WinFormsUtil.Alert(MsgDBSearchNone);
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SetResults(new List<MysteryGift>(results)); // updates Count Label as well.
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateScroll(object sender, ScrollEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.OldValue != e.NewValue)
|
|
|
|
FillPKXBoxes(e.NewValue);
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetResults(List<MysteryGift> res)
|
|
|
|
{
|
|
|
|
Results = new List<MysteryGift>(res);
|
|
|
|
ShowSet.Clear();
|
|
|
|
|
|
|
|
SCR_Box.Maximum = (int)Math.Ceiling((decimal)Results.Count / RES_MIN);
|
|
|
|
if (SCR_Box.Maximum > 0) SCR_Box.Maximum--;
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SCR_Box.Value = 0;
|
|
|
|
FillPKXBoxes(0);
|
|
|
|
|
|
|
|
L_Count.Text = string.Format(Counter, Results.Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FillPKXBoxes(int start)
|
|
|
|
{
|
|
|
|
if (Results.Count == 0)
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
2016-09-04 18:02:27 +00:00
|
|
|
{
|
2016-09-04 17:38:53 +00:00
|
|
|
PKXBOXES[i].Image = null;
|
2022-06-18 18:04:24 +00:00
|
|
|
PKXBOXES[i].BackgroundImage = null;
|
|
|
|
}
|
|
|
|
return;
|
2017-07-16 01:36:55 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
int begin = start * RES_MIN;
|
|
|
|
int end = Math.Min(RES_MAX, Results.Count - (start * RES_MIN));
|
|
|
|
for (int i = 0; i < end; i++)
|
|
|
|
PKXBOXES[i].Image = Results[i + begin].Sprite();
|
|
|
|
for (int i = end; i < RES_MAX; i++)
|
|
|
|
PKXBOXES[i].Image = null;
|
|
|
|
UpdateSlotColor(start);
|
|
|
|
}
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateSlotColor(int start)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
|
|
|
PKXBOXES[i].BackgroundImage = SpriteUtil.Spriter.Transparent;
|
|
|
|
if (slotSelected != -1 && slotSelected >= RES_MIN * start && slotSelected < (RES_MIN * start) + RES_MAX)
|
|
|
|
PKXBOXES[slotSelected - (start * RES_MIN)].BackgroundImage = slotColor ?? SpriteUtil.Spriter.View;
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Menu_Import_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!BoxView.GetBulkImportSettings(out var clearAll, out var overwrite, out var noSetb))
|
|
|
|
return;
|
2018-02-02 01:29:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int box = BoxView.Box.CurrentBox;
|
|
|
|
int ctr = SAV.LoadBoxes(Results, out var result, box, clearAll, overwrite, noSetb);
|
|
|
|
if (ctr <= 0)
|
|
|
|
return;
|
2018-02-02 01:29:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
BoxView.SetPKMBoxes();
|
|
|
|
BoxView.UpdateBoxViewers();
|
|
|
|
WinFormsUtil.Alert(result);
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Menu_Exit_Click(object sender, EventArgs e) => Close();
|
2018-09-27 01:56:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void OnMouseWheel(MouseEventArgs e)
|
|
|
|
{
|
|
|
|
if (!MysteryPokeGrid.RectangleToScreen(MysteryPokeGrid.ClientRectangle).Contains(MousePosition))
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ChangeFormatFilter(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (CB_FormatComparator.SelectedIndex == 0)
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_Format.Visible = false; // !any
|
|
|
|
CB_Format.SelectedIndex = 0;
|
2016-09-04 17:38:53 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2016-09-04 17:38:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
CB_Format.Visible = true;
|
|
|
|
int index = MAXFORMAT - SAV.Generation + 1;
|
|
|
|
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
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2021-02-07 16:32:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ShowHoverTextForSlot(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var pb = (PictureBox)sender;
|
|
|
|
int index = Array.IndexOf(PKXBOXES, pb);
|
|
|
|
if (!GetShiftedIndex(ref index))
|
|
|
|
return;
|
2021-02-07 16:32:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
ShowSet.Show(pb, Results[index]);
|
2016-09-04 17:38:53 +00:00
|
|
|
}
|
2022-09-17 09:00:06 +00:00
|
|
|
|
|
|
|
private void B_Add_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var s = UC_Builder.Create();
|
|
|
|
if (s.Length == 0)
|
|
|
|
{ WinFormsUtil.Alert(MsgBEPropertyInvalid); return; }
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
// If we already have text, add a new line (except if the last line is blank).
|
|
|
|
var tb = RTB_Instructions;
|
|
|
|
var batchText = tb.Text;
|
|
|
|
if (batchText.Length > 0 && !batchText.EndsWith('\n'))
|
|
|
|
tb.AppendText(Environment.NewLine);
|
2022-09-17 09:00:06 +00:00
|
|
|
RTB_Instructions.AppendText(s);
|
|
|
|
}
|
2016-09-04 17:38:53 +00:00
|
|
|
}
|