2014-04-07 08:48:02 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes.FindReplace
|
|
|
|
|
{
|
|
|
|
|
[FindReplace("Sector Ceiling Height", BrowseButton = false)]
|
|
|
|
|
internal class FindSectorCeilingHeight : BaseFindSector
|
|
|
|
|
{
|
|
|
|
|
#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
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public override FindReplaceObject[] Find(string value, bool withinselection, bool replace, string replacewith, bool keepselection)
|
|
|
|
|
{
|
2014-04-07 08:48:02 +00:00
|
|
|
|
List<FindReplaceObject> objs = new List<FindReplaceObject>();
|
|
|
|
|
|
|
|
|
|
// Interpret the replacement
|
|
|
|
|
int replaceheight = 0;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(replace)
|
|
|
|
|
{
|
2014-04-07 08:48:02 +00:00
|
|
|
|
// If it cannot be interpreted, set replacewith to null (not replacing at all)
|
|
|
|
|
if(!int.TryParse(replacewith, out replaceheight)) replacewith = null;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(replacewith == null)
|
|
|
|
|
{
|
2014-04-07 08:48:02 +00:00
|
|
|
|
MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return objs.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Interpret the number given
|
|
|
|
|
int height;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(int.TryParse(value, out height))
|
|
|
|
|
{
|
2014-04-07 08:48:02 +00:00
|
|
|
|
// Where to search?
|
|
|
|
|
ICollection<Sector> list = withinselection ? General.Map.Map.GetSelectedSectors(true) : General.Map.Map.Sectors;
|
|
|
|
|
|
|
|
|
|
// Go for all sectors
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Sector s in list)
|
|
|
|
|
{
|
2014-04-07 08:48:02 +00:00
|
|
|
|
// Height matches?
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(s.CeilHeight == height)
|
|
|
|
|
{
|
2014-04-07 08:48:02 +00:00
|
|
|
|
// Replace
|
2014-11-05 12:32:48 +00:00
|
|
|
|
if(replace) s.CeilHeight = replaceheight;
|
2014-04-07 08:48:02 +00:00
|
|
|
|
|
|
|
|
|
objs.Add(new FindReplaceObject(s, "Sector " + s.Index));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//refresh map
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(replace)
|
|
|
|
|
{
|
2014-04-07 08:48:02 +00:00
|
|
|
|
General.Map.Map.Update();
|
|
|
|
|
General.Map.IsChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return objs.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|