mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-06-02 23:34:13 -05:00
Add property type indication
Simplify so that only a list of types is specified on one line, no other type specific handling required when adding a new type. Closes #592
This commit is contained in:
parent
068da5ef9c
commit
863dc58ec3
26
PKHeX/Subforms/PKM Editors/BatchEditor.Designer.cs
generated
26
PKHeX/Subforms/PKM Editors/BatchEditor.Designer.cs
generated
|
|
@ -40,6 +40,7 @@ private void InitializeComponent()
|
|||
this.CB_Property = new System.Windows.Forms.ComboBox();
|
||||
this.CB_Require = new System.Windows.Forms.ComboBox();
|
||||
this.B_Add = new System.Windows.Forms.Button();
|
||||
this.L_PropType = new System.Windows.Forms.Label();
|
||||
this.FLP_RB.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
|
|
@ -102,9 +103,9 @@ private void InitializeComponent()
|
|||
this.RTB_Instructions.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.RTB_Instructions.Location = new System.Drawing.Point(12, 68);
|
||||
this.RTB_Instructions.Location = new System.Drawing.Point(12, 84);
|
||||
this.RTB_Instructions.Name = "RTB_Instructions";
|
||||
this.RTB_Instructions.Size = new System.Drawing.Size(370, 157);
|
||||
this.RTB_Instructions.Size = new System.Drawing.Size(370, 141);
|
||||
this.RTB_Instructions.TabIndex = 5;
|
||||
this.RTB_Instructions.Text = "";
|
||||
//
|
||||
|
|
@ -132,14 +133,6 @@ private void InitializeComponent()
|
|||
//
|
||||
this.CB_Format.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.CB_Format.FormattingEnabled = true;
|
||||
this.CB_Format.Items.AddRange(new object[] {
|
||||
"All",
|
||||
"pk7",
|
||||
"pk6",
|
||||
"pk5",
|
||||
"pk4",
|
||||
"pk3",
|
||||
"Any"});
|
||||
this.CB_Format.Location = new System.Drawing.Point(11, 40);
|
||||
this.CB_Format.Name = "CB_Format";
|
||||
this.CB_Format.Size = new System.Drawing.Size(44, 21);
|
||||
|
|
@ -158,6 +151,7 @@ private void InitializeComponent()
|
|||
this.CB_Property.Name = "CB_Property";
|
||||
this.CB_Property.Size = new System.Drawing.Size(140, 21);
|
||||
this.CB_Property.TabIndex = 9;
|
||||
this.CB_Property.SelectedIndexChanged += new System.EventHandler(this.CB_Property_SelectedIndexChanged);
|
||||
//
|
||||
// CB_Require
|
||||
//
|
||||
|
|
@ -184,12 +178,22 @@ private void InitializeComponent()
|
|||
this.B_Add.UseVisualStyleBackColor = true;
|
||||
this.B_Add.Click += new System.EventHandler(this.B_Add_Click);
|
||||
//
|
||||
// L_PropType
|
||||
//
|
||||
this.L_PropType.AutoSize = true;
|
||||
this.L_PropType.Location = new System.Drawing.Point(58, 64);
|
||||
this.L_PropType.Name = "L_PropType";
|
||||
this.L_PropType.Size = new System.Drawing.Size(70, 13);
|
||||
this.L_PropType.TabIndex = 12;
|
||||
this.L_PropType.Text = "PropertyType";
|
||||
//
|
||||
// BatchEditor
|
||||
//
|
||||
this.AllowDrop = true;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(394, 261);
|
||||
this.Controls.Add(this.L_PropType);
|
||||
this.Controls.Add(this.B_Add);
|
||||
this.Controls.Add(this.CB_Require);
|
||||
this.Controls.Add(this.CB_Property);
|
||||
|
|
@ -208,6 +212,7 @@ private void InitializeComponent()
|
|||
this.FLP_RB.ResumeLayout(false);
|
||||
this.FLP_RB.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -224,5 +229,6 @@ private void InitializeComponent()
|
|||
private System.Windows.Forms.ComboBox CB_Property;
|
||||
private System.Windows.Forms.ComboBox CB_Require;
|
||||
private System.Windows.Forms.Button B_Add;
|
||||
private System.Windows.Forms.Label L_PropType;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,19 +15,38 @@ public BatchEditor()
|
|||
InitializeComponent();
|
||||
DragDrop += tabMain_DragDrop;
|
||||
DragEnter += tabMain_DragEnter;
|
||||
|
||||
CB_Format.Items.Clear();
|
||||
CB_Format.Items.Add("All");
|
||||
foreach (Type t in types) CB_Format.Items.Add(t.Name.ToLower());
|
||||
CB_Format.Items.Add("Any");
|
||||
|
||||
CB_Format.SelectedIndex = CB_Require.SelectedIndex = 0;
|
||||
}
|
||||
private static string[][] getPropArray()
|
||||
{
|
||||
var p = new string[types.Length][];
|
||||
for (int i = 0; i < p.Length; i++)
|
||||
p[i] = ReflectUtil.getPropertiesCanWritePublic(types[i]).ToArray();
|
||||
|
||||
IEnumerable<string> all = p.SelectMany(prop => prop).Distinct();
|
||||
IEnumerable<string> any = p[0];
|
||||
for (int i = 1; i < p.Length; i++)
|
||||
any = any.Union(p[i]);
|
||||
|
||||
var p1 = new string[types.Length + 2][];
|
||||
Array.Copy(p, 0, p1, 1, p.Length);
|
||||
p1[0] = all.ToArray();
|
||||
p1[p1.Length-1] = any.ToArray();
|
||||
|
||||
return p1;
|
||||
}
|
||||
|
||||
private const string CONST_RAND = "$rand";
|
||||
private const string CONST_SHINY = "$shiny";
|
||||
private int currentFormat = -1;
|
||||
private static readonly string[] pk7 = ReflectUtil.getPropertiesCanWritePublic(typeof(PK7)).OrderBy(i => i).ToArray();
|
||||
private static readonly string[] pk6 = ReflectUtil.getPropertiesCanWritePublic(typeof(PK6)).OrderBy(i=>i).ToArray();
|
||||
private static readonly string[] pk5 = ReflectUtil.getPropertiesCanWritePublic(typeof(PK5)).OrderBy(i=>i).ToArray();
|
||||
private static readonly string[] pk4 = ReflectUtil.getPropertiesCanWritePublic(typeof(PK4)).OrderBy(i=>i).ToArray();
|
||||
private static readonly string[] pk3 = ReflectUtil.getPropertiesCanWritePublic(typeof(PK3)).OrderBy(i=>i).ToArray();
|
||||
private static readonly string[] all = pk7.Intersect(pk6).Intersect(pk5).Intersect(pk4).Intersect(pk3).OrderBy(i => i).ToArray();
|
||||
private static readonly string[] any = pk7.Union(pk6).Union(pk5).Union(pk4).Union(pk3).Distinct().OrderBy(i => i).ToArray();
|
||||
private static readonly Type[] types = {typeof (PK7), typeof (PK6), typeof (PK5), typeof (PK4), typeof (PK3)};
|
||||
private static readonly string[][] properties = getPropArray();
|
||||
|
||||
// GUI Methods
|
||||
private void B_Open_Click(object sender, EventArgs e)
|
||||
|
|
@ -264,6 +283,23 @@ private void tabMain_DragDrop(object sender, DragEventArgs e)
|
|||
RB_SAV.Checked = false;
|
||||
RB_Path.Checked = true;
|
||||
}
|
||||
private void CB_Property_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
L_PropType.Text = getPropertyType(CB_Property.Text);
|
||||
}
|
||||
private string getPropertyType(string propertyName)
|
||||
{
|
||||
int typeIndex = CB_Format.SelectedIndex;
|
||||
|
||||
if (typeIndex == 0) // All
|
||||
return types[0].GetProperty(propertyName).PropertyType.Name;
|
||||
|
||||
if (typeIndex == properties.Length - 1) // Any
|
||||
foreach (var p in types.Select(t => t.GetProperty(propertyName)).Where(p => p != null))
|
||||
return p.PropertyType.Name;
|
||||
|
||||
return types[typeIndex - 1].GetProperty(propertyName).PropertyType.Name;
|
||||
}
|
||||
|
||||
// Utility Methods
|
||||
public class StringInstruction
|
||||
|
|
@ -373,19 +409,11 @@ private void CB_Format_SelectedIndexChanged(object sender, EventArgs e)
|
|||
if (currentFormat == CB_Format.SelectedIndex)
|
||||
return;
|
||||
|
||||
int format = CB_Format.SelectedIndex;
|
||||
CB_Property.Items.Clear();
|
||||
switch (CB_Format.SelectedIndex)
|
||||
{
|
||||
case 0: CB_Property.Items.AddRange(all.ToArray()); break; // All
|
||||
case 1: CB_Property.Items.AddRange(pk7.ToArray()); break;
|
||||
case 2: CB_Property.Items.AddRange(pk6.ToArray()); break;
|
||||
case 3: CB_Property.Items.AddRange(pk5.ToArray()); break;
|
||||
case 4: CB_Property.Items.AddRange(pk4.ToArray()); break;
|
||||
case 5: CB_Property.Items.AddRange(pk3.ToArray()); break;
|
||||
case 6: CB_Property.Items.AddRange(any.ToArray()); break; // Any
|
||||
}
|
||||
CB_Property.Items.AddRange(properties[format]);
|
||||
CB_Property.SelectedIndex = 0;
|
||||
currentFormat = CB_Format.SelectedIndex;
|
||||
currentFormat = format;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user