From 0bc23a589360c6f1d8d51d701ce6634d0ea887ee Mon Sep 17 00:00:00 2001 From: codeimp Date: Tue, 3 Jun 2008 19:02:06 +0000 Subject: [PATCH] some bug fixes and completed the things filter --- Documents/todo.txt | 2 - Source/Editing/ThingsFilter.cs | 45 +++++----- Source/General/MapManager.cs | 3 + Source/Windows/LinedefEditForm.cs | 2 + Source/Windows/SectorEditForm.Designer.cs | 3 +- Source/Windows/SectorEditForm.cs | 6 ++ Source/Windows/TextEditForm.Designer.cs | 10 ++- Source/Windows/TextEditForm.cs | 7 ++ Source/Windows/TextEditForm.resx | 12 +++ Source/Windows/ThingEditForm.cs | 6 ++ Source/Windows/ThingsFiltersForm.Designer.cs | 2 +- Source/Windows/ThingsFiltersForm.cs | 90 ++++++++++++++++++-- Source/Windows/ThingsFiltersForm.resx | 6 -- 13 files changed, 152 insertions(+), 42 deletions(-) diff --git a/Documents/todo.txt b/Documents/todo.txt index 520f9cb0..e28be2b2 100644 --- a/Documents/todo.txt +++ b/Documents/todo.txt @@ -1,5 +1,3 @@ -- Complete Things filter with UDMF fields - - Controls to increase/decrease grid size - "Insert Thing" control diff --git a/Source/Editing/ThingsFilter.cs b/Source/Editing/ThingsFilter.cs index a51e8b31..e680d0d1 100644 --- a/Source/Editing/ThingsFilter.cs +++ b/Source/Editing/ThingsFilter.cs @@ -110,9 +110,9 @@ namespace CodeImp.DoomBuilder.Editing { // Add to the corresponding list if((bool)de.Value == true) - requiredfields.Add(de.Value.ToString()); + requiredfields.Add(de.Key.ToString()); else - forbiddenfields.Add(de.Value.ToString()); + forbiddenfields.Add(de.Key.ToString()); } // We have no destructor @@ -196,10 +196,19 @@ namespace CodeImp.DoomBuilder.Editing // Get thing info ThingTypeInfo ti = General.Map.Config.GetThingInfo(t.Type); - - // Check if the thing matches category and id - qualifies = ((t.Type == thingtype) || (thingtype == -1)) && - ((ti.Category.Name == categoryname) || (categoryname.Length == 0)); + + // Check if thing is in unknown category + if(ti.Category == null) + { + // Check if the thing matches id + qualifies = ((t.Type == thingtype) || (thingtype == -1)) && (categoryname.Length == 0); + } + else + { + // Check if the thing matches category and id + qualifies = ((t.Type == thingtype) || (thingtype == -1)) && + ((ti.Category.Name == categoryname) || (categoryname.Length == 0)); + } // Still qualifies? if(qualifies) @@ -207,16 +216,10 @@ namespace CodeImp.DoomBuilder.Editing // Go for all required fields foreach(string s in requiredfields) { - if(t.Fields.ContainsKey(s)) + if(t.Flags.ContainsKey(s)) { - if(t.Fields[s] is bool) - { - if((bool)t.Fields[s].Value == false) - { - qualifies = false; - break; - } - } + qualifies = (t.Flags[s] == true); + break; } else { @@ -232,16 +235,10 @@ namespace CodeImp.DoomBuilder.Editing // Go for all forbidden fields foreach(string s in forbiddenfields) { - if(t.Fields.ContainsKey(s)) + if(t.Flags.ContainsKey(s)) { - if(t.Fields[s] is bool) - { - if((bool)t.Fields[s].Value == true) - { - qualifies = false; - break; - } - } + qualifies = (t.Flags[s] == false); + break; } } } diff --git a/Source/General/MapManager.cs b/Source/General/MapManager.cs index a5afdc97..ad37d54f 100644 --- a/Source/General/MapManager.cs +++ b/Source/General/MapManager.cs @@ -497,6 +497,9 @@ namespace CodeImp.DoomBuilder ReloadResources(); } + // Reset changed status + if(savemode != SAVE_TEST) changed = false; + // Success! General.WriteLogLine("Map saving done"); return true; diff --git a/Source/Windows/LinedefEditForm.cs b/Source/Windows/LinedefEditForm.cs index 293697ab..031d7dad 100644 --- a/Source/Windows/LinedefEditForm.cs +++ b/Source/Windows/LinedefEditForm.cs @@ -84,6 +84,7 @@ namespace CodeImp.DoomBuilder.Windows // Hexen map? else if(General.Map.IsType(typeof(HexenMapSetIO))) { + tabs.TabPages.Remove(tabcustom); hexenpanel.Visible = true; argspanel.Visible = true; actiongroup.Height = 210; @@ -92,6 +93,7 @@ namespace CodeImp.DoomBuilder.Windows // Doom map? else { + tabs.TabPages.Remove(tabcustom); actiongroup.Height = 68; this.Height = 470; } diff --git a/Source/Windows/SectorEditForm.Designer.cs b/Source/Windows/SectorEditForm.Designer.cs index db249db3..4e0a1f16 100644 --- a/Source/Windows/SectorEditForm.Designer.cs +++ b/Source/Windows/SectorEditForm.Designer.cs @@ -110,7 +110,7 @@ namespace CodeImp.DoomBuilder.Windows groupaction.Size = new System.Drawing.Size(436, 71); groupaction.TabIndex = 5; groupaction.TabStop = false; - groupaction.Text = " Action "; + groupaction.Text = " Identification "; // // tag // @@ -395,6 +395,7 @@ namespace CodeImp.DoomBuilder.Windows | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.fieldslist.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.fieldslist.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.fieldslist.Location = new System.Drawing.Point(11, 11); this.fieldslist.Margin = new System.Windows.Forms.Padding(8); this.fieldslist.Name = "fieldslist"; diff --git a/Source/Windows/SectorEditForm.cs b/Source/Windows/SectorEditForm.cs index 9e880cc3..8fcd7b63 100644 --- a/Source/Windows/SectorEditForm.cs +++ b/Source/Windows/SectorEditForm.cs @@ -55,6 +55,12 @@ namespace CodeImp.DoomBuilder.Windows floortex.Initialize(); ceilingtex.Initialize(); + // Not a UDMF map? + if(!General.Map.IsType(typeof(UniversalMapSetIO))) + { + tabs.TabPages.Remove(tabcustom); + } + // Initialize custom fields editor fieldslist.Setup("sector"); } diff --git a/Source/Windows/TextEditForm.Designer.cs b/Source/Windows/TextEditForm.Designer.cs index 105f14d2..2b87209d 100644 --- a/Source/Windows/TextEditForm.Designer.cs +++ b/Source/Windows/TextEditForm.Designer.cs @@ -41,7 +41,8 @@ namespace CodeImp.DoomBuilder.Windows this.cancel.Margin = new System.Windows.Forms.Padding(1); this.cancel.Name = "cancel"; this.cancel.Size = new System.Drawing.Size(112, 25); - this.cancel.TabIndex = 21; + this.cancel.TabIndex = 2; + this.cancel.TabStop = false; this.cancel.Text = "Cancel"; this.cancel.UseVisualStyleBackColor = true; this.cancel.Click += new System.EventHandler(this.cancel_Click); @@ -53,7 +54,8 @@ namespace CodeImp.DoomBuilder.Windows this.apply.Margin = new System.Windows.Forms.Padding(1); this.apply.Name = "apply"; this.apply.Size = new System.Drawing.Size(112, 25); - this.apply.TabIndex = 20; + this.apply.TabIndex = 1; + this.apply.TabStop = false; this.apply.Text = "OK"; this.apply.UseVisualStyleBackColor = true; this.apply.Click += new System.EventHandler(this.apply_Click); @@ -69,7 +71,8 @@ namespace CodeImp.DoomBuilder.Windows this.textbox.Name = "textbox"; this.textbox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.textbox.Size = new System.Drawing.Size(456, 194); - this.textbox.TabIndex = 22; + this.textbox.TabIndex = 0; + this.textbox.TabStop = false; // // TextEditForm // @@ -90,6 +93,7 @@ namespace CodeImp.DoomBuilder.Windows this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Edit Text"; + this.Activated += new System.EventHandler(this.TextEditForm_Activated); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Source/Windows/TextEditForm.cs b/Source/Windows/TextEditForm.cs index 96ff7d4c..274903d2 100644 --- a/Source/Windows/TextEditForm.cs +++ b/Source/Windows/TextEditForm.cs @@ -71,5 +71,12 @@ namespace CodeImp.DoomBuilder.Windows this.DialogResult = DialogResult.Cancel; this.Close(); } + + // Window activated + private void TextEditForm_Activated(object sender, EventArgs e) + { + // Focus to textbox + textbox.Focus(); + } } } \ No newline at end of file diff --git a/Source/Windows/TextEditForm.resx b/Source/Windows/TextEditForm.resx index ff31a6db..e214ef43 100644 --- a/Source/Windows/TextEditForm.resx +++ b/Source/Windows/TextEditForm.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/Source/Windows/ThingEditForm.cs b/Source/Windows/ThingEditForm.cs index 6a10b0be..3e6e4247 100644 --- a/Source/Windows/ThingEditForm.cs +++ b/Source/Windows/ThingEditForm.cs @@ -69,6 +69,12 @@ namespace CodeImp.DoomBuilder.Windows // Initialize custom fields editor fieldslist.Setup("thing"); + + // Not a UDMF map? + if(!General.Map.IsType(typeof(UniversalMapSetIO))) + { + tabs.TabPages.Remove(tabcustom); + } // Go for all predefined categories typelist.Nodes.Clear(); diff --git a/Source/Windows/ThingsFiltersForm.Designer.cs b/Source/Windows/ThingsFiltersForm.Designer.cs index cb3772e8..8e3e9168 100644 --- a/Source/Windows/ThingsFiltersForm.Designer.cs +++ b/Source/Windows/ThingsFiltersForm.Designer.cs @@ -117,7 +117,7 @@ namespace CodeImp.DoomBuilder.Windows this.filterfields.Columns = 2; this.filterfields.Location = new System.Drawing.Point(18, 125); this.filterfields.Name = "filterfields"; - this.filterfields.Size = new System.Drawing.Size(350, 198); + this.filterfields.Size = new System.Drawing.Size(329, 198); this.filterfields.TabIndex = 5; // // label3 diff --git a/Source/Windows/ThingsFiltersForm.cs b/Source/Windows/ThingsFiltersForm.cs index e3a46270..444313db 100644 --- a/Source/Windows/ThingsFiltersForm.cs +++ b/Source/Windows/ThingsFiltersForm.cs @@ -37,20 +37,33 @@ namespace CodeImp.DoomBuilder.Windows { public partial class ThingsFiltersForm : DelayedForm { + #region ================== Variables + + private bool settingup; + + #endregion + #region ================== Constructor // Constructor public ThingsFiltersForm() { + settingup = true; + // Initialize InitializeComponent(); // Fill the categories combobox + filtercategory.Items.Add("(any category)"); filtercategory.Items.AddRange(General.Map.Config.ThingCategories.ToArray()); // Fill checkboxes list - // TODO: When UDMF is implemented - filterfields.Add("TODO: When UDMF is implemented!", null); + foreach(KeyValuePair flag in General.Map.Config.ThingFlags) + { + CheckBox box = filterfields.Add(flag.Value, flag.Key); + box.ThreeState = true; + box.CheckStateChanged += new EventHandler(filterfield_Check); + } // Fill list of filters foreach(ThingsFilter f in General.Map.ConfigSettings.ThingsFilters) @@ -69,6 +82,9 @@ namespace CodeImp.DoomBuilder.Windows // Sort the list listfilters.Sort(); + + // Done + settingup = false; } #endregion @@ -137,13 +153,38 @@ namespace CodeImp.DoomBuilder.Windows ThingsFilter f = listfilters.SelectedItems[0].Tag as ThingsFilter; // Enable settings + settingup = true; deletefilter.Enabled = true; filtergroup.Enabled = true; - // Show settings + // Show name filtername.Text = f.Name; + + // Show category foreach(ThingCategory c in filtercategory.Items) if(c.Name == f.CategoryName) filtercategory.SelectedItem = c; + + // Show fields + foreach(CheckBox b in filterfields.Checkboxes) + { + // Field name forbidden? + if(f.ForbiddenFields.Contains(b.Tag.ToString())) + { + b.CheckState = CheckState.Unchecked; + } + // Field name required? + else if(f.RequiredFields.Contains(b.Tag.ToString())) + { + b.CheckState = CheckState.Checked; + } + else + { + b.CheckState = CheckState.Indeterminate; + } + } + + // Done + settingup = false; } else { @@ -169,9 +210,12 @@ namespace CodeImp.DoomBuilder.Windows // Get selected filter ThingsFilter f = listfilters.SelectedItems[0].Tag as ThingsFilter; - // Set new category name - if(filtercategory.SelectedIndex > -1) + // Category selected + if((filtercategory.SelectedIndex > -1) && (filtercategory.SelectedItem is ThingCategory)) + { + // Set new category name f.CategoryName = (filtercategory.SelectedItem as ThingCategory).Name; + } } } @@ -195,6 +239,42 @@ namespace CodeImp.DoomBuilder.Windows } } + // Field clicked + private void filterfield_Check(object sender, EventArgs e) + { + // Get the checkbox + CheckBox box = (sender as CheckBox); + + // Not setting up? + if(!settingup) + { + // Anything selected? + if(listfilters.SelectedItems.Count > 0) + { + // Get selected filter + ThingsFilter f = listfilters.SelectedItems[0].Tag as ThingsFilter; + + // New state is required? + if(box.CheckState == CheckState.Checked) + { + f.ForbiddenFields.Remove(box.Tag.ToString()); + if(!f.RequiredFields.Contains(box.Tag.ToString())) f.RequiredFields.Add(box.Tag.ToString()); + } + // New state is forbidden? + else if(box.CheckState == CheckState.Unchecked) + { + f.RequiredFields.Remove(box.Tag.ToString()); + if(!f.ForbiddenFields.Contains(box.Tag.ToString())) f.ForbiddenFields.Add(box.Tag.ToString()); + } + else + { + f.ForbiddenFields.Remove(box.Tag.ToString()); + f.RequiredFields.Remove(box.Tag.ToString()); + } + } + } + } + #endregion } } \ No newline at end of file diff --git a/Source/Windows/ThingsFiltersForm.resx b/Source/Windows/ThingsFiltersForm.resx index a9e69f6f..a96b2f4a 100644 --- a/Source/Windows/ThingsFiltersForm.resx +++ b/Source/Windows/ThingsFiltersForm.resx @@ -153,12 +153,6 @@ True - - True - - - True - True