From ae3aa6272b652256df442e74eaa2fcb6b56b30e1 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 29 Nov 2016 22:49:27 -0800 Subject: [PATCH] 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) --- .../Save Editors/SAV_Inventory.Designer.cs | 10 +-- PKHeX/Subforms/Save Editors/SAV_Inventory.cs | 85 +++++++++++++++---- .../Subforms/Save Editors/SAV_Inventory.resx | 2 +- 3 files changed, 76 insertions(+), 21 deletions(-) diff --git a/PKHeX/Subforms/Save Editors/SAV_Inventory.Designer.cs b/PKHeX/Subforms/Save Editors/SAV_Inventory.Designer.cs index ccf9b3bc1..e9a7e64fe 100644 --- a/PKHeX/Subforms/Save Editors/SAV_Inventory.Designer.cs +++ b/PKHeX/Subforms/Save Editors/SAV_Inventory.Designer.cs @@ -54,7 +54,7 @@ private void InitializeComponent() // 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 @@ private void InitializeComponent() // 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 @@ private void InitializeComponent() 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 @@ private void InitializeComponent() // 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 @@ private void InitializeComponent() 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"; diff --git a/PKHeX/Subforms/Save Editors/SAV_Inventory.cs b/PKHeX/Subforms/Save Editors/SAV_Inventory.cs index c9d5811a5..4d5272cf2 100644 --- a/PKHeX/Subforms/Save Editors/SAV_Inventory.cs +++ b/PKHeX/Subforms/Save Editors/SAV_Inventory.cs @@ -18,6 +18,9 @@ public SAV_Inventory() 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 @@ public SAV_Inventory() 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 @@ private DataGridView getDGV(InventoryPouch pouch) AllowUserToResizeRows = false, AllowUserToResizeColumns = false, RowHeadersVisible = false, - ColumnHeadersVisible = false, + //ColumnHeadersVisible = false, MultiSelect = false, ShowEditingIcon = false, @@ -83,23 +88,48 @@ private DataGridView getDGV(InventoryPouch pouch) 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 @@ private void getBag(DataGridView dgv, InventoryPouch pouch) { 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 @@ private void setBag(DataGridView dgv, InventoryPouch pouch) 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 @@ private void setBag(DataGridView dgv, InventoryPouch pouch) 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 @@ private void giveAllItems(object sender, EventArgs e) 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 @@ private void giveAllItems(object sender, EventArgs e) } } - 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 @@ private void removeAllItems(object sender, EventArgs e) 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."); } diff --git a/PKHeX/Subforms/Save Editors/SAV_Inventory.resx b/PKHeX/Subforms/Save Editors/SAV_Inventory.resx index f863519a2..27866f6e8 100644 --- a/PKHeX/Subforms/Save Editors/SAV_Inventory.resx +++ b/PKHeX/Subforms/Save Editors/SAV_Inventory.resx @@ -125,7 +125,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAB0 - EwAAAk1TRnQBSQFMAgEBCwEAASgBAAEoAQABGAEAARgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + EwAAAk1TRnQBSQFMAgEBCwEAATABAAEwAQABGAEAARgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABYAMAAUgDAAEBAQABCAYAARsYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA