示例#1
0
        /// <summary>
        /// Converts the palette item into an object that can be inserted into an
        /// IInstancingContext</summary>
        /// <param name="item">Item to convert</param>
        /// <returns>Object that can be inserted into an IInstancingContext</returns>
        object IPaletteClient.Convert(object item)
        {
            DomNode             node        = null;
            NodeTypePaletteItem paletteItem = item.As <NodeTypePaletteItem>();

            if (paletteItem != null)
            {
                DomNodeType nodeType = paletteItem.NodeType;
                node = new DomNode(nodeType);

                if (nodeType.IdAttribute != null)
                {
                    node.SetAttribute(nodeType.IdAttribute, paletteItem.Name); // unique id, for referencing
                }
                if (nodeType == Schema.eventType.Type)
                {
                    node.SetAttribute(Schema.eventType.nameAttribute, paletteItem.Name);
                }
                else if (Schema.resourceType.Type.IsAssignableFrom(nodeType))
                {
                    node.SetAttribute(Schema.resourceType.nameAttribute, paletteItem.Name);
                }
            }
            return(node);
        }
示例#2
0
        /// <summary>
        /// Creates game by creating DomNodes and not using DOM adapters</summary>
        private static DomNode CreateGameUsingDomNode()
        {
            // Create DOM node of the root type defined by the schema
            DomNode game = new DomNode(GameSchema.gameType.Type, GameSchema.gameRootElement);

            game.SetAttribute(GameSchema.gameType.nameAttribute, "Ogre Adventure II");
            IList <DomNode> childList = game.GetChildList(GameSchema.gameType.gameObjectChild);

            // Add an ogre
            DomNode ogre = new DomNode(GameSchema.ogreType.Type);

            ogre.SetAttribute(GameSchema.ogreType.nameAttribute, "Bill");
            ogre.SetAttribute(GameSchema.ogreType.sizeAttribute, 12);
            ogre.SetAttribute(GameSchema.ogreType.strengthAttribute, 100);
            childList.Add(ogre);


            // Add a dwarf
            DomNode dwarf = new DomNode(GameSchema.dwarfType.Type);

            dwarf.SetAttribute(GameSchema.dwarfType.nameAttribute, "Sally");
            dwarf.SetAttribute(GameSchema.dwarfType.ageAttribute, 32);
            dwarf.SetAttribute(GameSchema.dwarfType.experienceAttribute, 55);
            childList.Add(dwarf);

            // Add a tree
            DomNode tree = new DomNode(GameSchema.treeType.Type);

            tree.SetAttribute(GameSchema.treeType.nameAttribute, "Mr. Oak");
            childList.Add(tree);

            return(game);
        }
示例#3
0
        public void TestGetAttribute()
        {
            DomNodeType   type = new DomNodeType("child");
            AttributeInfo info = GetIntAttribute("int");

            type.Define(info);
            DomNode test = new DomNode(type);

            Assert.True(test.IsAttributeDefault(info));
            Assert.Null(test.GetLocalAttribute(info));
            Assert.False(test.IsAttributeSet(info));

            test.SetAttribute(info, 2);
            Assert.AreEqual(test.GetAttribute(info), 2);
            Assert.AreEqual(test.GetLocalAttribute(info), 2);
            Assert.False(test.IsAttributeDefault(info));
            Assert.True(test.IsAttributeSet(info));

            test.SetAttribute(info, null);
            Assert.True(test.IsAttributeDefault(info));
            Assert.Null(test.GetLocalAttribute(info));
            Assert.False(test.IsAttributeSet(info));

            test.SetAttribute(info, 0);
            Assert.AreEqual(test.GetAttribute(info), 0);
            Assert.True(test.IsAttributeDefault(info));
            Assert.AreEqual(test.GetLocalAttribute(info), 0);
            Assert.True(test.IsAttributeSet(info));
        }
示例#4
0
        /// <summary>
        /// Inserts a new state with the specified location, label/name, and size.
        /// The x, y coordinates specify the upper left coordinates of the new state.</summary>
        /// <param name="xUpperLeft">Upper left x-coordinate of the new state</param>
        /// <param name="yUpperLeft">Upper left y-coordinate of the new state</param>
        /// <param name="label">State's label</param>
        /// <param name="size">State's size</param>
        /// <returns>New State</returns>
        public State InsertState(int xUpperLeft, int yUpperLeft, string label, int size)
        {
            xUpperLeft = xUpperLeft < 0 ? 0 : xUpperLeft;
            yUpperLeft = yUpperLeft < 0 ? 0 : yUpperLeft;
            size       = size < 64 ? 64 : size;
            DomNode domNode = new DomNode(Schema.stateType.Type);

            domNode.SetAttribute(Schema.stateType.nameAttribute, "State");
            domNode.SetAttribute(Schema.stateType.xAttribute, xUpperLeft);
            domNode.SetAttribute(Schema.stateType.yAttribute, yUpperLeft);
            domNode.SetAttribute(Schema.stateType.sizeAttribute, size);
            domNode.SetAttribute(Schema.stateType.labelAttribute, label);
            DataObject dataObject = new DataObject(new object[] { domNode });

            //The Point object passed to the Insert() function represents the center
            //of the new state (to match the drag and drop functionality), so convert
            //the upperLeft coordinates to the center coordinates:
            int xCenter = xUpperLeft + size / 2;
            int yCenter = yUpperLeft + size / 2;

            ITransactionContext transactionContext = this.As <ITransactionContext>();

            transactionContext.DoTransaction(
                delegate
            {
                Insert(dataObject, new Point(xCenter, yCenter));
            }, "Scripted InsertState");

            return(Selection.GetLastSelected <State>());
        }
示例#5
0
        /// <summary>
        /// Creates game using raw DomNode</summary>        
        private static DomNode CreateGameUsingDomNode()
        {                                     
            // create Dom node of the root type defined by the schema
            DomNode game = new DomNode(GameSchema.gameType.Type, GameSchema.gameRootElement);
            game.SetAttribute(GameSchema.gameType.nameAttribute, "Ogre Adventure II");
            IList<DomNode> childList = game.GetChildList(GameSchema.gameType.gameObjectChild);

            // Add an ogre
            DomNode ogre = new DomNode(GameSchema.ogreType.Type);
            ogre.SetAttribute(GameSchema.ogreType.nameAttribute, "Bill");
            ogre.SetAttribute(GameSchema.ogreType.sizeAttribute, 12);
            ogre.SetAttribute(GameSchema.ogreType.strengthAttribute, 100);
            childList.Add(ogre);


            // Add a dwarf
            DomNode dwarf = new DomNode(GameSchema.dwarfType.Type);
            dwarf.SetAttribute(GameSchema.dwarfType.nameAttribute, "Sally");
            dwarf.SetAttribute(GameSchema.dwarfType.ageAttribute, 32);
            dwarf.SetAttribute(GameSchema.dwarfType.experienceAttribute, 55);
            childList.Add(dwarf);

            // Add a tree
            DomNode tree = new DomNode(GameSchema.treeType.Type);
            tree.SetAttribute(GameSchema.treeType.nameAttribute, "Mr. Oak");
            childList.Add(tree);

            return game;           
        }
示例#6
0
        public void TestDefaultValue()
        {
            AttributeType type = new AttributeType("test", typeof(string));
            AttributeInfo test = new AttributeInfo("test", type);
            test.DefaultValue = "foo";
            Assert.AreEqual(test.DefaultValue, "foo");
            test.DefaultValue = null;
            Assert.AreEqual(test.DefaultValue, type.GetDefault());
            Assert.Throws<InvalidOperationException>(delegate { test.DefaultValue = 1; });

            AttributeType length2Type = new AttributeType("length2Type", typeof(int[]), 2);
            AttributeInfo length2Info = new AttributeInfo("length2", length2Type);
            Assert.AreEqual(length2Info.DefaultValue, length2Type.GetDefault());
            Assert.AreEqual(length2Info.DefaultValue, new int[] { default(int), default(int) });
            DomNodeType nodeType = new DomNodeType("testNodeType");
            nodeType.Define(length2Info);
            DomNode node = new DomNode(nodeType);
            Assert.AreEqual(node.GetAttribute(length2Info), length2Info.DefaultValue);
            node.SetAttribute(length2Info, new int[] { 1, 2 });
            Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1, 2 });
            node.SetAttribute(length2Info, new int[] { 1 });
            Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1 });

            AttributeType length1Type = new AttributeType("length1Type", typeof(int[]), 1);
            AttributeInfo length1Info = new AttributeInfo("length1", length1Type);
            Assert.AreEqual(length1Info.DefaultValue, length1Type.GetDefault());
            Assert.AreEqual(length1Info.DefaultValue, new int[] { default(int) });
            nodeType = new DomNodeType("testNodeType");
            nodeType.Define(length1Info);
            node = new DomNode(nodeType);
            Assert.AreEqual(node.GetAttribute(length1Info), length1Info.DefaultValue);
            node.SetAttribute(length1Info, new int[] { 1 });
            Assert.AreEqual(node.GetAttribute(length1Info), new int[] { 1 });
        }
示例#7
0
        public void TestDuplicateAttributeInfo()
        {
            // This would be illegal in a schema file, but it seems to be supported OK in the DOM.
            var attr1   = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var attr2   = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var domType = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { attr1, attr2 },
                EmptyEnumerable <ChildInfo> .Instance,
                EmptyEnumerable <ExtensionInfo> .Instance);

            var domNode = new DomNode(domType);

            var originalAttr1 = "setting attr1";
            var originalAttr2 = "setting attr2";

            domNode.SetAttribute(attr1, originalAttr1);
            domNode.SetAttribute(attr2, originalAttr2);

            string resultAttr1 = (string)domNode.GetAttribute(attr1);
            string resultAttr2 = (string)domNode.GetAttribute(attr2);

            Assert.IsTrue(string.Equals(resultAttr1, originalAttr1));
            Assert.IsTrue(string.Equals(resultAttr2, originalAttr2));
        }
示例#8
0
        // Finds an attribute of the form "{name}={value}" and sets the corresponding
        //  attribute on the given DomNode.
        private static void FindAttribute(string line, string name, DomNode node)
        {
            AttributeInfo attributeInfo = node.Type.GetAttributeInfo(name);

            if (attributeInfo.Type.ClrType == typeof(int))
            {
                int value;
                if (FindAttribute(line, name, out value))
                {
                    node.SetAttribute(attributeInfo, value);
                }
            }
            else if (attributeInfo.Type.ClrType == typeof(bool))
            {
                bool value;
                if (FindAttribute(line, name, out value))
                {
                    node.SetAttribute(attributeInfo, value);
                }
            }
            else
            {
                string value;
                if (FindAttribute(line, name, out value))
                {
                    node.SetAttribute(attributeInfo, value);
                }
            }
        }
示例#9
0
文件: Editor.cs 项目: vincenthamm/ATF
 private static DomNode CreateArmor(string name, int defense, int price)
 {
     var armor = new DomNode(Schema.armorType.Type);
     armor.SetAttribute(Schema.armorType.nameAttribute, name);
     armor.SetAttribute(Schema.armorType.defenseAttribute, defense);
     armor.SetAttribute(Schema.armorType.priceAttribute, price);
     return armor;
 }
示例#10
0
        public static DomNode Create(int materialId)
        {
            var mat = new DomNode(Schema.terrainMaterialType.Type);

            mat.SetAttribute(Schema.abstractTerrainMaterialDescType.MaterialIdAttribute, materialId);
            mat.SetAttribute(Schema.abstractTerrainMaterialDescType.NameAttribute, "Material: " + materialId.ToString());
            return(mat);
        }
示例#11
0
文件: Editor.cs 项目: vincenthamm/ATF
 private static DomNode CreateClub(bool hasSpikes, int damage, float weight)
 {
     var club = new DomNode(Schema.clubType.Type);
     club.SetAttribute(Schema.clubType.spikesAttribute, hasSpikes);
     club.SetAttribute(Schema.clubType.DamageAttribute, damage);
     club.SetAttribute(Schema.clubType.wieghtAttribute, weight);
     return club;
 }
示例#12
0
        public static DomNode Create(int materialId)
        {
            var mat = new DomNode(Schema.vegetationSpawnMaterialType.Type);

            mat.SetAttribute(Schema.vegetationSpawnMaterialType.MaterialIdAttribute, materialId);
            mat.SetAttribute(Schema.vegetationSpawnMaterialType.NameAttribute, "Material: " + materialId.ToString());
            return(mat);
        }
示例#13
0
        private static DomNode CreateClub(bool hasSpikes, int damage, float weight)
        {
            var club = new DomNode(GameSchema.clubType.Type);

            club.SetAttribute(GameSchema.clubType.spikesAttribute, hasSpikes);
            club.SetAttribute(GameSchema.clubType.DamageAttribute, damage);
            club.SetAttribute(GameSchema.clubType.wieghtAttribute, weight);
            return(club);
        }
