Add FreeSpace/NEW checkmarks to Inv edit

Closes #454 -- tracks Free Space when modifying
Closes #509 -- fills out grid view, no need to add item sprites (color
clutter)
This commit is contained in:
Kurt 2016-11-29 22:49:27 -08:00
parent 47b4d6edd0
commit ae3aa6272b
3 changed files with 76 additions and 21 deletions

View file

@ -54,7 +54,7 @@
// B_Cancel
//
this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Cancel.Location = new System.Drawing.Point(202, 378);
this.B_Cancel.Location = new System.Drawing.Point(232, 378);
this.B_Cancel.Name = "B_Cancel";
this.B_Cancel.Size = new System.Drawing.Size(70, 23);
this.B_Cancel.TabIndex = 14;
@ -65,7 +65,7 @@
// B_Save
//
this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Save.Location = new System.Drawing.Point(202, 354);
this.B_Save.Location = new System.Drawing.Point(232, 354);
this.B_Save.Name = "B_Save";
this.B_Save.Size = new System.Drawing.Size(70, 23);
this.B_Save.TabIndex = 15;
@ -82,7 +82,7 @@
this.tabControl1.Location = new System.Drawing.Point(12, 12);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(261, 336);
this.tabControl1.Size = new System.Drawing.Size(291, 336);
this.tabControl1.TabIndex = 17;
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.switchBag);
//
@ -215,7 +215,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 411);
this.ClientSize = new System.Drawing.Size(314, 411);
this.Controls.Add(this.NUD_Count);
this.Controls.Add(this.L_Count);
this.Controls.Add(this.B_Sort);
@ -226,7 +226,7 @@
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(300, 450);
this.MinimumSize = new System.Drawing.Size(330, 450);
this.Name = "SAV_Inventory";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Inventory Editor";

View file

