2014-01-10 15:08:39 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
2016-06-25 14:09:39 +00:00
|
|
|
|
using System;
|
2014-01-10 15:08:39 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-01-10 15:08:39 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
2013-03-18 13:52:27 +00:00
|
|
|
|
{
|
|
|
|
|
[FindReplace("Sector Brightness", BrowseButton = false)]
|
2014-01-10 15:08:39 +00:00
|
|
|
|
internal class FindSectorBrightness : BaseFindSector
|
2013-03-18 13:52:27 +00:00
|
|
|
|
{
|
2016-06-25 14:09:39 +00:00
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
|
|
//mxd. Prefixes usage
|
|
|
|
|
public override string UsageHint { get { return "Supported prefixes:" + Environment.NewLine
|
|
|
|
|
+ "\"<=\" - finds values less or equal to given value;" + Environment.NewLine
|
|
|
|
|
+ "\">=\" - finds values greater or equal to given value;" + Environment.NewLine
|
|
|
|
|
+ "\"<\" - finds values less than given value;" + Environment.NewLine
|
|
|
|
|
+ "\">\" - finds values greater than given value."; } }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-01-10 15:08:39 +00:00
|
|
|
|
#region ================== Methods
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
|
List<FindReplaceObject> objs = new List<FindReplaceObject>();
|
|
|
|
|
|
|
|
|
|
// Interpret the replacement
|
|
|
|
|
int replacebrightness = 0;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(replace)
|
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
|
// If it cannot be interpreted, set replacewith to null (not replacing at all)
|
|
|
|
|
if(!int.TryParse(replacewith, out replacebrightness)) replacewith = null;
|
|
|
|
|
if(replacebrightness < 0) replacewith = null;
|
|
|
|
|
if(replacebrightness > 255) replacewith = null;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(replacewith == null)
|
|
|
|
|
{
|
2013-03-18 13:52:27 +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
|
2014-02-21 14:42:12 +00:00
|
|
|
|
int brightness;
|
2016-06-25 14:09:39 +00:00
|
|
|
|
string prefix = string.Empty; //mxd
|
|
|
|
|
|
|
|
|
|
//mxd. Check prefixes
|
|
|
|
|
value = value.Trim().Replace(" ", "");
|
|
|
|
|
if(value.StartsWith(">=") || value.StartsWith("<=")) prefix = value.Substring(0, 2);
|
|
|
|
|
else if(value.StartsWith(">") || value.StartsWith("<")) prefix = value.Substring(0, 1);
|
|
|
|
|
value = value.Remove(0, prefix.Length);
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(int.TryParse(value, out brightness))
|
|
|
|
|
{
|
2013-03-18 13:52:27 +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)
|
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
|
// Brightness matches?
|
2016-06-25 14:09:39 +00:00
|
|
|
|
if(BrightnessMatches(s.Brightness, brightness, prefix))
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
|
// Replace
|
2014-11-05 12:32:48 +00:00
|
|
|
|
if(replace) s.Brightness = replacebrightness;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2016-06-25 14:09:39 +00:00
|
|
|
|
objs.Add(new FindReplaceObject(s, "Sector " + s.Index + (!replace ? " (Brightness " + s.Brightness + ")" : "")));
|
2013-03-18 13:52:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//refresh map
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(replace)
|
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
|
General.Map.Map.Update();
|
|
|
|
|
General.Map.IsChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return objs.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-25 14:09:39 +00:00
|
|
|
|
//mxd
|
|
|
|
|
private static bool BrightnessMatches(int sectorbrightness, int brightness, string prefix)
|
|
|
|
|
{
|
|
|
|
|
switch(prefix)
|
|
|
|
|
{
|
|
|
|
|
case "": return sectorbrightness == brightness;
|
|
|
|
|
case "<=": return sectorbrightness <= brightness;
|
|
|
|
|
case ">=": return sectorbrightness >= brightness;
|
|
|
|
|
case "<": return sectorbrightness < brightness;
|
|
|
|
|
case ">": return sectorbrightness > brightness;
|
|
|
|
|
default: throw new NotImplementedException("Unknown prefix");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 15:08:39 +00:00
|
|
|
|
#endregion
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|