示例#14
0
        private static DomNode CreateArmor(string name, int defense, int price)
        {
            var armor = new DomNode(GameSchema.armorType.Type);

            armor.SetAttribute(GameSchema.armorType.nameAttribute, name);
            armor.SetAttribute(GameSchema.armorType.defenseAttribute, defense);
            armor.SetAttribute(GameSchema.armorType.priceAttribute, price);
            return(armor);
        }
示例#15
0
        public static DomNode Create(Uri reference, string name, Vec3F mins, Vec3F maxs)
        {
            var result = new DomNode(CellRefST.Type);

            result.SetAttribute(CellRefST.refAttribute, reference);
            result.SetAttribute(CellRefST.nameAttribute, name);
            DomNodeUtil.SetVector(result, CellRefST.captureMinsAttribute, mins);
            DomNodeUtil.SetVector(result, CellRefST.captureMaxsAttribute, maxs);
            return(result);
        }
        public static GameReference CreateNew(Uri uri)
        {
            string  fileName = System.IO.Path.GetFileName(uri.LocalPath);
            DomNode dom      = new DomNode(Schema.gameReferenceType.Type);

            dom.SetAttribute(Schema.gameReferenceType.nameAttribute, fileName);
            dom.SetAttribute(Schema.gameReferenceType.refAttribute, uri);
            GameReference gameRef = dom.As <GameReference>();

            return(gameRef);
        }
示例#17
0
        public void TestAttributeChangesNoTransaction()
        {
            DomNode child      = m_root.GetChild(ChildInfo);
            DomNode grandchild = child.GetChild(ChildInfo);

            grandchild.SetAttribute(StringAttrInfo, "foo1");
            grandchild.SetAttribute(StringAttrInfo, "foo2");
            grandchild.SetAttribute(StringAttrInfo, "foo3");

            // Because there's no transaction, each DOM change event should yield a TransactionFinishedXxx event.
            Assert.IsTrue(m_events.Count == 3);
            CheckAttributeEvent(m_events[0], grandchild, "", "foo1");
            CheckAttributeEvent(m_events[1], grandchild, "foo1", "foo2");
            CheckAttributeEvent(m_events[2], grandchild, "foo2", "foo3");
        }
示例#18
0
            public void Recall(DomNode domNode)
            {
                AttributeInfo diffuseInfo  = domNode.Type.GetAttributeInfo("diffuse");
                AttributeInfo ambientInfo  = domNode.Type.GetAttributeInfo("ambient");
                AttributeInfo specularInfo = domNode.Type.GetAttributeInfo("specular");

                if (diffuseInfo != null &&
                    ambientInfo != null &&
                    specularInfo != null)
                {
                    domNode.SetAttribute(ambientInfo, m_ambient.ToArgb());
                    domNode.SetAttribute(specularInfo, m_specular.ToArgb());
                    domNode.SetAttribute(diffuseInfo, m_diffuse.ToArgb());
                }
            }
示例#19
0
        public void RecursiveBuildFromVPK(ref ProjectFolder folder, IntPtr currentFolder)
        {
            uint folderCount = HLLib.hlFolderGetCount(currentFolder);

            for (uint i = 0; i < folderCount; i++)
            {
                IntPtr subItem = HLLib.hlFolderGetItem(currentFolder, i);
                string name    = HLLib.hlItemGetName(subItem);

                if (HLLib.hlItemGetType(subItem) == HLLib.HLDirectoryItemType.HL_ITEM_FOLDER)
                {
                    DomNode sf = new DomNode(DotaObjectsSchema.FolderType.Type);

                    sf.SetAttribute(DotaObjectsSchema.FolderType.NameAttribute, name);
                    sf.SetAttribute(DotaObjectsSchema.FolderType.PathAttribute, folder.Path + "/" + name);
                    sf.SetAttribute(DotaObjectsSchema.FolderType.InGCFAttribute, true);

                    DomNode par = folder.As <DomNode>();
                    par.GetChildList(DotaObjectsSchema.FolderType.FilesChild).Add(sf);


                    ProjectFolder subFolder = sf.As <ProjectFolder>();

                    RecursiveBuildFromVPK(ref subFolder, subItem);
                }
                if (HLLib.hlItemGetType(subItem) == HLLib.HLDirectoryItemType.HL_ITEM_FILE)
                {
                    string ext = name.Substring(name.LastIndexOf('.'));

                    ProjectFile f;
                    if (ProjectLoader.FileTypes.ContainsKey(ext))
                    {
                        ProjectLoader.FileTypeResolver resolver = ProjectLoader.FileTypes[ext];
                        f = (ProjectFile)(new DomNode(resolver.DomNodeType)).As(resolver.WrapperType);
                    }
                    else
                    {
                        f = (new DomNode(DotaObjectsSchema.FileType.Type)).As <ProjectFile>();
                    }

                    f.Name  = name;
                    f.Path  = folder.Path + "/" + name;
                    f.InGCF = true;

                    folder.Files.Add(f);
                }
            }
        }
示例#20
0
        static public DomNode _CreateSceneRoot(string name)
        {
            DomNode node = new DomNode(bitBoxSchema.graphType.Type, bitBoxSchema.sceneRootElement);

            node.SetAttribute(bitBoxSchema.graphType.nameAttribute, name);
            return(node);
        }
示例#21
0
        /// <summary>
        /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary>
        void IInitializable.Initialize()
        {
            m_mainform.Shown += (sender, e) =>
            {
                // create root node.
                var rootNode = new DomNode(Schema.gameType.Type, Schema.gameRootElement);
                rootNode.SetAttribute(Schema.gameType.nameAttribute, "Game");

                // create Orc game object and add it to rootNode.
                var orc1 = CreateOrc("Orc1");
                rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc1);

                // add a child Orc.
                var orcChildList = orc1.GetChildList(Schema.orcType.orcChild);
                orcChildList.Add(CreateOrc("Child Orc1"));


                var orc2 = CreateOrc("Orc2");
                rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc2);


                rootNode.InitializeExtensions();


                // set active context and select orc object.
                m_contextRegistry.ActiveContext = rootNode;

                var selectionContext = rootNode.Cast <ISelectionContext>();
                selectionContext.Set(new AdaptablePath <object>(orc1.GetPath()));
            };
        }
示例#22
0
        /// <summary>
        /// Inserts new object of given type using a transaction. Called by automated scripts during testing.</summary>
        /// <typeparam name="T">Type of object to insert</typeparam>
        /// <param name="insertingObject">DomNode that contains inserted object</param>
        /// <param name="insertionParent">Parent where object is inserted</param>
        /// <returns>Inserted object</returns>
        public T Insert <T>(DomNode insertingObject, DomNode insertionParent) where T : class
        {
            SetInsertionParent(insertionParent);
            insertingObject.SetAttribute(UISchema.UIType.nameAttribute, typeof(T).Name);
            DataObject dataObject = new DataObject(new object[] { insertingObject });

            ITransactionContext transactionContext = this.As <ITransactionContext>();

            transactionContext.DoTransaction(
                delegate
            {
                Insert(dataObject);
            }, "Scripted Insert Object");

            T         newItem   = null;
            ChildInfo childInfo = GetChildInfo(insertionParent, insertingObject.Type);

            if (childInfo != null)
            {
                if (childInfo.IsList)
                {
                    IList <DomNode> list = insertionParent.GetChildList(childInfo);
                    //This assumes the new object is always appended at the end of the list
                    DomNode newNode = list[list.Count - 1];
                    newItem = newNode.As <T>();
                }
                else
                {
                    DomNode newNode = insertionParent.GetChild(childInfo);
                    newItem = newNode.As <T>();
                }
            }

            return(newItem);
        }
        public static GameObjectReference Create(DomNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (!node.Is <IGameObject>())
            {
                throw new ArgumentException(node.Type.Name + " is not derived from " +
                                            Schema.gameObjectType.Type.Name);
            }
            DomNode      rootNode = node.GetRoot();
            GameDocument gameDoc  = rootNode.As <GameDocument>();

            if (gameDoc == null)
            {
                throw new ArgumentException("nod must belong to a document.");
            }


            // create game object reference.
            DomNode             refNode = new DomNode(Schema.gameObjectReferenceType.Type);
            GameObjectReference gobRef  = refNode.As <GameObjectReference>();

            // Create Uri
            Uri ur = new Uri(gameDoc.Uri + "#" + node.GetId());

            refNode.SetAttribute(Schema.gameObjectReferenceType.refAttribute, ur);
            gobRef.m_target = node;
            return(gobRef);
        }
示例#24
0
文件: Editor.cs 项目: Joxx0r/ATF
        /// <summary>
        /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary>
        void IInitializable.Initialize()
        {
            m_mainform.Shown += (sender, e) =>
                {
                    // create root node.
                    var rootNode = new DomNode(Schema.gameType.Type, Schema.gameRootElement);
                    rootNode.SetAttribute(Schema.gameType.nameAttribute, "Game");

                    // create Orc game object and add it to rootNode.
                    var orc = CreateOrc();
                    rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc);

                    // add a child Orc.
                    var orcChildList = orc.GetChildList(Schema.orcType.orcChild);
                    orcChildList.Add(CreateOrc("Child Orc1"));

                    rootNode.InitializeExtensions();

                    var edContext = rootNode.Cast<GameEditingContext>();
                    edContext.Set(orc);

                    // set active context and select orc object.
                    m_contextRegistry.ActiveContext = rootNode;
                    
                };
        }
示例#25
0
        /// <summary>
        /// Adds new objects of given type to statechart using a transaction.
        /// Called by automated scripts during testing.</summary>
        /// <typeparam name="T">Type of objects to add</typeparam>
        /// <param name="domNode">DomNode that contains added objects</param>
        /// <param name="xPos">X-coordinate at center of insertion position</param>
        /// <param name="yPos">Y-coordinate at center of insertion position</param>
        /// <param name="parentState">Insertion point for added objects</param>
        /// <returns>Last selected item</returns>
        public T Insert <T>(DomNode domNode, int xPos, int yPos, State parentState) where T : class
        {
            //Use a default name of the type of object.  Annotations don't have the nameAttribute though
            if (domNode.Type != Schema.annotationType.Type)
            {
                domNode.SetAttribute(Schema.stateBaseType.nameAttribute, typeof(T).Name);
            }
            DataObject dataObject = new DataObject(new object[] { domNode });

            Statechart insertionPoint = m_statechart;

            if (parentState != null)
            {
                insertionPoint = GetStatechart(parentState);
            }

            ITransactionContext transactionContext = this.As <ITransactionContext>();

            transactionContext.DoTransaction(
                delegate
            {
                Insert(dataObject, new Point(xPos, yPos), insertionPoint);
            }, "Scripted Insert Object");

            return(Selection.GetLastSelected <T>());
        }
示例#26
0
        /// <summary>
        /// Converts the palette item into an object that can be inserted into an
        /// IInstancingContext</summary>
        /// <param name="item">Item to convert</param>
        /// <returns>Object that can be inserted into an IInstancingContext</returns>
        object IPaletteClient.Convert(object item)
        {
            DomNodeType nodeType = (DomNodeType)item;
            DomNode node = new DomNode(nodeType);

            NodeTypePaletteItem paletteItem = nodeType.GetTag<NodeTypePaletteItem>();
            if (paletteItem != null)
            {
                if (nodeType.IdAttribute != null)
                    node.SetAttribute(nodeType.IdAttribute, paletteItem.Name); // unique id, for referencing

                if (nodeType == Schema.stateType.Type)
                    node.SetAttribute(Schema.stateType.labelAttribute, paletteItem.Name);   // user visible name for state
            }
            return node;
        }
示例#27
0
        /// <summary>
        /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary>
        void IInitializable.Initialize()
        {
            m_mainform.Shown += (sender, e) =>
            {
                // create root node.
                var rootNode = new DomNode(GameSchema.gameType.Type, GameSchema.gameRootElement);
                rootNode.SetAttribute(GameSchema.gameType.nameAttribute, "Game");

                // create Orc game object and add it to rootNode.
                var orc = CreateOrc();
                rootNode.GetChildList(GameSchema.gameType.gameObjectChild).Add(orc);

                // add a child Orc.
                var orcChildList = orc.GetChildList(GameSchema.orcType.orcChild);
                orcChildList.Add(CreateOrc("Child Orc1"));

                rootNode.InitializeExtensions();

                var edContext = rootNode.Cast <GameEditingContext>();
                edContext.Set(orc);

                // set active context and select orc object.
                m_contextRegistry.ActiveContext = rootNode;
            };
        }
示例#28
0
        public static IReference <IResource> Create(DomNodeType domtype, IResource resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }

            if (domtype == null)
            {
                domtype = Schema.resourceReferenceType.Type;
            }

            if (!Schema.resourceReferenceType.Type.IsAssignableFrom(domtype))
            {
                return(null);
            }

            ResourceReference resRef = null;

            if (CanReference(domtype, resource))
            {
                resRef          = new DomNode(domtype).As <ResourceReference>();
                resRef.m_target = resource;
                resRef.SetAttribute(Schema.resourceReferenceType.uriAttribute, resource.Uri);
            }
            return(resRef);
        }
