2014-07-22 05:47:18 +00:00
|
|
|
|
using System;
|
2014-10-11 07:22:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
2015-09-21 03:34:09 +00:00
|
|
|
|
using System.IO;
|
2014-07-22 05:47:18 +00:00
|
|
|
|
using System.Linq;
|
2021-01-17 01:25:55 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2014-10-11 07:22:22 +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;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
2014-12-14 04:02:15 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2014-07-22 05:47:18 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public partial class ReportGrid : Form
|
2014-07-22 05:47:18 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public ReportGrid()
|
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();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
GetContextMenu();
|
2016-12-28 19:31:32 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void GetContextMenu()
|
2016-12-28 19:31:32 +00:00
|
|
|
|
{
|
2021-08-20 20:49:20 +00:00
|
|
|
|
var mnuHide = new ToolStripMenuItem { Name = "mnuHide", Text = MsgReportColumnHide };
|
2016-12-28 19:31:32 +00:00
|
|
|
|
mnuHide.Click += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
int c = dgData.SelectedCells.Count;
|
|
|
|
|
if (c == 0)
|
2018-04-07 04:23:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert(MsgReportColumnHideFail); return; }
|
2016-12-28 19:31:32 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < c; i++)
|
|
|
|
|
dgData.Columns[dgData.SelectedCells[i].ColumnIndex].Visible = false;
|
|
|
|
|
};
|
2021-08-20 20:49:20 +00:00
|
|
|
|
var mnuRestore = new ToolStripMenuItem { Name = "mnuRestore", Text = MsgReportColumnRestore };
|
2016-12-28 19:31:32 +00:00
|
|
|
|
mnuRestore.Click += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
int c = dgData.ColumnCount;
|
|
|
|
|
for (int i = 0; i < c; i++)
|
|
|
|
|
dgData.Columns[i].Visible = true;
|
|
|
|
|
|
2018-04-07 04:23:09 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgReportColumnRestoreSuccess);
|
2016-12-28 19:31:32 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
ContextMenuStrip mnu = new();
|
2016-12-28 19:31:32 +00:00
|
|
|
|
mnu.Items.Add(mnuHide);
|
|
|
|
|
mnu.Items.Add(mnuRestore);
|
|
|
|
|
|
|
|
|
|
dgData.ContextMenuStrip = mnu;
|
2014-07-22 05:47:18 +00:00
|
|
|
|
}
|
2018-07-15 18:12:02 +00:00
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private sealed class PokemonList<T> : SortableBindingList<T> where T : class { }
|
2018-07-15 18:12:02 +00:00
|
|
|
|
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
public void PopulateData(IList<SlotCache> Data)
|
2015-10-11 01:29:02 +00:00
|
|
|
|
{
|
2016-07-24 08:31:02 +00:00
|
|
|
|
SuspendLayout();
|
2021-06-08 03:02:57 +00:00
|
|
|
|
var PL = new PokemonList<EntitySummaryImage>();
|
2018-08-04 17:06:06 +00:00
|
|
|
|
var strings = GameInfo.Strings;
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
foreach (var entry in Data)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
var pkm = entry.Entity;
|
2021-08-06 01:54:47 +00:00
|
|
|
|
if ((uint)(pkm.Species - 1) >= pkm.MaxSpeciesID)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
pkm.Stat_Level = pkm.CurrentLevel; // recalc Level
|
|
|
|
|
PL.Add(new EntitySummaryImage(pkm, strings, entry.Identify()));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2015-10-11 01:29:02 +00:00
|
|
|
|
|
|
|
|
|
dgData.DataSource = PL;
|
|
|
|
|
dgData.AutoGenerateColumns = true;
|
|
|
|
|
for (int i = 0; i < dgData.Columns.Count; i++)
|
|
|
|
|
{
|
2021-08-06 01:54:47 +00:00
|
|
|
|
var col = dgData.Columns[i];
|
|
|
|
|
if (col is DataGridViewImageColumn)
|
|
|
|
|
continue; // Don't add sorting for Sprites
|
|
|
|
|
col.SortMode = DataGridViewColumnSortMode.Automatic;
|
2015-10-11 01:29:02 +00:00
|
|
|
|
}
|
2016-12-28 19:31:32 +00:00
|
|
|
|
|
|
|
|
|
// Trigger Resizing
|
|
|
|
|
dgData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
|
|
|
|
for (int i = 0; i < dgData.Columns.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
int w = dgData.Columns[i].Width;
|
|
|
|
|
dgData.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
|
|
|
|
|
dgData.Columns[i].Width = w;
|
|
|
|
|
}
|
|
|
|
|
dgData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
|
2020-10-18 18:02:39 +00:00
|
|
|
|
Data_Sorted(this, EventArgs.Empty); // trigger row resizing
|
2016-12-28 19:31:32 +00:00
|
|
|
|
|
2016-07-24 08:31:02 +00:00
|
|
|
|
ResumeLayout();
|
2015-10-11 01:29:02 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void Data_Sorted(object sender, EventArgs e)
|
2016-12-28 19:31:32 +00:00
|
|
|
|
{
|
2021-08-06 01:54:47 +00:00
|
|
|
|
int height = SpriteUtil.Spriter.Height + 1; // max height of a row, +1px
|
2016-12-28 19:31:32 +00:00
|
|
|
|
for (int i = 0; i < dgData.Rows.Count; i++)
|
|
|
|
|
dgData.Rows[i].Height = height;
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2021-10-26 03:00:47 +00:00
|
|
|
|
private void PromptSaveCSV(object sender, FormClosingEventArgs e)
|
2014-12-14 04:02:15 +00:00
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
|
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgReportExportCSV) != DialogResult.Yes)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return;
|
2019-10-26 19:33:58 +00:00
|
|
|
|
using var savecsv = new SaveFileDialog
|
2014-12-14 04:02:15 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Filter = "Spreadsheet|*.csv",
|
2021-08-20 20:49:20 +00:00
|
|
|
|
FileName = "Box Data Dump.csv",
|
2017-06-18 01:37:19 +00:00
|
|
|
|
};
|
|
|
|
|
if (savecsv.ShowDialog() == DialogResult.OK)
|
2021-10-26 03:00:47 +00:00
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
var path = savecsv.FileName;
|
|
|
|
|
var t = Task.Run(() => Export_CSV(path));
|
|
|
|
|
t.Wait(); // don't start disposing until the saving is complete
|
|
|
|
|
}
|
2014-12-14 04:02:15 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2021-01-17 01:25:55 +00:00
|
|
|
|
private async Task Export_CSV(string path)
|
2014-12-14 04:02:15 +00:00
|
|
|
|
{
|
2021-01-17 01:25:55 +00:00
|
|
|
|
using var fs = new FileStream(path, FileMode.Create);
|
|
|
|
|
using var s = new StreamWriter(fs);
|
2014-12-14 04:02:15 +00:00
|
|
|
|
|
|
|
|
|
var headers = dgData.Columns.Cast<DataGridViewColumn>();
|
2021-01-17 01:25:55 +00:00
|
|
|
|
await s.WriteLineAsync(string.Join(",", headers.Skip(1).Select(column => $"\"{column.HeaderText}\""))).ConfigureAwait(false);
|
2016-07-24 08:31:02 +00:00
|
|
|
|
|
|
|
|
|
foreach (var cells in from DataGridViewRow row in dgData.Rows select row.Cells.Cast<DataGridViewCell>())
|
2021-01-17 01:25:55 +00:00
|
|
|
|
await s.WriteLineAsync(string.Join(",", cells.Skip(1).Select(cell => $"\"{cell.Value}\""))).ConfigureAwait(false);
|
2014-12-14 04:02:15 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-12-08 01:48:45 +00:00
|
|
|
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
|
|
|
|
{
|
|
|
|
|
bool cp = keyData == (Keys.Control | Keys.C) && ActiveControl is DataGridView;
|
|
|
|
|
if (!cp)
|
|
|
|
|
return base.ProcessCmdKey(ref msg, keyData);
|
|
|
|
|
|
2021-05-29 22:31:47 +00:00
|
|
|
|
var content = dgData.GetClipboardContent();
|
|
|
|
|
if (content == null)
|
|
|
|
|
return base.ProcessCmdKey(ref msg, keyData);
|
|
|
|
|
|
|
|
|
|
string data = content.GetText();
|
2018-04-07 04:23:09 +00:00
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgReportExportTable);
|
2016-12-08 01:48:45 +00:00
|
|
|
|
if (dr != DialogResult.Yes)
|
|
|
|
|
{
|
2019-11-23 05:23:00 +00:00
|
|
|
|
WinFormsUtil.SetClipboardText(data);
|
2016-12-08 01:48:45 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reformat datagrid clipboard content
|
|
|
|
|
string[] lines = data.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
2018-07-15 18:12:02 +00:00
|
|
|
|
string[] newlines = ConvertTabbedToRedditTable(lines);
|
2019-11-23 05:23:00 +00:00
|
|
|
|
WinFormsUtil.SetClipboardText(string.Join(Environment.NewLine, newlines));
|
2018-07-15 18:12:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-12-08 01:48:45 +00:00
|
|
|
|
|
2018-07-15 18:12:02 +00:00
|
|
|
|
private static string[] ConvertTabbedToRedditTable(string[] lines)
|
|
|
|
|
{
|
2016-12-08 01:48:45 +00:00
|
|
|
|
string[] newlines = new string[lines.Length + 1];
|
2018-07-15 18:12:02 +00:00
|
|
|
|
int tabcount = lines[0].Count(c => c == '\t');
|
|
|
|
|
|
2016-12-08 01:48:45 +00:00
|
|
|
|
newlines[0] = lines[0].Replace('\t', '|');
|
2020-07-19 22:48:45 +00:00
|
|
|
|
newlines[1] = string.Join(":--:", Enumerable.Repeat('|', tabcount + 2)); // 2 pipes for each end
|
2016-12-08 01:48:45 +00:00
|
|
|
|
for (int i = 1; i < lines.Length; i++)
|
|
|
|
|
newlines[i + 1] = lines[i].Replace('\t', '|');
|
2018-07-15 18:12:02 +00:00
|
|
|
|
return newlines;
|
2016-12-08 01:48:45 +00:00
|
|
|
|
}
|
2014-07-22 05:47:18 +00:00
|
|
|
|
}
|
2016-11-14 15:08:54 +00:00
|
|
|
|
}
|