SetContainedObject() public method

public SetContainedObject ( IRenderable containedObject ) : void
containedObject IRenderable
return void
コード例 #1
0
        private GraphicalUiElement CreateRepresentationsForInstanceFromComponent(InstanceSave instance,
                                                                                 List <ElementWithState> elementStack, InstanceSave parentInstance, GraphicalUiElement parentIpso,
                                                                                 ComponentSave baseComponentSave)
        {
            StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(instance);

            GraphicalUiElement rootIpso = null;

            if (ses != null)
            {
                rootIpso = new GraphicalUiElement(null, parentIpso);

                string type = ses.Name;

                var renderable = PluginManager.Self.CreateRenderableForType(type);

                if (renderable != null)
                {
                    rootIpso.SetContainedObject(renderable);
                    rootIpso.Tag            = instance;
                    rootIpso.Component.Name = instance.Name;
                    rootIpso.Component.Tag  = instance;
                }

                else if (type == "Sprite" || type == "ColoredRectangle" || type == "NineSlice" || type == "Text" || type == "Circle" || type == "Rectangle")
                {
                    ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);
                    rootIpso.CreateGraphicalComponent(instanceBase, null);
                    rootIpso.Tag            = instance;
                    rootIpso.Component.Name = instance.Name;
                    rootIpso.Component.Tag  = instance;

                    if (type == "Text")
                    {
                        (rootIpso.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines;
                    }
                }
                else
                {
                    // give the plugin manager a shot at it:

                    CreateRectangleFor(instance, elementStack, rootIpso);
                }

                var selectedState = SelectedState.Self.SelectedStateSave;

                if (selectedState == null)
                {
                    selectedState = SelectedState.Self.SelectedElement.DefaultState;
                }

                RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(selectedState);

                string guide = rvf.GetValue <string>("Guide");
                SetGuideParent(parentIpso, rootIpso, guide);

                ElementWithState elementWithState = new ElementWithState(baseComponentSave);
                var tempRvf = new DataTypes.RecursiveVariableFinder(instance, elementStack);
                var state   = tempRvf.GetValue("State") as string;
                elementWithState.StateName = state;

                foreach (var category in baseComponentSave.Categories)
                {
                    elementWithState.CategorizedStates.Add(category.Name, tempRvf.GetValue <string>(category.Name + "State"));
                }

                elementWithState.InstanceName = instance.Name;

                // Does this element already exist?
                bool alreadyExists = elementStack.Any(item => item.Element == elementWithState.Element);
                if (!alreadyExists)
                {
                    elementStack.Add(elementWithState);

                    foreach (InstanceSave internalInstance in baseComponentSave.Instances)
                    {
                        // let's make sure we don't recursively create the same instance causing a stack overflow:

                        GraphicalUiElement createdIpso = CreateRepresentationForInstance(internalInstance, instance, elementStack, rootIpso);
                    }
                }

                SetUpParentRelationship(rootIpso.ContainedElements, elementStack, baseComponentSave.Instances);

                elementStack.Remove(elementStack.FirstOrDefault(item => item.Element == baseComponentSave));
            }

            return(rootIpso);
        }
コード例 #2
0
        private GraphicalUiElement CreateRepresentationForInstance(InstanceSave instance, InstanceSave parentInstance, List <ElementWithState> elementStack, GraphicalUiElement container)
        {
            IPositionedSizedObject newIpso = null;

            GraphicalUiElement graphicalElement = newIpso as GraphicalUiElement;
            var baseElement = ObjectFinder.Self.GetElementSave(instance.BaseType);

            string type = instance.BaseType;

            var renderable = PluginManager.Self.CreateRenderableForType(type);

            if (renderable != null)
            {
                graphicalElement = new GraphicalUiElement(null, container);
                ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);
                graphicalElement.SetContainedObject(renderable);
                graphicalElement.Tag            = instance;
                graphicalElement.Component.Name = instance.Name;
                graphicalElement.Component.Tag  = instance;
            }


            else if (type == "Sprite" || type == "ColoredRectangle" || type == "NineSlice" || type == "Text" || type == "Circle" || type == "Rectangle")
            {
                graphicalElement = new GraphicalUiElement(null, container);
                ElementSave instanceBase = ObjectFinder.Self.GetElementSave(type);
                graphicalElement.CreateGraphicalComponent(instanceBase, null);
                graphicalElement.Tag            = instance;
                graphicalElement.Component.Name = instance.Name;
                graphicalElement.Component.Tag  = instance;

                if (type == "Text")
                {
                    (graphicalElement.RenderableComponent as Text).RenderBoundary = ProjectManager.Self.GeneralSettingsFile.ShowTextOutlines;
                    if (SelectedState.Self.SelectedStateSave != null)
                    {
                        FontManager.Self.ReactToFontValueSet(instance);
                    }
                }
            }
            else if (instance.IsComponent())
            {
                newIpso = CreateRepresentationsForInstanceFromComponent(instance, elementStack, parentInstance, container, ObjectFinder.Self.GetComponent(instance.BaseType));
            }
            else
            {
                // Make sure the base type is valid.
                // This could be null if a base type changed
                // its name but the derived wasn't updated, or
                // if someone screwed with the XML files.  Who knows...

                if (baseElement != null)
                {
                    graphicalElement = new GraphicalUiElement(null, container);

                    CreateRectangleFor(instance, elementStack, graphicalElement);
                }
            }



            if (newIpso != null && (newIpso is GraphicalUiElement) == false)
            {
                graphicalElement = new GraphicalUiElement(newIpso as IRenderable, container);
            }
            else if (newIpso is GraphicalUiElement)
            {
                graphicalElement = newIpso as GraphicalUiElement;
            }

            if (graphicalElement != null)
            {
                if (baseElement != null)
                {
                    graphicalElement.ElementSave = baseElement;
                    foreach (var exposedVariable in baseElement.DefaultState.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName)))
                    {
                        graphicalElement.AddExposedVariable(exposedVariable.ExposedAsName, exposedVariable.Name);
                    }
                }



                var selectedState = SelectedState.Self.SelectedStateSave;
                if (selectedState == null)
                {
                    selectedState = SelectedState.Self.SelectedElement.DefaultState;
                }

                RecursiveVariableFinder rvf = new DataTypes.RecursiveVariableFinder(selectedState);

                string guide  = rvf.GetValue <string>("Guide");
                string parent = rvf.GetValue <string>(instance.Name + ".Parent");

                SetGuideParent(container, graphicalElement, guide);

                if (baseElement != null)
                {
                    graphicalElement.SetStatesAndCategoriesRecursively(baseElement);

                    // for performance reasons, we'll suspend the layout here:
                    graphicalElement.SuspendLayout();
                    {
                        graphicalElement.SetVariablesRecursively(baseElement, baseElement.DefaultState);
                    }
                    graphicalElement.ResumeLayout();
                }
            }

            return(graphicalElement);
        }