Add water flower button

control: all water states
shift: all map (instead of current viewport)

Closes #230
This commit is contained in:
Kurt
2020-05-16 11:30:25 -07:00
parent 88695bc677
commit a4b4a3c24a
7 changed files with 107 additions and 26 deletions

View File

@@ -36,6 +36,7 @@ public FileHashRegion(int hashOfs, int begOfs, int size)
#region Equality Comparison
public override bool Equals(object obj) => obj is FileHashRegion r && r == this;
// ReSharper disable once PossiblyImpureMethodCallOnReadonlyVariable
public override int GetHashCode() => BeginOffset.GetHashCode();
public static bool operator !=(FileHashRegion left, FileHashRegion right) => !(left == right);

View File

@@ -137,7 +137,6 @@ public string GetItemName(Item item)
var kind = ItemInfo.GetItemKind(index);
if (kind.IsFlower())
{
var display = GetItemName(index);

View File

@@ -64,6 +64,23 @@ public int ClearFieldPlanted(int xmin, int ymin, int width, int height, Func<Fie
return count;
}
public int ModifyAll(int xmin, int ymin, int width, int height, Func<Item, bool> criteria, Action<Item> action)
{
int count = 0;
for (int x = xmin; x < xmin + width; x++)
{
for (int y = ymin; y < ymin + height; y++)
{
var t = GetTile(x, y);
if (!criteria(t))
continue;
action(t);
count++;
}
}
return count;
}
public int RemoveAllHoles(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z == FieldItemKind.UnitIconHole);
public int RemoveAllWeeds(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsWeed());
public int RemoveAllPlants(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsPlant());
@@ -75,6 +92,26 @@ public int ClearFieldPlanted(int xmin, int ymin, int width, int height, Func<Fie
public int RemoveAllShells(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width, height, z => GameLists.Shells.Contains(z.DisplayItemId));
public int RemoveAllBranches(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width, height, z => z.DisplayItemId == 2500);
public int RemoveAllPlacedItems(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width,
height, z => z.DisplayItemId != Item.NONE && !FieldItemList.Items.ContainsKey(z.DisplayItemId));
height, z => !z.IsNone && !FieldItemList.Items.ContainsKey(z.DisplayItemId));
public int WaterAllFlowers(int xmin, int ymin, int width, int height, bool all)
{
var fi = FieldItemList.Items;
bool IsFlowerWaterable(Item item)
{
if (item.IsNone)
return false;
if (!item.IsRoot)
return false;
if (!fi.TryGetValue(item.ItemId, out var def))
return false;
if (!def.Kind.IsFlower())
return false;
return true;
}
return ModifyAll(xmin, ymin, width, height, IsFlowerWaterable, z => z.Water(all));
}
}
}

View File

@@ -72,12 +72,12 @@ public void SetViewToAcre(in int acre)
SetViewTo(x, y);
}
public int RemoveFieldItems(Func<int, int, int, int, int> removal, bool wholeMap = false)
public int ModifyFieldItems(Func<int, int, int, int, int> action, in bool wholeMap)
{
var layer = Map.CurrentLayer;
return wholeMap
? removal(0, 0, layer.MaxWidth, layer.MaxHeight)
: removal(X, Y, layer.GridWidth, layer.GridHeight);
? action(0, 0, layer.MaxWidth, layer.MaxHeight)
: action(X, Y, layer.GridWidth, layer.GridHeight);
}
public void GetCursorCoordinates(in int mX, in int mY, out int x, out int y)

View File

