Exemplo n.º 1
0
 private void SetFieldPanel(BlockContainerPanel panel)
 {
     SuspendLayout();
     if (panel != fieldPanel)
     {
         if (fieldPanel != null)
         {
             Controls.Remove(fieldPanel);
         }
         fieldPanel = panel;
         Controls.Add(fieldPanel);
         OnFieldPanelChanged(this, new EventArgs());
     }
     ResumeLayout();
 }
Exemplo n.º 2
0
        protected void ProcessGroup(BlockContainerPanel container, XmlNode node, bool mainBlock, int maxDepth)
        {
            // Make sure that this node is a direct child of the Main Struct.
            // (That's the only place that groups are allowed to exist.)
            if (node.ParentNode.Name.ToLower() == "struct")
            {
                if (node.ParentNode.Attributes["name"] != null)
                {
                    groupCount++;

                    string groupCaption = "";
                    if (node.Attributes["caption"] != null)
                    {
                        groupCaption = node.Attributes["caption"].InnerText;
                    }
                    else if (node.Attributes["name"] != null)
                    {
                        groupCaption = node.Attributes["name"].InnerText;
                    }
                    else
                    {
                        groupCaption = "Group " + groupCount;
                    }
                    //buildDepth.Push(0);
                    CreateTab(groupCaption);
                    //BlockContainerPanel newContainer = BuildStruct(new BlockGlobals(null, node, maxDepth));

                    TabArguments tabArgs = new TabArguments();
                    tabArgs.Container     = containers.Pop();
                    tabArgs.TagDefinition = tagDefinition;
                    tabArgs.Game          = gameDefinition;
                    tabArgs.MainNode      = node;
                    tabArgs.MaxDepth      = maxDepth;
                    tabArgs.TagData       = tagData;
                    tabArguments.Add(tabArgs);

                    //newContainer.DatabindChildrenToBlock(tagData);
                    //containers.Peek().AddFieldContainer(newContainer);
                    //containers.Pop();
                    //buildDepth.Pop();
                    return;
                }
            }
            throw new Exception("Unable to create group: Not a direct member of the main struct.");
        }
Exemplo n.º 3
0
        private void LoadTab(TabArguments tabArgs)
        {
            this.tagData       = tabArgs.TagData;
            this.tagDefinition = tabArgs.TagDefinition;
            //XmlNode nameNode = tabArgs.NameNode;
            XmlNode mainNode = tabArgs.MainNode;
            int     maxDepth = tabArgs.MaxDepth;

            //tagDefinition = tabArgs.TagDefinition;
            containers.Push(tabArgs.Container);

            className = tagDefinition.SelectSingleNode("//xml/name").InnerText;

            buildDepth.Push(0);

            tabArgs.MainBlockGlobals = new ContainerGlobals(null, mainNode, maxDepth);
            tabArgs.MainBlockGlobals.DepthDifference = maxDepth;
            tabArgs.MainBlockGlobals.TagDefinition   = tabArgs.TagDefinition;

            // This is the top-most block container and is placed directly into the tab, because CreateTab pushes itself onto the stack.
            BlockContainerPanel container = BuildStruct(tabArgs.MainBlockGlobals);

            container.Location        = new Point((containers.Peek() as Control).Margin.Left, (containers.Peek() as Control).Margin.Top);
            container.DepthDifference = maxDepth;
            container.DatabindChildrenToBlock(tagData);
            container.AutoSizeMode = Prometheus.Controls.TagEditor.AutoSizeType.GrowAndShrink | Prometheus.Controls.TagEditor.AutoSizeType.WidthAndHeight;
            container.DrawBorder   = true;

            IFieldControlContainer cont = containers.Peek();

            cont.AddFieldContainer(container);

            buildDepth.Pop();

            ConnectBlocks(container);
            tabArgs.IsLoaded = true;

            //AttachedControl_SizeChanged(tabControl.Tabs[tabControl.TabIndex].AttachedControl, null);
        }
