mirror of
https://git.do.srb2.org/STJr/ZoneBuilder.git
synced 2025-03-13 06:02:38 +00:00
Allow searching for thing height
This commit is contained in:
parent
c09774d9f6
commit
c3027c0d9b
3 changed files with 215 additions and 0 deletions
|
@ -106,6 +106,8 @@
|
|||
<Compile Include="ErrorChecks\ErrorCheckerAttribute.cs" />
|
||||
<Compile Include="ErrorChecks\ErrorChecker.cs" />
|
||||
<Compile Include="ErrorChecks\ResultThingOutside.cs" />
|
||||
<Compile Include="FindReplace\FindThingHeightAbsolute.cs" />
|
||||
<Compile Include="FindReplace\FindThingHeight.cs" />
|
||||
<Compile Include="FindReplace\FindLinedefTypes.cs" />
|
||||
<Compile Include="FindReplace\FindReplaceAttribute.cs" />
|
||||
<Compile Include="FindReplace\FindReplaceObject.cs" />
|
||||
|
|
106
Source/Plugins/BuilderModes/FindReplace/FindThingHeight.cs
Normal file
106
Source/Plugins/BuilderModes/FindReplace/FindThingHeight.cs
Normal file
|
@ -0,0 +1,106 @@
|
|||
#region ================== Namespaces
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.FindReplace
|
||||
{
|
||||
[FindReplace("Thing Height", BrowseButton = false)]
|
||||
internal class FindThingHeight : BaseFindThing
|
||||
{
|
||||
#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<Thing> list = withinselection ? General.Map.Map.GetSelectedThings(true) : General.Map.Map.Things;
|
||||
|
||||
// Go for all things
|
||||
foreach (Thing t in list)
|
||||
{
|
||||
// Height matches?
|
||||
if ((t.Position.z == height && comparer.ToString() == "") ||
|
||||
(t.Position.z > height && comparer.ToString() == ">") ||
|
||||
(t.Position.z < height && comparer.ToString() == "<") ||
|
||||
(t.Position.z >= height && comparer.ToString() == ">=") ||
|
||||
(t.Position.z <= height && comparer.ToString() == "<=") ||
|
||||
(t.Position.z != height && (comparer.ToString() == "!" || comparer.ToString() == "!=")))
|
||||
{
|
||||
// Replace
|
||||
if (replace) t.Move(t.Position.x, t.Position.y, replaceheight);
|
||||
|
||||
objs.Add(new FindReplaceObject(t, "Thing " + t.Index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//refresh map
|
||||
if (replace)
|
||||
{
|
||||
General.Map.Map.Update();
|
||||
General.Map.IsChanged = true;
|
||||
}
|
||||
|
||||
return objs.ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
#region ================== Namespaces
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using CodeImp.DoomBuilder.Map;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.BuilderModes.FindReplace
|
||||
{
|
||||
[FindReplace("Thing Height (Absolute)", BrowseButton = false)]
|
||||
internal class FindThingHeightAbsolute : BaseFindThing
|
||||
{
|
||||
#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<Thing> list = withinselection ? General.Map.Map.GetSelectedThings(true) : General.Map.Map.Things;
|
||||
|
||||
// Go for all things
|
||||
foreach (Thing t in list)
|
||||
{
|
||||
float abs = Sector.GetFloorPlane(t.Sector).GetZ(t.Position) + t.Height;
|
||||
// Height matches?
|
||||
if ((abs == height && comparer.ToString() == "") ||
|
||||
(abs > height && comparer.ToString() == ">") ||
|
||||
(abs < height && comparer.ToString() == "<") ||
|
||||
(abs >= height && comparer.ToString() == ">=") ||
|
||||
(abs <= height && comparer.ToString() == "<=") ||
|
||||
(abs != height && (comparer.ToString() == "!" || comparer.ToString() == "!=")))
|
||||
{
|
||||
// Replace
|
||||
if (replace) t.Move(t.Position.x, t.Position.y, replaceheight - Sector.GetFloorPlane(t.Sector).GetZ(t.Position));
|
||||
|
||||
objs.Add(new FindReplaceObject(t, "Thing " + t.Index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//refresh map
|
||||
if (replace)
|
||||
{
|
||||
General.Map.Map.Update();
|
||||
General.Map.IsChanged = true;
|
||||
}
|
||||
|
||||
return objs.ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue