2014-07-22 05:47:18 +00:00
|
|
|
|
using System;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
using System.Collections;
|
2014-10-11 07:22:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2015-09-24 03:29:31 +00:00
|
|
|
|
using System.Drawing;
|
2015-09-21 03:34:09 +00:00
|
|
|
|
using System.IO;
|
2014-07-22 05:47:18 +00:00
|
|
|
|
using System.Linq;
|
2015-03-11 01:44:51 +00:00
|
|
|
|
using System.Reflection;
|
2014-07-22 05:47:18 +00:00
|
|
|
|
using System.Text;
|
2014-10-11 07:22:22 +00:00
|
|
|
|
using System.Windows.Forms;
|
2014-12-14 04:02:15 +00:00
|
|
|
|
|
2014-07-22 05:47:18 +00:00
|
|
|
|
namespace PKHeX
|
|
|
|
|
{
|
2014-10-11 07:22:22 +00:00
|
|
|
|
public partial class frmReport : Form
|
2014-07-22 05:47:18 +00:00
|
|
|
|
{
|
2015-09-24 03:29:31 +00:00
|
|
|
|
public class Preview
|
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
private readonly PKM pkm;
|
|
|
|
|
public string Position => pkm.Identifier;
|
|
|
|
|
public Image Sprite => pkm.Sprite;
|
|
|
|
|
public string Nickname => pkm.Nickname;
|
|
|
|
|
public string Species => Main.specieslist[pkm.Species];
|
|
|
|
|
public string Nature => Main.natures[pkm.Nature];
|
|
|
|
|
public string Gender => Main.gendersymbols[pkm.Gender];
|
|
|
|
|
public string ESV => pkm.PSV.ToString("0000");
|
|
|
|
|
public string HP_Type => Main.types[pkm.HPType+1];
|
|
|
|
|
public string Ability => Main.abilitylist[pkm.Ability];
|
|
|
|
|
public string Move1 => Main.movelist[pkm.Move1];
|
|
|
|
|
public string Move2 => Main.movelist[pkm.Move2];
|
|
|
|
|
public string Move3 => Main.movelist[pkm.Move3];
|
|
|
|
|
public string Move4 => Main.movelist[pkm.Move4];
|
|
|
|
|
public string HeldItem => Main.itemlist[pkm.HeldItem];
|
|
|
|
|
public string MetLoc => PKX.getLocation(pkm, egg: false);
|
|
|
|
|
public string EggLoc => PKX.getLocation(pkm, egg: true);
|
|
|
|
|
public string Ball => Main.balllist[pkm.Ball];
|
|
|
|
|
public string OT => pkm.OT_Name;
|
|
|
|
|
public string Version => Main.gamelist[pkm.Version];
|
|
|
|
|
public string OTLang => Main.gamelanguages[pkm.Language] ?? $"UNK {pkm.Language}";
|
2016-07-18 18:51:26 +00:00
|
|
|
|
public string CountryID => pkm.Format > 5 ? ((PK6) pkm).Country.ToString() : "N/A";
|
|
|
|
|
public string RegionID => pkm.Format > 5 ? ((PK6) pkm).Region.ToString() : "N/A";
|
|
|
|
|
public string DSRegionID => pkm.Format > 5 ? ((PK6) pkm).ConsoleRegion.ToString() : "N/A";
|
2015-09-24 03:29:31 +00:00
|
|
|
|
|
|
|
|
|
#region Extraneous
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public string EC => pkm.EncryptionConstant.ToString("X8");
|
|
|
|
|
public string PID => pkm.PID.ToString("X8");
|
|
|
|
|
public int HP_IV => pkm.IV_HP;
|
|
|
|
|
public int ATK_IV => pkm.IV_ATK;
|
|
|
|
|
public int DEF_IV => pkm.IV_DEF;
|
|
|
|
|
public int SPA_IV => pkm.IV_SPA;
|
|
|
|
|
public int SPD_IV => pkm.IV_SPD;
|
|
|
|
|
public int SPE_IV => pkm.IV_SPE;
|
|
|
|
|
public uint EXP => pkm.EXP;
|
|
|
|
|
public int Level => pkm.CurrentLevel;
|
|
|
|
|
public int HP_EV => pkm.EV_HP;
|
|
|
|
|
public int ATK_EV => pkm.EV_ATK;
|
|
|
|
|
public int DEF_EV => pkm.EV_DEF;
|
|
|
|
|
public int SPA_EV => pkm.EV_SPA;
|
|
|
|
|
public int SPD_EV => pkm.EV_SPD;
|
|
|
|
|
public int SPE_EV => pkm.EV_SPE;
|
|
|
|
|
public int Cool => pkm.CNT_Cool;
|
|
|
|
|
public int Beauty => pkm.CNT_Beauty;
|
|
|
|
|
public int Cute => pkm.CNT_Cute;
|
|
|
|
|
public int Smart => pkm.CNT_Smart;
|
|
|
|
|
public int Tough => pkm.CNT_Tough;
|
|
|
|
|
public int Sheen => pkm.CNT_Sheen;
|
|
|
|
|
public int Markings => pkm.MarkByte;
|
|
|
|
|
|
2016-07-18 18:51:26 +00:00
|
|
|
|
public string NotOT => pkm.Format > 5 ? ((PK6) pkm).HT_Name : "N/A";
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2016-07-18 18:51:26 +00:00
|
|
|
|
public int AbilityNum => pkm.Format > 5 ? ((PK6) pkm).AbilityNumber : -1;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public int GenderFlag => pkm.Gender;
|
|
|
|
|
public int AltForms => pkm.AltForm;
|
|
|
|
|
public int PKRS_Strain => pkm.PKRS_Strain;
|
|
|
|
|
public int PKRS_Days => pkm.PKRS_Days;
|
|
|
|
|
public int MetLevel => pkm.Met_Level;
|
|
|
|
|
public int OT_Gender => pkm.OT_Gender;
|
|
|
|
|
|
|
|
|
|
public bool FatefulFlag => pkm.FatefulEncounter;
|
|
|
|
|
public bool IsEgg => pkm.IsEgg;
|
|
|
|
|
public bool IsNicknamed => pkm.IsNicknamed;
|
|
|
|
|
public bool IsShiny => pkm.IsShiny;
|
|
|
|
|
|
|
|
|
|
public int TID => pkm.TID;
|
|
|
|
|
public int SID => pkm.SID;
|
|
|
|
|
public int TSV => pkm.TSV;
|
|
|
|
|
public int Move1_PP => pkm.Move1_PP;
|
|
|
|
|
public int Move2_PP => pkm.Move2_PP;
|
|
|
|
|
public int Move3_PP => pkm.Move3_PP;
|
|
|
|
|
public int Move4_PP => pkm.Move4_PP;
|
|
|
|
|
public int Move1_PPUp => pkm.Move1_PPUps;
|
|
|
|
|
public int Move2_PPUp => pkm.Move2_PPUps;
|
|
|
|
|
public int Move3_PPUp => pkm.Move3_PPUps;
|
|
|
|
|
public int Move4_PPUp => pkm.Move4_PPUps;
|
|
|
|
|
public string Relearn1 => Main.movelist[pkm.RelearnMove1];
|
|
|
|
|
public string Relearn2 => Main.movelist[pkm.RelearnMove2];
|
|
|
|
|
public string Relearn3 => Main.movelist[pkm.RelearnMove3];
|
|
|
|
|
public string Relearn4 => Main.movelist[pkm.RelearnMove4];
|
|
|
|
|
public ushort Checksum => pkm.Checksum;
|
|
|
|
|
public int mFriendship => pkm.OT_Friendship;
|
|
|
|
|
public int OT_Affection => pkm.OT_Affection;
|
|
|
|
|
public int Egg_Year => pkm.Egg_Year;
|
|
|
|
|
public int Egg_Month => pkm.Egg_Month;
|
|
|
|
|
public int Egg_Day => pkm.Egg_Day;
|
|
|
|
|
public int Met_Year => pkm.Met_Year;
|
|
|
|
|
public int Met_Month => pkm.Met_Month;
|
|
|
|
|
public int Met_Day => pkm.Met_Day;
|
|
|
|
|
public int Encounter => pkm.EncounterType;
|
2015-09-24 03:29:31 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public Preview(PKM p) { pkm = p; }
|
2015-09-24 03:29:31 +00:00
|
|
|
|
}
|
2014-10-11 07:22:22 +00:00
|
|
|
|
public frmReport()
|
2014-07-22 05:47:18 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-07-24 16:20:08 +00:00
|
|
|
|
dgData.DoubleBuffered(true);
|
2016-04-15 23:11:46 +00:00
|
|
|
|
CenterToParent();
|
2014-07-22 05:47:18 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public void PopulateData(SaveFile SAV)
|
2014-07-22 05:47:18 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
PopulateData(SAV.BoxData);
|
2014-07-22 05:47:18 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public void PopulateData(PKM[] Data)
|
2015-10-11 01:29:02 +00:00
|
|
|
|
{
|
|
|
|
|
BoxBar.Step = 1;
|
|
|
|
|
PokemonList PL = new PokemonList();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
foreach (PKM pkm in Data.Where(pkm => pkm.ChecksumValid && pkm.Species != 0))
|
|
|
|
|
{
|
|
|
|
|
pkm.Stat_Level = PKX.getLevel(pkm.Species, pkm.EXP); // recalc Level
|
|
|
|
|
PL.Add(new Preview(pkm));
|
|
|
|
|
BoxBar.PerformStep();
|
|
|
|
|
}
|
2015-10-11 01:29:02 +00:00
|
|
|
|
|
|
|
|
|
dgData.DataSource = PL;
|
|
|
|
|
dgData.AutoGenerateColumns = true;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
BoxBar.Maximum = Data.Length + dgData.Columns.Count;
|
2015-10-11 01:29:02 +00:00
|
|
|
|
for (int i = 0; i < dgData.Columns.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
BoxBar.PerformStep();
|
|
|
|
|
if (dgData.Columns[i] is DataGridViewImageColumn) continue; // Don't add sorting for Sprites
|
|
|
|
|
dgData.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
|
|
|
|
|
}
|
|
|
|
|
BoxBar.Visible = false;
|
|
|
|
|
}
|
2014-12-14 04:02:15 +00:00
|
|
|
|
private void promptSaveCSV(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Util.Prompt(MessageBoxButtons.YesNo,"Save all the data to CSV?") == DialogResult.Yes)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
SaveFileDialog savecsv = new SaveFileDialog
|
|
|
|
|
{
|
|
|
|
|
Filter = "Spreadsheet|*.csv",
|
|
|
|
|
FileName = "Box Data Dump.csv"
|
|
|
|
|
};
|
2014-12-14 04:02:15 +00:00
|
|
|
|
if (savecsv.ShowDialog() == DialogResult.OK)
|
|
|
|
|
Export_CSV(savecsv.FileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void Export_CSV(string path)
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
var headers = dgData.Columns.Cast<DataGridViewColumn>();
|
|
|
|
|
sb.AppendLine(string.Join(",", headers.Select(column => "\"" + column.HeaderText + "\"").ToArray()));
|
|
|
|
|
|
|
|
|
|
foreach (DataGridViewRow row in dgData.Rows)
|
|
|
|
|
{
|
|
|
|
|
var cells = row.Cells.Cast<DataGridViewCell>();
|
|
|
|
|
sb.AppendLine(string.Join(",", cells.Select(cell => "\"" + cell.Value + "\"").ToArray()));
|
|
|
|
|
}
|
2015-09-21 03:34:09 +00:00
|
|
|
|
File.WriteAllText(path, sb.ToString(), Encoding.UTF8);
|
2014-12-14 04:02:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 03:29:31 +00:00
|
|
|
|
public class PokemonList : SortableBindingList<Preview> { }
|
2014-07-22 05:47:18 +00:00
|
|
|
|
}
|
2014-07-24 16:20:08 +00:00
|
|
|
|
public static class ExtensionMethods // Speed up scrolling
|
|
|
|
|
{
|
|
|
|
|
public static void DoubleBuffered(this DataGridView dgv, bool setting)
|
|
|
|
|
{
|
|
|
|
|
Type dgvType = dgv.GetType();
|
|
|
|
|
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
|
pi.SetValue(dgv, setting, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-14 03:32:51 +00:00
|
|
|
|
public class SortableBindingList<T> : BindingList<T>
|
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<Type, PropertyComparer<T>> comparers;
|
|
|
|
|
private bool isSorted;
|
|
|
|
|
private ListSortDirection listSortDirection;
|
|
|
|
|
private PropertyDescriptor propertyDescriptor;
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
protected SortableBindingList() : base(new List<T>())
|
2014-12-14 03:32:51 +00:00
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
comparers = new Dictionary<Type, PropertyComparer<T>>();
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override bool SupportsSortingCore => true;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override bool IsSortedCore => isSorted;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override PropertyDescriptor SortPropertyCore => propertyDescriptor;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override ListSortDirection SortDirectionCore => listSortDirection;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override bool SupportsSearchingCore => true;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
|
|
|
|
protected override void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
List<T> itemsList = (List<T>)Items;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
|
|
|
|
Type propertyType = property.PropertyType;
|
|
|
|
|
PropertyComparer<T> comparer;
|
2015-03-11 01:44:51 +00:00
|
|
|
|
if (!comparers.TryGetValue(propertyType, out comparer))
|
2014-12-14 03:32:51 +00:00
|
|
|
|
{
|
|
|
|
|
comparer = new PropertyComparer<T>(property, direction);
|
2015-03-11 01:44:51 +00:00
|
|
|
|
comparers.Add(propertyType, comparer);
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comparer.SetPropertyAndDirection(property, direction);
|
|
|
|
|
itemsList.Sort(comparer);
|
|
|
|
|
|
2015-03-11 01:44:51 +00:00
|
|
|
|
propertyDescriptor = property;
|
|
|
|
|
listSortDirection = direction;
|
|
|
|
|
isSorted = true;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2015-03-11 01:44:51 +00:00
|
|
|
|
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void RemoveSortCore()
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
isSorted = false;
|
|
|
|
|
propertyDescriptor = base.SortPropertyCore;
|
|
|
|
|
listSortDirection = base.SortDirectionCore;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2015-03-11 01:44:51 +00:00
|
|
|
|
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override int FindCore(PropertyDescriptor property, object key)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
int count = Count;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
for (int i = 0; i < count; ++i)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (property.GetValue(this[i]).Equals(key))
|
2014-12-14 03:32:51 +00:00
|
|
|
|
return i;
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class PropertyComparer<T> : IComparer<T>
|
|
|
|
|
{
|
|
|
|
|
private readonly IComparer comparer;
|
|
|
|
|
private PropertyDescriptor propertyDescriptor;
|
|
|
|
|
private int reverse;
|
|
|
|
|
|
|
|
|
|
public PropertyComparer(PropertyDescriptor property, ListSortDirection direction)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
propertyDescriptor = property;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
Type comparerForPropertyType = typeof(Comparer<>).MakeGenericType(property.PropertyType);
|
2015-03-11 01:44:51 +00:00
|
|
|
|
comparer = (IComparer)comparerForPropertyType.InvokeMember("Default", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public, null, null, null);
|
|
|
|
|
SetListSortDirection(direction);
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IComparer<T> Members
|
|
|
|
|
|
|
|
|
|
public int Compare(T x, T y)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
return reverse * comparer.Compare(propertyDescriptor.GetValue(x), propertyDescriptor.GetValue(y));
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void SetPropertyDescriptor(PropertyDescriptor descriptor)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
propertyDescriptor = descriptor;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetListSortDirection(ListSortDirection direction)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
reverse = direction == ListSortDirection.Ascending ? 1 : -1;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPropertyAndDirection(PropertyDescriptor descriptor, ListSortDirection direction)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
SetPropertyDescriptor(descriptor);
|
|
|
|
|
SetListSortDirection(direction);
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-11 07:22:22 +00:00
|
|
|
|
}
|