From 760468fcaef2fd8fa9b133594807fdaf395d4eec Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sun, 17 Jul 2016 17:06:50 -0700 Subject: [PATCH] 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). --- Subforms/PKM Editors/BatchEditor.Designer.cs | 92 +++++++++++++++++--- Subforms/PKM Editors/BatchEditor.cs | 38 ++++++++ Util/ReflectUtil.cs | 4 + 3 files changed, 123 insertions(+), 11 deletions(-) diff --git a/Subforms/PKM Editors/BatchEditor.Designer.cs b/Subforms/PKM Editors/BatchEditor.Designer.cs index 12b69494b..24ba24601 100644 --- a/Subforms/PKM Editors/BatchEditor.Designer.cs +++ b/Subforms/PKM Editors/BatchEditor.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/Subforms/PKM Editors/BatchEditor.cs b/Subforms/PKM Editors/BatchEditor.cs index a05ed20ae..b105f1d52 100644 --- a/Subforms/PKM Editors/BatchEditor.cs +++ b/Subforms/PKM Editors/BatchEditor.cs @@ -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; + } } } diff --git a/Util/ReflectUtil.cs b/Util/ReflectUtil.cs index 31c99e0b0..e0d843d7f 100644 --- a/Util/ReflectUtil.cs +++ b/Util/ReflectUtil.cs @@ -30,5 +30,9 @@ namespace PKHeX .Where(p => p.Name.StartsWith(prefix)) .Select(p => p.Name); } + internal static IEnumerable getPropertiesCanWrite(Type type) + { + return type.GetProperties().Where(p => p.CanWrite).Select(p => p.Name); + } } }