示例#29
0
        public static DomNode Create(string name)
        {
            var result = new DomNode(Schema.envSettingsType.Type);

            result.SetAttribute(Schema.envSettingsType.NameAttribute, name);
            return(result);
        }
示例#30
0
        public static TerrainGob Create(string name, string hmPath, float cellSize)
        {            
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentNullException(name);

            if (!File.Exists(hmPath))
                throw new ArgumentException(hmPath + " does not exist");
            
            Uri ur = new Uri(hmPath);
            DomNode terrainNode = new DomNode(Schema.terrainGobType.Type);            
            terrainNode.SetAttribute(Schema.terrainGobType.cellSizeAttribute, cellSize);
            terrainNode.SetAttribute(Schema.terrainGobType.heightMapAttribute, ur);
            terrainNode.InitializeExtensions();
            TerrainGob terrain = terrainNode.As<TerrainGob>();
            terrain.Name = name;
            return terrain;
        }
示例#31
0
文件: Editor.cs 项目: vincenthamm/ATF
        /// <summary>
        /// Helper method to create instance of orcType.</summary>
        private static DomNode CreateOrc(string name = "Orc")
        {
            var orc = new DomNode(Schema.orcType.Type);
            orc.SetAttribute(Schema.orcType.nameAttribute, name);
            orc.SetAttribute(Schema.orcType.TextureRevDateAttribute, DateTime.Now);
            orc.SetAttribute(Schema.orcType.resourceFolderAttribute,System.Windows.Forms.Application.StartupPath);
            orc.SetAttribute(Schema.orcType.skinColorAttribute, System.Drawing.Color.DarkGray.ToArgb());
            orc.SetAttribute(Schema.orcType.healthAttribute, 80);
            var armorList = orc.GetChildList(Schema.orcType.armorChild);

            armorList.Add(CreateArmor("Iron breast plate",20,300));

            var clubList = orc.GetChildList(Schema.orcType.clubChild);
            clubList.Add(CreateClub(true, 20, 30));

            return orc;
        }
示例#32
0
        void ICommandClient.DoCommand(object commandTag)
        {
            if (!(commandTag is Command))
            {
                return;
            }

            switch ((Command)commandTag)
            {
            case Command.AddAmbientSettings:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.ambientSettingsType.Type),
                    "Add Ambient Settings", null);
                break;

            case Command.AddToneMapSettings:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.toneMapSettingsType.Type),
                    "Add Tone Map Settings", null);
                break;

            case Command.AddSun:
            {
                // the "Sun" is just a directional light with the name "Sun"
                var sun = new DomNode(Schema.directionalLightType.Type);
                sun.SetAttribute(Schema.envObjectType.nameAttribute, "Sun");
                ApplicationUtil.Insert(DomNode.GetRoot(), this, sun, "Add Sun", null);
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.envUtilityType.Type),
                    "Add Environment Utility", null);
                break;
            }

            case Command.AddAreaLight:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.areaLightType.Type),
                    "Add Area Light", null);
                break;

            case Command.AddDirectionalLight:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.directionalLightType.Type),
                    "Add Directional Light", null);
                break;

            case Command.AddShadowSettings:
                ApplicationUtil.Insert(
                    DomNode.GetRoot(), this,
                    new DomNode(Schema.envSettingsType.Type),
                    "Add Environment Settings", null);
                break;
            }
        }
示例#33
0
 public void _CheckNodeName(DomNode node)
 {
     if (bitBoxSchema.nodeType.Type.IsAssignableFrom(node.Type))
     {
         string name    = (string)node.GetAttribute(bitBoxSchema.nodeType.nameAttribute);
         string newName = m_uniqueNamer.Name(name);
         node.SetAttribute(bitBoxSchema.nodeType.nameAttribute, newName);
     }
 }
示例#34
0
        /// <summary>
        /// Converts the palette item into an object that can be inserted into an
        /// IInstancingContext</summary>
        /// <param name="item">Item to convert</param>
        /// <returns>Object that can be inserted into an IInstancingContext</returns>
        object IPaletteClient.Convert(object item)
        {
            DomNodeType nodeType = (DomNodeType)item;
            DomNode node = new DomNode(nodeType);

            NodeTypePaletteItem paletteItem = nodeType.GetTag<NodeTypePaletteItem>();
            if (paletteItem != null)
            {
                if (nodeType.IdAttribute != null)
                    node.SetAttribute(nodeType.IdAttribute, paletteItem.Name); // unique id, for referencing

                if (nodeType == Schema.eventType.Type)
                    node.SetAttribute(Schema.eventType.nameAttribute, paletteItem.Name);
                else if (Schema.resourceType.Type.IsAssignableFrom(nodeType))
                    node.SetAttribute(Schema.resourceType.nameAttribute, paletteItem.Name);
            }
            return node;
        }
示例#35
0
 /// <summary>
 /// Sets the DomNode attribute value to the given Sphere3F</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <param name="s">Sphere3F value to be set</param>
 public static void SetSphere(DomNode domNode, AttributeInfo attribute, Sphere3F s)
 {
     float[] value = new float[4];
     value[0] = s.Center.X;
     value[1] = s.Center.Y;
     value[2] = s.Center.Z;
     value[3] = s.Radius;
     domNode.SetAttribute(attribute, value);
 }
示例#36
0
        private static DomNode Deserialize(BinaryReader reader, Func <string, DomNodeType> getNodeType, List <Reference> references)
        {
            string      typeName = reader.ReadString();
            DomNodeType type     = getNodeType(typeName);

            if (type == null)
            {
                throw new InvalidOperationException("unknown node type");
            }

            DomNode node = new DomNode(type);

            foreach (AttributeInfo info in type.Attributes)
            {
                bool hasAttribute = reader.ReadBoolean();
                if (hasAttribute)
                {
                    // references are reconstituted after all nodes are read
                    if (info.Type.Type == AttributeTypes.Reference)
                    {
                        int refId = reader.ReadInt32();
                        references.Add(new Reference(node, info, refId));
                    }
                    else
                    {
                        string valueString = reader.ReadString();
                        object value       = info.Type.Convert(valueString);
                        node.SetAttribute(info, value);
                    }
                }
            }

            foreach (ChildInfo info in type.Children)
            {
                if (info.IsList)
                {
                    int             count     = reader.ReadInt32();
                    IList <DomNode> childList = node.GetChildList(info);
                    for (int i = 0; i < count; i++)
                    {
                        DomNode child = Deserialize(reader, getNodeType, references);
                        childList.Add(child);
                    }
                }
                else
                {
                    bool hasChild = reader.ReadBoolean();
                    if (hasChild)
                    {
                        DomNode child = Deserialize(reader, getNodeType, references);
                        node.SetChild(info, child);
                    }
                }
            }

            return(node);
        }
        /// <summary>
        /// When overridden in a derived class, sets the value of the component to a different value</summary>
        /// <param name="component">The component with the property value that is to be set</param>
        /// <param name="value">The new value</param>
        public override void SetValue(object component, object value)
        {
            DomNode node = GetNode(component);

            if (node != null)
            {
                node.SetAttribute(m_attributeInfo, value);
            }
        }
