ZoneBuilder/Source/Plugins/BuilderModes/FindReplace/FindSectorFloorHeight.cs
MaxED 747f268af2 Fixed, "Check Polyobjects" error check: an error is no longer added when "Mirror Polyobject Number" of "Polyobj_Startline" is 0.
Fixed, "Find and Replace" mode: "Find and Replace" window no longer closes when no results are found and Replace mode is enabled.
Changed, "Find and Replace" mode: renamed some search modes for better grouping.
2023-01-04 14:26:07 +01:00

106 lines
3.2 KiB
C#

#region ================== Namespaces
using System.Collections.Generic;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Map;
#endregion
namespace CodeImp.DoomBuilder.BuilderModes.FindReplace
{
[FindReplace("Sector Height (Floor)", BrowseButton = false)]
internal class FindSectorFloorHeight : BaseFindSector
{
#region ================== Properties
//mxd. Prefixes usage
public override string UsageHint
{
get
{
return "Supported prefixes:" + System.Environment.NewLine
+ "\"<=\" for values less or equal to given value;" + System.Environment.NewLine
+ "\">=\" for values greater or equal to given value;" + System.Environment.NewLine
+ "\"<\" for values less than given value;" + System.Environment.NewLine
+ "\">\" for values greater than given value." + System.Environment.NewLine
+ "\"!\" or \"!=\" for values not equal to given value.";
}
}
#endregion
#region ================== Methods
// This is called to perform a search (and replace)
// Returns a list of items to show in the results list
// replacewith is null when not replacing
public override FindReplaceObject[] Find(string value, bool withinselection, bool replace, string replacewith, bool keepselection)
{
List<FindReplaceObject> objs = new List<FindReplaceObject>();
// Interpret the replacement
int replaceheight = 0;
if(replace)
{
// If it cannot be interpreted, set replacewith to null (not replacing at all)
if(!int.TryParse(replacewith, out replaceheight)) replacewith = null;
if(replacewith == null)
{
MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
return objs.ToArray();
}
}
// Check for comparison operators
string comparer = "";
if (value[0].ToString() == ">" || value[0].ToString() == "<" || value[0].ToString() == "!")
{
comparer = value.Substring(0, 1);
if (value.Length > 1)
if (value[1].ToString() == "=")
comparer = value.Substring(0, 2);
value = value.Remove(0, comparer.Length);
}
if (value.Length == 0)
return objs.ToArray();
// Interpret the number given
int height;
if(int.TryParse(value, out height))
{
// Where to search?
ICollection<Sector> list = withinselection ? General.Map.Map.GetSelectedSectors(true) : General.Map.Map.Sectors;
// Go for all sectors
foreach(Sector s in list)
{
// Height matches?
if ((s.FloorHeight == height && comparer.ToString() == "") ||
(s.FloorHeight > height && comparer.ToString() == ">") ||
(s.FloorHeight < height && comparer.ToString() == "<") ||
(s.FloorHeight >= height && comparer.ToString() == ">=") ||
(s.FloorHeight <= height && comparer.ToString() == "<=") ||
(s.FloorHeight != height && (comparer.ToString() == "!" || comparer.ToString() == "!=")))
{
// Replace
if(replace) s.FloorHeight = replaceheight;
objs.Add(new FindReplaceObject(s, "Sector " + s.Index));
}
}
}
//refresh map
if(replace)
{
General.Map.Map.Update();
General.Map.IsChanged = true;
}
return objs.ToArray();
}
#endregion
}
}