Esempio n. 1
0
        private void LoadBlock(IDynamicContainer container)
        {
            this.tagDefinition = container.Globals.TagDefinition;
            //int depth = (int)buildDepth.Pop();
            //buildDepth.Push(depth + 1);
            BlockContainerPanel panel = BuildStruct(container.Globals);

            panel.SuspendLayout();
            panel.DepthDifference = container.Globals.DepthDifference;
            container.FieldPanel  = panel;
            //container.Block.BlockChanged += new BlockChangedHandler(panel.DatabindChildrenToBlock);

            /*if (container.Block != null)
             * {
             * container.Block.BlockChanged += new BlockChangedHandler((panel as BlockContainerPanel).DatabindChildrenToBlock);
             * if (container.Block.SelectedBlockIndex > -1)
             *  (panel as BlockContainerPanel).DatabindChildrenToBlock(container.Block.BlockCollection.GetBlock(container.Block.SelectedBlockIndex));
             * else
             * {
             *  if ((container.Parent != null) && (container.Parent.Block != null) && (container.Parent.Block.SelectedBlockIndex != null))
             *    ((tabArguments[tabControl.SelectedTabIndex].Container as IDynamicContainer).FieldPanel).DatabindChildrenToBlock(container.Parent.Block.BlockCollection.GetBlock(container.Parent.Block.SelectedBlockIndex));
             *  else
             *    ((tabArguments[tabControl.SelectedTabIndex].Container as Control).Controls[0] as BlockContainerPanel).DatabindChildrenToBlock(tabArguments[tabControl.SelectedTabIndex].TagData, container);
             * }
             * }
             * else
             * {
             * //((tabArguments[tabControl.SelectedTabIndex].Container as Control).Controls[0] as BlockContainerPanel).DatabindChildrenToBlock(tabArguments[tabControl.SelectedTabIndex].TagData);
             * if ((container.Parent != null) && (container.Parent.Block != null) && (container.Parent.Block.SelectedBlockIndex != null))
             *  ((tabArguments[tabControl.SelectedTabIndex].Container as IDynamicContainer).FieldPanel).DatabindChildrenToBlock(container.Parent.Block.BlockCollection.GetBlock(container.Parent.Block.SelectedBlockIndex));
             * else
             *  ((tabArguments[tabControl.SelectedTabIndex].Container as Control).Controls[0] as BlockContainerPanel).DatabindChildrenToBlock(tabArguments[tabControl.SelectedTabIndex].TagData, container);
             * }*/
            // Sets the active block to being the block's selection and performs databinding
            IBlockControl block = panel.GetParentBlock();

            if ((block != null) && (block.BlockCollection != null))
            {
                block.BlockChanged += new BlockChangedHandler(panel.DatabindChildrenToBlock);
                IBlock tempBlock = null;
                if (block.BlockCollection.BlockCount > 0)
                {
                    if (block.SelectedBlockIndex > 0)
                    {
                        tempBlock = block.BlockCollection.GetBlock(block.SelectedBlockIndex);
                    }
                    else
                    {
                        block.SelectedBlockIndex = 0;
                        tempBlock = block.BlockCollection.GetBlock(0);
                    }
                }


                // if this is a region, we don't want the databinding to disable the controls.
                // Basically, it will always databind if it's not null, or if it is a block, rather than a region/section/whatever.
                if ((tempBlock != null) || (container is BlockContainer))
                {
                    panel.DatabindChildrenToBlock(tempBlock);
                }
            }
            else
            {
                panel.DatabindChildrenToBlock(tabArguments[tabControl.SelectedTabIndex].TagData, panel);
            }

            // Databind the block.
            if (panel != null)
            {
                panel.Visible = true;
                if (panel is BlockContainerPanel)
                {
                    ConnectBlocks(panel as BlockContainerPanel);
                }
            }
            container.Globals.IsLoaded = true;
            panel.ResumeLayout();
        }
Esempio n. 2
0
        /// <summary>
        /// Builds a BlockContainer control, populating it with the appropriate controls
        /// based on the supplied XML TDF data.
        /// </summary>
        protected BlockContainerPanel BuildStruct(ContainerGlobals globals)
        {
            XmlNode node      = globals.BlockNode;
            bool    mainBlock = globals.MainBlock;
            int     maxDepth  = globals.MaxDepth;

            //int depth = (int)buildDepth.Peek();

            // Setup the block container.
            BlockContainerPanel container = new BlockContainerPanel();

            container.Name = node.Attributes["name"].Value;
            container.SuspendLayout();
            container.Location          = new Point(0, 0);
            container.LinkedUndoManager = undoManager;
            container.LinkedUndoManager.StateChanged += new StateChangedHandler(LinkedUndoManager_StateChanged);
            containers.Push(container);

            XmlNodeList valueNodes = node.SelectNodes("*");

            foreach (XmlNode valueNode in valueNodes)
            {
                if (valueNode.Name.ToLower() == "group")
                {
                    ProcessGroup(container, valueNode, mainBlock, maxDepth);
                }
                else if (valueNode.Name.ToLower() == "section")
                {
                    ProcessSection(globals, valueNode, mainBlock, maxDepth);
                }
                else if (valueNode.Name.ToLower() == "region")
                {
                    ProcessRegion(globals, valueNode, mainBlock, maxDepth);
                }
                else if (valueNode.Name.ToLower() == "value")
                {
                    string        valueName = valueNode.Attributes["name"].InnerText;
                    IFieldControl fieldControl;
                    string        valueText        = valueNode.Attributes["type"].InnerText;
                    string        fullPropertyName = (mainBlock ? className + "Values." : "") + GlobalMethods.MakePublicName(valueName);

                    // Create the proper control based on the name that we got from the XML.
                    if (gameDefinition.FieldControlTable.ContainsKey(valueText))
                    {
                        Type     fieldControlType = gameDefinition.FieldControlTable[valueText];
                        Assembly targetAssembly   = Assembly.GetAssembly(fieldControlType);
                        fieldControl = (targetAssembly.CreateInstance(fieldControlType.FullName) as IFieldControl);

                        fieldControl.Configure(valueNode);
                        //((Control)fieldControl).Font = new Font("Verdana", 6.75f); // Set in Interfaces\TagEditor\FieldControl.cs
                        if (valueText != "Block")
                        {
                            // If this is a tag reference control, hook up its events.
                            if (fieldControl is ITagReferenceControl)
                            {
                                (fieldControl as ITagReferenceControl).OpenTag += new OpenTagEventHandler(TagEditorControl_OpenTag);
                            }

                            IFieldControlContainer c = containers.Peek();
                            c.AddField(fieldControl);
                            (fieldControl as Control).Visible = true;
                        }
                        else
                        {
                            ProcessBlock(globals, valueNode, fieldControl, fullPropertyName);
                        }
                    }
                    else
                    {
                        continue;
                    }
                    fieldControl.BoundPropertyName = fullPropertyName;
                }
            }
//      depth = (int)(buildDepth.Pop());
//    buildDepth.Push(depth - 1);
            containers.Pop();
            container.ResumeLayout(false);
            container.Width = container.Width;
            return(container);
        }