Exemplo n.º 4
0
        private static void ConnectBlocks(BlockContainerPanel container)
        {
            IFieldControl[]           controls           = container.GetChildFields();
            List <IBlockControl>      blocks             = new List <IBlockControl>();
            List <IBlockIndexControl> blockIndexControls = new List <IBlockIndexControl>();

            foreach (IFieldControl control in controls)
            {
                if (control is IBlockControl)
                {
                    if (!blocks.Contains(control as IBlockControl))
                    {
                        blocks.Add(control as IBlockControl);
                    }
                }
                if (control is IBlockIndexControl)
                {
                    if (!blockIndexControls.Contains(control as IBlockIndexControl))
                    {
                        blockIndexControls.Add(control as IBlockIndexControl);
                    }
                }
            }

            foreach (IBlockIndexControl blockIndex in blockIndexControls)
            {
                foreach (IBlockControl block in blocks)
                {
                    if (block.LinkedStructName == blockIndex.LinkedStructName)
                    {
                        blockIndex.ConnectBlockControl(block);
                        break;
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void DatabindChildrenToBlock(IBlock block, IFieldControlContainer container)
        {
            #region Old Method

            /*linkedBlock = block;
             *
             * if (block != null)
             * {
             * int index = -1;
             * IFieldControl[] childFields = GetChildFields();
             * foreach (FieldControlBase field in childFields)
             * {
             *  index++;
             *  field.Enabled = true;
             *
             *  try
             *  {
             *    // If the field is not a block, we will need to databind it.
             *    if (!(field is IBlockControl))
             *    {
             *      IField binding = (LocateFieldByName(linkedBlock, field.BoundPropertyName) as IField);
             *      if (binding != null)
             *      {
             *        field.DataBind(binding);
             *        Binding[] bindings = field.GetDataBindings();
             *        foreach (Binding bind in bindings)
             *        {
             *          bind.Parse += bind_Parse;
             *        }
             *      }
             *    }
             *    // If it is a block, we need to recurse on the block so that its children get databound.
             *    else
             *    {
             *      IBlockCollection binding = LocateFieldByName(linkedBlock, field.BoundPropertyName) as IBlockCollection;
             *      if (binding != null)
             *      {
             *        (field as IBlockControl).DataBindCollection(binding);
             *        (field as IBlockControl).Initialize();
             *      }
             *      else
             *        field.Enabled = false;
             *    }
             *  }
             *  catch (Exception ex)
             *  {
             *    Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "There was an error databinding to " + field.BoundPropertyName + ":" + ex.Message, ex);
             *    //MessageBox.Show("There was an error binding \"" + field.BoundPropertyName + ":\" " + ex.Message);
             *  }
             * }
             * }
             * else
             * {
             * foreach (FieldControlBase field in GetChildFields())
             *  field.Enabled = false;
             * }*/
            #endregion

            #region New Method
            if (container is FieldContainerBase)
            {
                container = (container as FieldContainerBase).FieldPanel;
            }
            if (container == null)
            {
                return;
            }
            //(container as Control).Enabled = (block != null);
            if (block == null)
            {
                IFieldControl[] children = container.GetChildFields();
                foreach (FieldControlBase field in children)
                {
                    field.Enabled = false;
                }
                return;
            }

            Control control = container as Control;
            // This is a bug-fix. At some point along the line, databinding was attached to an FieldContainerBase... so to fix it, we relink to the FieldPanel property.
            if (container is FieldContainerBase)
            {
                control = (container as FieldContainerBase).FieldPanel;
            }

            for (int x = 0; x < control.Controls.Count; x++)
            {
                Control curControl = control.Controls[x];
                curControl.Visible = true;

                // Determine whether or not the field is a FieldControlBase or not.
                FieldControlBase field = (curControl is FieldControlBase) ? curControl as FieldControlBase : null;

                #region the current control is a field
                if (field != null)
                {
                    field.Enabled = true;
                    #region If the field is not a block, we will need to databind it.
                    if (!(field is IBlockControl))
                    {
                        IField binding = (LocateFieldByName(block, field.BoundPropertyName) as IField);
                        if (binding != null)
                        {
                            field.DataBind(binding);
                            Binding[] bindings = field.GetDataBindings();
                            foreach (Binding bind in bindings)
                            {
                                bind.Parse += bind_Parse;
                            }
                        }
                        else
                        {
                            field.Enabled = false;
                        }
                    }
                    #endregion
                    else // This shouldn't happen, EVER!
                    {
                        Interfaces.Output.Write(Interfaces.OutputTypes.Information, "DatabindChildrenToBlock came across an IBlockControl.");
                    }
                }
                #endregion
                #region the current control is a block container.
                else if (curControl is Prometheus.Controls.BlockContainer)
                {
                    Prometheus.Controls.BlockContainer blockContainer = curControl as Prometheus.Controls.BlockContainer;
                    blockContainer.Enabled = true;
                    IBlock nextBlock = null;
                    BlockContainerPanel nextContainer = null;

                    #region get the next container
                    // We're getting all of the controls of type FieldContainerPanel, though there should only be one.

                    /*Control[] fieldContainerPanels = GetChildControlsByType(blockContainer, typeof(BlockContainerPanel));
                     * if (fieldContainerPanels.Length > 0)
                     * {
                     * nextContainer = fieldContainerPanels[0] as BlockContainerPanel;
                     * }
                     * else
                     * {
                     * // This is a warning because the rest of the tag will work properly and execution can continue as normal.
                     * Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "During databinding, the block \"" + blockContainer.BoundPropertyName + "\" did not have a field container panel!");
                     * continue;
                     * }*/
                    if (blockContainer.FieldPanel != null)
                    {
                        nextContainer = blockContainer.FieldPanel;
                    }

                    #endregion

                    #region get the next block

                    /*Control[] blocks = GetChildControlsByType(blockContainer, typeof(IBlockControl));
                     * if (blocks.Length > 0)
                     * {
                     * IBlockControl blockControl = blocks[0] as IBlockControl;
                     * blockControl.Container = nextContainer as IFieldControlContainer;
                     * IBlockCollection binding = LocateFieldByName(block, (blockControl as IBoundPropertyCapable).BoundPropertyName) as IBlockCollection;
                     * if (binding != null)
                     * {
                     *  blockControl.DataBindCollection(binding);
                     *  blockControl.Initialize();
                     * }
                     * }
                     * else
                     * {
                     * Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "During databinding, the block \"" + blockContainer.BoundPropertyName + "\" did not have an IBlockControl!");
                     * continue;
                     * }*/
                    if (blockContainer.Block != null)
                    {
                        IBlockControl blockControl = blockContainer.Block;
                        if (blockContainer.FieldPanel == null)
                        {
                            blockControl.Container = blockContainer;
                        }
                        else
                        {
                            blockControl.Container = blockContainer.FieldPanel;
                        }
                        IBlockCollection binding = LocateFieldByName(block, (blockControl as IBoundPropertyCapable).BoundPropertyName) as IBlockCollection;
                        if (binding != null)
                        {
                            blockControl.DataBindCollection(binding);
                            blockControl.Initialize();
                        }
                        if (blockControl.SelectedBlockIndex > -1)
                        {
                            nextBlock = blockControl.BlockCollection.GetBlock(blockControl.SelectedBlockIndex);
                        }
                    }
                    #endregion

                    if ((nextBlock != null) && (nextContainer != null))
                    {
                        DatabindChildrenToBlock(nextBlock, nextContainer);
                    }
                }
                else if (curControl is FieldContainerBase)
                {
                    FieldContainerBase fieldContainer = curControl as FieldContainerBase;
                    fieldContainer.Enabled = true;

                    DatabindChildrenToBlock(block, fieldContainer.FieldPanel);
                }
                #endregion
            }
            #endregion
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
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);
        }