Add more user friendly command building

Thanks \ for the suggestion; user has to enter in the value (true/false,
integer).

Provides a list of properties for a pkm file that have setters
(CanWrite).
This commit is contained in:
Kaphotics 2016-07-17 17:06:50 -07:00
parent d6d2503051
commit 760468fcae
3 changed files with 123 additions and 11 deletions

View file

@ -36,6 +36,10 @@
this.RTB_Instructions = new System.Windows.Forms.RichTextBox();
this.B_Go = new System.Windows.Forms.Button();
this.PB_Show = new System.Windows.Forms.ProgressBar();
this.CB_Format = new System.Windows.Forms.ComboBox();
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.FLP_RB.SuspendLayout();
this.SuspendLayout();
//
@ -78,17 +82,18 @@
this.FLP_RB.Controls.Add(this.TB_Folder);
this.FLP_RB.Location = new System.Drawing.Point(12, 10);
this.FLP_RB.Name = "FLP_RB";
this.FLP_RB.Size = new System.Drawing.Size(260, 24);
this.FLP_RB.Size = new System.Drawing.Size(370, 24);
this.FLP_RB.TabIndex = 2;
//
// TB_Folder
//
this.TB_Folder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.TB_Folder.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TB_Folder.Location = new System.Drawing.Point(118, 2);
this.TB_Folder.Margin = new System.Windows.Forms.Padding(2);
this.TB_Folder.Name = "TB_Folder";
this.TB_Folder.ReadOnly = true;
this.TB_Folder.Size = new System.Drawing.Size(140, 20);
this.TB_Folder.Size = new System.Drawing.Size(250, 20);
this.TB_Folder.TabIndex = 4;
this.TB_Folder.Visible = false;
//
@ -99,16 +104,16 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.RTB_Instructions.Location = new System.Drawing.Point(12, 68);
this.RTB_Instructions.Name = "RTB_Instructions";
this.RTB_Instructions.Size = new System.Drawing.Size(260, 181);
this.RTB_Instructions.Size = new System.Drawing.Size(370, 157);
this.RTB_Instructions.TabIndex = 5;
this.RTB_Instructions.Text = "!HeldItem=0\n=Gender=2\n.Species=1";
this.RTB_Instructions.Text = "";
//
// B_Go
//
this.B_Go.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.B_Go.Location = new System.Drawing.Point(197, 39);
this.B_Go.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Go.Location = new System.Drawing.Point(325, 230);
this.B_Go.Name = "B_Go";
this.B_Go.Size = new System.Drawing.Size(75, 23);
this.B_Go.Size = new System.Drawing.Size(57, 23);
this.B_Go.TabIndex = 6;
this.B_Go.Text = "Run";
this.B_Go.UseVisualStyleBackColor = true;
@ -116,17 +121,77 @@
//
// PB_Show
//
this.PB_Show.Location = new System.Drawing.Point(12, 41);
this.PB_Show.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.PB_Show.Location = new System.Drawing.Point(12, 231);
this.PB_Show.Name = "PB_Show";
this.PB_Show.Size = new System.Drawing.Size(180, 18);
this.PB_Show.Size = new System.Drawing.Size(307, 21);
this.PB_Show.TabIndex = 7;
//
// CB_Format
//
this.CB_Format.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CB_Format.FormattingEnabled = true;
this.CB_Format.Items.AddRange(new object[] {
"All",
"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);
this.CB_Format.TabIndex = 8;
this.CB_Format.SelectedIndexChanged += new System.EventHandler(this.CB_Format_SelectedIndexChanged);
//
// CB_Property
//
this.CB_Property.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CB_Property.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CB_Property.DropDownWidth = 200;
this.CB_Property.FormattingEnabled = true;
this.CB_Property.Location = new System.Drawing.Point(61, 40);
this.CB_Property.Name = "CB_Property";
this.CB_Property.Size = new System.Drawing.Size(140, 21);
this.CB_Property.TabIndex = 9;
//
// CB_Require
//
this.CB_Require.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.CB_Require.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CB_Require.FormattingEnabled = true;
this.CB_Require.Items.AddRange(new object[] {
"Set Equal To",
"Require Equals",
"Require Not Equals"});
this.CB_Require.Location = new System.Drawing.Point(207, 40);
this.CB_Require.Name = "CB_Require";
this.CB_Require.Size = new System.Drawing.Size(111, 21);
this.CB_Require.TabIndex = 10;
//
// B_Add
//
this.B_Add.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.B_Add.Location = new System.Drawing.Point(324, 39);
this.B_Add.Name = "B_Add";
this.B_Add.Size = new System.Drawing.Size(57, 23);
this.B_Add.TabIndex = 11;
this.B_Add.Text = "Add";
this.B_Add.UseVisualStyleBackColor = true;
this.B_Add.Click += new System.EventHandler(this.B_Add_Click);
//
// 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(284, 261);
this.ClientSize = new System.Drawing.Size(394, 261);
this.Controls.Add(this.B_Add);
this.Controls.Add(this.CB_Require);
this.Controls.Add(this.CB_Property);
this.Controls.Add(this.CB_Format);
this.Controls.Add(this.PB_Show);
this.Controls.Add(this.B_Go);
this.Controls.Add(this.RTB_Instructions);
@ -134,6 +199,7 @@
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimumSize = new System.Drawing.Size(410, 300);
this.Name = "BatchEditor";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Batch Editor";
@ -152,5 +218,9 @@
private System.Windows.Forms.RichTextBox RTB_Instructions;
private System.Windows.Forms.Button B_Go;
private System.Windows.Forms.ProgressBar PB_Show;
private System.Windows.Forms.ComboBox CB_Format;
private System.Windows.Forms.ComboBox CB_Property;
private System.Windows.Forms.ComboBox CB_Require;
private System.Windows.Forms.Button B_Add;
}
}

