mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-26 13:51:40 +00:00
more work on the custom fields editor
This commit is contained in:
parent
aa398bcf70
commit
e640dfbc04
14 changed files with 328 additions and 66 deletions
|
@ -357,7 +357,7 @@ universalfields
|
|||
type = 1;
|
||||
default = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
xscalefloor
|
||||
{
|
||||
type = 1;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
- Finish the custom fields editor
|
||||
- Enums should drop down in list
|
||||
- Remember sort order
|
||||
- Booleans should be enumerable (dropdown true/false)
|
||||
- Strings should have a mutliline edit window on browse button
|
||||
|
||||
- Complete Things filter with UDMF fields
|
||||
|
|
|
@ -47,6 +47,11 @@ namespace CodeImp.DoomBuilder.Config
|
|||
|
||||
#region ================== Constructor
|
||||
|
||||
// Constructor for custom list
|
||||
internal EnumList()
|
||||
{
|
||||
}
|
||||
|
||||
// Constructor to load from dictionary
|
||||
internal EnumList(IDictionary dic)
|
||||
{
|
||||
|
|
|
@ -265,7 +265,7 @@ namespace CodeImp.DoomBuilder.Config
|
|||
try
|
||||
{
|
||||
// Read the field info and add to list
|
||||
uf = new UniversalFieldInfo(elementname, de.Key.ToString(), cfg);
|
||||
uf = new UniversalFieldInfo(elementname, de.Key.ToString(), cfg, enums);
|
||||
list.Add(uf);
|
||||
}
|
||||
catch(Exception)
|
||||
|
|
|
@ -44,6 +44,7 @@ namespace CodeImp.DoomBuilder.Config
|
|||
private string name;
|
||||
private int type;
|
||||
private object defaultvalue;
|
||||
private EnumList enumlist;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -52,13 +53,14 @@ namespace CodeImp.DoomBuilder.Config
|
|||
public string Name { get { return name; } }
|
||||
public int Type { get { return type; } }
|
||||
public object Default { get { return defaultvalue; } }
|
||||
public EnumList Enum { get { return enumlist; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
internal UniversalFieldInfo(string path, string name, Configuration cfg)
|
||||
internal UniversalFieldInfo(string path, string name, Configuration cfg, IDictionary<string, EnumList> enums)
|
||||
{
|
||||
string setting = "universalfields." + path + "." + name;
|
||||
|
||||
|
@ -69,6 +71,23 @@ namespace CodeImp.DoomBuilder.Config
|
|||
this.type = cfg.ReadSetting(setting + ".type", 0);
|
||||
this.defaultvalue = cfg.ReadSettingObject(setting + ".default", null);
|
||||
|
||||
// Read enum
|
||||
object enumsetting = cfg.ReadSettingObject(setting + ".enum", null);
|
||||
if(enumsetting != null)
|
||||
{
|
||||
// Reference to existing enums list?
|
||||
if(enumsetting is string)
|
||||
{
|
||||
// Link to it
|
||||
enumlist = enums[enumsetting.ToString()];
|
||||
}
|
||||
else if(enumsetting is IDictionary)
|
||||
{
|
||||
// Make list
|
||||
enumlist = new EnumList(enumsetting as IDictionary);
|
||||
}
|
||||
}
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
|
30
Source/Controls/FieldsEditorControl.Designer.cs
generated
30
Source/Controls/FieldsEditorControl.Designer.cs
generated
|
@ -39,6 +39,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
this.fieldvalue = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.deleterowstimer = new System.Windows.Forms.Timer(this.components);
|
||||
this.browsebutton = new System.Windows.Forms.Button();
|
||||
this.enumscombo = new System.Windows.Forms.ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.fieldslist)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
|
@ -58,7 +59,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
this.fieldvalue});
|
||||
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.Font = new System.Drawing.Font("Arial", 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;
|
||||
|
@ -75,13 +76,15 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
this.fieldslist.RowTemplate.DefaultCellStyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||
this.fieldslist.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.fieldslist.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||
this.fieldslist.Size = new System.Drawing.Size(444, 244);
|
||||
this.fieldslist.Size = new System.Drawing.Size(444, 263);
|
||||
this.fieldslist.TabIndex = 1;
|
||||
this.fieldslist.Scroll += new System.Windows.Forms.ScrollEventHandler(this.fieldslist_Scroll);
|
||||
this.fieldslist.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.fieldslist_UserDeletingRow);
|
||||
this.fieldslist.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.fieldslist_CellBeginEdit);
|
||||
this.fieldslist.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.fieldslist_CellDoubleClick);
|
||||
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);
|
||||
//
|
||||
// fieldname
|
||||
|
@ -99,6 +102,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
//
|
||||
// fieldtype
|
||||
//
|
||||
this.fieldtype.AutoComplete = false;
|
||||
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
|
||||
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||
|
@ -133,22 +137,33 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
this.browsebutton.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.browsebutton.Image = global::CodeImp.DoomBuilder.Properties.Resources.treeview;
|
||||
this.browsebutton.ImageAlign = System.Drawing.ContentAlignment.BottomCenter;
|
||||
this.browsebutton.Location = new System.Drawing.Point(370, 43);
|
||||
this.browsebutton.Location = new System.Drawing.Point(370, 46);
|
||||
this.browsebutton.Name = "browsebutton";
|
||||
this.browsebutton.Size = new System.Drawing.Size(30, 24);
|
||||
this.browsebutton.Size = new System.Drawing.Size(28, 26);
|
||||
this.browsebutton.TabIndex = 2;
|
||||
this.browsebutton.UseVisualStyleBackColor = true;
|
||||
this.browsebutton.Visible = false;
|
||||
this.browsebutton.Click += new System.EventHandler(this.browsebutton_Click);
|
||||
//
|
||||
// enumscombo
|
||||
//
|
||||
this.enumscombo.FormattingEnabled = true;
|
||||
this.enumscombo.ItemHeight = 14;
|
||||
this.enumscombo.Location = new System.Drawing.Point(295, 121);
|
||||
this.enumscombo.Name = "enumscombo";
|
||||
this.enumscombo.Size = new System.Drawing.Size(128, 22);
|
||||
this.enumscombo.TabIndex = 3;
|
||||
this.enumscombo.Validating += new System.ComponentModel.CancelEventHandler(this.enumscombo_Validating);
|
||||
//
|
||||
// FieldsEditorControl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.Controls.Add(this.enumscombo);
|
||||
this.Controls.Add(this.browsebutton);
|
||||
this.Controls.Add(this.fieldslist);
|
||||
this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.Name = "FieldsEditorControl";
|
||||
this.Size = new System.Drawing.Size(474, 266);
|
||||
this.Size = new System.Drawing.Size(474, 286);
|
||||
this.Layout += new System.Windows.Forms.LayoutEventHandler(this.FieldsEditorControl_Layout);
|
||||
this.Resize += new System.EventHandler(this.FieldsEditorControl_Resize);
|
||||
((System.ComponentModel.ISupportInitialize)(this.fieldslist)).EndInit();
|
||||
|
@ -161,6 +176,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
private System.Windows.Forms.DataGridView fieldslist;
|
||||
private System.Windows.Forms.Timer deleterowstimer;
|
||||
private System.Windows.Forms.Button browsebutton;
|
||||
private System.Windows.Forms.ComboBox enumscombo;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn fieldname;
|
||||
private System.Windows.Forms.DataGridViewComboBoxColumn fieldtype;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn fieldvalue;
|
||||
|
|
|
@ -40,19 +40,33 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
{
|
||||
public partial class FieldsEditorControl : UserControl
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
// Constants
|
||||
private const string ADD_FIELD_TEXT = " (click to add custom field)";
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
// Variables
|
||||
private string elementname;
|
||||
private string lasteditfieldname;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor
|
||||
|
||||
// Constructor
|
||||
public FieldsEditorControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Setup / Apply
|
||||
|
||||
// This sets up the control
|
||||
public void Setup(string elementname)
|
||||
{
|
||||
|
@ -211,18 +225,9 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
}
|
||||
}
|
||||
|
||||
// This sets up the new row
|
||||
private void SetupNewRowStyle()
|
||||
{
|
||||
// Show text for new row
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[0].Value = ADD_FIELD_TEXT;
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[0].Style.ForeColor = SystemColors.GrayText;
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[0].ReadOnly = false;
|
||||
|
||||
// Make sure user can only enter property name in a new row
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[1].ReadOnly = true;
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[2].ReadOnly = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ================== Events
|
||||
|
||||
// Resized
|
||||
private void FieldsEditorControl_Resize(object sender, EventArgs e)
|
||||
|
@ -241,6 +246,8 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// Cell clicked
|
||||
private void fieldslist_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
ApplyEnums(true);
|
||||
|
||||
// Edit immediately
|
||||
if(fieldslist.SelectedCells.Count > 0) fieldslist.BeginEdit(true);
|
||||
}
|
||||
|
@ -290,7 +297,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// User selects a cell for editing
|
||||
private void fieldslist_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
|
||||
{
|
||||
// Property cell?
|
||||
// Field name cell?
|
||||
if(e.ColumnIndex == 0)
|
||||
{
|
||||
// New row index?
|
||||
|
@ -301,6 +308,62 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
fieldslist.Rows[e.RowIndex].Cells[0].Value = "";
|
||||
}
|
||||
}
|
||||
// Value cell?
|
||||
else if(e.ColumnIndex == 2)
|
||||
{
|
||||
// Get the row
|
||||
FieldsEditorRow frow = null;
|
||||
DataGridViewRow row = fieldslist.Rows[e.RowIndex];
|
||||
if(row is FieldsEditorRow)
|
||||
{
|
||||
// Get specializedrow
|
||||
frow = row as FieldsEditorRow;
|
||||
|
||||
// Enumerable?
|
||||
if(frow.TypeHandler.IsEnumerable)
|
||||
{
|
||||
// Fill combo with enums
|
||||
enumscombo.SelectedItem = null;
|
||||
enumscombo.Text = "";
|
||||
enumscombo.Items.Clear();
|
||||
enumscombo.Items.AddRange(frow.TypeHandler.GetEnumList().ToArray());
|
||||
enumscombo.Tag = frow;
|
||||
|
||||
// Lock combo to enums?
|
||||
if(frow.TypeHandler.IsLimitedToEnums)
|
||||
enumscombo.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
else
|
||||
enumscombo.DropDownStyle = ComboBoxStyle.DropDown;
|
||||
|
||||
// Position combobox
|
||||
Rectangle cellrect = fieldslist.GetCellDisplayRectangle(2, row.Index, false);
|
||||
enumscombo.Location = new Point(cellrect.Left, cellrect.Top);
|
||||
enumscombo.Width = cellrect.Width;
|
||||
int internalheight = cellrect.Height - (enumscombo.Height - enumscombo.ClientRectangle.Height) - 6;
|
||||
General.SendMessage(enumscombo.Handle, General.CB_SETITEMHEIGHT, -1, internalheight);
|
||||
|
||||
// Select the value of this field (for DropDownList style combo)
|
||||
foreach(EnumItem i in enumscombo.Items)
|
||||
{
|
||||
// Matches?
|
||||
if(string.Compare(i.Title, frow.TypeHandler.GetStringValue(), true, CultureInfo.InvariantCulture) == 0)
|
||||
{
|
||||
// Select this item
|
||||
enumscombo.SelectedItem = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Put the display text in the text (for DropDown style combo)
|
||||
enumscombo.Text = frow.TypeHandler.GetStringValue();
|
||||
|
||||
// Show combo
|
||||
// Why does it not select all and focus the combobox?
|
||||
enumscombo.Show();
|
||||
enumscombo.Focus();
|
||||
enumscombo.SelectAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Done editing cell contents
|
||||
|
@ -412,11 +475,8 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// Changing field value?
|
||||
if((e.ColumnIndex == 2) && (frow != null))
|
||||
{
|
||||
// Defined?
|
||||
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();
|
||||
// Apply changes
|
||||
ApplyValue(frow, row.Cells[2].Value);
|
||||
}
|
||||
|
||||
// Updated
|
||||
|
@ -451,10 +511,109 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// Selection changes
|
||||
private void fieldslist_SelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
ApplyEnums(true);
|
||||
|
||||
// Update button
|
||||
UpdateBrowseButton();
|
||||
}
|
||||
|
||||
// Browse clicked
|
||||
private void browsebutton_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Any row selected?
|
||||
if(fieldslist.SelectedRows.Count > 0)
|
||||
{
|
||||
// Get selected row
|
||||
DataGridViewRow row = fieldslist.SelectedRows[0];
|
||||
if(row is FieldsEditorRow)
|
||||
{
|
||||
// Browse
|
||||
(row as FieldsEditorRow).Browse(this.ParentForm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This handles field data errors
|
||||
private void fieldslist_DataError(object sender, DataGridViewDataErrorEventArgs e)
|
||||
{
|
||||
// Ignore this, because we want to display values
|
||||
// in the type column that are not in their combobox
|
||||
e.ThrowException = false;
|
||||
}
|
||||
|
||||
// Validate value in enums combobox
|
||||
private void enumscombo_Validating(object sender, CancelEventArgs e)
|
||||
{
|
||||
ApplyEnums(false);
|
||||
}
|
||||
|
||||
// Scrolling
|
||||
private void fieldslist_Scroll(object sender, ScrollEventArgs e)
|
||||
{
|
||||
// Stop any cell editing
|
||||
ApplyEnums(true);
|
||||
fieldslist.EndEdit();
|
||||
HideBrowseButton();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Private Methods
|
||||
|
||||
// This applies a value to a row
|
||||
private void ApplyValue(FieldsEditorRow frow, object value)
|
||||
{
|
||||
// Defined?
|
||||
if((value != null) && (!frow.IsFixed || !frow.Info.Default.Equals(value)))
|
||||
frow.Define(value);
|
||||
else if(frow.IsFixed)
|
||||
frow.Undefine();
|
||||
}
|
||||
|
||||
// This applies the contents of the enums combobox and hides (if opened)
|
||||
private void ApplyEnums(bool hide)
|
||||
{
|
||||
// Enums combobox shown?
|
||||
if((enumscombo.Visible) && (enumscombo.Tag is FieldsEditorRow))
|
||||
{
|
||||
// Get the row
|
||||
FieldsEditorRow frow = (enumscombo.Tag as FieldsEditorRow);
|
||||
|
||||
// Take the selected value and apply it
|
||||
ApplyValue(frow, enumscombo.Text);
|
||||
|
||||
// Updated
|
||||
frow.CellChanged();
|
||||
}
|
||||
|
||||
if(hide)
|
||||
{
|
||||
// Hide combobox
|
||||
enumscombo.Tag = null;
|
||||
enumscombo.Visible = false;
|
||||
enumscombo.Items.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
// This sets up the new row
|
||||
private void SetupNewRowStyle()
|
||||
{
|
||||
// Show text for new row
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[0].Value = ADD_FIELD_TEXT;
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[0].Style.ForeColor = SystemColors.GrayText;
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[0].ReadOnly = false;
|
||||
|
||||
// Make sure user can only enter property name in a new row
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[1].ReadOnly = true;
|
||||
fieldslist.Rows[fieldslist.NewRowIndex].Cells[2].ReadOnly = true;
|
||||
}
|
||||
|
||||
// This hides the browse button
|
||||
private void HideBrowseButton()
|
||||
{
|
||||
browsebutton.Visible = false;
|
||||
}
|
||||
|
||||
// This updates the button
|
||||
private void UpdateBrowseButton()
|
||||
{
|
||||
|
@ -467,16 +626,17 @@ 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.TypeHandler.IsBrowseable)
|
||||
if(frow.TypeHandler.IsBrowseable && !frow.TypeHandler.IsEnumerable)
|
||||
{
|
||||
Rectangle cellrect = fieldslist.GetCellDisplayRectangle(2, row.Index, false);
|
||||
|
||||
// Show button
|
||||
enumscombo.Visible = false;
|
||||
browsebutton.Location = new Point(cellrect.Right - browsebutton.Width, cellrect.Top);
|
||||
browsebutton.Height = cellrect.Height;
|
||||
browsebutton.Visible = true;
|
||||
|
@ -498,34 +658,20 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
}
|
||||
else
|
||||
{
|
||||
browsebutton.Visible = false;
|
||||
HideBrowseButton();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
browsebutton.Visible = false;
|
||||
HideBrowseButton();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
browsebutton.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Browse clicked
|
||||
private void browsebutton_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Any row selected?
|
||||
if(fieldslist.SelectedRows.Count > 0)
|
||||
{
|
||||
// Get selected row
|
||||
DataGridViewRow row = fieldslist.SelectedRows[0];
|
||||
if(row is FieldsEditorRow)
|
||||
{
|
||||
// Browse
|
||||
(row as FieldsEditorRow).Browse(this.ParentForm);
|
||||
}
|
||||
HideBrowseButton();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
#region ================== Constructor
|
||||
|
||||
// Constructor for a fixed, undefined field
|
||||
public FieldsEditorRow(DataGridView view, UniversalFieldInfo fixedfield)
|
||||
|
@ -88,7 +88,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
isfixed = true;
|
||||
|
||||
// Type
|
||||
this.fieldtype = General.Types.GetFieldHandler(fixedfield.Type, fixedfield.Default);
|
||||
this.fieldtype = General.Types.GetFieldHandler(fixedfield);
|
||||
|
||||
// Make all cells
|
||||
base.CreateCells(view);
|
||||
|
@ -98,7 +98,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
this.Cells[0].ReadOnly = true;
|
||||
|
||||
// Setup type cell
|
||||
this.Cells[1].Value = fieldtype.Attribute;
|
||||
this.Cells[1].Value = fieldtype.GetDisplayType();
|
||||
this.Cells[1].ReadOnly = true;
|
||||
|
||||
// Setup value cell
|
||||
|
@ -129,7 +129,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
this.Cells[0].ReadOnly = true;
|
||||
|
||||
// Setup type cell
|
||||
this.Cells[1].Value = fieldtype.Attribute;
|
||||
this.Cells[1].Value = fieldtype.GetDisplayType();
|
||||
this.Cells[1].ReadOnly = false;
|
||||
|
||||
// Setup value cell
|
||||
|
@ -188,8 +188,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
if(attrib.Index != fieldtype.Index)
|
||||
{
|
||||
// Change field type!
|
||||
fieldtype = General.Types.GetFieldHandler(attrib.Index, this.Cells[2].Value);
|
||||
this.Cells[1].Value = attrib;
|
||||
this.ChangeType(attrib.Index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,13 +240,16 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// This changes the type
|
||||
public void ChangeType(int typeindex)
|
||||
{
|
||||
// Can't do this for a fixed field!
|
||||
if(isfixed) throw new InvalidOperationException();
|
||||
|
||||
// Different?
|
||||
if(typeindex != fieldtype.Index)
|
||||
{
|
||||
// Change field type!
|
||||
TypeHandlerAttribute attrib = General.Types.GetAttribute(typeindex);
|
||||
fieldtype = General.Types.GetFieldHandler(typeindex, this.Cells[2].Value);
|
||||
this.Cells[1].Value = attrib;
|
||||
this.Cells[1].Value = fieldtype.GetDisplayType();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,9 @@ namespace CodeImp.DoomBuilder
|
|||
[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)]
|
||||
internal static extern unsafe void CopyMemory(void* dst, void* src, UIntPtr length);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
|
||||
internal static extern int SendMessage(IntPtr hwnd, uint Msg, int wParam, int lParam);
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constants
|
||||
|
@ -79,6 +82,9 @@ namespace CodeImp.DoomBuilder
|
|||
internal const uint PAGE_NOCACHE = 0x200;
|
||||
internal const uint PAGE_WRITECOMBINE = 0x400;
|
||||
|
||||
// SendMessage API
|
||||
internal const int CB_SETITEMHEIGHT = 0x153;
|
||||
|
||||
// Files and Folders
|
||||
private const string SETTINGS_FILE = "Builder.cfg";
|
||||
private const string SETTINGS_DIR = "Doom Builder";
|
||||
|
|
|
@ -25,6 +25,7 @@ using CodeImp.DoomBuilder.IO;
|
|||
using CodeImp.DoomBuilder.Data;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using CodeImp.DoomBuilder.Config;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -39,12 +40,29 @@ namespace CodeImp.DoomBuilder.Types
|
|||
|
||||
#region ================== Variables
|
||||
|
||||
private EnumList list;
|
||||
private bool value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public override bool IsEnumerable { get { return true; } }
|
||||
public override bool IsLimitedToEnums { get { return true; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor
|
||||
|
||||
// When set up for an argument
|
||||
public BoolHandler() : base()
|
||||
{
|
||||
// Make enums
|
||||
list = new EnumList();
|
||||
list.Add(new EnumItem("true", "True"));
|
||||
list.Add(new EnumItem("false", "False"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
@ -99,6 +117,12 @@ namespace CodeImp.DoomBuilder.Types
|
|||
return this.value.ToString();
|
||||
}
|
||||
|
||||
// This returns an enum list
|
||||
public override EnumList GetEnumList()
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,16 @@ namespace CodeImp.DoomBuilder.Types
|
|||
// Keep enum list reference
|
||||
list = arginfo.Enum;
|
||||
}
|
||||
|
||||
|
||||
// When set up for a universal field
|
||||
public override void SetupField(TypeHandlerAttribute attr, UniversalFieldInfo fieldinfo)
|
||||
{
|
||||
base.SetupField(attr, fieldinfo);
|
||||
|
||||
// Keep enum list reference
|
||||
if(fieldinfo != null) list = fieldinfo.Enum; else list = new EnumList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
@ -130,6 +139,7 @@ namespace CodeImp.DoomBuilder.Types
|
|||
{
|
||||
// Make a dummy value
|
||||
this.value = new EnumItem(value.ToString(), value.ToString());
|
||||
this.value = new EnumItem(this.value.GetIntValue().ToString(CultureInfo.InvariantCulture), value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +181,13 @@ namespace CodeImp.DoomBuilder.Types
|
|||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
// This returns the type to display for fixed fields
|
||||
// Must be a custom usable type
|
||||
public override TypeHandlerAttribute GetDisplayType()
|
||||
{
|
||||
return General.Types.GetAttribute((int)UniversalType.Integer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ using System.Diagnostics;
|
|||
|
||||
namespace CodeImp.DoomBuilder.Types
|
||||
{
|
||||
[TypeHandler(1, "Float", true)]
|
||||
[TypeHandler(1, "Decimal", true)]
|
||||
internal class FloatHandler : TypeHandler
|
||||
{
|
||||
#region ================== Constants
|
||||
|
|
|
@ -61,6 +61,7 @@ namespace CodeImp.DoomBuilder.Types
|
|||
|
||||
public virtual bool IsBrowseable { get { return false; } }
|
||||
public virtual bool IsEnumerable { get { return false; } }
|
||||
public virtual bool IsLimitedToEnums { get { return false; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -95,7 +96,7 @@ namespace CodeImp.DoomBuilder.Types
|
|||
}
|
||||
|
||||
// This sets up the handler for arguments
|
||||
public virtual void SetupField(TypeHandlerAttribute attr)
|
||||
public virtual void SetupField(TypeHandlerAttribute attr, UniversalFieldInfo fieldinfo)
|
||||
{
|
||||
// Setup
|
||||
this.arginfo = arginfo;
|
||||
|
@ -155,6 +156,13 @@ namespace CodeImp.DoomBuilder.Types
|
|||
return this.GetStringValue();
|
||||
}
|
||||
|
||||
// This returns the type to display for fixed fields
|
||||
// Must be a custom usable type
|
||||
public virtual TypeHandlerAttribute GetDisplayType()
|
||||
{
|
||||
return this.attribute;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,8 +121,8 @@ namespace CodeImp.DoomBuilder.Types
|
|||
return th;
|
||||
}
|
||||
|
||||
// This returns the type handler for a given universal field
|
||||
public TypeHandler GetFieldHandler(int type, object defaultvalue)
|
||||
// This returns the type handler for a custom universal field
|
||||
public TypeHandler GetFieldHandler(int type, object defaultsetting)
|
||||
{
|
||||
Type t = typeof(NullHandler);
|
||||
TypeHandlerAttribute ta = null;
|
||||
|
@ -136,8 +136,28 @@ namespace CodeImp.DoomBuilder.Types
|
|||
|
||||
// Create instance
|
||||
TypeHandler th = (TypeHandler)General.ThisAssembly.CreateInstance(t.FullName);
|
||||
th.SetupField(ta);
|
||||
th.SetValue(defaultvalue);
|
||||
th.SetupField(ta, null);
|
||||
th.SetValue(defaultsetting);
|
||||
return th;
|
||||
}
|
||||
|
||||
// This returns the type handler for a given universal field
|
||||
public TypeHandler GetFieldHandler(UniversalFieldInfo fieldinfo)
|
||||
{
|
||||
Type t = typeof(NullHandler);
|
||||
TypeHandlerAttribute ta = null;
|
||||
|
||||
// Do we have a handler type for this?
|
||||
if(handlertypes.ContainsKey(fieldinfo.Type))
|
||||
{
|
||||
ta = handlertypes[fieldinfo.Type];
|
||||
t = ta.Type;
|
||||
}
|
||||
|
||||
// Create instance
|
||||
TypeHandler th = (TypeHandler)General.ThisAssembly.CreateInstance(t.FullName);
|
||||
th.SetupField(ta, fieldinfo);
|
||||
th.SetValue(fieldinfo.Default);
|
||||
return th;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue