2015-12-31 12:21:44 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
|
{
|
|
|
|
|
[FindReplace("Sector Brightness", BrowseButton = false)]
|
|
|
|
|
internal class FindSectorBrightness : 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
|
|
|
|
|
public override FindReplaceObject[] Find(string value, bool withinselection, bool replace, string replacewith, bool keepselection)
|
|
|
|
|
{
|
|
|
|
|
List<FindReplaceObject> objs = new List<FindReplaceObject>();
|
|
|
|
|
|
|
|
|
|
// Interpret the replacement
|
|
|
|
|
int replacebrightness = 0;
|
|
|
|
|
if(replace)
|
|
|
|
|
{
|
|
|
|
|
// 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;
|
|
|
|
|
if(replacewith == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return objs.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-17 14:58:13 +00:00
|
|
|
|
// Check for comparison operators
|
2021-02-21 14:22:14 +00:00
|
|
|
|
string comparer = "";
|
|
|
|
|
if (value[0].ToString() == ">" || value[0].ToString() == "<" || value[0].ToString() == "!")
|
2021-02-17 14:58:13 +00:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
2015-12-31 12:21:44 +00:00
|
|
|
|
// Interpret the number given
|
|
|
|
|
int brightness;
|
|
|
|
|
if(int.TryParse(value, out brightness))
|
|
|
|
|
{
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
|
|
|
|
// Brightness matches?
|
2021-02-17 14:58:13 +00:00
|
|
|
|
if ((s.Brightness == brightness && comparer.ToString() == "") ||
|
|
|
|
|
(s.Brightness > brightness && comparer.ToString() == ">") ||
|
|
|
|
|
(s.Brightness < brightness && comparer.ToString() == "<") ||
|
|
|
|
|
(s.Brightness >= brightness && comparer.ToString() == ">=") ||
|
2021-02-21 14:22:14 +00:00
|
|
|
|
(s.Brightness <= brightness && comparer.ToString() == "<=") ||
|
|
|
|
|
(s.Brightness != brightness && (comparer.ToString() == "!" || comparer.ToString() == "!=")))
|
2015-12-31 12:21:44 +00:00
|
|
|
|
{
|
|
|
|
|
// Replace
|
|
|
|
|
if(replace) s.Brightness = replacebrightness;
|
|
|
|
|
|
|
|
|
|
objs.Add(new FindReplaceObject(s, "Sector " + s.Index));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//refresh map
|
|
|
|
|
if(replace)
|
|
|
|
|
{
|
|
|
|
|
General.Map.Map.Update();
|
|
|
|
|
General.Map.IsChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return objs.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|