//mxd
        private void FilterEffects(string text)
        {
            List <ListViewItem> filtereditems = new List <ListViewItem>();
            HashSet <string>    added         = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            // First add nodes, which titles start with given text
            foreach (ListViewItem i in allitems)
            {
                SectorEffectInfo si = i.Tag as SectorEffectInfo;
                if (si != null && si.Title.ToUpperInvariant().StartsWith(text))
                {
                    filtereditems.Add(i);
                    added.Add(si.Title);
                }
            }

            // Then add nodes, which titles contain given text
            foreach (ListViewItem i in allitems)
            {
                SectorEffectInfo si = i.Tag as SectorEffectInfo;
                if (si != null && !added.Contains(si.Title) && si.Title.ToUpperInvariant().Contains(text))
                {
                    filtereditems.Add(i);
                    added.Add(si.Title);
                }
            }

            effects.BeginUpdate();
            effects.Items.Clear();
            effects.Items.AddRange(filtereditems.ToArray());
            effects.EndUpdate();
        }
Example #2
0
        // 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, string replacewith, bool keepselection)
        {
            List <FindReplaceObject> objs = new List <FindReplaceObject>();

            // Interpret the number given
            int index = 0;

            if (int.TryParse(value, out index))
            {
                Sector s = General.Map.Map.GetSectorByIndex(index);
                if (s != null)
                {
                    SectorEffectInfo info = General.Map.Config.GetSectorEffectInfo(s.Effect);
                    if (!info.IsNull)
                    {
                        objs.Add(new FindReplaceObject(s, "Sector " + index + " (" + info.Title + ")"));
                    }
                    else
                    {
                        objs.Add(new FindReplaceObject(s, "Sector " + index));
                    }
                }
            }

            return(objs.ToArray());
        }
Example #3
0
        // 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, string replacewith, bool keepselection)
        {
            List <FindReplaceObject> objs = new List <FindReplaceObject>();

            // Interpret the replacement
            int replaceeffect = 0;

            if (replacewith != null)
            {
                // If it cannot be interpreted, set replacewith to null (not replacing at all)
                if (!int.TryParse(replacewith, out replaceeffect))
                {
                    replacewith = null;
                }
                if (replaceeffect < 0)
                {
                    replacewith = null;
                }
                if (replaceeffect > Int16.MaxValue)
                {
                    replacewith = null;
                }
                if (replacewith == null)
                {
                    MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(objs.ToArray());
                }
            }

            // Interpret the number given
            int effect = 0;

            if (int.TryParse(value, out effect))
            {
                // 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)
                {
                    // Tag matches?
                    if (s.Effect == effect)
                    {
                        // Replace
                        if (replacewith != null)
                        {
                            s.Effect = replaceeffect;
                        }

                        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());
        }
        // 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;

            // Find what? (mxd)
            Dictionary <string, bool> findflagslist = new Dictionary <string, bool>();

            foreach (string flag in value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string f       = flag.Trim();
                bool   setflag = true;
                if (f.StartsWith("!"))
                {
                    setflag = false;
                    f       = f.Substring(1, f.Length - 1);
                }

                if (General.Map.Config.SectorFlags.ContainsKey(f))
                {
                    findflagslist.Add(f, setflag);
                }
            }
            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)
            Dictionary <string, bool> replaceflagslist = new Dictionary <string, bool>();

            if (replace)
            {
                string[] replaceflags = replacewith.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string flag in replaceflags)
                {
                    string f       = flag.Trim();
                    bool   setflag = true;
                    if (f.StartsWith("!"))
                    {
                        setflag = false;
                        f       = f.Substring(1, f.Length - 1);
                    }

                    if (!General.Map.Config.SectorFlags.ContainsKey(f))
                    {
                        MessageBox.Show("Invalid replace value \"" + f + "\" for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(objs.ToArray());
                    }
                    replaceflagslist.Add(f, setflag);
                }
            }

            // Go for all linedefs
            foreach (Sector s in list)
            {
                bool match = true;

                // Parse the value string...
                foreach (KeyValuePair <string, bool> group in findflagslist)
                {
                    // ...and check if the flag doesn't match
                    if (group.Value != s.IsFlagSet(group.Key))
                    {
                        match = false;
                        break;
                    }
                }

                // Flags matches?
                if (match)
                {
                    // Replace flags (mxd)
                    if (replace)
                    {
                        // Set new flags
                        foreach (KeyValuePair <string, bool> group in replaceflagslist)
                        {
                            s.SetFlag(group.Key, group.Value);
                        }
                    }

                    // 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());
        }
Example #5
0
        // 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 replaceeffect = 0;

            if (replace)
            {
                // If it cannot be interpreted, set replacewith to null (not replacing at all)
                if (!int.TryParse(replacewith, out replaceeffect))
                {
                    replacewith = null;
                }
                if (replaceeffect < 0)
                {
                    replacewith = null;
                }
                if (replaceeffect > Int16.MaxValue)
                {
                    replacewith = null;
                }
                if (replacewith == null)
                {
                    MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(objs.ToArray());
                }
            }

            // Interpret the number given
            int effect;

            if (int.TryParse(value, out effect))
            {
                //mxd
                SectorEffectData sd = General.Map.Config.GetSectorEffectData(effect);

                // 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)
                {
                    bool match = false;

                    //mxd. Effect matches? -1 means any effect
                    if (effect == -1)
                    {
                        match = s.Effect > 0;
                    }
                    else if (effect == s.Effect)
                    {
                        match = true;
                    }
                    else if (General.Map.Config.GeneralizedEffects && effect != 0 && s.Effect != 0)
                    {
                        SectorEffectData sdo = General.Map.Config.GetSectorEffectData(s.Effect);
                        match = (sd.Effect == sdo.Effect || (sd.GeneralizedBits.Count == sdo.GeneralizedBits.Count && sd.GeneralizedBits.Overlaps(sdo.GeneralizedBits)));
                    }

                    if (match)
                    {
                        // Replace
                        if (replace)
                        {
                            s.Effect = replaceeffect;
                        }

                        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());
        }
        // 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 replacetag = 0;

            if (replace)
            {
                // If it cannot be interpreted, set replacewith to null (not replacing at all)
                if (!int.TryParse(replacewith, out replacetag))
                {
                    replacewith = null;
                }
                if (replacetag < General.Map.FormatInterface.MinTag)
                {
                    replacewith = null;
                }
                if (replacetag > General.Map.FormatInterface.MaxTag)
                {
                    replacewith = null;
                }
                if (replacewith == null)
                {
                    MessageBox.Show("Invalid replace value for this search type!", "Find and Replace", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(objs.ToArray());
                }
            }

            // Interpret the number given
            int tag;

            if (int.TryParse(value, out tag))
            {
                // 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)
                {
                    // Tag matches?
                    int index = s.Tags.IndexOf(tag);
                    if (index != -1)
                    {
                        // Replace
                        if (replace)
                        {
                            //mxd. Make a copy of tags, otherwise BeforePropsChange will be triggered after tag changes
                            List <int> tags = new List <int>(s.Tags);
                            tags[index] = replacetag;
                            s.Tags      = tags.Distinct().ToList();                        // We don't want duplicates
                        }

                        // 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());
        }