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
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!
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;
}
}
}

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
sectorbrightness
{

View file

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

View file

@ -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);

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()
{
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;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -40,7 +40,7 @@ namespace CodeImp.DoomBuilder.Types
#region ================== Variables
// List of handler types
private Dictionary<int, Type> handlertypes;
private Dictionary<int, TypeHandlerAttribute> handlertypes;
// Disposing
private bool isdisposed = false;
@ -59,7 +59,7 @@ namespace CodeImp.DoomBuilder.Types
public TypesManager()
{
// Initialize
handlertypes = new Dictionary<int, Type>();
handlertypes = new Dictionary<int, TypeHandlerAttribute>();
// 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<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
}
}

View file

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