Ejemplo n.º 1
0
        /// <summary>
        /// Method called after the schema set has been loaded and the DomNodeTypes have been created, but
        /// before the DomNodeTypes have been frozen. This means that DomNodeType.SetIdAttribute, for example, has
        /// not been called on the DomNodeTypes. Is called shortly before OnDomNodeTypesFrozen.</summary>
        /// <param name="schemaSet">XML schema sets being loaded</param>
        protected override void OnSchemaSetLoaded(XmlSchemaSet schemaSet)
        {
            foreach (XmlSchemaTypeCollection typeCollection in GetTypeCollections())
            {
                m_namespace = typeCollection.TargetNamespace;
                m_typeCollection = typeCollection;
                Schema.Initialize(typeCollection);


                // register extensions
                Schema.gameType.Type.Define(new ExtensionInfo<GameEditingContext>());
                Schema.gameType.Type.Define(new ExtensionInfo<UniqueIdValidator>());


                // Add required property descriptors to GameObject and OrcType so it can be edited 
                // with two column PropertyGrid.

                // Note: this is programmatic approach: Decorate DomNode types with 
                //       property descriptors.
                //       Alternatively schema annotations can used.
                //       However, programmatic approach is recommend because of type safety.


                // Descriptors for armorType.
                string general = "General".Localize();
                var armorDescriptors = new PropertyDescriptorCollection(null);
                armorDescriptors.Add(new AttributePropertyDescriptor(
                           "Name".Localize(),
                           Schema.armorType.nameAttribute,
                           general,
                           "Armor name".Localize(),
                           false
                    ));

                armorDescriptors.Add(new AttributePropertyDescriptor(
                           "Defense".Localize(),
                           Schema.armorType.defenseAttribute,
                           general,
                           "Armor defense".Localize(),
                           false,
                           new NumericEditor(typeof(int))
                    ));

                armorDescriptors.Add(new AttributePropertyDescriptor(
                           "Price".Localize(),
                           Schema.armorType.priceAttribute,
                           general,
                           "Armor price in gold".Localize(),
                           false,
                           new NumericEditor(typeof(int))
                    ));

                Schema.armorType.Type.SetTag(armorDescriptors);
                
                // club type property descriptors.
                var clubDescriptors = new PropertyDescriptorCollection(null);
                clubDescriptors.Add(new AttributePropertyDescriptor(
                         "Spike".Localize(),
                         Schema.clubType.spikesAttribute,
                         general,
                         "Club Has Spikes".Localize(),
                         false,
                         new BoolEditor()
                  ));


                clubDescriptors.Add(new AttributePropertyDescriptor(
                       "Damage".Localize(),
                       Schema.clubType.DamageAttribute,
                       general,
                       "Amount of damage per strike".Localize(),
                       false,
                       new NumericEditor(typeof(int))
                ));

                clubDescriptors.Add(new AttributePropertyDescriptor(
                        "Weight".Localize(),
                        Schema.clubType.wieghtAttribute,
                        general,
                        "Weight of the club".Localize(),
                        false,
                        new NumericEditor(typeof(float))
                 ));

                Schema.clubType.Type.SetTag(clubDescriptors);
               
                var gobDescriptors = new PropertyDescriptorCollection(null);
                gobDescriptors.Add(
                     new AttributePropertyDescriptor(
                           "Name".Localize(),
                            Schema.gameObjectType.nameAttribute,
                            null,
                            "Object name".Localize(),
                            false
                            ));

                // bool editor:  shows checkBox instead of textual (true,false).
                gobDescriptors.Add(
                     new AttributePropertyDescriptor(
                            "Visible".Localize(),
                            Schema.gameObjectType.visibleAttribute,
                            null,
                            "Show/Hide object in editor".Localize(),
                            false,
                            new BoolEditor()
                            ));

                // NumericTupleEditor can be used for vector values.
                string xformCategory = "Transformation".Localize();
                var transEditor =
                    new NumericTupleEditor(typeof(float), new string[] { "Tx", "Ty", "Tz" });

                gobDescriptors.Add(
                    new AttributePropertyDescriptor(
                           "Translate".Localize(),
                           Schema.gameObjectType.translateAttribute,
                           xformCategory,
                           "Object's position".Localize(),
                           false,
                           transEditor
                           ));

                var scaleEditor =
                    new NumericTupleEditor(typeof(float), new string[] { "Sx", "Sy", "Sz" });
                gobDescriptors.Add(
                    new AttributePropertyDescriptor(
                           "Scale".Localize(),
                           Schema.gameObjectType.scaleAttribute,
                           xformCategory,
                           "Object's scale".Localize(),
                           false,
                           scaleEditor
                           ));

                var rotationEditor =
                    new NumericTupleEditor(typeof(float), new string[] { "Rx", "Ry", "Rz" });
                rotationEditor.ScaleFactor = 360.0f / (2.0f * (float)Math.PI); // Radians to Degrees
                gobDescriptors.Add(
                    new AttributePropertyDescriptor(
                           "Rotation".Localize(),
                           Schema.gameObjectType.rotateAttribute,
                           xformCategory,
                           "Object's orientation".Localize(),
                           false,
                           rotationEditor
                           ));

                Schema.gameObjectType.Type.SetTag(gobDescriptors);

                // Defines property descriptors for orcType.
                var orcDescriptors = new PropertyDescriptorCollection(null);
                string chCategory = "Character attributes".Localize();

                // Bounded int editor: used for editing bounded int properties.
                orcDescriptors.Add(
                    new AttributePropertyDescriptor(
                           "Skill".Localize(),
                           Schema.orcType.skillAttribute,
                           chCategory,
                           "Skill".Localize(),
                           false,
                           new BoundedIntEditor(1,120)
                           ));

                // Bounded float editor: similar to bounded int editor 
                // but it operates on float instead.
                orcDescriptors.Add(
                   new AttributePropertyDescriptor(
                          "Weight".Localize(),
                          Schema.orcType.weightAttribute,
                          chCategory,
                          "Weight".Localize(),
                          false,                          
                          new BoundedFloatEditor(80, 400)
                          ));

                
                // store the value of enum as string.
                LongEnumEditor emotionEditor = new LongEnumEditor(typeof(OrcEmotion));
                orcDescriptors.Add(
                  new AttributePropertyDescriptor(
                         "Emotion".Localize(),
                         Schema.orcType.emotionAttribute,
                         chCategory,
                         "Emotion".Localize(),
                         false,
                         emotionEditor
                         ));


                // FlagsUITypeEditor store flags as int.
                // doesn't implement IPropertyEditor
                
                FlagsUITypeEditor goalsEditor = new FlagsUITypeEditor(Enum.GetNames(typeof(OrcGoals)));
                FlagsTypeConverter goalsConverter = new FlagsTypeConverter(Enum.GetNames(typeof(OrcGoals)));
                orcDescriptors.Add(
                 new AttributePropertyDescriptor(
                        "Goals".Localize(),
                        Schema.orcType.goalsAttribute,
                        chCategory,
                        "Goals".Localize(),
                        false,
                        goalsEditor,
                        goalsConverter
                        ));


                orcDescriptors.Add(
                new AttributePropertyDescriptor(
                       "Health".Localize(),
                       Schema.orcType.healthAttribute,
                       chCategory,
                       "Orc's health".Localize(),
                       false,
                       new NumericEditor(typeof(int))
                       ));


                //EmbeddedCollectionEditor edit children (edit, add, remove, move).
                // note: EmbeddedCollectionEditor needs some work (effecienty and implementation issues).
                var collectionEditor = new EmbeddedCollectionEditor();

                // the following  lambda's handles (add, remove, move ) items.
                collectionEditor.GetItemInsertersFunc = (context)=>
                    {
                        var insertors
                            = new EmbeddedCollectionEditor.ItemInserter[1];

                        var list = context.GetValue() as IList<DomNode>;
                        if (list != null)
                        {
                            var childDescriptor
                                = context.Descriptor as ChildPropertyDescriptor;
                            if (childDescriptor != null)
                            {
                                insertors[0] = new EmbeddedCollectionEditor.ItemInserter(childDescriptor.ChildInfo.Type.Name,
                            delegate
                            {
                                DomNode node = new DomNode(childDescriptor.ChildInfo.Type);
                                if (node.Type.IdAttribute != null)
                                {
                                    node.SetAttribute(node.Type.IdAttribute, node.Type.Name);
                                }
                                list.Add(node);
                                return node;
                            });
                                return insertors;
                            }
                        }
                        return EmptyArray<EmbeddedCollectionEditor.ItemInserter>.Instance;
                    };


                collectionEditor.RemoveItemFunc = (context, item) =>
                    {
                        var list = context.GetValue() as IList<DomNode>;
                        if (list != null)
                            list.Remove(item.Cast<DomNode>());
                    };


                collectionEditor.MoveItemFunc = (context, item, delta) =>
                    {
                        var list = context.GetValue() as IList<DomNode>;
                        if (list != null)
                        {
                            DomNode node = item.Cast<DomNode>();
                            int index = list.IndexOf(node);
                            int insertIndex = index + delta;
                            if (insertIndex < 0 || insertIndex >= list.Count)
                                return;
                            list.RemoveAt(index);
                            list.Insert(insertIndex, node);
                        }

                    };

                string weaponCategory = "Weapons and Defense".Localize();
                orcDescriptors.Add(
                 new ChildPropertyDescriptor(
                        "Armor".Localize(),
                        Schema.orcType.armorChild,
                        weaponCategory,
                        "Armors".Localize(),
                        false,
                        collectionEditor
                        ));

                orcDescriptors.Add(
                new ChildPropertyDescriptor(
                       "Club".Localize(),
                       Schema.orcType.clubChild,
                       weaponCategory,
                       "Club".Localize(),
                       false,
                       collectionEditor
                       ));

                orcDescriptors.Add(
                new ChildPropertyDescriptor(
                       "Orcs".Localize(),
                       Schema.orcType.orcChild,
                       "Children".Localize(),
                       "Orc children".Localize(),
                       false,
                       collectionEditor
                       ));



                 string renderingCategory = "Rendering".Localize();

                // color picker.
                // note: ColorPickerEditor doesn't implement IPropertyEditor
                 orcDescriptors.Add(
                  new AttributePropertyDescriptor(
                         "Skin".Localize(),
                         Schema.orcType.skinColorAttribute,
                         renderingCategory,
                         "Skin color".Localize(),
                         false,
                         new ColorPickerEditor(),
                         new IntColorConverter()
                         ));

                
                // file picker.
                 orcDescriptors.Add(
                  new AttributePropertyDescriptor(
                         "Texture file".Localize(),
                         Schema.orcType.textureFileAttribute,
                         renderingCategory,
                         "Texture file".Localize(),
                         false,
                         new FileUriEditor("Texture file (*.dds)|*.dds")
                         ));
                 
                // Edit matrix.
                //NumericMatrixEditor
                 orcDescriptors.Add(
                  new AttributePropertyDescriptor(
                         "Texture Transform".Localize(),
                         Schema.orcType.textureTransformAttribute,
                         renderingCategory,
                         "Texture Transform".Localize(),
                         false,
                         new NumericMatrixEditor()
                         ));


                // Edit array.
                // ArrayEditor, need some work, it has some efficiency and implementation issues.
                orcDescriptors.Add(
                  new AttributePropertyDescriptor(
                         "Texture Array".Localize(),
                         Schema.orcType.textureArrayAttribute,
                         renderingCategory,
                         "Texture Array".Localize(),
                         false,
                         new ArrayEditor()
                         ));


                // readonly property,
                // show datetime as readonly.
                orcDescriptors.Add(
                 new AttributePropertyDescriptor(
                        "Revision data".Localize(),
                        Schema.orcType.TextureRevDateAttribute,
                        renderingCategory,
                        "Texture revision data and time".Localize(),
                        true
                        ));
            
                // folder picker.
                // FolderUriEditor and FolderBrowserDialogUITypeEditor
                orcDescriptors.Add(
                 new AttributePropertyDescriptor(
                        "Resource Folder".Localize(),
                        Schema.orcType.resourceFolderAttribute,
                        renderingCategory,
                        "Resource folder".Localize(),
                        false,
                        new FolderUriEditor()
                        ));
                
                Schema.orcType.Type.SetTag(orcDescriptors);
                // only one namespace
                break;
            }
        }
Ejemplo n.º 2
0
            private static EmbeddedCollectionEditor CreateEmbeddedCollectionEditor()
            {
                var objectName = "Objects";
                var result = new EmbeddedCollectionEditor();
                result.GetItemInsertersFunc = (context) =>
                {
                    var list = context.GetValue() as IList<Object>;
                    if (list == null) return EmptyArray<EmbeddedCollectionEditor.ItemInserter>.Instance;

                    // create ItemInserter for each component type.
                    var insertors = new EmbeddedCollectionEditor.ItemInserter[1]
                    {
                        new EmbeddedCollectionEditor.ItemInserter(objectName,
                        delegate
                        {
                            var o = new Object();
                            list.Add(o);
                            return o;
                        })
                    };
                    return insertors;
                };

                result.RemoveItemFunc = (context, item) =>
                {
                    var list = context.GetValue() as IList<Object>;
                    if (list != null)
                        list.Remove(item as Object);
                };

                result.MoveItemFunc = (context, item, delta) =>
                {
                    var list = context.GetValue() as IList<Object>;
                    if (list != null)
                    {
                        var node = item as Object;
                        int index = list.IndexOf(node);
                        int insertIndex = index + delta;
                        if (insertIndex < 0 || insertIndex >= list.Count)
                            return;
                        list.RemoveAt(index);
                        list.Insert(insertIndex, node);
                    }
                };

                return result;
            }
