mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-25 13:21:28 +00:00
some stuff with argument types
This commit is contained in:
parent
8aa99cfb88
commit
fef9b74ca2
17 changed files with 804 additions and 105 deletions
|
@ -23,8 +23,9 @@ all supported data types:
|
|||
|
||||
- Only types indicates with * are usable for standard hexen args
|
||||
- When no type is specified, the default type is 0 (integer)
|
||||
- Enum types (11, 12 and 16) cannot be used in custom UDMF fields
|
||||
|
||||
For types 11, 12 and 16 there must be an "enum" field that
|
||||
For enum types 11, 12 and 16 there must be an "enum" field that
|
||||
either specifies the values or refers to an existing enum set:
|
||||
|
||||
enum
|
||||
|
@ -37,7 +38,7 @@ either specifies the values or refers to an existing enum set:
|
|||
|
||||
enum = "yesno";
|
||||
|
||||
Type 16 uses case-sensitive strings for value and can only be
|
||||
Type 16 uses case-sensitive strings for values and can only be
|
||||
used as an option, not as bit flags:
|
||||
|
||||
enum
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
</Target>
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Config\ArgumentInfo.cs" />
|
||||
<Compile Include="Config\EnumItem.cs" />
|
||||
<Compile Include="Config\EnumList.cs" />
|
||||
<Compile Include="Config\SectorEffectInfo.cs" />
|
||||
|
@ -117,6 +118,12 @@
|
|||
<Compile Include="Data\DataLocationList.cs" />
|
||||
<Compile Include="Data\DataManager.cs" />
|
||||
<Compile Include="Data\WADReader.cs" />
|
||||
<Compile Include="Types\EnumOptionHandler.cs" />
|
||||
<Compile Include="Types\IntegerHandler.cs" />
|
||||
<Compile Include="Types\NullHandler.cs" />
|
||||
<Compile Include="Types\TypeHandler.cs" />
|
||||
<Compile Include="Types\TypeHandlerAttribute.cs" />
|
||||
<Compile Include="Types\TypesManager.cs" />
|
||||
<Compile Include="Windows\AboutForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
109
Source/Config/ArgumentInfo.cs
Normal file
109
Source/Config/ArgumentInfo.cs
Normal file
|
@ -0,0 +1,109 @@
|
|||
|
||||
#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;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Config
|
||||
{
|
||||
public class ArgumentInfo
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
private string title;
|
||||
private bool used;
|
||||
private int type;
|
||||
private EnumList enumlist;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public string Title { get { return title; } }
|
||||
public bool Used { get { return false; } }
|
||||
public int Type { get { return type; } }
|
||||
public EnumList Enum { get { return enumlist; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor for argument info from configuration
|
||||
internal ArgumentInfo(Configuration cfg, string argspath, int argindex, IDictionary<string, EnumList> enums)
|
||||
{
|
||||
// Read
|
||||
string istr = argindex.ToString(CultureInfo.InvariantCulture);
|
||||
this.used = cfg.SettingExists(argspath + ".arg" + istr);
|
||||
this.title = cfg.ReadSetting(argspath + ".arg" + istr + ".title", "Argument " + (argindex + 1));
|
||||
this.type = cfg.ReadSetting(argspath + ".arg" + istr + ".type", 0);
|
||||
|
||||
// Determine enum type
|
||||
EnumList enumlist = null;
|
||||
IDictionary argdic = cfg.ReadSetting(argspath + ".arg" + istr, new Hashtable());
|
||||
if(argdic.Contains("enum"))
|
||||
{
|
||||
// Enum fully specified?
|
||||
if(argdic["enum"] is IDictionary)
|
||||
{
|
||||
// Create anonymous enum
|
||||
this.enumlist = new EnumList(argdic["enum"] as IDictionary);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if referenced enum exists
|
||||
if((argdic["enum"].ToString().Length > 0) && enums.ContainsKey(argdic["enum"].ToString()))
|
||||
{
|
||||
// Get the enum list
|
||||
this.enumlist = enums[argdic["enum"].ToString()] as EnumList;
|
||||
}
|
||||
else
|
||||
{
|
||||
General.WriteLogLine("WARNING: '" + argspath + ".arg" + istr + "' references unknown enumeration '" + argdic["enum"] + "'!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This gets the description for an argument value
|
||||
public string GetValueDescription(int value)
|
||||
{
|
||||
// TODO: Use the registered type editor to get the description!
|
||||
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ using System.Windows.Forms;
|
|||
|
||||
namespace CodeImp.DoomBuilder.Config
|
||||
{
|
||||
public class EnumItem : INumberedTitle
|
||||
public class EnumItem
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
|
@ -39,14 +39,14 @@ namespace CodeImp.DoomBuilder.Config
|
|||
|
||||
#region ================== Variables
|
||||
|
||||
private int index;
|
||||
private string value;
|
||||
private string title;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public int Index { get { return index; } }
|
||||
public string Value { get { return value; } }
|
||||
public string Title { get { return title; } }
|
||||
|
||||
#endregion
|
||||
|
@ -54,10 +54,10 @@ namespace CodeImp.DoomBuilder.Config
|
|||
#region ================== Constructor
|
||||
|
||||
// Constructor
|
||||
public EnumItem(int index, string title)
|
||||
public EnumItem(string value, string title)
|
||||
{
|
||||
// Initialize
|
||||
this.index = index;
|
||||
this.value = value;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,16 @@ namespace CodeImp.DoomBuilder.Config
|
|||
return title;
|
||||
}
|
||||
|
||||
// This returns the value as int
|
||||
public int GetIntValue()
|
||||
{
|
||||
int result;
|
||||
if(int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out result))
|
||||
return result;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,43 +39,40 @@ namespace CodeImp.DoomBuilder.Config
|
|||
|
||||
#region ================== Variables
|
||||
|
||||
private string name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public string Name { get { return name; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor
|
||||
|
||||
// Constructor to load from dictionary
|
||||
internal EnumList(IDictionary dic)
|
||||
{
|
||||
int index;
|
||||
|
||||
// Read the dictionary
|
||||
foreach(DictionaryEntry de in dic)
|
||||
{
|
||||
// Add item
|
||||
EnumItem item = new EnumItem(de.Key.ToString(), de.Value.ToString());
|
||||
base.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor to load from configuration
|
||||
internal EnumList(string name, Configuration cfg)
|
||||
{
|
||||
int index;
|
||||
|
||||
// Initialize
|
||||
this.name = name;
|
||||
|
||||
// Read the list from configuration
|
||||
IDictionary dic = cfg.ReadSetting("enums." + name, new Hashtable());
|
||||
foreach(DictionaryEntry de in dic)
|
||||
{
|
||||
// Try paring the bit value
|
||||
if(int.TryParse(de.Key.ToString(),
|
||||
NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite,
|
||||
CultureInfo.InvariantCulture, out index))
|
||||
{
|
||||
// Add item
|
||||
EnumItem item = new EnumItem(index, de.Value.ToString());
|
||||
base.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
General.WriteLogLine("WARNING: Enum structure '" + name + "' contains invalid keys!");
|
||||
}
|
||||
// Add item
|
||||
EnumItem item = new EnumItem(de.Key.ToString(), de.Value.ToString());
|
||||
base.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,14 +80,14 @@ namespace CodeImp.DoomBuilder.Config
|
|||
|
||||
#region ================== Methods
|
||||
|
||||
// This gets an item by enum index
|
||||
// This gets an item by value
|
||||
// Returns null when item could not be found
|
||||
public EnumItem GetByEnumIndex(int enumindex)
|
||||
public EnumItem GetByEnumIndex(string value)
|
||||
{
|
||||
// Find the item
|
||||
foreach(EnumItem i in this)
|
||||
{
|
||||
if(i.Index == enumindex) return i;
|
||||
if(i.Value == value) return i;
|
||||
}
|
||||
|
||||
// Nothing found
|
||||
|
|
|
@ -46,10 +46,7 @@ namespace CodeImp.DoomBuilder.Config
|
|||
private string category;
|
||||
private string name;
|
||||
private string title;
|
||||
private string[] argtitle;
|
||||
private TagType[] argtagtype;
|
||||
private bool[] argused;
|
||||
private string[] argenum;
|
||||
private ArgumentInfo[] args;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -60,10 +57,7 @@ namespace CodeImp.DoomBuilder.Config
|
|||
public string Category { get { return category; } }
|
||||
public string Name { get { return name; } }
|
||||
public string Title { get { return title; } }
|
||||
public string[] ArgTitle { get { return argtitle; } }
|
||||
public TagType[] ArgTagType { get { return argtagtype; } }
|
||||
public bool[] ArgUsed { get { return argused; } }
|
||||
public string[] ArgEnum { get { return argenum; } }
|
||||
public ArgumentInfo[] Args { get { return args; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -77,34 +71,17 @@ namespace CodeImp.DoomBuilder.Config
|
|||
// Initialize
|
||||
this.index = index;
|
||||
this.category = categoryname;
|
||||
this.argtitle = new string[Linedef.NUM_ARGS];
|
||||
this.argtagtype = new TagType[Linedef.NUM_ARGS];
|
||||
this.argused = new bool[Linedef.NUM_ARGS];
|
||||
this.argenum = new string[Linedef.NUM_ARGS];
|
||||
|
||||
this.args = new ArgumentInfo[Linedef.NUM_ARGS];
|
||||
|
||||
// Read settings
|
||||
this.name = cfg.ReadSetting(actionsetting + ".title", "Unnamed");
|
||||
this.prefix = cfg.ReadSetting(actionsetting + ".prefix", "");
|
||||
this.title = this.prefix + " " + this.name;
|
||||
this.title = this.title.Trim();
|
||||
|
||||
// Read the args and marks
|
||||
// Read the args
|
||||
for(int i = 0; i < Linedef.NUM_ARGS; i++)
|
||||
{
|
||||
// Read
|
||||
string istr = i.ToString(CultureInfo.InvariantCulture);
|
||||
this.argused[i] = cfg.SettingExists(actionsetting + ".arg" + istr);
|
||||
this.argtitle[i] = cfg.ReadSetting(actionsetting + ".arg" + istr + ".title", "Argument " + (i + 1));
|
||||
this.argtagtype[i] = (TagType)cfg.ReadSetting(actionsetting + ".arg" + istr + ".tag", (int)TagType.None);
|
||||
this.argenum[i] = cfg.ReadSetting(actionsetting + ".arg" + istr + ".enum", "");
|
||||
|
||||
// Verify enums
|
||||
if((this.argenum[i].Length > 0) && !enums.ContainsKey(this.argenum[i]))
|
||||
{
|
||||
General.WriteLogLine("WARNING: Linedef type enumeration '" + this.argenum[i] + "' does not exist! (found on linedef type " + index + ")");
|
||||
this.argenum[i] = "";
|
||||
}
|
||||
}
|
||||
this.args[i] = new ArgumentInfo(cfg, actionsetting, i, enums);
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
|
|
|
@ -70,31 +70,21 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
}
|
||||
|
||||
// This fills the box with the given enum
|
||||
public void SetupEnums(string enumslistname)
|
||||
public void SetupEnums(EnumList enumslist)
|
||||
{
|
||||
EnumList list;
|
||||
|
||||
// Keep old value
|
||||
int value = this.GetResult(0);
|
||||
|
||||
// Find the enums list
|
||||
if(General.Map.Config.Enums.ContainsKey(enumslistname))
|
||||
{
|
||||
// Enums found
|
||||
list = General.Map.Config.Enums[enumslistname];
|
||||
if(enumslist != null)
|
||||
this.DropDownStyle = ComboBoxStyle.DropDown;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No enums
|
||||
list = null;
|
||||
this.DropDownStyle = ComboBoxStyle.Simple;
|
||||
}
|
||||
|
||||
// Fill list
|
||||
this.enums = list;
|
||||
this.enums = enumslist;
|
||||
this.Items.Clear();
|
||||
if(list != null) this.Items.AddRange(list.ToArray());
|
||||
if(enumslist != null) this.Items.AddRange(enumslist.ToArray());
|
||||
|
||||
// Re-apply value
|
||||
this.Text = value.ToString();
|
||||
|
@ -115,7 +105,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
// Enum selected?
|
||||
if(this.SelectedItem != null)
|
||||
{
|
||||
return (this.SelectedItem as EnumItem).Index;
|
||||
return (this.SelectedItem as EnumItem).GetIntValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -174,7 +164,7 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
{
|
||||
// Try selecting this enum
|
||||
EnumItem item = null;
|
||||
if(enums != null) item = enums.GetByEnumIndex(num);
|
||||
if(enums != null) item = enums.GetByEnumIndex(num.ToString());
|
||||
if(item != null)
|
||||
{
|
||||
// Select enum
|
||||
|
|
|
@ -36,6 +36,7 @@ using CodeImp.DoomBuilder.Config;
|
|||
using SlimDX.Direct3D9;
|
||||
using System.Drawing;
|
||||
using CodeImp.DoomBuilder.Plugins;
|
||||
using CodeImp.DoomBuilder.Types;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -109,6 +110,7 @@ namespace CodeImp.DoomBuilder
|
|||
private static ActionManager actions;
|
||||
private static PluginManager plugins;
|
||||
private static ColorCollection colors;
|
||||
private static TypesManager types;
|
||||
private static Clock clock;
|
||||
|
||||
// Configurations
|
||||
|
@ -145,6 +147,7 @@ namespace CodeImp.DoomBuilder
|
|||
public static Clock Clock { get { return clock; } }
|
||||
public static bool DebugBuild { get { return debugbuild; } }
|
||||
internal static Triangulator EarClipper { get { return earclipper; } }
|
||||
internal static TypesManager Types { get { return types; } }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -524,6 +527,10 @@ namespace CodeImp.DoomBuilder
|
|||
General.WriteLogLine("Creating application clock...");
|
||||
clock = new Clock();
|
||||
|
||||
// Create types manager
|
||||
General.WriteLogLine("Creating types manager...");
|
||||
types = new TypesManager();
|
||||
|
||||
// Run application from the main window
|
||||
General.WriteLogLine("Startup done");
|
||||
mainwindow.DisplayReady();
|
||||
|
@ -597,6 +604,7 @@ namespace CodeImp.DoomBuilder
|
|||
if(actions != null) actions.Dispose();
|
||||
if(clock != null) clock.Dispose();
|
||||
if(plugins != null) plugins.Dispose();
|
||||
if(types != null) types.Dispose();
|
||||
try { Direct3D.Terminate(); } catch(Exception) { }
|
||||
|
||||
// Application ends here and now
|
||||
|
|
143
Source/Types/EnumOptionHandler.cs
Normal file
143
Source/Types/EnumOptionHandler.cs
Normal file
|
@ -0,0 +1,143 @@
|
|||
|
||||
#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 CodeImp.DoomBuilder.Config;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Types
|
||||
{
|
||||
[TypeHandler(11)]
|
||||
internal class EnumOptionHandler : TypeHandler
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
private EnumList list;
|
||||
private EnumItem value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public virtual bool IsBrowseable { get { return true; } }
|
||||
public virtual bool IsEnumerable { get { return true; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor
|
||||
|
||||
// When set up for an argument
|
||||
public override void SetupArgument(ArgumentInfo arginfo)
|
||||
{
|
||||
base.SetupArgument(arginfo);
|
||||
|
||||
// Keep enum list reference
|
||||
list = arginfo.Enum;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
public override void SetValue(object value)
|
||||
{
|
||||
this.value = null;
|
||||
|
||||
// First try to match the value against the enum values
|
||||
foreach(EnumItem item in list)
|
||||
{
|
||||
// Matching value?
|
||||
if(item.Value == value.ToString())
|
||||
{
|
||||
// Set this value
|
||||
this.value = item;
|
||||
}
|
||||
}
|
||||
|
||||
// No match found yet?
|
||||
if(this.value == null)
|
||||
{
|
||||
// Try to match against the titles
|
||||
foreach(EnumItem item in list)
|
||||
{
|
||||
// Matching value?
|
||||
if(item.Title.ToLowerInvariant() == value.ToString().ToLowerInvariant())
|
||||
{
|
||||
// Set this value
|
||||
this.value = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Still no match found?
|
||||
if(this.value == null)
|
||||
{
|
||||
// Make a dummy value
|
||||
this.value = new EnumItem(value.ToString(), value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetIntValue()
|
||||
{
|
||||
if(this.value != null)
|
||||
{
|
||||
// Parse the value to integer
|
||||
int result;
|
||||
if(int.TryParse(this.value.Value, NumberStyles.Integer,
|
||||
CultureInfo.InvariantCulture, out result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override string GetStringValue()
|
||||
{
|
||||
if(this.value != null) return this.value.Title; else return "NULL";
|
||||
}
|
||||
|
||||
// This returns an enum list
|
||||
public override EnumList GetEnumList()
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
90
Source/Types/IntegerHandler.cs
Normal file
90
Source/Types/IntegerHandler.cs
Normal file
|
@ -0,0 +1,90 @@
|
|||
|
||||
#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;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Types
|
||||
{
|
||||
[TypeHandler(0)]
|
||||
internal class IntegerHandler : TypeHandler
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
private int value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public override bool IsCustomType { get { return true; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
public override void SetValue(object value)
|
||||
{
|
||||
int result;
|
||||
|
||||
// Already an int or float?
|
||||
if((value is int) || (value is float))
|
||||
{
|
||||
// Return the same
|
||||
this.value = (int)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try parsing as string
|
||||
if(int.TryParse(value.ToString(), NumberStyles.Integer, CultureInfo.CurrentCulture, out result))
|
||||
{
|
||||
this.value = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetIntValue()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return this.value.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
63
Source/Types/NullHandler.cs
Normal file
63
Source/Types/NullHandler.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
|
||||
#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;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Types
|
||||
{
|
||||
internal class NullHandler : TypeHandler
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
private object value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
public override void SetValue(object value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public override string GetStringValue()
|
||||
{
|
||||
return this.value.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
117
Source/Types/TypeHandler.cs
Normal file
117
Source/Types/TypeHandler.cs
Normal file
|
@ -0,0 +1,117 @@
|
|||
|
||||
#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;
|
||||
using CodeImp.DoomBuilder.Config;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Types
|
||||
{
|
||||
internal abstract class TypeHandler
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
protected int index;
|
||||
protected ArgumentInfo arginfo;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public int Index { get { return index; } }
|
||||
|
||||
public virtual bool IsBrowseable { get { return false; } }
|
||||
public virtual bool IsEnumerable { get { return false; } }
|
||||
public virtual bool IsCustomType { get { return false; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor
|
||||
|
||||
// Constructor
|
||||
public TypeHandler()
|
||||
{
|
||||
// Get my attributes
|
||||
object[] attrs = this.GetType().GetCustomAttributes(typeof(TypeHandlerAttribute), false);
|
||||
TypeHandlerAttribute attr = (attrs[0] as TypeHandlerAttribute);
|
||||
|
||||
// Initialize
|
||||
this.index = attr.Index;
|
||||
}
|
||||
|
||||
// This sets up the handler for arguments
|
||||
public virtual void SetupArgument(ArgumentInfo arginfo)
|
||||
{
|
||||
// Setup
|
||||
this.arginfo = arginfo;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This must set the value
|
||||
// How the value is actually validated and stored is up to the implementation
|
||||
public abstract void SetValue(object value);
|
||||
|
||||
// This must return the value as integer (for arguments)
|
||||
public virtual int GetIntValue()
|
||||
{
|
||||
throw new NotSupportedException("Override this method to support it as integer for arguments");
|
||||
}
|
||||
|
||||
// This must return the value as a string for displaying
|
||||
public abstract string GetStringValue();
|
||||
|
||||
// This is called when the user presses the browse button
|
||||
public virtual object Browse(IWin32Window parent)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// String representation
|
||||
public override string ToString()
|
||||
{
|
||||
return this.GetStringValue();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
66
Source/Types/TypeHandlerAttribute.cs
Normal file
66
Source/Types/TypeHandlerAttribute.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
|
||||
#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;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Types
|
||||
{
|
||||
internal class TypeHandlerAttribute : Attribute
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
private int index;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public int Index { get { return index; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Destructor
|
||||
|
||||
// Constructor
|
||||
public TypeHandlerAttribute(int index)
|
||||
{
|
||||
// Initialize
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
120
Source/Types/TypesManager.cs
Normal file
120
Source/Types/TypesManager.cs
Normal file
|
@ -0,0 +1,120 @@
|
|||
|
||||
#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 CodeImp.DoomBuilder.Config;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Types
|
||||
{
|
||||
internal class TypesManager : IDisposable
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
// List of handler types
|
||||
private Dictionary<int, Type> handlertypes;
|
||||
|
||||
// Disposing
|
||||
private bool isdisposed = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public bool IsDisposed { get { return isdisposed; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
public TypesManager()
|
||||
{
|
||||
// Initialize
|
||||
handlertypes = new Dictionary<int, Type>();
|
||||
|
||||
// Go for all types in this assembly
|
||||
Type[] types = General.ThisAssembly.GetTypes();
|
||||
foreach(Type tp in types)
|
||||
{
|
||||
// Check if this type is a class
|
||||
if(tp.IsClass && !tp.IsAbstract && !tp.IsArray)
|
||||
{
|
||||
// Check if class has an TypeHandler attribute
|
||||
if(Attribute.IsDefined(tp, typeof(TypeHandlerAttribute), false))
|
||||
{
|
||||
// Add the type to the list
|
||||
object[] attribs = tp.GetCustomAttributes(typeof(TypeHandlerAttribute), false);
|
||||
TypeHandlerAttribute attr = (attribs[0] as TypeHandlerAttribute);
|
||||
handlertypes.Add(attr.Index, tp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Disposer
|
||||
public void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
if(!isdisposed)
|
||||
{
|
||||
// Clean up
|
||||
handlertypes.Clear();
|
||||
|
||||
// Done
|
||||
isdisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This returns the type handler for the given argument
|
||||
public TypeHandler GetArgumentHandler(ArgumentInfo arginfo)
|
||||
{
|
||||
Type t = typeof(NullHandler);
|
||||
|
||||
// Do we have a handler type for this?
|
||||
if(handlertypes.ContainsKey(arginfo.Type)) t = handlertypes[arginfo.Type];
|
||||
|
||||
// Create instance
|
||||
TypeHandler th = (TypeHandler)General.ThisAssembly.CreateInstance(t.FullName);
|
||||
th.SetupArgument(arginfo);
|
||||
return th;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
1
Source/Windows/LinedefEditForm.Designer.cs
generated
1
Source/Windows/LinedefEditForm.Designer.cs
generated
|
@ -378,6 +378,7 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
//
|
||||
// arg4
|
||||
//
|
||||
this.arg4.DropDownWidth = 200;
|
||||
this.arg4.FormattingEnabled = true;
|
||||
this.arg4.ImeMode = System.Windows.Forms.ImeMode.Off;
|
||||
this.arg4.Location = new System.Drawing.Point(400, 81);
|
||||
|
|
|
@ -352,26 +352,26 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
if(General.Map.Config.LinedefActions.ContainsKey(action.Value)) showaction = action.Value;
|
||||
|
||||
// Change the argument descriptions
|
||||
arg0label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[0] + ":";
|
||||
arg1label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[1] + ":";
|
||||
arg2label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[2] + ":";
|
||||
arg3label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[3] + ":";
|
||||
arg4label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[4] + ":";
|
||||
arg0label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[0];
|
||||
arg1label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[1];
|
||||
arg2label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[2];
|
||||
arg3label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[3];
|
||||
arg4label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[4];
|
||||
arg0label.Text = General.Map.Config.LinedefActions[showaction].Args[0].Title + ":";
|
||||
arg1label.Text = General.Map.Config.LinedefActions[showaction].Args[1].Title + ":";
|
||||
arg2label.Text = General.Map.Config.LinedefActions[showaction].Args[2].Title + ":";
|
||||
arg3label.Text = General.Map.Config.LinedefActions[showaction].Args[3].Title + ":";
|
||||
arg4label.Text = General.Map.Config.LinedefActions[showaction].Args[4].Title + ":";
|
||||
arg0label.Enabled = General.Map.Config.LinedefActions[showaction].Args[0].Used;
|
||||
arg1label.Enabled = General.Map.Config.LinedefActions[showaction].Args[1].Used;
|
||||
arg2label.Enabled = General.Map.Config.LinedefActions[showaction].Args[2].Used;
|
||||
arg3label.Enabled = General.Map.Config.LinedefActions[showaction].Args[3].Used;
|
||||
arg4label.Enabled = General.Map.Config.LinedefActions[showaction].Args[4].Used;
|
||||
if(arg0label.Enabled) arg0.ForeColor = SystemColors.WindowText; else arg0.ForeColor = SystemColors.GrayText;
|
||||
if(arg1label.Enabled) arg1.ForeColor = SystemColors.WindowText; else arg1.ForeColor = SystemColors.GrayText;
|
||||
if(arg2label.Enabled) arg2.ForeColor = SystemColors.WindowText; else arg2.ForeColor = SystemColors.GrayText;
|
||||
if(arg3label.Enabled) arg3.ForeColor = SystemColors.WindowText; else arg3.ForeColor = SystemColors.GrayText;
|
||||
if(arg4label.Enabled) arg4.ForeColor = SystemColors.WindowText; else arg4.ForeColor = SystemColors.GrayText;
|
||||
arg0.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[0]);
|
||||
arg1.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[1]);
|
||||
arg2.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[2]);
|
||||
arg3.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[3]);
|
||||
arg4.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[4]);
|
||||
arg0.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[0].Enum);
|
||||
arg1.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[1].Enum);
|
||||
arg2.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[2].Enum);
|
||||
arg3.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[3].Enum);
|
||||
arg4.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[4].Enum);
|
||||
}
|
||||
|
||||
// Browse Action clicked
|
||||
|
|
|
@ -199,26 +199,26 @@ namespace CodeImp.DoomBuilder.Windows
|
|||
if(General.Map.Config.LinedefActions.ContainsKey(action.Value)) showaction = action.Value;
|
||||
|
||||
// Change the argument descriptions
|
||||
arg0label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[0] + ":";
|
||||
arg1label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[1] + ":";
|
||||
arg2label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[2] + ":";
|
||||
arg3label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[3] + ":";
|
||||
arg4label.Text = General.Map.Config.LinedefActions[showaction].ArgTitle[4] + ":";
|
||||
arg0label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[0];
|
||||
arg1label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[1];
|
||||
arg2label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[2];
|
||||
arg3label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[3];
|
||||
arg4label.Enabled = General.Map.Config.LinedefActions[showaction].ArgUsed[4];
|
||||
arg0label.Text = General.Map.Config.LinedefActions[showaction].Args[0].Title + ":";
|
||||
arg1label.Text = General.Map.Config.LinedefActions[showaction].Args[1].Title + ":";
|
||||
arg2label.Text = General.Map.Config.LinedefActions[showaction].Args[2].Title + ":";
|
||||
arg3label.Text = General.Map.Config.LinedefActions[showaction].Args[3].Title + ":";
|
||||
arg4label.Text = General.Map.Config.LinedefActions[showaction].Args[4].Title + ":";
|
||||
arg0label.Enabled = General.Map.Config.LinedefActions[showaction].Args[0].Used;
|
||||
arg1label.Enabled = General.Map.Config.LinedefActions[showaction].Args[1].Used;
|
||||
arg2label.Enabled = General.Map.Config.LinedefActions[showaction].Args[2].Used;
|
||||
arg3label.Enabled = General.Map.Config.LinedefActions[showaction].Args[3].Used;
|
||||
arg4label.Enabled = General.Map.Config.LinedefActions[showaction].Args[4].Used;
|
||||
if(arg0label.Enabled) arg0.ForeColor = SystemColors.WindowText; else arg0.ForeColor = SystemColors.GrayText;
|
||||
if(arg1label.Enabled) arg1.ForeColor = SystemColors.WindowText; else arg1.ForeColor = SystemColors.GrayText;
|
||||
if(arg2label.Enabled) arg2.ForeColor = SystemColors.WindowText; else arg2.ForeColor = SystemColors.GrayText;
|
||||
if(arg3label.Enabled) arg3.ForeColor = SystemColors.WindowText; else arg3.ForeColor = SystemColors.GrayText;
|
||||
if(arg4label.Enabled) arg4.ForeColor = SystemColors.WindowText; else arg4.ForeColor = SystemColors.GrayText;
|
||||
arg0.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[0]);
|
||||
arg1.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[1]);
|
||||
arg2.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[2]);
|
||||
arg3.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[3]);
|
||||
arg4.SetupEnums(General.Map.Config.LinedefActions[showaction].ArgEnum[4]);
|
||||
arg0.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[0].Enum);
|
||||
arg1.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[1].Enum);
|
||||
arg2.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[2].Enum);
|
||||
arg3.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[3].Enum);
|
||||
arg4.SetupEnums(General.Map.Config.LinedefActions[showaction].Args[4].Enum);
|
||||
}
|
||||
|
||||
// Browse Action clicked
|
||||
|
|
Loading…
Reference in a new issue