2014-11-05 12:32:48 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
2016-10-11 12:58:35 +00:00
|
|
|
|
using System.Linq;
|
2014-11-05 12:32:48 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
using CodeImp.DoomBuilder.Windows;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
|
{
|
|
|
|
|
[FindReplace("Sector Flags", BrowseButton = true)]
|
|
|
|
|
internal class FindSectorFlags : BaseFindSector
|
|
|
|
|
{
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
|
|
public override Image BrowseImage { get { return Properties.Resources.List; } }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
|
|
// This is called to test if the item should be displayed
|
|
|
|
|
public override bool DetermineVisiblity()
|
|
|
|
|
{
|
2016-10-11 12:58:35 +00:00
|
|
|
|
return General.Map.Config.SectorFlags.Count > 0
|
|
|
|
|
|| General.Map.Config.CeilingPortalFlags.Count > 0
|
|
|
|
|
|| General.Map.Config.FloorPortalFlags.Count > 0;
|
2014-11-05 12:32:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is called when the browse button is pressed
|
|
|
|
|
public override string Browse(string initialvalue)
|
|
|
|
|
{
|
2016-10-11 12:58:35 +00:00
|
|
|
|
return FlagsForm.ShowDialog(Form.ActiveForm, initialvalue, GetAllFlags());
|
2014-11-05 12:32:48 +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
|
|
|
|
|
public override FindReplaceObject[] Find(string value, bool withinselection, bool replace, string replacewith, bool keepselection)
|
|
|
|
|
{
|
|
|
|
|
List<FindReplaceObject> objs = new List<FindReplaceObject>();
|
|
|
|
|
|
|
|
|
|
// Where to search?
|
|
|
|
|
ICollection<Sector> list = withinselection ? General.Map.Map.GetSelectedSectors(true) : General.Map.Map.Sectors;
|
|
|
|
|
|
2016-10-11 12:58:35 +00:00
|
|
|
|
// Combine all sector flags...
|
|
|
|
|
Dictionary<string, string> allflags = GetAllFlags();
|
|
|
|
|
|
2014-11-05 12:32:48 +00:00
|
|
|
|
// Find what? (mxd)
|
2016-06-08 00:06:20 +00:00
|
|
|
|
Dictionary<string, bool> findflagslist = new Dictionary<string, bool>();
|
2014-11-05 12:32:48 +00:00
|
|
|
|
foreach(string flag in value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
|
|
|
|
{
|
|
|
|
|
string f = flag.Trim();
|
2016-06-08 00:06:20 +00:00
|
|
|
|
bool setflag = true;
|
|
|
|
|
if(f.StartsWith("!"))
|
|
|
|
|
{
|
|
|
|
|
setflag = false;
|
|
|
|
|
f = f.Substring(1, f.Length - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 12:58:35 +00:00
|
|
|
|
if(allflags.ContainsKey(f)) findflagslist.Add(f, setflag);
|
2014-11-05 12:32:48 +00:00
|
|
|
|
}
|
|
|
|
|
if(findflagslist.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Invalid value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return objs.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Replace with what? (mxd)
|
2016-06-08 00:06:20 +00:00
|
|
|
|
Dictionary<string, bool> replaceflagslist = new Dictionary<string, bool>();
|
2014-11-05 12:32:48 +00:00
|
|
|
|
if(replace)
|
|
|
|
|
{
|
|
|
|
|
string[] replaceflags = replacewith.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
foreach(string flag in replaceflags)
|
|
|
|
|
{
|
|
|
|
|
string f = flag.Trim();
|
2016-06-08 00:06:20 +00:00
|
|
|
|
bool setflag = true;
|
|
|
|
|
if(f.StartsWith("!"))
|
|
|
|
|
{
|
|
|
|
|
setflag = false;
|
|
|
|
|
f = f.Substring(1, f.Length - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 12:58:35 +00:00
|
|
|
|
if(!allflags.ContainsKey(f))
|
2014-11-05 12:32:48 +00:00
|
|
|
|
{
|
2016-03-08 20:41:06 +00:00
|
|
|
|
MessageBox.Show("Invalid replace value \"" + f + "\" for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2014-11-05 12:32:48 +00:00
|
|
|
|
return objs.ToArray();
|
|
|
|
|
}
|
2016-06-08 00:06:20 +00:00
|
|
|
|
replaceflagslist.Add(f, setflag);
|
2014-11-05 12:32:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Go for all linedefs
|
2015-12-28 15:01:53 +00:00
|
|
|
|
foreach(Sector s in list)
|
2014-11-05 12:32:48 +00:00
|
|
|
|
{
|
|
|
|
|
bool match = true;
|
|
|
|
|
|
|
|
|
|
// Parse the value string...
|
2016-06-08 00:06:20 +00:00
|
|
|
|
foreach(KeyValuePair<string, bool> group in findflagslist)
|
2014-11-05 12:32:48 +00:00
|
|
|
|
{
|
2016-06-08 00:06:20 +00:00
|
|
|
|
// ...and check if the flag doesn't match
|
2016-07-02 22:27:20 +00:00
|
|
|
|
if(group.Value != s.IsFlagSet(group.Key))
|
2014-11-05 12:32:48 +00:00
|
|
|
|
{
|
|
|
|
|
match = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Flags matches?
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(match)
|
2014-11-05 12:32:48 +00:00
|
|
|
|
{
|
|
|
|
|
// Replace flags (mxd)
|
|
|
|
|
if(replace)
|
|
|
|
|
{
|
|
|
|
|
// Set new flags
|
2016-06-08 00:06:20 +00:00
|
|
|
|
foreach(KeyValuePair<string, bool> group in replaceflagslist) s.SetFlag(group.Key, group.Value);
|
2014-11-05 12:32:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add to list
|
|
|
|
|
SectorEffectInfo info = General.Map.Config.GetSectorEffectInfo(s.Effect);
|
|
|
|
|
if(!info.IsNull)
|
|
|
|
|
objs.Add(new FindReplaceObject(s, "Sector " + s.Index + " (" + info.Title + ")"));
|
|
|
|
|
else
|
|
|
|
|
objs.Add(new FindReplaceObject(s, "Sector " + s.Index));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return objs.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 12:58:35 +00:00
|
|
|
|
private static Dictionary<string, string> GetAllFlags()
|
|
|
|
|
{
|
|
|
|
|
// Combine all sector flags...
|
|
|
|
|
Dictionary<string, string> allflags = new Dictionary<string, string>(General.Map.Config.SectorFlags);
|
|
|
|
|
|
|
|
|
|
foreach(var group in General.Map.Config.CeilingPortalFlags)
|
|
|
|
|
allflags[group.Key] = group.Value + " (ceil. portal)";
|
|
|
|
|
|
|
|
|
|
foreach(var group in General.Map.Config.FloorPortalFlags)
|
|
|
|
|
allflags[group.Key] = group.Value + " (floor portal)";
|
|
|
|
|
|
|
|
|
|
return allflags;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-05 12:32:48 +00:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|