Ejemplo n.º 3
0
        protected override void OnSchemaSetLoaded(XmlSchemaSet schemaSet)
        {
            m_typeCollection = null;
            foreach (XmlSchemaTypeCollection typeCollection in GetTypeCollections())
            {
                m_namespace = typeCollection.TargetNamespace;
                m_typeCollection = typeCollection;
                Schema.Initialize(typeCollection);
                GameAdapters.Initialize(this);
                // the level editor schema defines only one type collection
                break;
            }
            if (m_typeCollection == null) return;

            Schema.gameObjectComponentType.Type.SetTag(
                    new PropertyDescriptorCollection(
                        new PropertyDescriptor[] {
                            new AttributePropertyDescriptor(
                                "Name".Localize(),
                                Schema.gameObjectComponentType.nameAttribute,
                                null,
                                "Component name".Localize(),
                                false),
                            new AttributePropertyDescriptor(
                                "Active".Localize(),
                                Schema.gameObjectComponentType.activeAttribute,
                                null,
                                "Is this component active".Localize(),
                                false,
                                new BoolEditor())
                }));

            Schema.renderComponentType.Type.SetTag(
                   new PropertyDescriptorCollection(
                       new PropertyDescriptor[] {
                            new AttributePropertyDescriptor(
                                "Visible".Localize(),
                                Schema.renderComponentType.visibleAttribute,
                                null,
                                "Component visiblity".Localize(),
                                false,
                                new BoolEditor()),
                            new AttributePropertyDescriptor(
                                "cast Shadow".Localize(),
                                Schema.renderComponentType.castShadowAttribute,
                                null,
                                "Is component casts shadaw".Localize(),
                                false,
                                new BoolEditor()),
                           new AttributePropertyDescriptor(
                                "Receive Shadow".Localize(),
                                Schema.renderComponentType.receiveShadowAttribute,
                                null,
                                "Is component receive  shadow".Localize(),
                                false,
                                new BoolEditor()),

                           new AttributePropertyDescriptor(
                                "Draw Distance".Localize(),
                                Schema.renderComponentType.drawDistanceAttribute,
                                null,
                                "Minimum distance to draw the component".Localize(),
                                false)
                }));

            Schema.spinnerComponentType.Type.SetTag(
                   new PropertyDescriptorCollection(
                       new PropertyDescriptor[] {
                            new AttributePropertyDescriptor(
                                "RPS".Localize(),
                                Schema.spinnerComponentType.rpsAttribute,
                                null,
                                "Revolutions per second".Localize(),
                                false,
                                new NumericTupleEditor(typeof(float),new string[] { "x", "y", "z" })
                                )
                       }));

            ResourceInfo resInfo = m_gameEngine.Info.ResourceInfos.GetByType(ResourceTypes.Model);
            string filter = resInfo != null ? resInfo.Filter : null;
            var refEdit = new FileUriEditor(filter);
            Schema.meshComponentType.Type.SetTag(
                   new PropertyDescriptorCollection(
                       new PropertyDescriptor[] {
                            new AttributePropertyDescriptor(
                                "3d Model".Localize(),
                                Schema.meshComponentType.refAttribute,
                                null,
                                "path to 3d model".Localize(),
                                false,
                                refEdit
                                )}));

            var collectionEditor = new EmbeddedCollectionEditor();

            // the following  lambda's handles (add, remove, move ) items.
            collectionEditor.GetItemInsertersFunc = (context) =>
            {
                var list = context.GetValue() as IList<DomNode>;
                if (list == null) return EmptyArray<EmbeddedCollectionEditor.ItemInserter>.Instance;

                // create ItemInserter for each component type.
                var insertors = new EmbeddedCollectionEditor.ItemInserter[2];

                insertors[0] = new EmbeddedCollectionEditor.ItemInserter("StaticMeshComponent",
                    delegate
                    {
                        DomNode node = new DomNode(Schema.meshComponentType.Type);
                        node.SetAttribute(Schema.gameObjectComponentType.nameAttribute, node.Type.Name);
                        list.Add(node);
                        return node;
                    });

                insertors[1] = new EmbeddedCollectionEditor.ItemInserter("SpinnerComponent",
                    delegate
                    {
                        DomNode node = new DomNode(Schema.spinnerComponentType.Type);
                        node.SetAttribute(Schema.gameObjectComponentType.nameAttribute, node.Type.Name);
                        list.Add(node);
                        return node;
                    });

                return insertors;
            };

            collectionEditor.RemoveItemFunc = (context, item) =>
            {
                var list = context.GetValue() as IList<DomNode>;
                if (list != null)
                    list.Remove(item.Cast<DomNode>());
            };

            collectionEditor.MoveItemFunc = (context, item, delta) =>
            {
                var list = context.GetValue() as IList<DomNode>;
                if (list != null)
                {
                    DomNode node = item.Cast<DomNode>();
                    int index = list.IndexOf(node);
                    int insertIndex = index + delta;
                    if (insertIndex < 0 || insertIndex >= list.Count)
                        return;
                    list.RemoveAt(index);
                    list.Insert(insertIndex, node);
                }

            };

            // add child property descriptors gameObjectType
            Schema.gameObjectWithComponentType.Type.SetTag(
                   new PropertyDescriptorCollection(
                       new PropertyDescriptor[] {
                            new ChildPropertyDescriptor(
                                "Components".Localize(),
                                Schema.gameObjectWithComponentType.componentChild,
                                null,
                                "List of GameObject Components".Localize(),
                                false,
                                collectionEditor)
                                }));

            LevelEditorXLE.Patches.OnSchemaSetLoaded(schemaSet, GetTypeCollections());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method called after the schema set has been loaded and the DomNodeTypes have been created, but
        /// before the DomNodeTypes have been frozen. This means that DomNodeType.SetIdAttribute, for example, has
        /// not been called on the DomNodeTypes. Is called shortly before OnDomNodeTypesFrozen.
        /// Create property descriptors for types.</summary>
        /// <param name="schemaSet">XML schema sets being loaded</param>
        protected override void OnSchemaSetLoaded(XmlSchemaSet schemaSet)
        {
            foreach (XmlSchemaTypeCollection typeCollection in GetTypeCollections())
            {
                m_namespace = typeCollection.TargetNamespace;
                m_typeCollection = typeCollection;
                Schema.Initialize(typeCollection);

                // register extensions

                // extend FSM root node with FSM, document, editing context, and printing support
                Schema.fsmType.Type.Define(new ExtensionInfo<Fsm>());
                Schema.fsmType.Type.Define(new ExtensionInfo<EditingContext>());
                Schema.fsmType.Type.Define(new ExtensionInfo<ViewingContext>());
                Schema.fsmType.Type.Define(new ExtensionInfo<TransitionRouter>());
                Schema.fsmType.Type.Define(new ExtensionInfo<Document>());
                Schema.fsmType.Type.Define(new ExtensionInfo<PrintableDocument>());

                // extend with adapter to synch multiple histories in document with document "Dirty" flag
                Schema.fsmType.Type.Define(new ExtensionInfo<MultipleHistoryContext>());
                // extend with adapter for prototyping
                Schema.fsmType.Type.Define(new ExtensionInfo<PrototypingContext>());
                // extend with adapters to validate references and unique ids
                Schema.fsmType.Type.Define(new ExtensionInfo<ReferenceValidator>());
                Schema.fsmType.Type.Define(new ExtensionInfo<UniqueIdValidator>());

                // define FSM object model
                Schema.prototypeFolderType.Type.Define(new ExtensionInfo<PrototypeFolder>());
                Schema.prototypeType.Type.Define(new ExtensionInfo<Prototype>());
                Schema.stateType.Type.Define(new ExtensionInfo<State>());
                Schema.transitionType.Type.Define(new ExtensionInfo<Transition>());
                Schema.annotationType.Type.Define(new ExtensionInfo<Annotation>());

                // annotate state and annotation types with display information for palette

                Schema.stateType.labelAttribute.DefaultValue = "State".Localize();

                Schema.stateType.Type.SetTag(
                    new NodeTypePaletteItem(
                        Schema.stateType.Type,
                        (string)Schema.stateType.labelAttribute.DefaultValue,
                        "State in a finite state machine".Localize(),
                        Resources.StateImage));

                Schema.annotationType.Type.SetTag(
                    new NodeTypePaletteItem(
                        Schema.annotationType.Type,
                        "Comment".Localize(),
                        "Comment on state machine".Localize(),
                        Resources.AnnotationImage));

                // register property descriptors on state, transition, folder types

                // TransitionType have a collection of child triggers.
                // use EmbeddedCollectionEditor to edit children (edit, add, remove, move).
                // Note: EmbeddedCollectionEditor needs some work (efficiency and implementation issues).                
                var collectionEditor = new EmbeddedCollectionEditor();

                // the following  lambda's handles (add, remove, move ) items.
                collectionEditor.GetItemInsertersFunc = (context) =>
                {
                    var insertors
                        = new EmbeddedCollectionEditor.ItemInserter[1];

                    var list = context.GetValue() as IList<DomNode>;
                    if (list != null)
                    {
                        var childDescriptor
                            = context.Descriptor as ChildPropertyDescriptor;
                        if (childDescriptor != null)
                        {
                            insertors[0] = new EmbeddedCollectionEditor.ItemInserter(childDescriptor.ChildInfo.Type.Name,
                        delegate
                        {
                            DomNode node = new DomNode(childDescriptor.ChildInfo.Type);
                            if (node.Type.IdAttribute != null)
                            {
                                node.SetAttribute(node.Type.IdAttribute, node.Type.Name);
                            }
                            list.Add(node);
                            return node;
                        });
                            return insertors;
                        }
                    }
                    return EmptyArray<EmbeddedCollectionEditor.ItemInserter>.Instance;
                };


                collectionEditor.RemoveItemFunc = (context, item) =>
                {
                    var list = context.GetValue() as IList<DomNode>;
                    if (list != null)
                        list.Remove(item.Cast<DomNode>());
                };


                collectionEditor.MoveItemFunc = (context, item, delta) =>
                {
                    var list = context.GetValue() as IList<DomNode>;
                    if (list != null)
                    {
                        DomNode node = item.Cast<DomNode>();
                        int index = list.IndexOf(node);
                        int insertIndex = index + delta;
                        if (insertIndex < 0 || insertIndex >= list.Count)
                            return;
                        list.RemoveAt(index);
                        list.Insert(insertIndex, node);
                    }

                };

                Schema.stateType.Type.SetTag(
                    new PropertyDescriptorCollection(
                        new PropertyDescriptor[] {
                            new AttributePropertyDescriptor(
                                "Name".Localize(),
                                Schema.stateType.labelAttribute, // 'nameAttribute' is unique id, label is user visible name
                                null,
                                "State name".Localize(),
                                false),
                            new AttributePropertyDescriptor(
                                "Size".Localize(),
                                Schema.stateType.sizeAttribute,
                                null,
                                "State size".Localize(),
                                false),
                            new AttributePropertyDescriptor(
                                "Hidden".Localize(),
                                Schema.stateType.hiddenAttribute,
                                null,
                                "Whether or not state is hidden".Localize(),
                                false,
                                new BoolEditor()),
                            new AttributePropertyDescriptor(
                                "Start".Localize(),
                                Schema.stateType.startAttribute,
                                null,
                                "Whether or not state is the start state".Localize(),
                                false,
                                new BoolEditor()),
                            new AttributePropertyDescriptor(
                                "Entry Action".Localize(),
                                Schema.stateType.entryActionAttribute,
                                null,
                                "Action performed when entering state".Localize(),
                                false),
                            new AttributePropertyDescriptor(
                                "Action".Localize(),
                                Schema.stateType.actionAttribute,
                                null,
                                "Action performed while in state".Localize(),
                                false),
                            new AttributePropertyDescriptor(
                                "Exit Action".Localize(),
                                Schema.stateType.exitActionAttribute,
                                null,
                                "Action performed when exiting state".Localize(),
                                false),
                    }));

               
                Schema.triggerType.Type.SetTag(
                    new PropertyDescriptorCollection(
                        new PropertyDescriptor[] {
                            new AttributePropertyDescriptor(
                                "Label".Localize(),
                                Schema.triggerType.labelAttribute,
                                null,
                                "Label displayed on trigger".Localize(),
                                false),                            
                            new AttributePropertyDescriptor(
                                "Id".Localize(),
                                Schema.triggerType.idAttribute,
                                null,
                                "Trigger id".Localize(),
                                false),
                            new AttributePropertyDescriptor(
                                "Action".Localize(),
                                Schema.triggerType.actionAttribute,
                                null,
                                "Action on trigger".Localize(),
                                false)

                }));



               


                Schema.transitionType.Type.SetTag(
                    new PropertyDescriptorCollection(
                        new PropertyDescriptor[] {
                            new AttributePropertyDescriptor(
                                "Label".Localize(),
                                Schema.transitionType.labelAttribute,
                                null,
                                "Label displayed on transition".Localize(),
                                false),                            
                            new AttributePropertyDescriptor(
                                "Action".Localize(),
                                Schema.transitionType.actionAttribute,
                                null,
                                "Action performed when making transition".Localize(),
                                false),
                           new ChildPropertyDescriptor(
                               "Triggers".Localize(),
                               Schema.transitionType.triggerChild,
                               null,
                               "List of triggers".Localize(),
                               false,
                               collectionEditor)
                        }));

                Schema.prototypeFolderType.Type.SetTag(
                    new PropertyDescriptorCollection(
                        new PropertyDescriptor[] {
                            new AttributePropertyDescriptor(
                                "Name".Localize(),
                                Schema.prototypeFolderType.nameAttribute,
                                null,
                                "Prototype folder name".Localize(),
                                false)
                    }));

                Schema.annotationType.Type.SetTag(
                    new PropertyDescriptorCollection(
                        new PropertyDescriptor[] {
                            new AttributePropertyDescriptor(
                                "Text".Localize(),
                                Schema.annotationType.textAttribute,
                                null,
                                "Comment text".Localize(),
                                false)
                    }));

                // the fsm schema defines only one type collection
                break;
            }
        }
            /// <summary>
            /// Constructor</summary>
            /// <param name="editor">Embedded property editor</param>
            /// <param name="context">Context for embedded property editing controls</param>
            /// <param name="toolStripLabelsEnabled">Whether toolstrip labels are enabled or not</param>
            public CollectionControl(EmbeddedCollectionEditor editor, PropertyEditorControlContext context, bool toolStripLabelsEnabled)
            {
                m_editor = editor;
                m_context = context;

                // Get active contexts and subscribe to ContextChanged event
                IContextRegistry contextRegistry = m_context.ContextRegistry;
                if (contextRegistry != null)
                {
                    contextRegistry.ActiveContextChanged += contextRegistry_ActiveContextChanged;
                    ObservableContext = contextRegistry.GetActiveContext<IObservableContext>();
                    ValidationContext = contextRegistry.GetActiveContext<IValidationContext>();
                    TransactionContext = contextRegistry.GetActiveContext<ITransactionContext>();
                }
                else if (context.TransactionContext != null)
                {
                    ObservableContext = context.TransactionContext.As<IObservableContext>();
                    ValidationContext = context.TransactionContext.As<IValidationContext>();
                    TransactionContext = context.TransactionContext;
                }

                // Initialize Controls

                m_toolStrip = new ToolStrip { Dock = DockStyle.Top };
                
                m_addButton = new ToolStripButton
                {
                    Text = "Add".Localize(),
                    Image = s_addImage,
                    Enabled = false,
                    DisplayStyle = ToolStripItemDisplayStyle.Image
                };
                m_addButton.Click += addButton_Click;
                m_toolStrip.Items.Add(m_addButton);

                m_addSplitButton = new ToolStripSplitButton { Image = s_addImage, Visible = false };
                m_addSplitButton.ButtonClick += addButton_Click;
                m_toolStrip.Items.Add(m_addSplitButton);

                m_deleteButton = new ToolStripButton
                {
                    Text = "Delete".Localize(),
                    Image = s_removeImage,
                    DisplayStyle = ToolStripItemDisplayStyle.Image
                };
                UpdateDeleteButton(false);
                m_deleteButton.Click += deleteButton_Click;
                m_toolStrip.Items.Add(m_deleteButton);

                m_upButton = new ToolStripButton
                {
                    Text = "Up".Localize("this is the name of a button that causes the selected item to be moved up in a list"),
                    Image = s_upImage,
                    DisplayStyle = ToolStripItemDisplayStyle.Image
                };
                m_upButton.Click += upButton_Click;
                m_toolStrip.Items.Add(m_upButton);

                m_downButton = new ToolStripButton
                {
                    Text = "Down".Localize("this is the name of a button that causes the selected item to be moved down in a list"),
                    Image = s_downImage,
                    DisplayStyle = ToolStripItemDisplayStyle.Image
                };
                m_downButton.Click += downButton_Click;
                m_toolStrip.Items.Add(m_downButton);

                UpdateMoveButtons(false);

                m_itemsCountLabel = new ToolStripStatusLabel
                {
                    Text = "[0 items]",
                    DisplayStyle = ToolStripItemDisplayStyle.Text
                };
                m_toolStrip.Items.Add(m_itemsCountLabel);

                Controls.Add(m_toolStrip);
                Height = m_toolStrip.Height;
                m_toolStrip.GripStyle = ToolStripGripStyle.Hidden;

                if (toolStripLabelsEnabled)
                    m_toolStrip.SizeChanged += toolStrip_SizeChanged;
            }
Ejemplo n.º 6
0
        private static EmbeddedCollectionEditor SetupEmbeddedCollectionEditor(DomNodeType containedType, string objectName)
        {
            var result = new EmbeddedCollectionEditor();
            result.GetItemInsertersFunc = (context) =>
            {
                var list = context.GetValue() as IList<DomNode>;
                if (list == null) return EmptyArray<EmbeddedCollectionEditor.ItemInserter>.Instance;

                // create ItemInserter for each component type.
                var insertors = new EmbeddedCollectionEditor.ItemInserter[1]
                    {
                        new EmbeddedCollectionEditor.ItemInserter(objectName,
                        delegate
                        {
                            DomNode node = new DomNode(containedType);
                            list.Add(node);
                            return node;
                        })
                    };
                return insertors;
            };

            result.RemoveItemFunc = (context, item) =>
            {
                var list = context.GetValue() as IList<DomNode>;
                if (list != null)
                    list.Remove(item.Cast<DomNode>());
            };

            result.MoveItemFunc = (context, item, delta) =>
            {
                var list = context.GetValue() as IList<DomNode>;
                if (list != null)
                {
                    DomNode node = item.Cast<DomNode>();
                    int index = list.IndexOf(node);
                    int insertIndex = index + delta;
                    if (insertIndex < 0 || insertIndex >= list.Count)
                        return;
                    list.RemoveAt(index);
                    list.Insert(insertIndex, node);
                }
            };

            return result;
        }