Inheritance: ElementSave
        public static void InitializeDefaultAndComponentVariables(this ComponentSave componentSave)
        {
            // June 27, 2012
            // We used to pass
            // null here because
            // passing a non-null
            // variable meant replacing
            // the existing StateSave with
            // the argument StateSave.  However,
            // now when the type of a Component is
            // changed, old values are not removed, but
            // are rather preserved so that changing the
            // type doesn't wipe out old values.
            //componentSave.Initialize(null);

            StateSave defaultStateSave = null;

            // We used to call initialize with the default state for the given component base type (which is usually a container)
            // But this copies all the variables from the container to this, which seems redundant...why do we do this if it inherits
            // from a container which has its own state? Most of the time the user won't change the defaults and it just adds bloat.
            //StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(componentSave);
            //if (ses != null)
            //{
            //    defaultStateSave = ses.DefaultState;
            //}

            componentSave.Initialize(new StateSave {
                Name = "Default"
            });

            componentSave.Initialize(StandardElementsManager.Self.DefaultStates["Component"]);
        }
Exemple #2
0
        public ComponentSave AddComponent(string componentName)
        {
            ComponentSave componentSave = new ComponentSave();

            componentSave.BaseType = "Container";
            componentSave.Name = componentName;

            ProjectManager.Self.GumProjectSave.ComponentReferences.Add(new ElementReference { Name = componentName, ElementType = ElementType.Component });
            ProjectManager.Self.GumProjectSave.ComponentReferences.Sort((first, second) => first.Name.CompareTo(second.Name));
            ProjectManager.Self.GumProjectSave.Components.Add(componentSave);

            componentSave.InitializeDefaultAndComponentVariables();

            // components shouldn't set their positions to 0 by default, so if the
            // default state sets those values, we should null them out:
            var xVariable = componentSave.DefaultState.GetVariableSave("X");
            var yVariable = componentSave.DefaultState.GetVariableSave("Y");

            if (xVariable != null)
            {
                xVariable.Value = null;
                xVariable.SetsValue = false;
            }
            if (yVariable != null)
            {
                yVariable.Value = null;
                yVariable.SetsValue = false;
            }

            return componentSave;
        }
Exemple #3
0
        private void PopulateElementSavesFromReferences(string projectRootDirectory, out string errors)
        {
            errors = "";

            Screens.Clear();
            Components.Clear();
            StandardElements.Clear();

            foreach (ElementReference reference in ScreenReferences)
            {
                ScreenSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave <ScreenSave>(projectRootDirectory, ScreenExtension, ref errors);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Screens.Add(toAdd);
                }
            }

            foreach (ElementReference reference in ComponentReferences)
            {
                ComponentSave toAdd = null;

                try
                {
                    toAdd = reference.ToElementSave <ComponentSave>(projectRootDirectory, ComponentExtension, ref errors);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Components.Add(toAdd);
                }
            }

            foreach (ElementReference reference in StandardElementReferences)
            {
                StandardElementSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave <StandardElementSave>(projectRootDirectory, StandardExtension, ref errors);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    StandardElements.Add(toAdd);
                }
            }
        }
Exemple #4
0
        public static void InitializeDefaultAndComponentVariables(this ComponentSave componentSave)
        {
            // June 27, 2012
            // We used to pass
            // null here because
            // passing a non-null
            // variable meant replacing
            // the existing StateSave with
            // the argument StateSave.  However,
            // now when the type of a Component is
            // changed, old values are not removed, but
            // are rather preserved so that changing the
            // type doesn't wipe out old values.
            //componentSave.Initialize(null);

            StateSave           defaultStateSave = null;
            StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(componentSave);

            if (ses != null)
            {
                defaultStateSave = ses.DefaultState;
            }

            componentSave.Initialize(defaultStateSave);

            componentSave.Initialize(StandardElementsManager.Self.DefaultStates["Component"]);
        }
Exemple #5
0
        internal void RemoveComponent(ComponentSave asComponentSave)
        {
            GumProjectSave gps = ProjectManager.Self.GumProjectSave;

            string name = asComponentSave.Name;
            List<ElementReference> references = gps.ComponentReferences;

            RemoveElementReferencesFromList(name, references);

            gps.Components.Remove(asComponentSave);
        }
Exemple #6
0
        public bool IsComponentNameValid(string componentName, ComponentSave component, out string whyNotValid)
        {
            IsNameValidCommon(componentName, out whyNotValid);

            if (string.IsNullOrEmpty(whyNotValid))
            {
                IsNameAnExistingElement(componentName, component, out whyNotValid);
            }

            return string.IsNullOrEmpty(whyNotValid);
        }