@@ -135,11 +135,13 @@ private void InitializeComponent()
this.B_ZeroElevation = new System.Windows.Forms.ToolStripMenuItem();
this.B_SetAllTerrain = new System.Windows.Forms.ToolStripMenuItem();
this.B_SetAllRoadTiles = new System.Windows.Forms.ToolStripMenuItem();
this.B_ClearPlacedDesigns = new System.Windows.Forms.ToolStripMenuItem();
this.RB_Item = new System.Windows.Forms.RadioButton();
this.RB_Terrain = new System.Windows.Forms.RadioButton();
this.L_TileMode = new System.Windows.Forms.Label();
this.CHK_RedirectExtensionLoad = new System.Windows.Forms.CheckBox();
this.B_ClearPlacedDesigns = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.B_WaterFlowers = new System.Windows.Forms.ToolStripMenuItem();
this.CM_Click.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PB_Map)).BeginInit();
this.CM_Picture.SuspendLayout();
@@ -460,78 +462,80 @@ private void InitializeComponent()
this.B_RemoveShells,
this.B_RemoveFlowers,
this.B_FillHoles,
this.B_RemoveAll});
this.B_RemoveAll,
this.toolStripSeparator1,
this.B_WaterFlowers});
this.CM_Remove.Name = "CM_Picture";
this.CM_Remove.ShowImageMargin = false;
this.CM_Remove.Size = new System.Drawing.Size(117, 224);
this.CM_Remove.Size = new System.Drawing.Size(156, 274);
//
// B_RemoveAllWeeds
//
this.B_RemoveAllWeeds.Name = "B_RemoveAllWeeds";
this.B_RemoveAllWeeds.Size = new System.Drawing.Size(116, 22);
this.B_RemoveAllWeeds.Size = new System.Drawing.Size(155, 22);
this.B_RemoveAllWeeds.Text = "Weeds";
this.B_RemoveAllWeeds.Click += new System.EventHandler(this.B_RemoveAllWeeds_Click);
//
// B_RemovePlants
//
this.B_RemovePlants.Name = "B_RemovePlants";
this.B_RemovePlants.Size = new System.Drawing.Size(116, 22);
this.B_RemovePlants.Size = new System.Drawing.Size(155, 22);
this.B_RemovePlants.Text = "Plants";
this.B_RemovePlants.Click += new System.EventHandler(this.B_RemovePlants_Click);
//
// B_RemoveObjects
//
this.B_RemoveObjects.Name = "B_RemoveObjects";
this.B_RemoveObjects.Size = new System.Drawing.Size(116, 22);
this.B_RemoveObjects.Size = new System.Drawing.Size(155, 22);
this.B_RemoveObjects.Text = "Objects";
this.B_RemoveObjects.Click += new System.EventHandler(this.B_RemoveObjects_Click);
//
// B_RemovePlacedItems
//
this.B_RemovePlacedItems.Name = "B_RemovePlacedItems";
this.B_RemovePlacedItems.Size = new System.Drawing.Size(116, 22);
this.B_RemovePlacedItems.Size = new System.Drawing.Size(155, 22);
this.B_RemovePlacedItems.Text = "Placed Items";
this.B_RemovePlacedItems.Click += new System.EventHandler(this.B_RemovePlacedItems_Click);
//
// B_RemoveFences
//
this.B_RemoveFences.Name = "B_RemoveFences";
this.B_RemoveFences.Size = new System.Drawing.Size(116, 22);
this.B_RemoveFences.Size = new System.Drawing.Size(155, 22);
this.B_RemoveFences.Text = "Fences";
this.B_RemoveFences.Click += new System.EventHandler(this.B_RemoveFences_Click);
//
// B_RemoveBranches
//
this.B_RemoveBranches.Name = "B_RemoveBranches";
this.B_RemoveBranches.Size = new System.Drawing.Size(116, 22);
this.B_RemoveBranches.Size = new System.Drawing.Size(155, 22);
this.B_RemoveBranches.Text = "Branches";
this.B_RemoveBranches.Click += new System.EventHandler(this.B_RemoveBranches_Click);
//
// B_RemoveShells
//
this.B_RemoveShells.Name = "B_RemoveShells";
this.B_RemoveShells.Size = new System.Drawing.Size(116, 22);
this.B_RemoveShells.Size = new System.Drawing.Size(155, 22);
this.B_RemoveShells.Text = "Shells";
this.B_RemoveShells.Click += new System.EventHandler(this.B_RemoveShells_Click);
//
// B_RemoveFlowers
//
this.B_RemoveFlowers.Name = "B_RemoveFlowers";
this.B_RemoveFlowers.Size = new System.Drawing.Size(116, 22);
this.B_RemoveFlowers.Size = new System.Drawing.Size(155, 22);
this.B_RemoveFlowers.Text = "Flowers";
this.B_RemoveFlowers.Click += new System.EventHandler(this.B_RemoveFlowers_Click);
//
// B_FillHoles
//
this.B_FillHoles.Name = "B_FillHoles";
this.B_FillHoles.Size = new System.Drawing.Size(116, 22);
this.B_FillHoles.Size = new System.Drawing.Size(155, 22);
this.B_FillHoles.Text = "Holes";
this.B_FillHoles.Click += new System.EventHandler(this.B_FillHoles_Click);
//
// B_RemoveAll
//
this.B_RemoveAll.Name = "B_RemoveAll";
this.B_RemoveAll.Size = new System.Drawing.Size(116, 22);
this.B_RemoveAll.Size = new System.Drawing.Size(155, 22);
this.B_RemoveAll.Text = "All";
this.B_RemoveAll.Click += new System.EventHandler(this.B_RemoveAll_Click);
//
@@ -1222,7 +1226,7 @@ private void InitializeComponent()
this.B_ClearPlacedDesigns});
this.CM_Terrain.Name = "CM_Picture";
this.CM_Terrain.ShowImageMargin = false;
this.CM_Terrain.Size = new System.Drawing.Size(225, 114);
this.CM_Terrain.Size = new System.Drawing.Size(225, 92);
//
// B_ZeroElevation
//
@@ -1245,6 +1249,13 @@ private void InitializeComponent()
this.B_SetAllRoadTiles.Text = "Set All Road Tiles from Editor";
this.B_SetAllRoadTiles.Click += new System.EventHandler(this.B_SetAllRoadTiles_Click);
//
// B_ClearPlacedDesigns
//
this.B_ClearPlacedDesigns.Name = "B_ClearPlacedDesigns";
this.B_ClearPlacedDesigns.Size = new System.Drawing.Size(224, 22);
this.B_ClearPlacedDesigns.Text = "Clear all Placed Designs";
this.B_ClearPlacedDesigns.Click += new System.EventHandler(this.B_ClearPlacedDesigns_Click);
//
// RB_Item
//
this.RB_Item.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
@@ -1290,12 +1301,17 @@ private void InitializeComponent()
this.CHK_RedirectExtensionLoad.Text = "View Root instead of Extension";
this.CHK_RedirectExtensionLoad.UseVisualStyleBackColor = true;
//
// B_ClearPlacedDesigns
// toolStripSeparator1
//
this.B_ClearPlacedDesigns.Name = "B_ClearPlacedDesigns";
this.B_ClearPlacedDesigns.Size = new System.Drawing.Size(224, 22);
this.B_ClearPlacedDesigns.Text = "Clear all Placed Designs";
this.B_ClearPlacedDesigns.Click += new System.EventHandler(this.B_ClearPlacedDesigns_Click);
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(152, 6);
//
// B_WaterFlowers
//
this.B_WaterFlowers.Name = "B_WaterFlowers";
this.B_WaterFlowers.Size = new System.Drawing.Size(155, 22);
this.B_WaterFlowers.Text = "Water Flowers";
this.B_WaterFlowers.Click += new System.EventHandler(this.B_WaterFlowers_Click);
//
// FieldItemEditor
//
@@ -1480,5 +1496,7 @@ private void InitializeComponent()
private System.Windows.Forms.CheckBox CHK_RedirectExtensionLoad;
private System.Windows.Forms.ToolStripMenuItem B_SetAllRoadTiles;
private System.Windows.Forms.ToolStripMenuItem B_ClearPlacedDesigns;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem B_WaterFlowers;
}
}

