// Number changes
        private void number_TextChanged(object sender, EventArgs e)
        {
            int itemindex = -1;

            // Not nothing?
            if (number.Text.Length > 0)
            {
                // Find the index in the list
                for (int i = 0; i < list.Items.Count; i++)
                {
                    // This is the item we're looking for?
                    INumberedTitle item = (INumberedTitle)list.Items[i];
                    if (item.Index.ToString() == number.Text)
                    {
                        // Found it
                        itemindex = i;
                        break;
                    }
                }
            }

            // Select item
            if (list.SelectedIndex != itemindex)
            {
                list.SelectedIndex = itemindex;
                list.Refresh();
            }
            //mxd. This may be generalized effect, and it may've changed
            else if (itemindex == -1)
            {
                list.Refresh();
            }

            // Raise change event
            //mxd. This HAS to be raised during Edit form setup, otherwise TypeHandlers in ArgumentBoxes won't be initialized
            if (ValueChanges != null)
            {
                ValueChanges(this, EventArgs.Empty);
            }
        }
        // Selection made
        private void list_SelectionChangeCommitted(object sender, EventArgs e)
        {
            INumberedTitle item = (INumberedTitle)list.SelectedItem;

            number.Text = item.Index.ToString();
        }
        // This draws an item in the combobox
        private void list_DrawItem(object sender, DrawItemEventArgs e)
        {
            Brush  displaybrush = SystemBrushes.WindowText;
            Brush  backbrush    = SystemBrushes.Window;
            string displayname  = string.Empty;

            // Only when running
            if (!this.DesignMode)
            {
                // Unknow item?
                if (e.Index < 0)
                {
                    // Grayed
                    displaybrush = new SolidBrush(SystemColors.GrayText);
                    backbrush    = new SolidBrush(SystemColors.Window);

                    // Try getting integral number
                    int intnumber;
                    int.TryParse(number.Text, out intnumber);

                    // Check what to display
                    if (number.Text.Length == 0)
                    {
                        displayname = "";
                    }
                    else if (intnumber == 0)
                    {
                        displayname = "None";
                    }
                    else if ((generalizedcategories != null) && GameConfiguration.IsGeneralized(intnumber, generalizedcategories))
                    {
                        displayname = "Generalized (" + General.Map.Config.GetGeneralizedActionCategory(intnumber) + ")";
                    }
                    else if ((generalizedoptions != null) && GameConfiguration.IsGeneralizedSectorEffect(intnumber, generalizedoptions)) //mxd
                    {
                        displayname = General.Map.Config.GetGeneralizedSectorEffectName(intnumber);                                      //mxd
                    }
                    else
                    {
                        displayname = "Unknown";
                    }
                }
                // In the display part of the combobox?
                else if ((e.State & DrawItemState.ComboBoxEdit) != 0)
                {
                    // Show without number
                    INumberedTitle item = (INumberedTitle)list.Items[e.Index];
                    displayname = item.Title.Trim();

                    // Determine colors to use
                    if (item.Index == 0)
                    {
                        // Grayed
                        displaybrush = new SolidBrush(SystemColors.GrayText);
                        backbrush    = new SolidBrush(SystemColors.Window);
                    }
                    else
                    {
                        // Normal color
                        displaybrush = new SolidBrush(list.ForeColor);
                        backbrush    = new SolidBrush(SystemColors.Window);
                    }
                }
                else
                {
                    // Use number and description
                    INumberedTitle item = (INumberedTitle)list.Items[e.Index];
                    displayname = item.Index + NUMBER_SEPERATOR + item.Title;

                    // Determine colors to use
                    if ((e.State & DrawItemState.Focus) != 0)
                    {
                        displaybrush = new SolidBrush(SystemColors.HighlightText);
                        backbrush    = new SolidBrush(SystemColors.Highlight);
                    }
                    else
                    {
                        displaybrush = new SolidBrush(list.ForeColor);
                        backbrush    = new SolidBrush(SystemColors.Window);
                    }
                }
            }

            // Draw item
            e.Graphics.FillRectangle(backbrush, e.Bounds);
            e.Graphics.DrawString(displayname, list.Font, displaybrush, e.Bounds.X, e.Bounds.Y);

            //mxd. Dispose brushes
            if (!this.DesignMode)
            {
                backbrush.Dispose();
                displaybrush.Dispose();
            }
        }
예제 #4
0
        // Constructor
        public ThingsFiltersForm()
        {
            settingup = true;

            // Initialize
            InitializeComponent();

            // Fill types list
            List <ThingTypeInfo> thingtypes = new List <ThingTypeInfo>(General.Map.Data.ThingTypes);

            INumberedTitle[] typeitems = new INumberedTitle[thingtypes.Count];
            for (int i = 0; i < thingtypes.Count; i++)
            {
                typeitems[i] = thingtypes[i];
            }
            filtertype.AddInfo(typeitems);

            // Fill the categories combobox
            filtercategory.Items.Add("(any category)");

            //mxd. Add ThingCategories with subcategories
            AddThingFilterCategories(General.Map.Data.ThingCategories, string.Empty);

            // Fill actions list
            filteraction.GeneralizedCategories = General.Map.Config.GenActionCategories;
            filteraction.AddInfo(General.Map.Config.SortedLinedefActions.ToArray());

            // Initialize custom fields editor
            if (General.Map.FormatInterface.HasCustomFields)            //mxd
            {
                fieldslist.ListNoFixedFields();
                fieldslist.Setup("thing");
            }

            // Fill checkboxes list
            foreach (KeyValuePair <string, string> flag in General.Map.Config.ThingFlags)
            {
                CheckBox box = filterfields.Add(flag.Value, flag.Key);
                box.ThreeState         = true;
                box.CheckStateChanged += filterfield_Check;
            }

            // Fill list of filters
            foreach (ThingsFilter f in General.Map.ConfigSettings.ThingsFilters)
            {
                // Make a copy (we don't want to modify the filters until OK is clicked)
                ThingsFilter nf = new ThingsFilter(f);

                // Make item in list
                ListViewItem item = new ListViewItem(nf.Name);
                item.Tag        = nf;
                item.ImageIndex = (nf.IsValid() ? -1 : 0);                 //mxd
                listfilters.Items.Add(item);

                // Select item if this is the current filter
                if (General.Map.ThingsFilter == f)
                {
                    item.Selected = true;
                }
            }

            // Sort the list
            listfilters.Sort();

            // Map format specific fields
            filterzheight.Visible  = General.Map.FormatInterface.HasThingHeight;
            labelzheight.Visible   = General.Map.FormatInterface.HasThingHeight;
            argumentspanel.Visible = General.Map.FormatInterface.HasActionArgs;
            labeltag.Visible       = General.Map.FormatInterface.HasThingTag;
            filtertag.Visible      = General.Map.FormatInterface.HasThingTag;
            if (!General.Map.FormatInterface.HasCustomFields)
            {
                tabs.TabPages.Remove(tabcustom);
            }
            if (!General.Map.FormatInterface.HasThingAction && !General.Map.FormatInterface.HasThingTag)
            {
                tabs.TabPages.Remove(tabaction);
            }

            // Done
            settingup = false;
        }