Exemple #7
0
        public void ReloadElement(ElementSave element)
        {
            string projectRootDirectory = FileManager.GetDirectory(this.FullFileName);

            var gumLoadResult = new GumLoadResult();

            if (element is ScreenSave)
            {
                var matchingReference = ScreenReferences.FirstOrDefault(item => item.Name == element.Name);

                ScreenSave newScreen = matchingReference?.ToElementSave <ScreenSave>(
                    projectRootDirectory, GumProjectSave.ScreenExtension, gumLoadResult);

                if (newScreen != null)
                {
                    Screens.Remove(element as ScreenSave);
                    Screens.Add(newScreen);
                }
            }
            else if (element is ComponentSave)
            {
                var matchingReference = ComponentReferences.FirstOrDefault(item => item.Name == element.Name);

                ComponentSave newComonent = matchingReference?.ToElementSave <ComponentSave>(
                    projectRootDirectory, GumProjectSave.ComponentExtension, gumLoadResult);

                if (newComonent != null)
                {
                    Components.Remove(element as ComponentSave);
                    Components.Add(newComonent);
                }
            }
            else if (element is StandardElementSave)
            {
                var matchingReference = StandardElementReferences.FirstOrDefault(item => item.Name == element.Name);

                StandardElementSave newStandardElement = matchingReference?.ToElementSave <StandardElementSave>(
                    projectRootDirectory, GumProjectSave.ComponentExtension, gumLoadResult);

                if (newStandardElement != null)
                {
                    StandardElements.Remove(element as StandardElementSave);
                    StandardElements.Add(newStandardElement);
                }
            }
        }
 public static bool IsOfType(this ComponentSave componentSave, string typeToCheck)
 {
     if (componentSave.Name == typeToCheck || componentSave.BaseType == typeToCheck)
     {
         return(true);
     }
     else if (!string.IsNullOrEmpty(componentSave.BaseType))
     {
         ComponentSave baseComponentSave = ObjectFinder.Self.GetComponent(componentSave.BaseType);
         if (baseComponentSave == null)
         {
             return(false);
         }
         else
         {
             return(baseComponentSave.IsOfType(typeToCheck));
         }
     }
     else
     {
         return(false);
     }
 }
        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;

                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
                {
                    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, false);

                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;
                elementStack.Add(elementWithState);

                foreach (InstanceSave internalInstance in baseComponentSave.Instances)
                {
                    GraphicalUiElement createdIpso = CreateRepresentationForInstance(internalInstance, instance, elementStack, rootIpso);

                }

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

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

            return rootIpso;
        }
Exemple #10
0
        private void PopulateElementSavesFromReferences(string projectRootDirectory, LinkLoadingPreference linkLoadingPreference, GumLoadResult result)
        {
            string errors = "";

            Screens.Clear();
            Components.Clear();
            StandardElements.Clear();
            Behaviors.Clear();

            foreach (ElementReference reference in ScreenReferences)
            {
                ScreenSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave <ScreenSave>(projectRootDirectory, ScreenExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Screens.Add(toAdd);
                }
            }

            foreach (ElementReference reference in ComponentReferences)
            {
                ComponentSave toAdd = null;

                try
                {
                    toAdd = reference.ToElementSave <ComponentSave>(projectRootDirectory, ComponentExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Components.Add(toAdd);
                }
            }

            foreach (ElementReference reference in StandardElementReferences)
            {
                StandardElementSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave <StandardElementSave>(projectRootDirectory, StandardExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    StandardElements.Add(toAdd);
                }
            }

            foreach (var reference in BehaviorReferences)
            {
                BehaviorSave toAdd = null;

                try
                {
                    toAdd = reference.ToBehaviorSave(projectRootDirectory);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Behaviors.Add(toAdd);
                }
            }

            result.ErrorMessage += errors;
        }
 public static bool CanContainInstanceOfType(this ComponentSave componentSave, string typeToCheck)
 {
     return(!componentSave.IsOfType(typeToCheck));
 }
 public TreeNode GetTreeNodeFor(ComponentSave componentSave)
 {
     return GetTreeNodeForTag(componentSave, RootComponentsTreeNode);
 }
        private EntitySave ToGlueEntitySave(ComponentSave component, Dictionary<string, CopiedFileReference> copiedFiles)
        {
            EntitySave toReturn = new EntitySave();
            toReturn.Name = "Entities\\" + component.Name;

            // Make RFS's first so we can rename NOS's if necessary
            AddReferencedFilesToElement(component, toReturn, copiedFiles);

            mInstanceToNos.AddNamedObjectSavesToGlueElement(component, toReturn, copiedFiles);
            return toReturn;
        }
        public static bool IsComponent(this InstanceSave instanceSave)
        {
            ComponentSave baseAsComponentSave = ObjectFinder.Self.GetComponent(instanceSave.BaseType);

            return(baseAsComponentSave != null);
        }