示例#38
0
        /// <summary>
        /// Helper method to create instance of orcType.</summary>
        private static DomNode CreateOrc(string name = "Orc")
        {
            var orc = new DomNode(GameSchema.orcType.Type);

            orc.SetAttribute(GameSchema.orcType.nameAttribute, name);
            orc.SetAttribute(GameSchema.orcType.TextureRevDateAttribute, DateTime.Now);
            orc.SetAttribute(GameSchema.orcType.resourceFolderAttribute, System.Windows.Forms.Application.StartupPath);
            orc.SetAttribute(GameSchema.orcType.skinColorAttribute, System.Drawing.Color.DarkGray.ToArgb());
            orc.SetAttribute(GameSchema.orcType.healthAttribute, 80);
            var armorList = orc.GetChildList(GameSchema.orcType.armorChild);

            armorList.Add(CreateArmor("Iron breast plate", 20, 300));

            var clubList = orc.GetChildList(GameSchema.orcType.clubChild);

            clubList.Add(CreateClub(true, 20, 30));

            return(orc);
        }
        public static GameReference CreateNew(GameDocument subDoc)
        {
            if (subDoc == null)
            {
                throw new ArgumentNullException("subDoc");
            }

            string  fileName    = System.IO.Path.GetFileName(subDoc.Uri.LocalPath);
            DomNode gameRefNode = new DomNode(Schema.gameReferenceType.Type);

            gameRefNode.SetAttribute(Schema.gameReferenceType.nameAttribute, fileName);
            gameRefNode.SetAttribute(Schema.gameReferenceType.refAttribute, subDoc.Uri);
            GameReference gameRef = gameRefNode.As <GameReference>();

            gameRef.m_target = subDoc.Cast <IGame>();
            subDoc.Cast <Game>().SetParent(gameRef);
            gameRef.m_error = string.Empty;
            return(gameRef);
        }
示例#40
0
文件: UIControl.cs 项目: Joxx0r/ATF
 /// <summary>
 /// Performs initialization when the adapter is connected to the diagram annotation's DomNode,
 /// creating child DomNode for transform and setting its scale.</summary>
 protected override void OnNodeSet()
 {
     DomNode transform = DomNode.GetChild(UISchema.UIControlType.TransformChild);
     if (transform == null)
     {
         transform = new DomNode(UISchema.UITransformType.Type);
         transform.SetAttribute(UISchema.UITransformType.ScaleAttribute, new float[] { 1.0f, 1.0f, 1.0f });
         DomNode.SetChild(UISchema.UIControlType.TransformChild, transform);
     }
 }
示例#41
0
 /// <summary>
 /// Converts the palette item into an object that can be inserted into an
 /// IInstancingContext</summary>
 /// <param name="item">Item to convert</param>
 /// <returns>Object that can be inserted into an IInstancingContext</returns>
 public object Convert(object item)
 {
     DomNodeType nodeType = (DomNodeType)item;
     DomNode node = new DomNode(nodeType);
     NodeTypePaletteItem paletteItem = nodeType.GetTag<NodeTypePaletteItem>();
     if (paletteItem != null)
     {
         node.SetAttribute(nodeType.IdAttribute, paletteItem.Name);
     }            
     return node;
 }
示例#42
0
        /// <summary>
        /// Converts the give string to attribute value and set it to given node
        /// using attributeInfo.         
        /// </summary>
        /// <param name="node">DomNode </param>
        /// <param name="attributeInfo">attributeInfo to set</param>
        /// <param name="valueString">The string representation of the attribute value</param>
        protected override void ReadAttribute(DomNode node, AttributeInfo attributeInfo, string valueString)
        {
            if (IsReferenceAttribute(attributeInfo))
            {
                // save reference so it can be resolved after all nodes have been read
                NodeReferences.Add(new XmlNodeReference(node, attributeInfo, valueString));
            }
            else if (!string.IsNullOrEmpty(valueString))
            {
                object value = attributeInfo.Type.Convert(valueString);

                if (value is Uri)
                {
                    //todo reference to objects in other documents must be made absolute using
                    //this Uri instead of resourceRoot.

                    // then convert it to absolute.
                    Uri ur = (Uri)value;
                    if (!ur.IsAbsoluteUri)
                    {
                        // todo use schema annotation to decide what to use 
                        // for converting relative uri to absolute.
                        if (node.Type == Schema.gameReferenceType.Type
                            || node.Type == Schema.gameObjectReferenceType.Type)
                        {
                            string urStr = ur.ToString();
                            int fragIndex = urStr.LastIndexOf('#');
                            if (fragIndex == -1)
                            {
                                value = new Uri(Uri, ur);
                            }
                            else
                            {
                                string frag = urStr.Substring(fragIndex);
                                string path = urStr.Substring(0, fragIndex);
                                Uri absUri = new Uri(Uri, path);
                                value = new Uri(absUri + frag);
                            }

                        }
                        else
                        {
                            value = new Uri(m_resourceRoot, ur);
                        }

                    }
                }
                node.SetAttribute(attributeInfo, value);
            }
        }
示例#43
0
        private void updateNode(DomNode node, ObjectOverride objectOverride)
        {
            if (node == null || objectOverride == null)
                return;
            string nodeId = node.GetId();
            System.Diagnostics.Debug.Assert(nodeId == objectOverride.ObjectName);

            foreach (AttributeOverride attrOverride in objectOverride.AttributeOverrides)
            {
                AttributeInfo attrInfo = node.Type.GetAttributeInfo(attrOverride.Name);
                node.SetAttribute(attrInfo, attrInfo.Type.Convert(attrOverride.AttribValue));
            }
        }
