123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using CommonFroms.Utils;
- using System.Reflection;
- using System.Drawing.Design;
- using CommonLang.Property;
- using CommonAI.Zone.Attributes;
- using CommonAI.Zone;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Globalization;
- using CommonAI.Zone.ZoneEditor;
- using System.IO;
- using CommonAIEditor.Scene;
- using CommonAI.ZoneEditor;
- using CommonAI.Zone.ZoneEditor.EventTrigger;
- using CommonAI.Zone.EventTrigger;
- using CommonLang;
- using System.Collections;
- using CommonFroms.G2D.DataGrid;
- using CommonFroms.G2D;
- using CommonAIEditor.Unit;
- namespace CommonAIEditor
- {
- public static class GameEditorPropertyAdapter
- {
- public static void Init()
- {
- G2DPropertyDescriptor.RegistPropertyAdapter(new DataAdapters());
- }
- }
- public class SceneDataAdapters : IG2DPropertyAdapter
- {
- public int SceneID { get { return scene.Data.ID; } }
- public readonly SceneEditor scene;
- public readonly SceneEventEditor evtEditor;
- public SceneDataAdapters(SceneEditor scene, SceneEventEditor evtEditor = null)
- {
- this.scene = scene;
- this.evtEditor = evtEditor;
- }
- public UITypeEditor GetEditor(MemberInfo field, Type fieldType, object ownerData)
- {
- if (field is FieldInfo)
- {
- if (PropertyUtil.GetAttribute<SceneScriptIDAttribute>(field) != null)
- {
- return new ScriptEditor(SceneID, field as FieldInfo, ownerData);
- }
- else if (PropertyUtil.GetAttribute<SceneObjectIDAttribute>(field) != null)
- {
- return new SceneObjectIDEditor(scene, field as FieldInfo, ownerData);
- }
- else if (PropertyUtil.GetAttribute<SceneEventIDAttribute>(field) != null)
- {
- return new SceneEventIDEditor(scene, field as FieldInfo, ownerData);
- }
- else if (PropertyUtil.GetAttribute<SceneVarIDAttribute>(field) != null)
- {
- return new SceneVarIDEditor(scene, field as FieldInfo, ownerData);
- }
- else if (PropertyUtil.GetAttribute<LocalVarIDAttribute>(field) != null)
- {
- if (evtEditor != null)
- {
- return new LocalVarIDEditor(evtEditor, field as FieldInfo, ownerData);
- }
- }
- }
- return null;
- }
- public TypeConverter GetConverter(MemberInfo field, Type fieldType, object ownerData)
- {
- return null;
- }
- public class ScriptEditor : UITypeEditor
- {
- private readonly int SceneID;
- private FieldInfo fieldInfo;
- private object ownerData;
- public ScriptEditor(int sceneID, FieldInfo field, object ownerData)
- {
- this.SceneID = sceneID;
- this.fieldInfo = field;
- this.ownerData = ownerData;
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
-
-
-
-
-
-
-
- return base.EditValue(context, provider, value);
- }
- }
- public class SceneObjectIDEditor : UITypeEditor
- {
- private SceneEditor scene;
- private FieldInfo fieldInfo;
- private object ownerData;
- private string objName;
- public SceneObjectIDEditor(
- SceneEditor scene,
- FieldInfo field,
- object ownerData)
- {
- this.scene = scene;
- this.fieldInfo = field;
- this.ownerData = ownerData;
- this.objName = fieldInfo.GetValue(ownerData) as string;
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
- SceneObjectIDAttribute soid = PropertyUtil.GetAttribute<SceneObjectIDAttribute>(fieldInfo);
- SceneObjectData sobj = scene.ShowSelectSceneObject(soid.ObjectType, objName);
- if (sobj != null)
- {
- return sobj.Name;
- }
- return base.EditValue(context, provider, value);
- }
- }
- public class SceneEventIDEditor : UITypeEditor
- {
- private SceneEditor scene;
- private FieldInfo fieldInfo;
- private object ownerData;
- private string objName;
- public SceneEventIDEditor(
- SceneEditor scene,
- FieldInfo field,
- object ownerData)
- {
- this.scene = scene;
- this.fieldInfo = field;
- this.ownerData = ownerData;
- this.objName = fieldInfo.GetValue(ownerData) as string;
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
- SceneEventIDAttribute soid = PropertyUtil.GetAttribute<SceneEventIDAttribute>(fieldInfo);
- CommonAI.Zone.ZoneEditor.ZoneEvent sobj = scene.ShowSelectSceneEvent(objName);
- if (sobj != null)
- {
- return sobj.Name;
- }
- return base.EditValue(context, provider, value);
- }
- }
- public class SceneVarIDEditor : UITypeEditor
- {
- private SceneEditor scene;
- private FieldInfo fieldInfo;
- private object ownerData;
- private string objName;
- public SceneVarIDEditor(
- SceneEditor scene,
- FieldInfo field,
- object ownerData)
- {
- this.scene = scene;
- this.fieldInfo = field;
- this.ownerData = ownerData;
- this.objName = fieldInfo.GetValue(ownerData) as string;
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
- SceneVarIDAttribute svid = PropertyUtil.GetAttribute<SceneVarIDAttribute>(fieldInfo);
- ZoneVar vobj = scene.ShowSelectSceneVar(objName, svid.VarType);
- if (vobj != null)
- {
- return vobj.Key;
- }
- return base.EditValue(context, provider, value);
- }
- }
- public class LocalVarIDEditor : UITypeEditor
- {
- private SceneEventEditor scene;
- private FieldInfo fieldInfo;
- private object ownerData;
- private string objName;
- public LocalVarIDEditor(
- SceneEventEditor scene,
- FieldInfo field,
- object ownerData)
- {
- this.scene = scene;
- this.fieldInfo = field;
- this.ownerData = ownerData;
- this.objName = fieldInfo.GetValue(ownerData) as string;
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
- LocalVarIDAttribute svid = PropertyUtil.GetAttribute<LocalVarIDAttribute>(fieldInfo);
- LocalVar vobj = scene.ShowSelectLocalVar(objName, svid.VarType);
- if (vobj != null)
- {
- return vobj.Key;
- }
- return base.EditValue(context, provider, value);
- }
- }
- }
- public class UnitEventAdapters : IG2DPropertyAdapter
- {
- public readonly UnitEventEditor evtEditor;
- public UnitEventAdapters(UnitEventEditor evtEditor)
- {
- this.evtEditor = evtEditor;
- }
- public UITypeEditor GetEditor(MemberInfo field, Type fieldType, object ownerData)
- {
- if (field is FieldInfo && PropertyUtil.GetAttribute<UnitEventIDAttribute>(field) != null)
- {
- return new UnitEventIDEditor(evtEditor, field as FieldInfo, ownerData);
- }
- return null;
- }
- public TypeConverter GetConverter(MemberInfo field, Type fieldType, object ownerData)
- {
- return null;
- }
- public class UnitEventIDEditor : UITypeEditor
- {
- private UnitEventEditor editor;
- private FieldInfo fieldInfo;
- private object ownerData;
- private string objName;
- public UnitEventIDEditor(
- UnitEventEditor editor,
- FieldInfo field,
- object ownerData)
- {
- this.editor = editor;
- this.fieldInfo = field;
- this.ownerData = ownerData;
- this.objName = fieldInfo.GetValue(ownerData) as string;
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
- var soid = PropertyUtil.GetAttribute<UnitEventIDAttribute>(fieldInfo);
- var sobj = editor.ShowSelectEvent(objName);
- if (sobj != null)
- {
- return sobj.Name;
- }
- return base.EditValue(context, provider, value);
- }
- }
- }
- public class DataAdapters : IG2DPropertyAdapter
- {
- public UITypeEditor GetEditor(MemberInfo field, Type fieldType, object ownerData)
- {
- if (field is FieldInfo)
- {
- if (PropertyUtil.GetAttribute<ObjectMemberNameAttribute>(field) != null)
- {
- return new ObjectMemberNameEditor(field as FieldInfo, ownerData);
- }
- if (PropertyUtil.GetAttribute<TemplateIDAttribute>(field) != null)
- {
- return new TemplateIDEditor(field as FieldInfo, ownerData, PropertyUtil.GetAttribute<TemplateIDAttribute>(field));
- }
- if (PropertyUtil.GetAttribute<TemplatesIDAttribute>(field) != null)
- {
- return new TemplatesIDEditor(field as FieldInfo, ownerData, PropertyUtil.GetAttribute<TemplatesIDAttribute>(field));
- }
- if (PropertyUtil.GetAttribute<ResourceIDAttribute>(field) != null)
- {
- return new ResourceIDEditor(field as FieldInfo, ownerData, PropertyUtil.GetAttribute<ResourceIDAttribute>(field));
- }
- if (PropertyUtil.GetAttribute<ColorValueAttribute>(field) != null)
- {
- return new G2DColorEditor(field, ownerData);
- }
- }
- return null;
- }
- public TypeConverter GetConverter(MemberInfo field, Type fieldType, object ownerData)
- {
- if (field is FieldInfo)
- {
- TemplateIDAttribute tid = PropertyUtil.GetAttribute<TemplateIDAttribute>(field);
- if (tid != null)
- {
- return new TemplateIDConvert(tid);
- }
- TemplatesIDAttribute tsid = PropertyUtil.GetAttribute<TemplatesIDAttribute>(field);
- if (tsid != null)
- {
- return new TemplatesIDConvert(tsid);
- }
- DescAttribute desc = PropertyUtil.GetAttribute<DescAttribute>(field);
- ColorValueAttribute color = PropertyUtil.GetAttribute<ColorValueAttribute>(field);
- if (color != null && fieldType.Equals(typeof(int)))
- {
- return new G2DIntToHexTypeConverter();
- }
- }
- return null;
- }
-
-
-
- public class ObjectMemberNameEditor : UITypeEditor
- {
- private FieldInfo fieldInfo;
- private object ownerData;
- private ObjectMemberNameAttribute member;
- private Type ownerType;
- public ObjectMemberNameEditor(FieldInfo field, object ownerData)
- {
- this.fieldInfo = field;
- this.ownerData = ownerData;
- this.member = PropertyUtil.GetAttribute<ObjectMemberNameAttribute>(field);
- if (ownerData is IFieldMemberValue)
- {
- ownerType = (ownerData as IFieldMemberValue).OwnerType;
- }
- else
- {
- ownerType = member.ObjectType;
- }
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
- if (ownerType != null)
- {
- FieldsMap fm = GameFields.Manager.GetFields(ownerType, member.FieldType);
- if (fm != null)
- {
- G2DListSelectEditor<MemberDescAttribute> dialog = new G2DListSelectEditor<MemberDescAttribute>(
- fm.ListFields, fm.GetFieldDesc(value + ""));
- if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- value = dialog.SelectedObject.DataField.Name;
- return value;
- }
- }
- }
- return base.EditValue(context, provider, value);
- }
- }
- public class ResourceIDEditor : UITypeEditor
- {
- private Brush brush = new SolidBrush(Color.Green);
- private FieldInfo fieldInfo;
- private object ownerData;
- private ResourceIDAttribute resourceID;
- public ResourceIDEditor(FieldInfo field, object ownerData, ResourceIDAttribute tid)
- {
- this.fieldInfo = field;
- this.ownerData = ownerData;
- this.resourceID = tid;
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
- string id = (string)fieldInfo.GetValue(ownerData);
- {
- string fullPath = Editor.EditorRootDir + "\\" + id;
- fullPath = fullPath.Replace('/', '\\');
- fullPath = fullPath.Replace("\\\\", "\\");
- OpenFileDialog fd = new OpenFileDialog();
- DirectoryInfo resdir = new DirectoryInfo(Editor.EditorRootDir + "/../xmds_Data/StreamingAssets/AssetBundles/PC");
- fd.InitialDirectory = resdir.FullName + "\\res";
- fd.FileName = fullPath;
- fd.Multiselect = false;
- if (fd.ShowDialog() == DialogResult.OK)
- {
- FileInfo fdinfo = new FileInfo(fd.FileName);
- if (fdinfo.FullName.StartsWith(resdir.FullName))
- {
- id = fdinfo.FullName.Substring(resdir.FullName.Length);
- id = id.Replace('\\', '/');
- return id;
- }
- else
- {
- MessageBox.Show("无法引用编辑器目录之外的资源");
- }
- }
- }
- return base.EditValue(context, provider, value);
- }
- }
- public class TemplateIDEditor : UITypeEditor
- {
- private FieldInfo fieldInfo;
- private object ownerData;
- private TemplateIDAttribute templateID;
- public TemplateIDEditor(FieldInfo field, object ownerData, TemplateIDAttribute tid)
- {
- this.fieldInfo = field;
- this.ownerData = ownerData;
- this.templateID = tid;
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
- int id = (int)fieldInfo.GetValue(ownerData);
- object obj = Editor.Instance.GetTemplateByType(id, templateID.TemplateType);
- if (Editor.Instance.ShowSelectTemplateIDDialog(obj, templateID.TemplateType, out id))
- {
- return id;
- }
- return base.EditValue(context, provider, value);
- }
- }
- public class TemplateIDConvert : TypeConverter
- {
- private TemplateIDAttribute templateID;
- public TemplateIDConvert(TemplateIDAttribute templateID)
- {
- this.templateID = templateID;
- }
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- if (sourceType == typeof(string))
- {
- return true;
- }
- return false;
- }
- public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
- {
- if (destinationType == typeof(string))
- {
- return true;
- }
- return false;
- }
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string) && value.GetType() == typeof(int))
- {
- int id = (int)value;
- object obj = Editor.Instance.GetTemplateByType(id, templateID.TemplateType);
- return obj + "";
- }
- else
- {
- return base.ConvertTo(context, culture, value, destinationType);
- }
- }
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- if (value.GetType() == typeof(string))
- {
- int id = 0;
- try
- {
- string text = value.ToString();
- int i1 = text.LastIndexOf("(") + 1;
- int i2 = text.LastIndexOf(")");
- text = text.Substring(i1, i2 - i1);
- id = int.Parse(text);
- }
- catch (Exception err) { }
- return id;
- }
- else
- {
- return base.ConvertFrom(context, culture, value);
- }
- }
- }
- public class TemplatesIDEditor : UITypeEditor
- {
- private FieldInfo fieldInfo;
- private object ownerData;
- private TemplatesIDAttribute templatesID;
- public TemplatesIDEditor(FieldInfo field, object ownerData, TemplatesIDAttribute tid)
- {
- this.fieldInfo = field;
- this.ownerData = ownerData;
- this.templatesID = tid;
- }
- public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return UITypeEditorEditStyle.Modal;
- }
- public override object EditValue(
- ITypeDescriptorContext context,
- IServiceProvider provider,
- object value)
- {
- if (fieldInfo.FieldType == typeof(List<int>) ||
- fieldInfo.FieldType == typeof(int[]))
- {
- int[] list = new int[] { };
- if (value != null)
- {
- if (fieldInfo.FieldType == typeof(List<int>))
- {
- list = (value as List<int>).ToArray();
- }
- else if (fieldInfo.FieldType == typeof(int[]))
- {
- list = (value as int[]);
- }
- }
- object listvalue = GetListByType(templatesID.TemplateType, list);
- G2DCollectionEditor listedit = new G2DCollectionEditor(
- listvalue.GetType(), listvalue,
- new Type[] { GetListElementType(templatesID.TemplateType) });
- if (listedit.ShowDialog() == DialogResult.OK)
- {
- List<int> ret = GetListValue(
- templatesID.TemplateType,
- listedit.GetEditCompleteData());
- if (fieldInfo.FieldType == typeof(List<int>))
- {
- return ret;
- }
- else if (fieldInfo.FieldType == typeof(int[]))
- {
- return ret.ToArray();
- }
- }
- }
- return base.EditValue(context, provider, value);
- }
-
- #region _static_
- private static HashMap<Type, Type> mElementTypeMap = new HashMap<Type, Type>();
- private static HashMap<Type, Type> mListTypeMap = new HashMap<Type, Type>();
- static TemplatesIDEditor()
- {
- mElementTypeMap[typeof(UnitInfo)] = typeof(UnitListItem);
- mElementTypeMap[typeof(SkillTemplate)] = typeof(SkillListItem);
- mElementTypeMap[typeof(SpellTemplate)] = typeof(SpellListItem);
- mElementTypeMap[typeof(BuffTemplate)] = typeof(BuffListItem);
- mElementTypeMap[typeof(ItemTemplate)] = typeof(ItemListItem);
- mElementTypeMap[typeof(UnitTriggerTemplate)] = typeof(UnitTriggerListItem);
- mElementTypeMap[typeof(UnitEventTemplate)] = typeof(UnitEventListItem);
- mListTypeMap[typeof(UnitInfo)] = typeof(List<UnitListItem>);
- mListTypeMap[typeof(SkillTemplate)] = typeof(List<SkillListItem>);
- mListTypeMap[typeof(SpellTemplate)] = typeof(List<SpellListItem>);
- mListTypeMap[typeof(BuffTemplate)] = typeof(List<BuffListItem>);
- mListTypeMap[typeof(ItemTemplate)] = typeof(List<ItemListItem>);
- mListTypeMap[typeof(UnitTriggerTemplate)] = typeof(List<UnitTriggerListItem>);
- mListTypeMap[typeof(UnitEventTemplate)] = typeof(List<UnitEventListItem>);
- }
- public static Type GetListElementType(Type template_type)
- {
- return mElementTypeMap[template_type];
- }
- static public IList GetListByType(Type type, int[] list)
- {
- Type list_type = mListTypeMap[type];
- Type element_type = mElementTypeMap[type];
- IList ret = (IList)Activator.CreateInstance(list_type);
- foreach (int tid in list)
- {
- IListItem item = (IListItem)Activator.CreateInstance(element_type);
- item.ID = tid;
- ret.Add(item);
- }
- return ret;
- }
- static public List<int> GetListValue(Type type, object completeData)
- {
- List<int> ret = new List<int>();
- IList list = completeData as IList;
- foreach (IListItem tid in list)
- {
- ret.Add(tid.ID);
- }
- return ret;
- }
- public interface IListItem
- {
- int ID { get; set; }
- }
- public class UnitListItem : IListItem
- {
- [TemplateID(typeof(UnitInfo))]
- public int TemplateID;
- public int ID { get { return TemplateID; } set { this.TemplateID = value; } }
- public override string ToString()
- {
- object obj = Editor.Instance.GetTemplateByType(TemplateID, typeof(UnitInfo));
- return obj + "";
- }
- }
- public class SkillListItem : IListItem
- {
- [TemplateID(typeof(SkillTemplate))]
- public int TemplateID;
- public int ID { get { return TemplateID; } set { this.TemplateID = value; } }
- public override string ToString()
- {
- object obj = Editor.Instance.GetTemplateByType(TemplateID, typeof(SkillTemplate));
- return obj + "";
- }
- }
- public class SpellListItem : IListItem
- {
- [TemplateID(typeof(SpellTemplate))]
- public int TemplateID;
- public int ID { get { return TemplateID; } set { this.TemplateID = value; } }
- public override string ToString()
- {
- object obj = Editor.Instance.GetTemplateByType(TemplateID, typeof(SpellTemplate));
- return obj + "";
- }
- }
- public class BuffListItem : IListItem
- {
- [TemplateID(typeof(BuffTemplate))]
- public int TemplateID;
- public int ID { get { return TemplateID; } set { this.TemplateID = value; } }
- public override string ToString()
- {
- object obj = Editor.Instance.GetTemplateByType(TemplateID, typeof(BuffTemplate));
- return obj + "";
- }
- }
- public class ItemListItem : IListItem
- {
- [TemplateID(typeof(ItemTemplate))]
- public int TemplateID;
- public int ID { get { return TemplateID; } set { this.TemplateID = value; } }
- public override string ToString()
- {
- object obj = Editor.Instance.GetTemplateByType(TemplateID, typeof(ItemTemplate));
- return obj + "";
- }
- }
- public class UnitTriggerListItem : IListItem
- {
- [TemplateID(typeof(UnitTriggerTemplate))]
- public int TemplateID;
- public int ID { get { return TemplateID; } set { this.TemplateID = value; } }
- public override string ToString()
- {
- object obj = Editor.Instance.GetTemplateByType(TemplateID, typeof(UnitTriggerTemplate));
- return obj + "";
- }
- }
- public class UnitEventListItem : IListItem
- {
- [TemplateID(typeof(UnitEventTemplate))]
- public int TemplateID;
- public int ID { get { return TemplateID; } set { this.TemplateID = value; } }
- public override string ToString()
- {
- object obj = Editor.Instance.GetTemplateByType(TemplateID, typeof(UnitEventTemplate));
- return obj + "";
- }
- }
- #endregion
- }
- public class TemplatesIDConvert : TypeConverter
- {
- private TemplatesIDAttribute templatesID;
- public TemplatesIDConvert(TemplatesIDAttribute templatesID)
- {
- this.templatesID = templatesID;
- }
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- return false;
- }
- public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
- {
- if (destinationType == typeof(string))
- {
- return true;
- }
- return false;
- }
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string) && value.GetType() == typeof(List<int>))
- {
- int[] list = (value as List<int>).ToArray();
- StringBuilder sb = new StringBuilder();
- sb.Append(list.Length + "个单位");
- return sb.ToString();
- }
- else if (destinationType == typeof(string) && value.GetType() == typeof(int[]))
- {
- int[] list = (value as int[]);
- StringBuilder sb = new StringBuilder();
- sb.Append(list.Length + "个单位");
- return sb.ToString();
- }
- else
- {
- return base.ConvertTo(context, culture, value, destinationType);
- }
- }
- }
- }
- }
|