diff --git a/NHSE.Core/Structures/Acres/Terrain/FieldItemLayer.cs b/NHSE.Core/Structures/Acres/Terrain/FieldItemLayer.cs index 4e01896..6e074f3 100644 --- a/NHSE.Core/Structures/Acres/Terrain/FieldItemLayer.cs +++ b/NHSE.Core/Structures/Acres/Terrain/FieldItemLayer.cs @@ -62,7 +62,7 @@ public void ImportAcre(int acre, byte[] data) } } - public int ClearField(Func criteria) + public int ClearFieldPlanted(Func criteria) { int count = 0; var fi = FieldItemList.Items; @@ -81,7 +81,22 @@ public int ClearField(Func criteria) return count; } - public int RemoveAllHoles() => ClearField(z => z == FieldItemKind.UnitIconHole); - public int RemoveAllWeeds() => ClearField(z => z.IsWeed()); + public int RemoveAll(Func criteria) + { + int count = 0; + foreach (var t in Tiles) + { + if (!criteria(t)) + continue; + t.Delete(); + count++; + } + + return count; + } + + public int RemoveAllHoles() => ClearFieldPlanted(z => z == FieldItemKind.UnitIconHole); + public int RemoveAllWeeds() => ClearFieldPlanted(z => z.IsWeed()); + public int RemoveAllPlants() => ClearFieldPlanted(_ => true); } } diff --git a/NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs b/NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs index d939ec8..baa257e 100644 --- a/NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs +++ b/NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs @@ -59,6 +59,8 @@ private void InitializeComponent() this.PB_Acre = new System.Windows.Forms.PictureBox(); this.B_RemoveAllWeeds = new System.Windows.Forms.Button(); this.B_FillHoles = new System.Windows.Forms.Button(); + this.B_RemovePlants = new System.Windows.Forms.Button(); + this.B_RemoveAll = new System.Windows.Forms.Button(); this.CM_Click.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.PB_Map)).BeginInit(); this.CM_Picture.SuspendLayout(); @@ -347,11 +349,33 @@ private void InitializeComponent() this.B_FillHoles.UseVisualStyleBackColor = true; this.B_FillHoles.Click += new System.EventHandler(this.B_FillHoles_Click); // + // B_RemovePlants + // + this.B_RemovePlants.Location = new System.Drawing.Point(767, 439); + this.B_RemovePlants.Name = "B_RemovePlants"; + this.B_RemovePlants.Size = new System.Drawing.Size(98, 40); + this.B_RemovePlants.TabIndex = 31; + this.B_RemovePlants.Text = "Remove Plants"; + this.B_RemovePlants.UseVisualStyleBackColor = true; + this.B_RemovePlants.Click += new System.EventHandler(this.B_RemovePlants_Click); + // + // B_RemoveAll + // + this.B_RemoveAll.Location = new System.Drawing.Point(871, 439); + this.B_RemoveAll.Name = "B_RemoveAll"; + this.B_RemoveAll.Size = new System.Drawing.Size(98, 40); + this.B_RemoveAll.TabIndex = 32; + this.B_RemoveAll.Text = "Remove Plants"; + this.B_RemoveAll.UseVisualStyleBackColor = true; + this.B_RemoveAll.Click += new System.EventHandler(this.B_RemoveAll_Click); + // // FieldItemEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(981, 537); + this.Controls.Add(this.B_RemoveAll); + this.Controls.Add(this.B_RemovePlants); this.Controls.Add(this.B_FillHoles); this.Controls.Add(this.B_RemoveAllWeeds); this.Controls.Add(this.PB_Acre); @@ -420,5 +444,7 @@ private void InitializeComponent() private System.Windows.Forms.PictureBox PB_Acre; private System.Windows.Forms.Button B_RemoveAllWeeds; private System.Windows.Forms.Button B_FillHoles; + private System.Windows.Forms.Button B_RemovePlants; + private System.Windows.Forms.Button B_RemoveAll; } } \ No newline at end of file diff --git a/NHSE.WinForms/Subforms/FieldItemEditor.cs b/NHSE.WinForms/Subforms/FieldItemEditor.cs index ee0db0d..53a8458 100644 --- a/NHSE.WinForms/Subforms/FieldItemEditor.cs +++ b/NHSE.WinForms/Subforms/FieldItemEditor.cs @@ -423,6 +423,40 @@ private void B_FillHoles_Click(object sender, EventArgs e) System.Media.SystemSounds.Asterisk.Play(); } + private void B_RemovePlants_Click(object sender, EventArgs e) + { + const string q = "Are you sure you want to remove all plants?"; + var question = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, q); + if (question != DialogResult.Yes) + return; + + int count = Layer.RemoveAllPlants(); + if (count == 0) + { + WinFormsUtil.Alert("Nothing removed from the map (none found)."); + return; + } + LoadGrid(X, Y); + System.Media.SystemSounds.Asterisk.Play(); + } + + private void B_RemoveAll_Click(object sender, EventArgs e) + { + const string q = "Are you sure you want to remove everything?"; + var question = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, q); + if (question != DialogResult.Yes) + return; + + int count = Layer.RemoveAll(_ => true); + if (count == 0) + { + WinFormsUtil.Alert("Nothing removed from the map (none found)."); + return; + } + LoadGrid(X, Y); + System.Media.SystemSounds.Asterisk.Play(); + } + private void PG_Tile_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) => PG_Tile.SelectedObject = PG_Tile.SelectedObject; } }