示例#44
0
        public void TestMoveDomNode()
        {
            var root = new DomNode(RootType.Type, RootElement);

            root.InitializeExtensions();

            var folderChild1 = new DomNode(FolderType.Type);
            var folderChild2 = new DomNode(FolderType.Type);
            var itemChild1 = new DomNode(ItemType.Type);
            var itemChild2 = new DomNode(ItemType.Type);

            var validationContext = root.As<ValidationContext>();
            
            // Set up the tree:
            // root
            //     folder
            //         item
            //     folder1
            //         item

            validationContext.RaiseBeginning();

            root.SetAttribute(RootType.NameAttribute, "root");
            itemChild1.SetAttribute(ItemType.NameAttribute, "item");
            itemChild2.SetAttribute(ItemType.NameAttribute, "item");
            folderChild1.SetAttribute(FolderType.NameAttribute, "folder");
            folderChild2.SetAttribute(FolderType.NameAttribute, "folder");

            folderChild1.GetChildList(FolderType.ItemChild).Add(itemChild1);
            folderChild2.GetChildList(FolderType.ItemChild).Add(itemChild2);

            root.GetChildList(RootType.FolderChild).Add(folderChild1);
            root.GetChildList(RootType.FolderChild).Add(folderChild2);

            // renames all folders and items with unique paths
            validationContext.RaiseEnding();
            validationContext.RaiseEnded(); 

            // Move item from first folder to second folder
            // root
            //     folder
            //     folder1
            //         item
            //         item1

            validationContext.RaiseBeginning();

            itemChild1.RemoveFromParent();
            folderChild2.GetChildList(FolderType.ItemChild).Add(itemChild1);

            validationContext.RaiseEnding();
            validationContext.RaiseEnded();
            Assert.DoesNotThrow(() => ValidateSubtree(folderChild2));
            // Make sure that the existing child wasn't renamed. Only the moved child should be renamed.
            Assert.True((string)itemChild2.GetAttribute(ItemType.NameAttribute) == "item");

            // Rename 'item_1' to 'item'.
            validationContext.RaiseBeginning();

            itemChild1.SetAttribute(ItemType.NameAttribute, "item");

            validationContext.RaiseEnding();
            validationContext.RaiseEnded();
            Assert.DoesNotThrow(() => ValidateSubtree(folderChild2));

            // Make sure that the existing child wasn't renamed. Only the moved child should be renamed.
            Assert.True((string)itemChild2.GetAttribute(ItemType.NameAttribute) == "item");

            // Rename the root.
            validationContext.RaiseBeginning();

            root.SetAttribute(RootType.NameAttribute, "new_root");

            validationContext.RaiseEnding();
            validationContext.RaiseEnded();
            Assert.DoesNotThrow(() => ValidateSubtree(root));
            Assert.True((string)root.GetAttribute(RootType.NameAttribute) == "new_root");
        }
示例#45
0
        public void TestSetAttribute()
        {
            DomNodeType type = new DomNodeType("child");
            AttributeInfo info = GetIntAttribute("int");
            type.Define(info);
            DomNode test = new DomNode(type);

            Assert.False(test.IsAttributeSet(info));
            test.SetAttribute(info, 2);
            Assert.AreEqual(test.GetAttribute(info), 2);
            Assert.AreEqual(test.GetLocalAttribute(info), 2);
            Assert.True(test.IsAttributeSet(info));

            test.SetAttribute(info, null);
            Assert.True(test.IsAttributeDefault(info));
            Assert.Null(test.GetLocalAttribute(info));
            Assert.False(test.IsAttributeSet(info));
        }
示例#46
0
 /// <summary>
 /// Converts the palette item into an object that can be inserted into an IInstancingContext</summary>
 /// <param name="item">Item to convert</param>
 /// <returns>Object that can be inserted into an IInstancingContext</returns>
 object IPaletteClient.Convert(object item)
 {
     var paletteItem = (NodeTypePaletteItem)item;
     var node = new DomNode(paletteItem.NodeType);
     if (paletteItem.NodeType.IdAttribute != null)
         node.SetAttribute(paletteItem.NodeType.IdAttribute, paletteItem.Name);
     return node;
 }
示例#47
0
 protected virtual void SetDynamicPropertyDomNode(string propertyName, string category, string description,
     string converter, string editor, string valueType, DomNode node)
 {
     node.SetAttribute(Schema.dynamicPropertyType.nameAttribute, propertyName);
     node.SetAttribute(Schema.dynamicPropertyType.categoryAttribute, category);
     node.SetAttribute(Schema.dynamicPropertyType.descriptionAttribute, description);
     node.SetAttribute(Schema.dynamicPropertyType.converterAttribute, converter);
     node.SetAttribute(Schema.dynamicPropertyType.editorAttribute, editor);
     node.SetAttribute(Schema.dynamicPropertyType.valueTypeAttribute, valueType);
 }
示例#48
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;
            }
        }
示例#49
0
 /// <summary>
 /// Sets the DomNode attribute to the given Vec3F</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <param name="v">DomNode attribute as Vec3F</param>
 public static void SetVector(DomNode domNode, AttributeInfo attribute, Vec3F v)
 {
     domNode.SetAttribute(attribute, v.ToArray());
 }
示例#50
0
        public void TestAttributeChangedEvents()
        {
            DomNodeType type = new DomNodeType("type");
            AttributeInfo stringTypeInfo = GetStringAttribute("string");
            AttributeInfo intTypeInfo = GetIntAttribute("int");
            type.Define(stringTypeInfo);
            type.Define(intTypeInfo);
            DomNode test = new DomNode(type);
            test.AttributeChanging += new EventHandler<AttributeEventArgs>(test_AttributeChanging);
            test.AttributeChanged += new EventHandler<AttributeEventArgs>(test_AttributeChanged);
            AttributeEventArgs expected;

            // test for no value change if setting to the default value and attribute is already the default
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            test.SetAttribute(stringTypeInfo, stringTypeInfo.DefaultValue);
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);
            test.SetAttribute(intTypeInfo, intTypeInfo.DefaultValue);
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);

            // test for value change, string type
            test = new DomNode(type);
            test.AttributeChanging += new EventHandler<AttributeEventArgs>(test_AttributeChanging);
            test.AttributeChanged += new EventHandler<AttributeEventArgs>(test_AttributeChanged);
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            object oldValue = test.GetAttribute(stringTypeInfo);
            test.SetAttribute(stringTypeInfo, "foo");
            expected = new AttributeEventArgs(test, stringTypeInfo, oldValue, "foo");
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            oldValue = test.GetAttribute(stringTypeInfo);
            test.SetAttribute(stringTypeInfo, "foobar");
            expected = new AttributeEventArgs(test, stringTypeInfo, oldValue, "foobar");
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            // test for value change, int type
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            oldValue = test.GetAttribute(intTypeInfo);
            test.SetAttribute(intTypeInfo, 5);
            expected = new AttributeEventArgs(test, intTypeInfo, oldValue, 5);
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            oldValue = test.GetAttribute(intTypeInfo);
            test.SetAttribute(intTypeInfo, 7);
            expected = new AttributeEventArgs(test, intTypeInfo, oldValue, 7);
            Assert.True(Equals(AttributeChangingArgs, expected));
            Assert.True(Equals(AttributeChangedArgs, expected));

            // test for no value change
            test.SetAttribute(stringTypeInfo, "foo");
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            test.SetAttribute(stringTypeInfo, "foo");
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);

            test.SetAttribute(intTypeInfo, 9);
            AttributeChangingArgs = null;
            AttributeChangedArgs = null;
            test.SetAttribute(intTypeInfo, 9);
            Assert.Null(AttributeChangingArgs);
            Assert.Null(AttributeChangedArgs);
        }
示例#51
0
        public void TestGetId()
        {
            DomNodeType testId = new DomNodeType("test");
            AttributeInfo info = GetStringAttribute("string");
            testId.Define(info);
            testId.SetIdAttribute(info.Name);
            DomNode test = new DomNode(testId);
            Assert.Null(test.GetId());

            test.SetAttribute(info, "foo");
            Assert.AreEqual(test.GetId(), "foo");
        }
示例#52
0
 /// <summary>
 /// Sets the DomNode attribute to the given Matrix4F</summary>
 /// <param name="domNode">DomNode holding attribute</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <param name="m">Matrix4F value to be set</param>
 public static void SetMatrix(DomNode domNode, AttributeInfo attribute, Matrix4F m)
 {
     domNode.SetAttribute(attribute, m.ToArray());
 }
示例#53
0
        public void TestDuplicateAttributeInfo()
        {
            // This would be illegal in a schema file, but it seems to be supported OK in the DOM.
            var attr1 = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var attr2 = new AttributeInfo("foo", new AttributeType("foo", typeof(string)));
            var domType = new DomNodeType(
                "test",
                null,
                new AttributeInfo[] { attr1, attr2 },
                EmptyEnumerable<ChildInfo>.Instance,
                EmptyEnumerable<ExtensionInfo>.Instance);

            var domNode = new DomNode(domType);
            
            var originalAttr1 = "setting attr1";
            var originalAttr2 = "setting attr2";

            domNode.SetAttribute(attr1, originalAttr1);
            domNode.SetAttribute(attr2, originalAttr2);

            string resultAttr1 = (string)domNode.GetAttribute(attr1);
            string resultAttr2 = (string)domNode.GetAttribute(attr2);

            Assert.IsTrue(string.Equals(resultAttr1,originalAttr1));
            Assert.IsTrue(string.Equals(resultAttr2, originalAttr2));
        }
示例#54
0
 private void NameNode(DomNode node)
 {
     // if the name isn't unique, make it so
     string id = node.GetId();
     
     // DAN: Edit here to allow nodes with no ID attribute to exist!
     if (node.Type.IdAttribute != null)
     {
         string unique = m_uniqueNamer.Name(id);
         if (id != unique)
         {
             node.SetAttribute(node.Type.IdAttribute, unique);
         }
     }
 }
示例#55
0
        public void TestCopy_SingleNode()
        {
            DomNodeType type = new DomNodeType("type");
            AttributeInfo info = GetStringAttribute("string");
            type.Define(info);
            DomNode test = new DomNode(type);
            test.SetAttribute(info, "foo");

            DomNode[] result = DomNode.Copy(new DomNode[] { test });
            Assert.True(Equals(result[0], test));

            DomNode singleResult = DomNode.Copy(test);
            Assert.True(Equals(singleResult, test));
        }
示例#56
0
 /// <summary>
 /// Sets the DomNode attribute value to the given Sphere3F</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <param name="s">Sphere3F value to be set</param>
 public static void SetSphere(DomNode domNode, AttributeInfo attribute, Sphere3F s)
 {
     float[] value = new float[4];
     value[0] = s.Center.X;
     value[1] = s.Center.Y;
     value[2] = s.Center.Z;
     value[3] = s.Radius;
     domNode.SetAttribute(attribute, value);
 }
示例#57
0
        /// <summary>
        /// Converts the palette item into an object that can be inserted into an
        /// IInstancingContext</summary>
        /// <param name="item">Item to convert</param>
        /// <returns>Object that can be inserted into an IInstancingContext</returns>
        object IPaletteClient.Convert(object item)
        {
            DomNodeType nodeType = (DomNodeType)item;
            DomNode node = new DomNode(nodeType);

            NodeTypePaletteItem paletteItem = nodeType.GetTag<NodeTypePaletteItem>();
            AttributeInfo idAttribute = nodeType.IdAttribute;
            if (paletteItem != null &&
                idAttribute != null)
            {
                node.SetAttribute(idAttribute, paletteItem.Name);
            }
            return node;
        }
示例#58
0
 // Finds an attribute of the form "{name}={value}" and sets the corresponding
 //  attribute on the given DomNode.
 private static void FindAttribute(string line, string name, DomNode node)
 {
     AttributeInfo attributeInfo = node.Type.GetAttributeInfo(name);
     if (attributeInfo.Type.ClrType == typeof(int))
     {
         int value;
         if (FindAttribute(line, name, out value))
             node.SetAttribute(attributeInfo, value);
     }
     else if (attributeInfo.Type.ClrType == typeof(bool))
     {
         bool value;
         if (FindAttribute(line, name, out value))
             node.SetAttribute(attributeInfo, value);
     }
     else
     {
         string value;
         if (FindAttribute(line, name, out value))
             node.SetAttribute(attributeInfo, value);
     }
 }
示例#59
0
 /// <summary>
 /// Sets the DomNode attribute value to the given Box</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <param name="b">Box</param>
 public static void SetBox(DomNode domNode, AttributeInfo attribute, Box b)
 {
     float[] value = new float[6];
     value[0] = b.Min.X;
     value[1] = b.Min.Y;
     value[2] = b.Min.Z;
     value[3] = b.Max.X;
     value[4] = b.Max.Y;
     value[5] = b.Max.Z;
     domNode.SetAttribute(attribute, value);
 }
示例#60
0
 public void Recall(DomNode domNode)
 {
     AttributeInfo diffuseInfo = domNode.Type.GetAttributeInfo("diffuse");
     AttributeInfo ambientInfo = domNode.Type.GetAttributeInfo("ambient");
     AttributeInfo specularInfo = domNode.Type.GetAttributeInfo("specular");
     if (diffuseInfo != null &&
         ambientInfo != null &&
         specularInfo != null)
     {
         domNode.SetAttribute(ambientInfo, m_ambient.ToArgb());
         domNode.SetAttribute(specularInfo, m_specular.ToArgb());
         domNode.SetAttribute(diffuseInfo, m_diffuse.ToArgb());
     }
 }