Add remove plants / remove all

This commit is contained in:
Kurt
2020-04-10 12:50:08 -07:00
parent 6ce0d1595d
commit 3ab70d593f
3 changed files with 78 additions and 3 deletions

View File

@@ -62,7 +62,7 @@ public void ImportAcre(int acre, byte[] data)
}
}
public int ClearField(Func<FieldItemKind, bool> criteria)
public int ClearFieldPlanted(Func<FieldItemKind, bool> criteria)
{
int count = 0;
var fi = FieldItemList.Items;
@@ -81,7 +81,22 @@ public int ClearField(Func<FieldItemKind, bool> criteria)
return count;
}
public int RemoveAllHoles() => ClearField(z => z == FieldItemKind.UnitIconHole);
public int RemoveAllWeeds() => ClearField(z => z.IsWeed());
public int RemoveAll(Func<FieldItem, bool> 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);
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}