From a04500f071d0471351e7e97bf10eff2feab24c1e Mon Sep 17 00:00:00 2001 From: codeimp Date: Fri, 30 May 2008 11:05:44 +0000 Subject: [PATCH] made the universal field editor control work with the type handlers --- Build/Configurations/Doom2.cfg | 113 ------------------ Build/Configurations/Eternity_DoomUDMF.cfg | 31 +++-- Build/Configurations/ZDoom_DoomHexen.cfg | 84 +++++++++++++ Source/Builder.csproj | 1 - Source/Config/UniversalFieldInfo.cs | 43 +------ Source/Config/UniversalFieldType.cs | 44 ------- .../Controls/FieldsEditorControl.Designer.cs | 61 +++++----- Source/Controls/FieldsEditorControl.cs | 20 ++-- Source/Controls/FieldsEditorRow.cs | 43 +++++-- Source/IO/Configuration.cs | 2 + Source/Types/BoolHandler.cs | 4 +- Source/Types/ColorHandler.cs | 3 +- Source/Types/EnumBitsHandler.cs | 6 +- Source/Types/EnumOptionHandler.cs | 6 +- Source/Types/FlatHandler.cs | 3 +- Source/Types/FloatHandler.cs | 4 +- Source/Types/IntegerHandler.cs | 4 +- Source/Types/LinedefTypeHandler.cs | 3 +- Source/Types/SectorEffectHandler.cs | 3 +- Source/Types/StringHandler.cs | 4 +- Source/Types/TextureHandler.cs | 3 +- Source/Types/TypeHandler.cs | 48 ++++++-- Source/Types/TypeHandlerAttribute.cs | 20 +++- Source/Types/TypesManager.cs | 59 ++++++++- Source/Windows/LinedefEditForm.cs | 2 +- 25 files changed, 310 insertions(+), 304 deletions(-) delete mode 100644 Source/Config/UniversalFieldType.cs diff --git a/Build/Configurations/Doom2.cfg b/Build/Configurations/Doom2.cfg index 2d31a2cd..dc5fbe50 100644 --- a/Build/Configurations/Doom2.cfg +++ b/Build/Configurations/Doom2.cfg @@ -206,119 +206,6 @@ maplumpnames } -/* -ADDITIONAL UNIVERSAL DOOM MAP FORMAT FIELD DEFINITIONS -Only add fields here that Doom Builder does not edit with its own user-interface! - -Field types: -0 = integer -1 = float -2 = string -3 = linedef action -4 = sector effect -5 = texture -6 = flat -*/ -universalfields -{ - linedefs - { - texture_scale_x - { - type = 1; - default = 1.0f; - } - - texture_scale_y - { - type = 1; - default = 1.0f; - } - - texture_offset_x - { - type = 1; - default = 0.0f; - } - - texture_offset_y - { - type = 1; - default = 0.0f; - } - - brightness - { - type = 0; - default = -1; - } - - colormap - { - type = 2; - default = ""; - } - - normalmap - { - type = 5; - default = "STARTAN3"; - } - - second_action - { - type = 3; - default = 0; - } - } - - sectors - { - flat_scale_x - { - type = 1; - default = 1.0f; - } - - flate_scale_y - { - type = 1; - default = 1.0f; - } - - flat_offset_x - { - type = 1; - default = 0.0f; - } - - flat_offset_y - { - type = 1; - default = 0.0f; - } - - colormap - { - type = 2; - default = ""; - } - - normalmap - { - type = 5; - default = "FLOOR1"; - } - - second_effect - { - type = 4; - default = 0; - } - } -} - - // DEFAULT SECTOR BRIGHTNESS LEVELS sectorbrightness { diff --git a/Build/Configurations/Eternity_DoomUDMF.cfg b/Build/Configurations/Eternity_DoomUDMF.cfg index 262d69e1..a90fd6f2 100644 --- a/Build/Configurations/Eternity_DoomUDMF.cfg +++ b/Build/Configurations/Eternity_DoomUDMF.cfg @@ -198,22 +198,23 @@ ADDITIONAL UNIVERSAL DOOM MAP FORMAT FIELD DEFINITIONS Only add fields here that Doom Builder does not edit with its own user-interface! Field data types: -0 = integer +0 = integer * 1 = float 2 = string 3 = bool -4 = linedeftype (integer) -5 = sectoreffect (integer) +4 = linedeftype (integer) * +5 = sectoreffect (integer) * 6 = texture (string) 7 = flat (string) 8 = angle in degrees (integer) 9 = angle in radians (float) 10 = XXRRGGBB color (integer) -11 = enum option (integer) -12 = enum bits (integer) -13 = sector tag (integer) -14 = thing tag (integer) -15 = linedef tag (integer) +11 = enum option (integer) * +12 = enum bits (integer) * +13 = sector tag (integer) * +14 = thing tag (integer) * +15 = linedef tag (integer) * +16 = enum option (string) */ universalfields { @@ -251,21 +252,27 @@ universalfields colormap { - type = 2; - default = ""; + type = 10; + default = 0; } normalmap { - type = 5; + type = 6; default = ""; } second_action { - type = 3; + type = 4; default = 0; } + + hidden + { + type = 3; + default = false; + } } } diff --git a/Build/Configurations/ZDoom_DoomHexen.cfg b/Build/Configurations/ZDoom_DoomHexen.cfg index 7672665d..003242bb 100644 --- a/Build/Configurations/ZDoom_DoomHexen.cfg +++ b/Build/Configurations/ZDoom_DoomHexen.cfg @@ -225,6 +225,90 @@ maplumpnames } +/* +ADDITIONAL UNIVERSAL DOOM MAP FORMAT FIELD DEFINITIONS +Only add fields here that Doom Builder does not edit with its own user-interface! + +Field data types: +0 = integer * +1 = float +2 = string +3 = bool +4 = linedeftype (integer) * +5 = sectoreffect (integer) * +6 = texture (string) +7 = flat (string) +8 = angle in degrees (integer) +9 = angle in radians (float) +10 = XXRRGGBB color (integer) +11 = enum option (integer) * +12 = enum bits (integer) * +13 = sector tag (integer) * +14 = thing tag (integer) * +15 = linedef tag (integer) * +16 = enum option (string) +*/ +universalfields +{ + linedefs + { + texture_scale_x + { + type = 1; + default = 1.0f; + } + + texture_scale_y + { + type = 1; + default = 1.0f; + } + + texture_offset_x + { + type = 1; + default = 0.0f; + } + + texture_offset_y + { + type = 1; + default = 0.0f; + } + + brightness + { + type = 0; + default = -1; + } + + colormap + { + type = 10; + default = 0; + } + + normalmap + { + type = 6; + default = ""; + } + + second_action + { + type = 4; + default = 0; + } + + hidden + { + type = 3; + default = false; + } + } +} + + // DEFAULT SECTOR BRIGHTNESS LEVELS sectorbrightness { diff --git a/Source/Builder.csproj b/Source/Builder.csproj index 7964d85d..e160e080 100644 --- a/Source/Builder.csproj +++ b/Source/Builder.csproj @@ -62,7 +62,6 @@ - diff --git a/Source/Config/UniversalFieldInfo.cs b/Source/Config/UniversalFieldInfo.cs index f5ad4faa..2803c8bf 100644 --- a/Source/Config/UniversalFieldInfo.cs +++ b/Source/Config/UniversalFieldInfo.cs @@ -42,20 +42,16 @@ namespace CodeImp.DoomBuilder.Config // Properties private string name; - private UniversalFieldType type; - private string defstring; - private int defint; - private float deffloat; + private int type; + private object defaultvalue; #endregion #region ================== Properties public string Name { get { return name; } } - public UniversalFieldType Type { get { return type; } } - public string DefaultStr { get { return defstring; } } - public int DefaultInt { get { return defint; } } - public float DefaultFloat { get { return deffloat; } } + public int Type { get { return type; } } + public object Default { get { return defaultvalue; } } #endregion @@ -70,35 +66,8 @@ namespace CodeImp.DoomBuilder.Config this.name = name; // Read type - this.type = (UniversalFieldType)cfg.ReadSetting(setting + ".type", 0); - switch(this.type) - { - case UniversalFieldType.Integer: - case UniversalFieldType.LinedefAction: - case UniversalFieldType.SectorEffect: - defint = cfg.ReadSetting(setting + ".default", 0); - deffloat = (float)defint; - defstring = DefaultInt.ToString(CultureInfo.InvariantCulture); - break; - - case UniversalFieldType.Float: - deffloat = cfg.ReadSetting(setting + ".default", 0.0f); - defint = (int)Math.Round(deffloat); - defstring = DefaultFloat.ToString(CultureInfo.InvariantCulture); - break; - - case UniversalFieldType.String: - case UniversalFieldType.Flat: - case UniversalFieldType.Texture: - defstring = cfg.ReadSetting(setting + ".default", ""); - float.TryParse(DefaultStr, NumberStyles.Number, CultureInfo.InvariantCulture, out deffloat); - int.TryParse(DefaultStr, NumberStyles.Number, CultureInfo.InvariantCulture, out defint); - break; - - default: - General.WriteLogLine("WARNING: Universal field '" + path + "." + name + "' is defined as unknown type " + (int)this.type + "!"); - break; - } + this.type = cfg.ReadSetting(setting + ".type", 0); + this.defaultvalue = cfg.ReadSettingObject(setting + ".default", null); // We have no destructor GC.SuppressFinalize(this); diff --git a/Source/Config/UniversalFieldType.cs b/Source/Config/UniversalFieldType.cs deleted file mode 100644 index b0597040..00000000 --- a/Source/Config/UniversalFieldType.cs +++ /dev/null @@ -1,44 +0,0 @@ - -#region ================== Copyright (c) 2007 Pascal vd Heiden - -/* - * Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com - * This program is released under GNU General Public License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#endregion - -#region ================== Namespaces - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using CodeImp.DoomBuilder.IO; -using CodeImp.DoomBuilder.Data; -using System.IO; -using System.Diagnostics; -using System.Windows.Forms; - -#endregion - -namespace CodeImp.DoomBuilder.Config -{ - public enum UniversalFieldType - { - Integer = 0, - Float = 1, - String = 2, - LinedefAction = 3, - SectorEffect = 4, - Texture = 5, - Flat = 6 - } -} diff --git a/Source/Controls/FieldsEditorControl.Designer.cs b/Source/Controls/FieldsEditorControl.Designer.cs index 9e600fe3..e959fbd4 100644 --- a/Source/Controls/FieldsEditorControl.Designer.cs +++ b/Source/Controls/FieldsEditorControl.Designer.cs @@ -29,10 +29,10 @@ namespace CodeImp.DoomBuilder.Controls private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle16 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle13 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle14 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle15 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); this.fieldslist = new System.Windows.Forms.DataGridView(); this.deleterowstimer = new System.Windows.Forms.Timer(this.components); this.browsebutton = new System.Windows.Forms.Button(); @@ -56,14 +56,14 @@ namespace CodeImp.DoomBuilder.Controls this.fieldname, this.fieldtype, this.fieldvalue}); - dataGridViewCellStyle16.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle16.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle16.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle16.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle16.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle16.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle16.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.fieldslist.DefaultCellStyle = dataGridViewCellStyle16; + dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.fieldslist.DefaultCellStyle = dataGridViewCellStyle4; this.fieldslist.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this.fieldslist.Location = new System.Drawing.Point(0, 0); this.fieldslist.MultiSelect = false; @@ -79,8 +79,9 @@ namespace CodeImp.DoomBuilder.Controls this.fieldslist.TabIndex = 1; this.fieldslist.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.fieldslist_UserDeletingRow); this.fieldslist.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.fieldslist_CellBeginEdit); - this.fieldslist.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.fieldslist_CellClick); this.fieldslist.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.fieldslist_CellEndEdit); + this.fieldslist.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.fieldslist_CellClick); + this.fieldslist.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.fieldslist_DataError); this.fieldslist.SelectionChanged += new System.EventHandler(this.fieldslist_SelectionChanged); // // deleterowstimer @@ -102,12 +103,12 @@ namespace CodeImp.DoomBuilder.Controls // // fieldname // - dataGridViewCellStyle13.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle13.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle13.NullValue = null; - dataGridViewCellStyle13.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle13.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - this.fieldname.DefaultCellStyle = dataGridViewCellStyle13; + dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle1.NullValue = null; + dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + this.fieldname.DefaultCellStyle = dataGridViewCellStyle1; this.fieldname.Frozen = true; this.fieldname.HeaderText = "Property"; this.fieldname.Name = "fieldname"; @@ -115,23 +116,25 @@ namespace CodeImp.DoomBuilder.Controls // // fieldtype // - dataGridViewCellStyle14.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle14.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle14.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle14.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - this.fieldtype.DefaultCellStyle = dataGridViewCellStyle14; + dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + this.fieldtype.DefaultCellStyle = dataGridViewCellStyle2; this.fieldtype.DisplayStyle = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing; this.fieldtype.HeaderText = "Type"; this.fieldtype.Name = "fieldtype"; this.fieldtype.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.fieldtype.Sorted = true; + this.fieldtype.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; // // fieldvalue // - dataGridViewCellStyle15.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle15.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle15.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle15.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - this.fieldvalue.DefaultCellStyle = dataGridViewCellStyle15; + dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + this.fieldvalue.DefaultCellStyle = dataGridViewCellStyle3; this.fieldvalue.HeaderText = "Value"; this.fieldvalue.Name = "fieldvalue"; this.fieldvalue.Resizable = System.Windows.Forms.DataGridViewTriState.True; diff --git a/Source/Controls/FieldsEditorControl.cs b/Source/Controls/FieldsEditorControl.cs index c434c396..c5bd3e6b 100644 --- a/Source/Controls/FieldsEditorControl.cs +++ b/Source/Controls/FieldsEditorControl.cs @@ -50,7 +50,7 @@ namespace CodeImp.DoomBuilder.Controls // Make types list fieldtype.Items.Clear(); - fieldtype.Items.AddRange(Enum.GetNames(typeof(UniversalFieldType))); + fieldtype.Items.AddRange(General.Types.GetCustomUseAttributes()); } // This adds a list of fixed fields (in undefined state) @@ -149,7 +149,7 @@ namespace CodeImp.DoomBuilder.Controls if((row.Cells[0].Value != null) && (row.Cells[0].Value.ToString().Trim().Length > 0)) { // Make new row - frow = new FieldsEditorRow(fieldslist, row.Cells[0].Value.ToString().Trim(), UniversalFieldType.Integer, 0); + frow = new FieldsEditorRow(fieldslist, row.Cells[0].Value.ToString().Trim(), 0, 0); frow.Visible = false; fieldslist.Rows.Insert(e.RowIndex + 1, frow); } @@ -163,7 +163,7 @@ namespace CodeImp.DoomBuilder.Controls if((e.ColumnIndex == 2) && (frow != null)) { // Defined? - if((row.Cells[2].Value != null) && (!frow.IsFixed || (frow.Info.DefaultStr != row.Cells[2].Value.ToString()))) + if((row.Cells[2].Value != null) && (!frow.IsFixed || (frow.Info.Default != row.Cells[2].Value))) frow.Define(row.Cells[2].Value); else if(frow.IsFixed) frow.Undefine(); @@ -217,15 +217,12 @@ namespace CodeImp.DoomBuilder.Controls // Get selected row row = fieldslist.SelectedRows[0]; if(row is FieldsEditorRow) frow = row as FieldsEditorRow; - + // Not the new row and FieldsEditorRow available? if((row.Index < fieldslist.NewRowIndex) && (frow != null)) { // Browse button available for this type? - if((frow.Type == UniversalFieldType.Flat) || - (frow.Type == UniversalFieldType.LinedefAction) || - (frow.Type == UniversalFieldType.SectorEffect) || - (frow.Type == UniversalFieldType.Texture)) + if(frow.TypeHandler.IsBrowseable) { Rectangle cellrect = fieldslist.GetCellDisplayRectangle(2, row.Index, false); @@ -234,6 +231,7 @@ namespace CodeImp.DoomBuilder.Controls browsebutton.Height = cellrect.Height; browsebutton.Visible = true; + /* // Determine image/text if((frow.Type == UniversalFieldType.SectorEffect) || (frow.Type == UniversalFieldType.LinedefAction)) @@ -246,6 +244,7 @@ namespace CodeImp.DoomBuilder.Controls browsebutton.Image = null; browsebutton.Text = "..."; } + */ } else { @@ -262,5 +261,10 @@ namespace CodeImp.DoomBuilder.Controls browsebutton.Visible = false; } } + + private void fieldslist_DataError(object sender, DataGridViewDataErrorEventArgs e) + { + e.ThrowException = false; + } } } diff --git a/Source/Controls/FieldsEditorRow.cs b/Source/Controls/FieldsEditorRow.cs index 34a151dc..896808e8 100644 --- a/Source/Controls/FieldsEditorRow.cs +++ b/Source/Controls/FieldsEditorRow.cs @@ -32,6 +32,7 @@ using SlimDX.Direct3D9; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Types; #endregion @@ -58,7 +59,7 @@ namespace CodeImp.DoomBuilder.Controls private bool isdefined; // Type - private UniversalFieldType fieldtype; + private TypeHandler fieldtype; #endregion @@ -66,7 +67,7 @@ namespace CodeImp.DoomBuilder.Controls public bool IsFixed { get { return isfixed; } } public bool IsDefined { get { return isdefined; } } - public UniversalFieldType Type { get { return fieldtype; } } + public TypeHandler TypeHandler { get { return fieldtype; } } public UniversalFieldInfo Info { get { return fieldinfo; } } #endregion @@ -85,7 +86,7 @@ namespace CodeImp.DoomBuilder.Controls isfixed = true; // Type - this.fieldtype = fixedfield.Type; + this.fieldtype = General.Types.GetFieldHandler(fixedfield.Type, fixedfield.Default); // Make all cells base.CreateCells(view); @@ -95,18 +96,18 @@ namespace CodeImp.DoomBuilder.Controls this.Cells[0].ReadOnly = true; // Setup type cell - this.Cells[1].Value = fixedfield.Type.ToString(); + this.Cells[1].Value = fieldtype.Attribute; this.Cells[1].ReadOnly = true; // Setup value cell - this.Cells[2].Value = fixedfield.DefaultStr; + this.Cells[2].Value = fieldtype.GetStringValue(); // We have no destructor GC.SuppressFinalize(this); } // Constructor for a non-fixed, defined field - public FieldsEditorRow(DataGridView view, string name, UniversalFieldType type, object value) + public FieldsEditorRow(DataGridView view, string name, int type, object value) { // Defined this.DefaultCellStyle.ForeColor = SystemColors.WindowText; @@ -116,7 +117,7 @@ namespace CodeImp.DoomBuilder.Controls isfixed = false; // Type - this.fieldtype = type; + this.fieldtype = General.Types.GetFieldHandler(type, value); // Make all cells base.CreateCells(view); @@ -126,11 +127,11 @@ namespace CodeImp.DoomBuilder.Controls this.Cells[0].ReadOnly = true; // Setup type cell - this.Cells[1].Value = type.ToString(); + this.Cells[1].Value = fieldtype.Attribute; this.Cells[1].ReadOnly = false; // Setup value cell - this.Cells[2].Value = value; + this.Cells[2].Value = fieldtype.GetStringValue(); // We have no destructor GC.SuppressFinalize(this); @@ -143,9 +144,25 @@ namespace CodeImp.DoomBuilder.Controls // This is called when a cell is edited public void CellChanged() { - // Update type from cell - try { fieldtype = (UniversalFieldType)Enum.Parse(typeof(UniversalFieldType), this.Cells[1].Value.ToString(), true); } - catch(Exception) { this.Cells[1].Value = fieldtype.ToString(); } + // This gdmn grid thing returns the chosen value as string instead + // of the object type I added to the combobox... + if(this.Cells[1].Value is string) + { + // Find the TypeHandlerAttribute with this name + TypeHandlerAttribute attrib = General.Types.GetNamedAttribute(this.Cells[1].Value.ToString()); + + // Different? + if(attrib.Index != fieldtype.Index) + { + // Change field type! + fieldtype = General.Types.GetFieldHandler(attrib.Index, this.Cells[2].Value); + this.Cells[1].Value = attrib; + } + } + + // Validate value + fieldtype.SetValue(this.Cells[2].Value); + this.Cells[2].Value = fieldtype.GetStringValue(); } // This undefines the field @@ -157,7 +174,7 @@ namespace CodeImp.DoomBuilder.Controls if(!isfixed) throw new InvalidOperationException(); // Now undefined - this.Cells[2].Value = fieldinfo.DefaultStr; + this.Cells[2].Value = fieldinfo.Default; this.DefaultCellStyle.ForeColor = SystemColors.GrayText; isdefined = false; } diff --git a/Source/IO/Configuration.cs b/Source/IO/Configuration.cs index fd6db960..612e962e 100644 --- a/Source/IO/Configuration.cs +++ b/Source/IO/Configuration.cs @@ -1112,6 +1112,8 @@ namespace CodeImp.DoomBuilder.IO public byte ReadSetting(string setting, byte defaultsetting, string pathseperator) { return Convert.ToByte(ReadAnySetting(setting, defaultsetting, pathseperator), CultureInfo.InvariantCulture); } public IDictionary ReadSetting(string setting, IDictionary defaultsetting) { return (IDictionary)ReadAnySetting(setting, defaultsetting, DEFAULT_SEPERATOR); } public IDictionary ReadSetting(string setting, IDictionary defaultsetting, string pathseperator) { return (IDictionary)ReadAnySetting(setting, defaultsetting, pathseperator); } + + public object ReadSettingObject(string setting, object defaultsetting) { return ReadAnySetting(setting, defaultsetting, DEFAULT_SEPERATOR); } // This writes a given setting to the configuration. diff --git a/Source/Types/BoolHandler.cs b/Source/Types/BoolHandler.cs index 8df8fa82..4c37ff83 100644 --- a/Source/Types/BoolHandler.cs +++ b/Source/Types/BoolHandler.cs @@ -30,7 +30,7 @@ using System.Diagnostics; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(3)] + [TypeHandler(3, "Boolean", true)] internal class BoolHandler : TypeHandler { #region ================== Constants @@ -45,8 +45,6 @@ namespace CodeImp.DoomBuilder.Types #region ================== Properties - public override bool IsCustomType { get { return true; } } - #endregion #region ================== Methods diff --git a/Source/Types/ColorHandler.cs b/Source/Types/ColorHandler.cs index beb30242..edd88d6b 100644 --- a/Source/Types/ColorHandler.cs +++ b/Source/Types/ColorHandler.cs @@ -34,7 +34,7 @@ using System.Drawing; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(10)] + [TypeHandler(10, "Color", true)] internal class ColorHandler : TypeHandler { #region ================== Constants @@ -50,7 +50,6 @@ namespace CodeImp.DoomBuilder.Types #region ================== Properties public override bool IsBrowseable { get { return true; } } - public override bool IsCustomType { get { return true; } } #endregion diff --git a/Source/Types/EnumBitsHandler.cs b/Source/Types/EnumBitsHandler.cs index 3f54fe6d..b7e6b568 100644 --- a/Source/Types/EnumBitsHandler.cs +++ b/Source/Types/EnumBitsHandler.cs @@ -33,7 +33,7 @@ using CodeImp.DoomBuilder.Windows; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(12)] + [TypeHandler(12, "Options", false)] internal class EnumBitsHandler : TypeHandler { #region ================== Constants @@ -56,9 +56,9 @@ namespace CodeImp.DoomBuilder.Types #region ================== Constructor // When set up for an argument - public override void SetupArgument(ArgumentInfo arginfo) + public override void SetupArgument(TypeHandlerAttribute attr, ArgumentInfo arginfo) { - base.SetupArgument(arginfo); + base.SetupArgument(attr, arginfo); // Keep enum list reference list = arginfo.Enum; diff --git a/Source/Types/EnumOptionHandler.cs b/Source/Types/EnumOptionHandler.cs index e10b6859..760540d2 100644 --- a/Source/Types/EnumOptionHandler.cs +++ b/Source/Types/EnumOptionHandler.cs @@ -31,7 +31,7 @@ using CodeImp.DoomBuilder.Config; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(11)] + [TypeHandler(11, "Setting", false)] internal class EnumOptionHandler : TypeHandler { #region ================== Constants @@ -55,9 +55,9 @@ namespace CodeImp.DoomBuilder.Types #region ================== Constructor // When set up for an argument - public override void SetupArgument(ArgumentInfo arginfo) + public override void SetupArgument(TypeHandlerAttribute attr, ArgumentInfo arginfo) { - base.SetupArgument(arginfo); + base.SetupArgument(attr, arginfo); // Keep enum list reference list = arginfo.Enum; diff --git a/Source/Types/FlatHandler.cs b/Source/Types/FlatHandler.cs index 9c3349f8..b2820b00 100644 --- a/Source/Types/FlatHandler.cs +++ b/Source/Types/FlatHandler.cs @@ -32,7 +32,7 @@ using CodeImp.DoomBuilder.Windows; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(7)] + [TypeHandler(7, "Flat", true)] internal class FlatHandler : TypeHandler { #region ================== Constants @@ -48,7 +48,6 @@ namespace CodeImp.DoomBuilder.Types #region ================== Properties public override bool IsBrowseable { get { return true; } } - public override bool IsCustomType { get { return true; } } #endregion diff --git a/Source/Types/FloatHandler.cs b/Source/Types/FloatHandler.cs index ba8c80ca..dd6ceeb4 100644 --- a/Source/Types/FloatHandler.cs +++ b/Source/Types/FloatHandler.cs @@ -30,7 +30,7 @@ using System.Diagnostics; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(1)] + [TypeHandler(1, "Float", true)] internal class FloatHandler : TypeHandler { #region ================== Constants @@ -45,8 +45,6 @@ namespace CodeImp.DoomBuilder.Types #region ================== Properties - public override bool IsCustomType { get { return true; } } - #endregion #region ================== Methods diff --git a/Source/Types/IntegerHandler.cs b/Source/Types/IntegerHandler.cs index 83dc873e..d0dacebb 100644 --- a/Source/Types/IntegerHandler.cs +++ b/Source/Types/IntegerHandler.cs @@ -30,7 +30,7 @@ using System.Diagnostics; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(0)] + [TypeHandler(0, "Integer", true)] internal class IntegerHandler : TypeHandler { #region ================== Constants @@ -45,8 +45,6 @@ namespace CodeImp.DoomBuilder.Types #region ================== Properties - public override bool IsCustomType { get { return true; } } - #endregion #region ================== Methods diff --git a/Source/Types/LinedefTypeHandler.cs b/Source/Types/LinedefTypeHandler.cs index da900020..aa8ee0ef 100644 --- a/Source/Types/LinedefTypeHandler.cs +++ b/Source/Types/LinedefTypeHandler.cs @@ -33,7 +33,7 @@ using System.Windows.Forms; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(4)] + [TypeHandler(4, "Linedef Action", true)] internal class LinedefTypeHandler : TypeHandler { #region ================== Constants @@ -49,7 +49,6 @@ namespace CodeImp.DoomBuilder.Types #region ================== Properties public override bool IsBrowseable { get { return true; } } - public override bool IsCustomType { get { return true; } } #endregion diff --git a/Source/Types/SectorEffectHandler.cs b/Source/Types/SectorEffectHandler.cs index ef8ab244..ace9d9df 100644 --- a/Source/Types/SectorEffectHandler.cs +++ b/Source/Types/SectorEffectHandler.cs @@ -33,7 +33,7 @@ using System.Windows.Forms; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(5)] + [TypeHandler(5, "Sector Effect", true)] internal class SectorEffectHandler : TypeHandler { #region ================== Constants @@ -49,7 +49,6 @@ namespace CodeImp.DoomBuilder.Types #region ================== Properties public override bool IsBrowseable { get { return true; } } - public override bool IsCustomType { get { return true; } } #endregion diff --git a/Source/Types/StringHandler.cs b/Source/Types/StringHandler.cs index 54cf2fa3..22d3eaad 100644 --- a/Source/Types/StringHandler.cs +++ b/Source/Types/StringHandler.cs @@ -30,7 +30,7 @@ using System.Diagnostics; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(2)] + [TypeHandler(2, "Text", true)] internal class StringHandler : TypeHandler { #region ================== Constants @@ -45,8 +45,6 @@ namespace CodeImp.DoomBuilder.Types #region ================== Properties - public override bool IsCustomType { get { return true; } } - #endregion #region ================== Methods diff --git a/Source/Types/TextureHandler.cs b/Source/Types/TextureHandler.cs index 764cd1b9..c762e521 100644 --- a/Source/Types/TextureHandler.cs +++ b/Source/Types/TextureHandler.cs @@ -32,7 +32,7 @@ using CodeImp.DoomBuilder.Windows; namespace CodeImp.DoomBuilder.Types { - [TypeHandler(6)] + [TypeHandler(6, "Texture", true)] internal class TextureHandler : TypeHandler { #region ================== Constants @@ -48,7 +48,6 @@ namespace CodeImp.DoomBuilder.Types #region ================== Properties public override bool IsBrowseable { get { return true; } } - public override bool IsCustomType { get { return true; } } #endregion diff --git a/Source/Types/TypeHandler.cs b/Source/Types/TypeHandler.cs index 09c73552..0962f6de 100644 --- a/Source/Types/TypeHandler.cs +++ b/Source/Types/TypeHandler.cs @@ -45,17 +45,22 @@ namespace CodeImp.DoomBuilder.Types #region ================== Variables protected int index; + protected string typename; + protected bool customusable; protected ArgumentInfo arginfo; + protected TypeHandlerAttribute attribute; #endregion #region ================== Properties public int Index { get { return index; } } + public string TypeName { get { return typename; } } + public bool IsCustomUsable { get { return customusable; } } + public TypeHandlerAttribute Attribute { get { return attribute; } } public virtual bool IsBrowseable { get { return false; } } public virtual bool IsEnumerable { get { return false; } } - public virtual bool IsCustomType { get { return false; } } #endregion @@ -64,25 +69,52 @@ namespace CodeImp.DoomBuilder.Types // Constructor public TypeHandler() { - // Get my attributes - object[] attrs = this.GetType().GetCustomAttributes(typeof(TypeHandlerAttribute), false); - if(attrs.Length > 0) + } + + // This sets up the handler for arguments + public virtual void SetupArgument(TypeHandlerAttribute attr, ArgumentInfo arginfo) + { + // Setup + this.arginfo = arginfo; + if(attr != null) { - // Set index from attribute - this.index = (attrs[0] as TypeHandlerAttribute).Index; + // Set attributes + this.attribute = attr; + this.index = attr.Index; + this.typename = attr.Name; + this.customusable = attr.IsCustomUsable; } else { // Indexless + this.attribute = null; this.index = -1; + this.typename = "Unknown"; + this.customusable = false; } } // This sets up the handler for arguments - public virtual void SetupArgument(ArgumentInfo arginfo) + public virtual void SetupField(TypeHandlerAttribute attr) { // Setup this.arginfo = arginfo; + if(attr != null) + { + // Set attributes + this.attribute = attr; + this.index = attr.Index; + this.typename = attr.Name; + this.customusable = attr.IsCustomUsable; + } + else + { + // Indexless + this.attribute = null; + this.index = -1; + this.typename = "Unknown"; + this.customusable = false; + } } #endregion @@ -112,8 +144,6 @@ namespace CodeImp.DoomBuilder.Types } // This must returns an enum list when IsEnumerable is true - // When the user chooses an enum from this list, it will be - // set using SetValue with the EnumItem as value. public virtual EnumList GetEnumList() { return null; diff --git a/Source/Types/TypeHandlerAttribute.cs b/Source/Types/TypeHandlerAttribute.cs index c5b575eb..09ef54d2 100644 --- a/Source/Types/TypeHandlerAttribute.cs +++ b/Source/Types/TypeHandlerAttribute.cs @@ -39,28 +39,42 @@ namespace CodeImp.DoomBuilder.Types #region ================== Variables private int index; - + private string name; + private Type type; + private bool customusable; + #endregion #region ================== Properties public int Index { get { return index; } } - + public string Name { get { return name; } } + public bool IsCustomUsable { get { return customusable; } } + public Type Type { get { return type; } set { type = value; } } + #endregion #region ================== Constructor / Destructor // Constructor - public TypeHandlerAttribute(int index) + public TypeHandlerAttribute(int index, string name, bool customusable) { // Initialize this.index = index; + this.name = name; + this.customusable = customusable; } #endregion #region ================== Methods + // String representation + public override string ToString() + { + return name; + } + #endregion } } diff --git a/Source/Types/TypesManager.cs b/Source/Types/TypesManager.cs index 12edbad2..bce1af34 100644 --- a/Source/Types/TypesManager.cs +++ b/Source/Types/TypesManager.cs @@ -40,7 +40,7 @@ namespace CodeImp.DoomBuilder.Types #region ================== Variables // List of handler types - private Dictionary handlertypes; + private Dictionary handlertypes; // Disposing private bool isdisposed = false; @@ -59,7 +59,7 @@ namespace CodeImp.DoomBuilder.Types public TypesManager() { // Initialize - handlertypes = new Dictionary(); + handlertypes = new Dictionary(); // Go for all types in this assembly Type[] types = General.ThisAssembly.GetTypes(); @@ -74,7 +74,8 @@ namespace CodeImp.DoomBuilder.Types // Add the type to the list object[] attribs = tp.GetCustomAttributes(typeof(TypeHandlerAttribute), false); TypeHandlerAttribute attr = (attribs[0] as TypeHandlerAttribute); - handlertypes.Add(attr.Index, tp); + attr.Type = tp; + handlertypes.Add(attr.Index, attr); } } } @@ -105,16 +106,62 @@ namespace CodeImp.DoomBuilder.Types public TypeHandler GetArgumentHandler(ArgumentInfo arginfo) { Type t = typeof(NullHandler); - + TypeHandlerAttribute ta = null; + // Do we have a handler type for this? - if(handlertypes.ContainsKey(arginfo.Type)) t = handlertypes[arginfo.Type]; + if(handlertypes.ContainsKey(arginfo.Type)) + { + ta = handlertypes[arginfo.Type]; + t = ta.Type; + } // Create instance TypeHandler th = (TypeHandler)General.ThisAssembly.CreateInstance(t.FullName); - th.SetupArgument(arginfo); + th.SetupArgument(ta, arginfo); return th; } + // This returns the type handler for a given universal field + public TypeHandler GetFieldHandler(int type, object defaultvalue) + { + Type t = typeof(NullHandler); + TypeHandlerAttribute ta = null; + + // Do we have a handler type for this? + if(handlertypes.ContainsKey(type)) + { + ta = handlertypes[type]; + t = ta.Type; + } + + // Create instance + TypeHandler th = (TypeHandler)General.ThisAssembly.CreateInstance(t.FullName); + th.SetupField(ta); + th.SetValue(defaultvalue); + return th; + } + + // This returns all custom attributes + public TypeHandlerAttribute[] GetCustomUseAttributes() + { + List attribs = new List(); + foreach(KeyValuePair ta in handlertypes) + if(ta.Value.IsCustomUsable) attribs.Add(ta.Value); + return attribs.ToArray(); + } + + // This returns the attribute with the give name + public TypeHandlerAttribute GetNamedAttribute(string name) + { + foreach(KeyValuePair ta in handlertypes) + { + if(ta.Value.Name == name) return ta.Value; + } + + // Nothing found + return null; + } + #endregion } } diff --git a/Source/Windows/LinedefEditForm.cs b/Source/Windows/LinedefEditForm.cs index bbe69a20..df7ebcf3 100644 --- a/Source/Windows/LinedefEditForm.cs +++ b/Source/Windows/LinedefEditForm.cs @@ -69,7 +69,7 @@ namespace CodeImp.DoomBuilder.Windows // Show appropriate panels/tabs doompanel.Visible = General.Map.IsType(typeof(DoomMapSetIO)); hexenpanel.Visible = General.Map.IsType(typeof(HexenMapSetIO)); - if(!General.Map.IsType(typeof(UniversalMapSetIO))) tabs.TabPages.Remove(tabcustom); + //if(!General.Map.IsType(typeof(UniversalMapSetIO))) tabs.TabPages.Remove(tabcustom); } // This sets up the form to edit the given lines