mirror of
https://github.com/kwsch/NHSE.git
synced 2026-07-13 14:51:01 -05:00
Add remove weeds/holes
This commit is contained in:
parent
284b7e6fab
commit
6df2fc1b04
|
|
@ -1,4 +1,5 @@
|
|||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace NHSE.Core
|
||||
{
|
||||
|
|
@ -60,5 +61,27 @@ public void ImportAcre(int acre, byte[] data)
|
|||
tile.CopyFrom(tiles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public int ClearField(Func<FieldItemKind, bool> criteria)
|
||||
{
|
||||
int count = 0;
|
||||
var fi = FieldItemList.Items;
|
||||
foreach (var t in Tiles)
|
||||
{
|
||||
var disp = t.DisplayItemId;
|
||||
if (!fi.TryGetValue(disp, out var val))
|
||||
continue;
|
||||
|
||||
if (!criteria(val.Kind))
|
||||
continue;
|
||||
t.Delete();
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public int RemoveAllHoles() => ClearField(z => z == FieldItemKind.UnitIconHole);
|
||||
public int RemoveAllWeeds() => ClearField(z => z.IsWeed());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,4 +49,9 @@ public enum FieldItemKind : byte
|
|||
StoneE,
|
||||
UnitIconHole,
|
||||
}
|
||||
|
||||
public static class FieldItemKindExtensions
|
||||
{
|
||||
public static bool IsWeed(this FieldItemKind type) => FieldItemKind.PltWeedAut0 <= type && type <= FieldItemKind.PltWeedWin1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
26
NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs
generated
26
NHSE.WinForms/Subforms/FieldItemEditor.Designer.cs
generated
|
|
@ -55,6 +55,8 @@ private void InitializeComponent()
|
|||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.TT_Hover = new System.Windows.Forms.ToolTip(this.components);
|
||||
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.CM_Click.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.PB_Map)).BeginInit();
|
||||
this.CM_Picture.SuspendLayout();
|
||||
|
|
@ -320,11 +322,33 @@ private void InitializeComponent()
|
|||
this.PB_Acre.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PB_Acre_MouseClick);
|
||||
this.PB_Acre.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PB_Acre_MouseMove);
|
||||
//
|
||||
// B_RemoveAllWeeds
|
||||
//
|
||||
this.B_RemoveAllWeeds.Location = new System.Drawing.Point(857, 235);
|
||||
this.B_RemoveAllWeeds.Name = "B_RemoveAllWeeds";
|
||||
this.B_RemoveAllWeeds.Size = new System.Drawing.Size(112, 40);
|
||||
this.B_RemoveAllWeeds.TabIndex = 29;
|
||||
this.B_RemoveAllWeeds.Text = "Remove Weeds";
|
||||
this.B_RemoveAllWeeds.UseVisualStyleBackColor = true;
|
||||
this.B_RemoveAllWeeds.Click += new System.EventHandler(this.B_RemoveAllWeeds_Click);
|
||||
//
|
||||
// B_FillHoles
|
||||
//
|
||||
this.B_FillHoles.Location = new System.Drawing.Point(857, 281);
|
||||
this.B_FillHoles.Name = "B_FillHoles";
|
||||
this.B_FillHoles.Size = new System.Drawing.Size(112, 40);
|
||||
this.B_FillHoles.TabIndex = 30;
|
||||
this.B_FillHoles.Text = "Fill Holes";
|
||||
this.B_FillHoles.UseVisualStyleBackColor = true;
|
||||
this.B_FillHoles.Click += new System.EventHandler(this.B_FillHoles_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_FillHoles);
|
||||
this.Controls.Add(this.B_RemoveAllWeeds);
|
||||
this.Controls.Add(this.PB_Acre);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.NUD_Layer);
|
||||
|
|
@ -389,5 +413,7 @@ private void InitializeComponent()
|
|||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.ToolTip TT_Hover;
|
||||
private System.Windows.Forms.PictureBox PB_Acre;
|
||||
private System.Windows.Forms.Button B_RemoveAllWeeds;
|
||||
private System.Windows.Forms.Button B_FillHoles;
|
||||
}
|
||||
}
|
||||
|
|
@ -381,5 +381,29 @@ private void PB_Map_MouseMove(object sender, MouseEventArgs e)
|
|||
}
|
||||
|
||||
private void NUD_Layer_ValueChanged(object sender, EventArgs e) => LoadGrid(X, Y);
|
||||
|
||||
private void B_RemoveAllWeeds_Click(object sender, EventArgs e)
|
||||
{
|
||||
int count = Layer.RemoveAllWeeds();
|
||||
if (count == 0)
|
||||
{
|
||||
WinFormsUtil.Alert("Nothing removed from the map (none found).");
|
||||
return;
|
||||
}
|
||||
LoadGrid(X, Y);
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
||||
private void B_FillHoles_Click(object sender, EventArgs e)
|
||||
{
|
||||
int count = Layer.RemoveAllHoles();
|
||||
if (count == 0)
|
||||
{
|
||||
WinFormsUtil.Alert("Nothing removed from the map (none found).");
|
||||
return;
|
||||
}
|
||||
LoadGrid(X, Y);
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user