@ -18,6 +18,9 @@ namespace PKHeX
for (int i = 0; i < itemlist.Length; i++)
if (itemlist[i] == "")
itemlist[i] = $"(Item #{i.ToString("000")})";
HasFreeSpace = SAV.Generation == 7;
HasNew = SAV.Generation == 7;
Pouches = SAV.Inventory;
initBags();
getBags();
@ -28,6 +31,8 @@ namespace PKHeX
private readonly InventoryPouch[] Pouches;
private const string TabPrefix = "TAB_";
private const string DGVPrefix = "DGV_";
private readonly bool HasFreeSpace;
private readonly bool HasNew;
private void B_Cancel_Click(object sender, EventArgs e)
{
@ -72,7 +77,7 @@ namespace PKHeX
AllowUserToResizeRows = false,
AllowUserToResizeColumns = false,
RowHeadersVisible = false,
ColumnHeadersVisible = false,
//ColumnHeadersVisible = false,
MultiSelect = false,
ShowEditingIcon = false,
@ -83,23 +88,48 @@ namespace PKHeX
CellBorderStyle = DataGridViewCellBorderStyle.None,
};
int c = 0;
DataGridViewComboBoxColumn dgvItemVal = new DataGridViewComboBoxColumn
{
HeaderText = "Item",
DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
DisplayIndex = 0,
DisplayIndex = c++,
Width = 135,
FlatStyle = FlatStyle.Flat
};
DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn();
{
dgvIndex.HeaderText = "CNT";
dgvIndex.DisplayIndex = 1;
dgvIndex.HeaderText = "Count";
dgvIndex.DisplayIndex = c++;
dgvIndex.Width = 45;
dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
}
dgv.Columns.Add(dgvItemVal);
dgv.Columns.Add(dgvIndex);
if (HasFreeSpace)
{
DataGridViewCheckBoxColumn dgvFree = new DataGridViewCheckBoxColumn
{
HeaderText = "Free",
DisplayIndex = c++,
Width = 40,
FlatStyle = FlatStyle.Flat
};
dgv.Columns.Add(dgvFree);
}
if (HasFreeSpace)
{
DataGridViewCheckBoxColumn dgvNew = new DataGridViewCheckBoxColumn
{
HeaderText = "NEW",
DisplayIndex = c++,
Width = 40,
FlatStyle = FlatStyle.Flat
};
dgv.Columns.Add(dgvNew);
}
var itemcount = pouch.Items.Length;
string[] itemarr = Main.HaX ? (string[])itemlist.Clone() : getItems(pouch.LegalItems);
@ -150,8 +180,13 @@ namespace PKHeX
{
for (int i = 0; i < dgv.Rows.Count; i++)
{
dgv.Rows[i].Cells[0].Value = itemlist[pouch.Items[i].Index];
dgv.Rows[i].Cells[1].Value = pouch.Items[i].Count;
int c = 0;
dgv.Rows[i].Cells[c++].Value = itemlist[pouch.Items[i].Index];
dgv.Rows[i].Cells[c++].Value = pouch.Items[i].Count;
if (HasFreeSpace)
dgv.Rows[i].Cells[c++].Value = pouch.Items[i].FreeSpace;
if (HasNew)
dgv.Rows[i].Cells[c].Value = pouch.Items[i].New;
}
}
private void setBag(DataGridView dgv, InventoryPouch pouch)
@ -159,13 +194,14 @@ namespace PKHeX
int ctr = 0;
for (int i = 0; i < dgv.Rows.Count; i++)
{
string item = dgv.Rows[i].Cells[0].Value.ToString();
int c = 0;
string item = dgv.Rows[i].Cells[c++].Value.ToString();
int itemindex = Array.IndexOf(itemlist, item);
if (itemindex <= 0) // Compression of Empty Slots
continue;
int itemcnt;
int.TryParse(dgv.Rows[i].Cells[1].Value.ToString(), out itemcnt);
int.TryParse(dgv.Rows[i].Cells[c++].Value.ToString(), out itemcnt);
if (Main.HaX && SAV.Generation != 7) // Gen7 has true cap at 1023, keep 999 cap.
{
@ -180,7 +216,12 @@ namespace PKHeX
else if (itemcnt <= 0)
continue; // ignore item
pouch.Items[ctr++] = new InventoryItem { Index = itemindex, Count = itemcnt };
pouch.Items[ctr] = new InventoryItem { Index = itemindex, Count = itemcnt };
if (HasFreeSpace)
pouch.Items[ctr].FreeSpace = (bool)dgv.Rows[i].Cells[c++].Value;
if (HasNew)
pouch.Items[ctr].New = (bool)dgv.Rows[i].Cells[c].Value;
ctr++;
}
for (int i = ctr; i < pouch.Items.Length; i++)
pouch.Items[i] = new InventoryItem(); // Empty Slots at the end
@ -232,9 +273,11 @@ namespace PKHeX
int pouch = CurrentPouch;
if (pouch < 0)
return;
ushort[] legalitems = Pouches[pouch].LegalItems;
var p = Pouches[pouch];
ushort[] legalitems = p.LegalItems;
DataGridView dgv = Controls.Find(DGVPrefix + Pouches[pouch].Type, true).FirstOrDefault() as DataGridView;
DataGridView dgv = Controls.Find(DGVPrefix + p.Type, true).FirstOrDefault() as DataGridView;
setBag(dgv, p);
int Count = (int)NUD_Count.Value;
for (int i = 0; i < legalitems.Length; i++)
@ -258,8 +301,15 @@ namespace PKHeX
}
}
dgv.Rows[i].Cells[0].Value = itemname;
dgv.Rows[i].Cells[1].Value = c;
int l = 0;
dgv.Rows[i].Cells[l++].Value = itemname;
dgv.Rows[i].Cells[l++].Value = c;
var t = p.Items.FirstOrDefault(m => m.Index == item);
if (HasFreeSpace)
dgv.Rows[i].Cells[l++].Value = t?.FreeSpace ?? false;
if (HasNew)
dgv.Rows[i].Cells[l].Value = t?.New ?? false;
}
System.Media.SystemSounds.Asterisk.Play();
}
@ -274,8 +324,13 @@ namespace PKHeX
for (int i = 0; i < dgv.RowCount; i++)
{
dgv.Rows[i].Cells[0].Value = itemlist[0];
dgv.Rows[i].Cells[1].Value = 0;
int c = 0;
dgv.Rows[i].Cells[c++].Value = itemlist[0];
dgv.Rows[i].Cells[c++].Value = 0;
if (HasFreeSpace)
dgv.Rows[i].Cells[c++].Value = false;
if (HasNew)
dgv.Rows[i].Cells[c].Value = false;
}
Util.Alert("Items cleared.");
}

View file

@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAB0
EwAAAk1TRnQBSQFMAgEBCwEAASgBAAEoAQABGAEAARgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
EwAAAk1TRnQBSQFMAgEBCwEAATABAAEwAQABGAEAARgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABYAMAAUgDAAEBAQABCAYAARsYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA