made the universal field editor control work with the type handlers

This commit is contained in:
codeimp 2008-05-30 11:05:44 +00:00
parent c2479dc0b5
commit a04500f071
25 changed files with 310 additions and 304 deletions

View file

@ -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 // DEFAULT SECTOR BRIGHTNESS LEVELS
sectorbrightness sectorbrightness
{ {

View file

@ -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! Only add fields here that Doom Builder does not edit with its own user-interface!
Field data types: Field data types:
0 = integer 0 = integer *
1 = float 1 = float
2 = string 2 = string
3 = bool 3 = bool
4 = linedeftype (integer) 4 = linedeftype (integer) *
5 = sectoreffect (integer) 5 = sectoreffect (integer) *
6 = texture (string) 6 = texture (string)
7 = flat (string) 7 = flat (string)
8 = angle in degrees (integer) 8 = angle in degrees (integer)
9 = angle in radians (float) 9 = angle in radians (float)
10 = XXRRGGBB color (integer) 10 = XXRRGGBB color (integer)
11 = enum option (integer) 11 = enum option (integer) *
12 = enum bits (integer) 12 = enum bits (integer) *
13 = sector tag (integer) 13 = sector tag (integer) *
14 = thing tag (integer) 14 = thing tag (integer) *
15 = linedef tag (integer) 15 = linedef tag (integer) *
16 = enum option (string)
*/ */
universalfields universalfields
{ {
@ -251,21 +252,27 @@ universalfields
colormap colormap
{ {
type = 2; type = 10;
default = ""; default = 0;
} }
normalmap normalmap
{ {
type = 5; type = 6;
default = ""; default = "";
} }
second_action second_action
{ {
type = 3; type = 4;
default = 0; default = 0;
} }
hidden
{
type = 3;
default = false;
}
} }
} }

View file

@ -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 // DEFAULT SECTOR BRIGHTNESS LEVELS
sectorbrightness sectorbrightness
{ {

View file

@ -62,7 +62,6 @@
<Compile Include="Config\ThingCategory.cs" /> <Compile Include="Config\ThingCategory.cs" />
<Compile Include="Config\ThingTypeInfo.cs" /> <Compile Include="Config\ThingTypeInfo.cs" />
<Compile Include="Config\UniversalFieldInfo.cs" /> <Compile Include="Config\UniversalFieldInfo.cs" />
<Compile Include="Config\UniversalFieldType.cs" />
<Compile Include="Actions\ActionAttribute.cs" /> <Compile Include="Actions\ActionAttribute.cs" />
<Compile Include="Actions\BeginActionAttribute.cs" /> <Compile Include="Actions\BeginActionAttribute.cs" />
<Compile Include="Actions\EndActionAttribute.cs" /> <Compile Include="Actions\EndActionAttribute.cs" />

View file

@ -42,20 +42,16 @@ namespace CodeImp.DoomBuilder.Config
// Properties // Properties
private string name; private string name;
private UniversalFieldType type; private int type;
private string defstring; private object defaultvalue;
private int defint;
private float deffloat;
#endregion #endregion
#region ================== Properties #region ================== Properties
public string Name { get { return name; } } public string Name { get { return name; } }
public UniversalFieldType Type { get { return type; } } public int Type { get { return type; } }
public string DefaultStr { get { return defstring; } } public object Default { get { return defaultvalue; } }
public int DefaultInt { get { return defint; } }
public float DefaultFloat { get { return deffloat; } }
#endregion #endregion
@ -70,35 +66,8 @@ namespace CodeImp.DoomBuilder.Config
this.name = name; this.name = name;
// Read type // Read type
this.type = (UniversalFieldType)cfg.ReadSetting(setting + ".type", 0); this.type = cfg.ReadSetting(setting + ".type", 0);
switch(this.type) this.defaultvalue = cfg.ReadSettingObject(setting + ".default", null);
{
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;
}
// We have no destructor // We have no destructor
GC.SuppressFinalize(this); GC.SuppressFinalize(this);

View file

@ -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
}
}

View file

@ -29,10 +29,10 @@ namespace CodeImp.DoomBuilder.Controls
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle16 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle13 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle14 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle15 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
this.fieldslist = new System.Windows.Forms.DataGridView(); this.fieldslist = new System.Windows.Forms.DataGridView();
this.deleterowstimer = new System.Windows.Forms.Timer(this.components); this.deleterowstimer = new System.Windows.Forms.Timer(this.components);
this.browsebutton = new System.Windows.Forms.Button(); this.browsebutton = new System.Windows.Forms.Button();
@ -56,14 +56,14 @@ namespace CodeImp.DoomBuilder.Controls
this.fieldname, this.fieldname,
this.fieldtype, this.fieldtype,
this.fieldvalue}); this.fieldvalue});
dataGridViewCellStyle16.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle16.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle4.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))); dataGridViewCellStyle4.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; dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle16.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle16.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle16.WrapMode = System.Windows.Forms.DataGridViewTriState.False; dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.fieldslist.DefaultCellStyle = dataGridViewCellStyle16; this.fieldslist.DefaultCellStyle = dataGridViewCellStyle4;
this.fieldslist.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this.fieldslist.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically;
this.fieldslist.Location = new System.Drawing.Point(0, 0); this.fieldslist.Location = new System.Drawing.Point(0, 0);
this.fieldslist.MultiSelect = false; this.fieldslist.MultiSelect = false;
@ -79,8 +79,9 @@ namespace CodeImp.DoomBuilder.Controls
this.fieldslist.TabIndex = 1; this.fieldslist.TabIndex = 1;
this.fieldslist.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.fieldslist_UserDeletingRow); this.fieldslist.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.fieldslist_UserDeletingRow);
this.fieldslist.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.fieldslist_CellBeginEdit); 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.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); this.fieldslist.SelectionChanged += new System.EventHandler(this.fieldslist_SelectionChanged);
// //
// deleterowstimer // deleterowstimer
@ -102,12 +103,12 @@ namespace CodeImp.DoomBuilder.Controls
// //
// fieldname // fieldname
// //
dataGridViewCellStyle13.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle13.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle13.NullValue = null; dataGridViewCellStyle1.NullValue = null;
dataGridViewCellStyle13.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle13.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.fieldname.DefaultCellStyle = dataGridViewCellStyle13; this.fieldname.DefaultCellStyle = dataGridViewCellStyle1;
this.fieldname.Frozen = true; this.fieldname.Frozen = true;
this.fieldname.HeaderText = "Property"; this.fieldname.HeaderText = "Property";
this.fieldname.Name = "fieldname"; this.fieldname.Name = "fieldname";
@ -115,23 +116,25 @@ namespace CodeImp.DoomBuilder.Controls
// //
// fieldtype // fieldtype
// //
dataGridViewCellStyle14.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle14.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle14.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle14.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.fieldtype.DefaultCellStyle = dataGridViewCellStyle14; this.fieldtype.DefaultCellStyle = dataGridViewCellStyle2;
this.fieldtype.DisplayStyle = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing; this.fieldtype.DisplayStyle = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing;
this.fieldtype.HeaderText = "Type"; this.fieldtype.HeaderText = "Type";
this.fieldtype.Name = "fieldtype"; this.fieldtype.Name = "fieldtype";
this.fieldtype.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.fieldtype.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.fieldtype.Sorted = true;
this.fieldtype.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
// //
// fieldvalue // fieldvalue
// //
dataGridViewCellStyle15.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle15.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle15.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle15.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.fieldvalue.DefaultCellStyle = dataGridViewCellStyle15; this.fieldvalue.DefaultCellStyle = dataGridViewCellStyle3;
this.fieldvalue.HeaderText = "Value"; this.fieldvalue.HeaderText = "Value";
this.fieldvalue.Name = "fieldvalue"; this.fieldvalue.Name = "fieldvalue";
this.fieldvalue.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.fieldvalue.Resizable = System.Windows.Forms.DataGridViewTriState.True;

View file

@ -50,7 +50,7 @@ namespace CodeImp.DoomBuilder.Controls
// Make types list // Make types list
fieldtype.Items.Clear(); 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) // 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)) if((row.Cells[0].Value != null) && (row.Cells[0].Value.ToString().Trim().Length > 0))
{ {
// Make new row // 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; frow.Visible = false;
fieldslist.Rows.Insert(e.RowIndex + 1, frow); fieldslist.Rows.Insert(e.RowIndex + 1, frow);
} }
@ -163,7 +163,7 @@ namespace CodeImp.DoomBuilder.Controls
if((e.ColumnIndex == 2) && (frow != null)) if((e.ColumnIndex == 2) && (frow != null))
{ {
// Defined? // 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); frow.Define(row.Cells[2].Value);
else if(frow.IsFixed) else if(frow.IsFixed)
frow.Undefine(); frow.Undefine();
@ -222,10 +222,7 @@ namespace CodeImp.DoomBuilder.Controls
if((row.Index < fieldslist.NewRowIndex) && (frow != null)) if((row.Index < fieldslist.NewRowIndex) && (frow != null))
{ {
// Browse button available for this type? // Browse button available for this type?
if((frow.Type == UniversalFieldType.Flat) || if(frow.TypeHandler.IsBrowseable)
(frow.Type == UniversalFieldType.LinedefAction) ||
(frow.Type == UniversalFieldType.SectorEffect) ||
(frow.Type == UniversalFieldType.Texture))
{ {
Rectangle cellrect = fieldslist.GetCellDisplayRectangle(2, row.Index, false); Rectangle cellrect = fieldslist.GetCellDisplayRectangle(2, row.Index, false);
@ -234,6 +231,7 @@ namespace CodeImp.DoomBuilder.Controls
browsebutton.Height = cellrect.Height; browsebutton.Height = cellrect.Height;
browsebutton.Visible = true; browsebutton.Visible = true;
/*
// Determine image/text // Determine image/text
if((frow.Type == UniversalFieldType.SectorEffect) || if((frow.Type == UniversalFieldType.SectorEffect) ||
(frow.Type == UniversalFieldType.LinedefAction)) (frow.Type == UniversalFieldType.LinedefAction))
@ -246,6 +244,7 @@ namespace CodeImp.DoomBuilder.Controls
browsebutton.Image = null; browsebutton.Image = null;
browsebutton.Text = "..."; browsebutton.Text = "...";
} }
*/
} }
else else
{ {
@ -262,5 +261,10 @@ namespace CodeImp.DoomBuilder.Controls
browsebutton.Visible = false; browsebutton.Visible = false;
} }
} }
private void fieldslist_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
e.ThrowException = false;
}
} }
} }

View file

@ -32,6 +32,7 @@ using SlimDX.Direct3D9;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using CodeImp.DoomBuilder.Map; using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Types;
#endregion #endregion
@ -58,7 +59,7 @@ namespace CodeImp.DoomBuilder.Controls
private bool isdefined; private bool isdefined;
// Type // Type
private UniversalFieldType fieldtype; private TypeHandler fieldtype;
#endregion #endregion
@ -66,7 +67,7 @@ namespace CodeImp.DoomBuilder.Controls
public bool IsFixed { get { return isfixed; } } public bool IsFixed { get { return isfixed; } }
public bool IsDefined { get { return isdefined; } } public bool IsDefined { get { return isdefined; } }
public UniversalFieldType Type { get { return fieldtype; } } public TypeHandler TypeHandler { get { return fieldtype; } }
public UniversalFieldInfo Info { get { return fieldinfo; } } public UniversalFieldInfo Info { get { return fieldinfo; } }
#endregion #endregion
@ -85,7 +86,7 @@ namespace CodeImp.DoomBuilder.Controls
isfixed = true; isfixed = true;
// Type // Type
this.fieldtype = fixedfield.Type; this.fieldtype = General.Types.GetFieldHandler(fixedfield.Type, fixedfield.Default);
// Make all cells // Make all cells
base.CreateCells(view); base.CreateCells(view);
@ -95,18 +96,18 @@ namespace CodeImp.DoomBuilder.Controls
this.Cells[0].ReadOnly = true; this.Cells[0].ReadOnly = true;
// Setup type cell // Setup type cell
this.Cells[1].Value = fixedfield.Type.ToString(); this.Cells[1].Value = fieldtype.Attribute;
this.Cells[1].ReadOnly = true; this.Cells[1].ReadOnly = true;
// Setup value cell // Setup value cell
this.Cells[2].Value = fixedfield.DefaultStr; this.Cells[2].Value = fieldtype.GetStringValue();
// We have no destructor // We have no destructor
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
// Constructor for a non-fixed, defined field // 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 // Defined
this.DefaultCellStyle.ForeColor = SystemColors.WindowText; this.DefaultCellStyle.ForeColor = SystemColors.WindowText;
@ -116,7 +117,7 @@ namespace CodeImp.DoomBuilder.Controls
isfixed = false; isfixed = false;
// Type // Type
this.fieldtype = type; this.fieldtype = General.Types.GetFieldHandler(type, value);
// Make all cells // Make all cells
base.CreateCells(view); base.CreateCells(view);
@ -126,11 +127,11 @@ namespace CodeImp.DoomBuilder.Controls
this.Cells[0].ReadOnly = true; this.Cells[0].ReadOnly = true;
// Setup type cell // Setup type cell
this.Cells[1].Value = type.ToString(); this.Cells[1].Value = fieldtype.Attribute;
this.Cells[1].ReadOnly = false; this.Cells[1].ReadOnly = false;
// Setup value cell // Setup value cell
this.Cells[2].Value = value; this.Cells[2].Value = fieldtype.GetStringValue();
// We have no destructor // We have no destructor
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
@ -143,9 +144,25 @@ namespace CodeImp.DoomBuilder.Controls
// This is called when a cell is edited // This is called when a cell is edited
public void CellChanged() public void CellChanged()
{ {
// Update type from cell // This gdmn grid thing returns the chosen value as string instead
try { fieldtype = (UniversalFieldType)Enum.Parse(typeof(UniversalFieldType), this.Cells[1].Value.ToString(), true); } // of the object type I added to the combobox...
catch(Exception) { this.Cells[1].Value = fieldtype.ToString(); } 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 // This undefines the field
@ -157,7 +174,7 @@ namespace CodeImp.DoomBuilder.Controls
if(!isfixed) throw new InvalidOperationException(); if(!isfixed) throw new InvalidOperationException();
// Now undefined // Now undefined
this.Cells[2].Value = fieldinfo.DefaultStr; this.Cells[2].Value = fieldinfo.Default;
this.DefaultCellStyle.ForeColor = SystemColors.GrayText; this.DefaultCellStyle.ForeColor = SystemColors.GrayText;
isdefined = false; isdefined = false;
} }

View file

@ -1113,6 +1113,8 @@ namespace CodeImp.DoomBuilder.IO
public IDictionary ReadSetting(string setting, IDictionary defaultsetting) { return (IDictionary)ReadAnySetting(setting, defaultsetting, DEFAULT_SEPERATOR); } 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 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. // This writes a given setting to the configuration.
// Wont change existing structs, but will add them as needed. // Wont change existing structs, but will add them as needed.

View file

@ -30,7 +30,7 @@ using System.Diagnostics;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(3)] [TypeHandler(3, "Boolean", true)]
internal class BoolHandler : TypeHandler internal class BoolHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -45,8 +45,6 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Properties #region ================== Properties
public override bool IsCustomType { get { return true; } }
#endregion #endregion
#region ================== Methods #region ================== Methods

View file

@ -34,7 +34,7 @@ using System.Drawing;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(10)] [TypeHandler(10, "Color", true)]
internal class ColorHandler : TypeHandler internal class ColorHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -50,7 +50,6 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Properties #region ================== Properties
public override bool IsBrowseable { get { return true; } } public override bool IsBrowseable { get { return true; } }
public override bool IsCustomType { get { return true; } }
#endregion #endregion

View file

@ -33,7 +33,7 @@ using CodeImp.DoomBuilder.Windows;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(12)] [TypeHandler(12, "Options", false)]
internal class EnumBitsHandler : TypeHandler internal class EnumBitsHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -56,9 +56,9 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Constructor #region ================== Constructor
// When set up for an argument // 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 // Keep enum list reference
list = arginfo.Enum; list = arginfo.Enum;

View file

@ -31,7 +31,7 @@ using CodeImp.DoomBuilder.Config;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(11)] [TypeHandler(11, "Setting", false)]
internal class EnumOptionHandler : TypeHandler internal class EnumOptionHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -55,9 +55,9 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Constructor #region ================== Constructor
// When set up for an argument // 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 // Keep enum list reference
list = arginfo.Enum; list = arginfo.Enum;

View file

@ -32,7 +32,7 @@ using CodeImp.DoomBuilder.Windows;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(7)] [TypeHandler(7, "Flat", true)]
internal class FlatHandler : TypeHandler internal class FlatHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -48,7 +48,6 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Properties #region ================== Properties
public override bool IsBrowseable { get { return true; } } public override bool IsBrowseable { get { return true; } }
public override bool IsCustomType { get { return true; } }
#endregion #endregion

View file

@ -30,7 +30,7 @@ using System.Diagnostics;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(1)] [TypeHandler(1, "Float", true)]
internal class FloatHandler : TypeHandler internal class FloatHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -45,8 +45,6 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Properties #region ================== Properties
public override bool IsCustomType { get { return true; } }
#endregion #endregion
#region ================== Methods #region ================== Methods

View file

@ -30,7 +30,7 @@ using System.Diagnostics;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(0)] [TypeHandler(0, "Integer", true)]
internal class IntegerHandler : TypeHandler internal class IntegerHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -45,8 +45,6 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Properties #region ================== Properties
public override bool IsCustomType { get { return true; } }
#endregion #endregion
#region ================== Methods #region ================== Methods

View file

@ -33,7 +33,7 @@ using System.Windows.Forms;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(4)] [TypeHandler(4, "Linedef Action", true)]
internal class LinedefTypeHandler : TypeHandler internal class LinedefTypeHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -49,7 +49,6 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Properties #region ================== Properties
public override bool IsBrowseable { get { return true; } } public override bool IsBrowseable { get { return true; } }
public override bool IsCustomType { get { return true; } }
#endregion #endregion

View file

@ -33,7 +33,7 @@ using System.Windows.Forms;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(5)] [TypeHandler(5, "Sector Effect", true)]
internal class SectorEffectHandler : TypeHandler internal class SectorEffectHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -49,7 +49,6 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Properties #region ================== Properties
public override bool IsBrowseable { get { return true; } } public override bool IsBrowseable { get { return true; } }
public override bool IsCustomType { get { return true; } }
#endregion #endregion

View file

@ -30,7 +30,7 @@ using System.Diagnostics;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(2)] [TypeHandler(2, "Text", true)]
internal class StringHandler : TypeHandler internal class StringHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -45,8 +45,6 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Properties #region ================== Properties
public override bool IsCustomType { get { return true; } }
#endregion #endregion
#region ================== Methods #region ================== Methods

View file

@ -32,7 +32,7 @@ using CodeImp.DoomBuilder.Windows;
namespace CodeImp.DoomBuilder.Types namespace CodeImp.DoomBuilder.Types
{ {
[TypeHandler(6)] [TypeHandler(6, "Texture", true)]
internal class TextureHandler : TypeHandler internal class TextureHandler : TypeHandler
{ {
#region ================== Constants #region ================== Constants
@ -48,7 +48,6 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Properties #region ================== Properties
public override bool IsBrowseable { get { return true; } } public override bool IsBrowseable { get { return true; } }
public override bool IsCustomType { get { return true; } }
#endregion #endregion

View file

@ -45,17 +45,22 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Variables #region ================== Variables
protected int index; protected int index;
protected string typename;
protected bool customusable;
protected ArgumentInfo arginfo; protected ArgumentInfo arginfo;
protected TypeHandlerAttribute attribute;
#endregion #endregion
#region ================== Properties #region ================== Properties
public int Index { get { return index; } } 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 IsBrowseable { get { return false; } }
public virtual bool IsEnumerable { get { return false; } } public virtual bool IsEnumerable { get { return false; } }
public virtual bool IsCustomType { get { return false; } }
#endregion #endregion
@ -64,25 +69,52 @@ namespace CodeImp.DoomBuilder.Types
// Constructor // Constructor
public TypeHandler() 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)
{ {
// Set index from attribute // Setup
this.index = (attrs[0] as TypeHandlerAttribute).Index; this.arginfo = arginfo;
if(attr != null)
{
// Set attributes
this.attribute = attr;
this.index = attr.Index;
this.typename = attr.Name;
this.customusable = attr.IsCustomUsable;
} }
else else
{ {
// Indexless // Indexless
this.attribute = null;
this.index = -1; this.index = -1;
this.typename = "Unknown";
this.customusable = false;
} }
} }
// This sets up the handler for arguments // This sets up the handler for arguments
public virtual void SetupArgument(ArgumentInfo arginfo) public virtual void SetupField(TypeHandlerAttribute attr)
{ {
// Setup // Setup
this.arginfo = arginfo; 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 #endregion
@ -112,8 +144,6 @@ namespace CodeImp.DoomBuilder.Types
} }
// This must returns an enum list when IsEnumerable is true // 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() public virtual EnumList GetEnumList()
{ {
return null; return null;

View file

@ -39,28 +39,42 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Variables #region ================== Variables
private int index; private int index;
private string name;
private Type type;
private bool customusable;
#endregion #endregion
#region ================== Properties #region ================== Properties
public int Index { get { return index; } } 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 #endregion
#region ================== Constructor / Destructor #region ================== Constructor / Destructor
// Constructor // Constructor
public TypeHandlerAttribute(int index) public TypeHandlerAttribute(int index, string name, bool customusable)
{ {
// Initialize // Initialize
this.index = index; this.index = index;
this.name = name;
this.customusable = customusable;
} }
#endregion #endregion
#region ================== Methods #region ================== Methods
// String representation
public override string ToString()
{
return name;
}
#endregion #endregion
} }
} }

View file

@ -40,7 +40,7 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Variables #region ================== Variables
// List of handler types // List of handler types
private Dictionary<int, Type> handlertypes; private Dictionary<int, TypeHandlerAttribute> handlertypes;
// Disposing // Disposing
private bool isdisposed = false; private bool isdisposed = false;
@ -59,7 +59,7 @@ namespace CodeImp.DoomBuilder.Types
public TypesManager() public TypesManager()
{ {
// Initialize // Initialize
handlertypes = new Dictionary<int, Type>(); handlertypes = new Dictionary<int, TypeHandlerAttribute>();
// Go for all types in this assembly // Go for all types in this assembly
Type[] types = General.ThisAssembly.GetTypes(); Type[] types = General.ThisAssembly.GetTypes();
@ -74,7 +74,8 @@ namespace CodeImp.DoomBuilder.Types
// Add the type to the list // Add the type to the list
object[] attribs = tp.GetCustomAttributes(typeof(TypeHandlerAttribute), false); object[] attribs = tp.GetCustomAttributes(typeof(TypeHandlerAttribute), false);
TypeHandlerAttribute attr = (attribs[0] as TypeHandlerAttribute); 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) public TypeHandler GetArgumentHandler(ArgumentInfo arginfo)
{ {
Type t = typeof(NullHandler); Type t = typeof(NullHandler);
TypeHandlerAttribute ta = null;
// Do we have a handler type for this? // 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 // Create instance
TypeHandler th = (TypeHandler)General.ThisAssembly.CreateInstance(t.FullName); TypeHandler th = (TypeHandler)General.ThisAssembly.CreateInstance(t.FullName);
th.SetupArgument(arginfo); th.SetupArgument(ta, arginfo);
return th; 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<TypeHandlerAttribute> attribs = new List<TypeHandlerAttribute>();
foreach(KeyValuePair<int, TypeHandlerAttribute> 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<int, TypeHandlerAttribute> ta in handlertypes)
{
if(ta.Value.Name == name) return ta.Value;
}
// Nothing found
return null;
}
#endregion #endregion
} }
} }

View file

@ -69,7 +69,7 @@ namespace CodeImp.DoomBuilder.Windows
// Show appropriate panels/tabs // Show appropriate panels/tabs
doompanel.Visible = General.Map.IsType(typeof(DoomMapSetIO)); doompanel.Visible = General.Map.IsType(typeof(DoomMapSetIO));
hexenpanel.Visible = General.Map.IsType(typeof(HexenMapSetIO)); 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 // This sets up the form to edit the given lines