View File

@@ -638,14 +638,14 @@ private void NUD_Layer_ValueChanged(object sender, EventArgs e)
private void Remove(ToolStripItem sender, Func<int, int, int, int, int> removal)
{
bool wholeMap = ModifierKeys == Keys.Shift;
bool wholeMap = (ModifierKeys & Keys.Shift) != 0;
string q = string.Format(MessageStrings.MsgFieldItemRemoveAsk, sender.Text);
var question = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, q);
if (question != DialogResult.Yes)
return;
int count = View.RemoveFieldItems(removal, wholeMap);
int count = View.ModifyFieldItems(removal, wholeMap);
if (count == 0)
{
@@ -656,6 +656,26 @@ private void Remove(ToolStripItem sender, Func<int, int, int, int, int> removal)
WinFormsUtil.Alert(string.Format(MessageStrings.MsgFieldItemRemoveCount, count));
}
private void Modify(ToolStripItem sender, Func<int, int, int, int, int> action)
{
bool wholeMap = (ModifierKeys & Keys.Shift) != 0;
string q = string.Format(MessageStrings.MsgFieldItemModifyAsk, sender.Text);
var question = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, q);
if (question != DialogResult.Yes)
return;
int count = View.ModifyFieldItems(action, wholeMap);
if (count == 0)
{
WinFormsUtil.Alert(MessageStrings.MsgFieldItemModifyNone);
return;
}
LoadItemGridAcre();
WinFormsUtil.Alert(string.Format(MessageStrings.MsgFieldItemModifyCount, count));
}
private void B_RemoveAllWeeds_Click(object sender, EventArgs e) => Remove(B_RemoveAllWeeds, Map.CurrentLayer.RemoveAllWeeds);
private void B_FillHoles_Click(object sender, EventArgs e) => Remove(B_FillHoles, Map.CurrentLayer.RemoveAllHoles);
private void B_RemovePlants_Click(object sender, EventArgs e) => Remove(B_RemovePlants, Map.CurrentLayer.RemoveAllPlants);
@@ -667,6 +687,9 @@ private void Remove(ToolStripItem sender, Func<int, int, int, int, int> removal)
private void B_RemoveBranches_Click(object sender, EventArgs e) => Remove(B_RemoveBranches, Map.CurrentLayer.RemoveAllBranches);
private void B_RemoveFlowers_Click(object sender, EventArgs e) => Remove(B_RemoveFlowers, Map.CurrentLayer.RemoveAllFlowers);
private void B_WaterFlowers_Click(object sender, EventArgs e) => Modify(B_WaterFlowers, (xmin, ymin, width, height)
=> Map.CurrentLayer.WaterAllFlowers(xmin, ymin, width, height, (ModifierKeys & Keys.Control) != 0));
private static void ShowContextMenuBelow(ToolStripDropDown c, Control n) => c.Show(n.PointToScreen(new Point(0, n.Height)));
private void B_RemoveItemDropDown_Click(object sender, EventArgs e) => ShowContextMenuBelow(CM_Remove, B_RemoveItemDropDown);
private void B_DumpLoadField_Click(object sender, EventArgs e) => ShowContextMenuBelow(CM_DLField, B_DumpLoadField);

View File

@@ -32,6 +32,9 @@ public static class MessageStrings
public static string MsgFieldItemRemoveAsk { get; set; } = "Are you sure you want to remove {0}?";
public static string MsgFieldItemRemoveNone { get; set; } = "Nothing removed (none found).";
public static string MsgFieldItemRemoveCount { get; set; } = "Removed {0} from the map.";
public static string MsgFieldItemModifyAsk { get; set; } = "Are you sure you want to {0}?";
public static string MsgFieldItemModifyNone { get; set; } = "Nothing modified (none found).";
public static string MsgFieldItemModifyCount { get; set; } = "Modified {0} tiles on the map.";
public static string MsgFieldItemUnsupportedLayer2Tile { get; set; } = "Unsupported Layer2 items detected.";
public static string MsgSysBotInfo { get; set; } = "This SysBot reads and writes RAM directly to your game when called to Read/Write.";