From adda0af96e8e0b97f49d8300a3de601fffd51686 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 14 Feb 2022 21:46:22 -0800 Subject: [PATCH] Rework apricorn/bean editors to be text entry Combobox for count is an antipattern, just parse like all the other quantity datagrids --- .../Save Editors/Gen4/SAV_Apricorn.cs | 37 +++++++++---------- .../Gen7/SAV_Pokebean.Designer.cs | 1 - .../Save Editors/Gen7/SAV_Pokebean.cs | 21 ++++------- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Apricorn.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Apricorn.cs index b39ab3b06..5a2f9fa74 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Apricorn.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Apricorn.cs @@ -33,31 +33,24 @@ namespace PKHeX.WinForms dgvApricorn.ReadOnly = true; dgvApricorn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; } - DataGridViewComboBoxColumn dgvCount = new() + DataGridViewTextBoxColumn dgvCount = new() { - DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing, - DisplayIndex = 0, - Width = 135, - FlatStyle = FlatStyle.Flat, - ValueType = typeof(int), + DisplayIndex = 1, + Width = 45, }; - { - for (var i = 0; i <= 99; i++) - dgvCount.Items.Add(i); - - dgvCount.DisplayIndex = 1; - dgvCount.Width = 45; - dgvCount.FlatStyle = FlatStyle.Flat; - } dgv.Columns.Add(dgvApricorn); dgv.Columns.Add(dgvCount); dgv.Rows.Add(Count); for (int i = 0; i < Count; i++) - { dgv.Rows[i].Cells[0].Value = itemlist[i]; - dgv.Rows[i].Cells[1].Value = SAV.GetApricornCount(i); - } + LoadCount(); + } + + private void LoadCount() + { + for (int i = 0; i < Count; i++) + dgv.Rows[i].Cells[1].Value = SAV.GetApricornCount(i).ToString(); } private void B_Cancel_Click(object sender, EventArgs e) @@ -69,20 +62,24 @@ namespace PKHeX.WinForms { for (int i = 0; i < Count; i++) SAV.SetApricornCount(i, 99); - Setup(); + LoadCount(); } private void B_None_Click(object sender, EventArgs e) { for (int i = 0; i < Count; i++) SAV.SetApricornCount(i, 0); - Setup(); + LoadCount(); } private void B_Save_Click(object sender, EventArgs e) { for (int i = 0; i < Count; i++) - SAV.SetApricornCount(i, (int)dgv.Rows[i].Cells[1].Value); + { + var cells = dgv.Rows[i].Cells; + var count = int.TryParse(cells[1].Value?.ToString() ?? "0", out var val) ? val : 0; + SAV.SetApricornCount(i, Math.Min(byte.MaxValue, count)); + } Origin.CopyChangesFrom(SAV); Close(); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.Designer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.Designer.cs index 33ef2f643..a3b4ebfd1 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.Designer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.Designer.cs @@ -57,7 +57,6 @@ this.dgv.ShowEditingIcon = false; this.dgv.Size = new System.Drawing.Size(200, 186); this.dgv.TabIndex = 11; - this.dgv.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(SAV_Pokebean.DropClick); // // B_Save // diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.cs index e5cf30d6d..3936691c5 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.cs @@ -31,7 +31,7 @@ namespace PKHeX.WinForms for (int i = 0; i < beans.Length; i++) { dgv.Rows[i].Cells[0].Value = BeanPouch.BeanIndexNames[i]; - dgv.Rows[i].Cells[1].Value = beans[i]; + dgv.Rows[i].Cells[1].Value = beans[i].ToString(); } } @@ -45,27 +45,16 @@ namespace PKHeX.WinForms ReadOnly = true, DefaultCellStyle = {Alignment = DataGridViewContentAlignment.MiddleCenter}, }; - var dgvCount = new DataGridViewComboBoxColumn + var dgvCount = new DataGridViewTextBoxColumn { - DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing, - FlatStyle = FlatStyle.Flat, - ValueType = typeof(int), DisplayIndex = 1, Width = 45, }; - for (var i = 0; i < 256; i++) - dgvCount.Items.Add(i); dgv.Columns.Add(dgvBean); dgv.Columns.Add(dgvCount); } - private static void DropClick(object sender, DataGridViewCellEventArgs e) - { - if (e.ColumnIndex != 1) return; - ((ComboBox)((DataGridView) sender).EditingControl).DroppedDown = true; - } - private void B_Cancel_Click(object sender, EventArgs e) { Close(); @@ -89,7 +78,11 @@ namespace PKHeX.WinForms { var beans = Pouch.Beans; for (int i = 0; i < beans.Length; i++) - beans[i] = (byte)dgv.Rows[i].Cells[1].Value; + { + var cells = dgv.Rows[i].Cells; + var count = int.TryParse(cells[1].Value?.ToString() ?? "0", out var val) ? val : 0; + beans[i] = (byte)Math.Min(byte.MaxValue, count); + } Origin.CopyChangesFrom(SAV); Close(); }