View file

@ -14,8 +14,17 @@ namespace PKHeX
InitializeComponent();
DragDrop += tabMain_DragDrop;
DragEnter += tabMain_DragEnter;
CB_Format.SelectedIndex = CB_Require.SelectedIndex = 0;
}
private int currentFormat = -1;
private static readonly string[] pk6 = ReflectUtil.getPropertiesCanWrite(typeof(PK6)).OrderBy(i=>i).ToArray();
private static readonly string[] pk5 = ReflectUtil.getPropertiesCanWrite(typeof(PK5)).OrderBy(i=>i).ToArray();
private static readonly string[] pk4 = ReflectUtil.getPropertiesCanWrite(typeof(PK4)).OrderBy(i=>i).ToArray();
private static readonly string[] pk3 = ReflectUtil.getPropertiesCanWrite(typeof(PK3)).OrderBy(i=>i).ToArray();
private static readonly string[] all = pk6.Intersect(pk5).Intersect(pk4).Intersect(pk3).OrderBy(i => i).ToArray();
private static readonly string[] any = pk6.Union(pk5).Union(pk4).Union(pk3).Distinct().OrderBy(i => i).ToArray();
// GUI Methods
private void B_Open_Click(object sender, EventArgs e)
{
@ -208,5 +217,34 @@ namespace PKHeX
}
return true;
}
private void B_Add_Click(object sender, EventArgs e)
{
char[] prefix = {'.', '=', '!'};
string s = prefix[CB_Require.SelectedIndex] + CB_Property.Text + "=";
if (RTB_Instructions.Lines.Length != 0 && RTB_Instructions.Lines.Last().Length > 0)
s = Environment.NewLine + s;
RTB_Instructions.AppendText(s);
}
private void CB_Format_SelectedIndexChanged(object sender, EventArgs e)
{
if (currentFormat == CB_Format.SelectedIndex)
return;
CB_Property.Items.Clear();
switch (CB_Format.SelectedIndex)
{
case 0: CB_Property.Items.AddRange(all.ToArray()); break; // All
case 1: CB_Property.Items.AddRange(pk6.ToArray()); break;
case 2: CB_Property.Items.AddRange(pk5.ToArray()); break;
case 3: CB_Property.Items.AddRange(pk4.ToArray()); break;
case 4: CB_Property.Items.AddRange(pk3.ToArray()); break;
case 5: CB_Property.Items.AddRange(any.ToArray()); break; // Any
}
CB_Property.SelectedIndex = 0;
currentFormat = CB_Format.SelectedIndex;
}
}
}

View file

@ -30,5 +30,9 @@ namespace PKHeX
.Where(p => p.Name.StartsWith(prefix))
.Select(p => p.Name);
}
internal static IEnumerable<string> getPropertiesCanWrite(Type type)
{
return type.GetProperties().Where(p => p.CanWrite).Select(p => p.Name);
}
}
}