private static void AddSetByDerivedNos(INamedObjectContainer namedObjectContainer,
                                               NamedObjectSave namedObjectSetByDerived, bool instantiatedByBase)
        {
            NamedObjectSave existingNamedObject = null;

            foreach (NamedObjectSave namedObjectInDerived in namedObjectContainer.NamedObjects)
            {
                if (namedObjectInDerived.InstanceName == namedObjectSetByDerived.InstanceName)
                {
                    existingNamedObject = namedObjectInDerived;
                    break;
                }
            }

            if (existingNamedObject != null)
            {
                existingNamedObject.DefinedByBase      = true;
                existingNamedObject.InstantiatedByBase = instantiatedByBase;
            }
            else
            {
                NamedObjectSave namedObjectSave = namedObjectSetByDerived.Clone();

                namedObjectSave.SetDefinedByBaseRecursively(true);
                namedObjectSave.SetInstantiatedByBaseRecursively(instantiatedByBase);

                // This can't be set by derived because an object it inherits from has that already set
                namedObjectSave.SetSetByDerivedRecursively(false);


                namedObjectContainer.NamedObjects.Add(namedObjectSave);
            }
        }
Пример #2
0
        public static void UpdateCustomProperties(this INamedObjectContainer container)
        {
            if (container == null)
            {
                throw new ArgumentException("Argument container is null", "container");
            }

            container.UpdateCustomProperties(container.NamedObjects);
        }
Пример #3
0
        /// <summary>
        /// Calls UpdateCustomProperties on all contained NamedObjects.  This is done recurisvely.
        /// </summary>
        /// <param name="container">The INamedObjectContainer (which is going to be an IElement at the time of this writing)</param>
        /// <param name="namedObjectList">The List of NamedObjectSaves - so that this can be called recursively.</param>
        private static void UpdateCustomProperties(this INamedObjectContainer container, List <NamedObjectSave> namedObjectList)
        {
            for (int i = 0; i < namedObjectList.Count; i++)
            {
                namedObjectList[i].UpdateCustomProperties();

                container.UpdateCustomProperties(namedObjectList[i].ContainedObjects);
            }
        }
        public static NamedObjectSave GetNamedObjectThatIsContainerFor(INamedObjectContainer element, NamedObjectSave containedNamedObject)
        {
            foreach (NamedObjectSave namedObjectSave in element.NamedObjects)
            {
                NamedObjectSave returnValue = GetNamedObjectThatIsContainerFor(namedObjectSave, containedNamedObject);

                if (returnValue != null)
                {
                    return(returnValue);
                }
            }

            return(null);
        }
Пример #5
0
        private static bool CheckIfNodeNeedsUpdate(INamedObjectContainer save)
        {
            foreach (var noSave in save.NamedObjects)
            {
                if (noSave.IsNodeHidden)
                {
                    return true;
                }

                if (noSave.ContainedObjects.Any(coSave => coSave.IsNodeHidden))
                {
                    return true;
                }
            }

            return false;
        }
        public static bool ReactToRenamedReferencedFile(this INamedObjectContainer namedObjectContainer, string oldName, string newName)
        {
            bool toReturn = false;

            for (int i = 0; i < namedObjectContainer.NamedObjects.Count; i++)
            {
                NamedObjectSave namedObject = namedObjectContainer.NamedObjects[i];

                if (namedObject.SourceFile == oldName)
                {
                    toReturn = true;
                    namedObject.SourceFile = newName;
                }
            }

            return(toReturn);
        }
Пример #7
0
        private static bool CheckIfNodeNeedsUpdate(INamedObjectContainer save)
        {
            foreach (var noSave in save.NamedObjects)
            {
                if (noSave.IsNodeHidden)
                {
                    return(true);
                }

                if (noSave.ContainedObjects.Any(coSave => coSave.IsNodeHidden))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #8
0
        internal static CheckResult VerifyInheritanceGraph(INamedObjectContainer node)
        {
            if (mGlueProjectSave != null)
            {
                VerificationId++;
                string resultString = "";

                if (InheritanceVerificationHelper(ref node, ref resultString) == CheckResult.Failed)
                {
                    MessageBox.Show("This assignment has created an inheritence cycle containing the following classes:\n\n" +
                                    resultString +
                                    "\nThe assignment will be undone.");
                    node.BaseObject = null;
                    return(CheckResult.Failed);
                }
            }

            return(CheckResult.Passed);
        }
Пример #9
0
        private static CheckResult InheritanceVerificationHelper(ref INamedObjectContainer node, ref string cycleString)
        {
            //Assign the current VerificationId to identify nodes that have been visited
            node.VerificationIndex = VerificationId;

            //Travel upward through the inheritence tree from this object, stopping when either the
            //tree stops, or you reach a node that's already been visited.
            if (!string.IsNullOrEmpty(node.BaseObject))
            {
                INamedObjectContainer baseNode = ObjectFinder.Self.GetNamedObjectContainer(node.BaseObject);

                if (baseNode == null)
                {
                    // We do nothing - the base object for this
                    // Entity doesn't exist, so we'll continue as if this thing doesn't really have
                    // a base Entity.  The user will have to address this in the Glue UI
                }
                else if (baseNode.VerificationIndex != VerificationId)
                {
                    //If baseNode verification failed, add this node's name to the list and return Failed
                    if (InheritanceVerificationHelper(ref baseNode, ref cycleString) == CheckResult.Failed)
                    {
                        cycleString = (node as FlatRedBall.Utilities.INameable).Name + "\n" + cycleString;
                        return(CheckResult.Failed);
                    }
                }
                else
                {
                    //If the basenode has already been visited, begin the cycleString and return Failed

                    cycleString = (node as FlatRedBall.Utilities.INameable).Name + "\n" +
                                  (baseNode as FlatRedBall.Utilities.INameable).Name + "\n";

                    return(CheckResult.Failed);
                }
            }


            return(CheckResult.Passed);
        }
        public static NamedObjectSave GetNamedObjectRecursively(this INamedObjectContainer namedObjectContainer, string namedObjectName)
        {
            List <NamedObjectSave> namedObjectList = namedObjectContainer.NamedObjects;

            NamedObjectSave foundNos = GetNamedObjectInList(namedObjectList, namedObjectName);

            if (foundNos != null)
            {
                return(foundNos);
            }

            // These methods need to check if the baseScreen/baseEntity is not null.
            // They can be null if the user deletes a base Screen/Entity and the tool
            // managing the Glux doesn't handle the changes.

            if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject))
            {
                if (namedObjectContainer is EntitySave)
                {
                    EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject);
                    if (baseEntity != null)
                    {
                        return(GetNamedObjectRecursively(baseEntity, namedObjectName));
                    }
                }

                else if (namedObjectContainer is ScreenSave)
                {
                    ScreenSave baseScreen = ObjectFinder.Self.GetScreenSave(namedObjectContainer.BaseObject);

                    if (baseScreen != null)
                    {
                        return(GetNamedObjectRecursively(baseScreen, namedObjectName));
                    }
                }
            }

            return(null);
        }
Пример #11
0
        internal static CheckResult VerifyInheritanceGraph(INamedObjectContainer node)
        {
            if (mGlueProjectSave != null)
            {
                VerificationId++;
                string resultString = "";

                if (InheritanceVerificationHelper(ref node, ref resultString) == CheckResult.Failed)
                {
                    MessageBox.Show("This assignment has created an inheritence cycle containing the following classes:\n\n" +
                                    resultString +
                                    "\nThe assignment will be undone.");
                    node.BaseObject = null;
                    return CheckResult.Failed;
                }

            }

            return CheckResult.Passed;
        }
Пример #12
0
        public static bool UpdateNamedObjectsFromBaseType(INamedObjectContainer namedObjectContainer)
        {
            bool haveChangesOccurred = false;

            List<NamedObjectSave> referencedObjectsBeforeUpdate = new List<NamedObjectSave>();

            for (int i = 0; i < namedObjectContainer.NamedObjects.Count; i++)
            {
                if (namedObjectContainer.NamedObjects[i].DefinedByBase)
                {
                    referencedObjectsBeforeUpdate.Add(namedObjectContainer.NamedObjects[i]);
                }
            }

            List<NamedObjectSave> namedObjectsSetByDerived = new List<NamedObjectSave>();
            List<NamedObjectSave> namedObjectsExposedInDerived = new List<NamedObjectSave>();

            List<INamedObjectContainer> baseElements = new List<INamedObjectContainer>();

            // June 1, 2011:
            // The following code
            // was using AddRange instead
            // of manually looping, but this
            // is only possible in .NET 4.0, and
            // GlueView still uses 3.1.  
            // July 24, 2011
            // Before today, this
            // code would loop through
            // all base Entities and search
            // for SetByDerived properties in
            // any NamedObjectSave. This caused
            // bugs.  Basically if you had 3 Elements
            // in an inheritance chain and the one at the
            // very base defined a NOS to be SetByDerived, then
            // anything that inherited directly from the base should
            // be forced to define it.  If it does, then the 3rd Element
            // in the inheritance chain shouldn't have to define it, but before
            // to day it did.  This caused a lot of problems including generated
            // code creating the element twice.
            if (namedObjectContainer is EntitySave)
            {
                if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject))
                {
                    baseElements.Add(ObjectFinder.Self.GetIElement(namedObjectContainer.BaseObject));
                }
                //List<EntitySave> allBase = ((EntitySave)namedObjectContainer).GetAllBaseEntities();
                //foreach (EntitySave baseEntitySave in allBase)
                //{
                //    baseElements.Add(baseEntitySave);
                //}
            }
            else
            {
                if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject))
                {
                    baseElements.Add(ObjectFinder.Self.GetIElement(namedObjectContainer.BaseObject));
                }
                //List<ScreenSave> allBase = ((ScreenSave)namedObjectContainer).GetAllBaseScreens();
                //foreach (ScreenSave baseScreenSave in allBase)
                //{
                //    baseElements.Add(baseScreenSave);
                //}
            }


            foreach (INamedObjectContainer baseNamedObjectContainer in baseElements)
            {

                if (baseNamedObjectContainer != null)
                {
                    namedObjectsSetByDerived.AddRange(baseNamedObjectContainer.GetNamedObjectsToBeSetByDerived());
                    namedObjectsExposedInDerived.AddRange(baseNamedObjectContainer.GetNamedObjectsToBeExposedInDerived());
                }
            }

            #region See if there are any objects to be removed from the derived.
            for (int i = referencedObjectsBeforeUpdate.Count - 1; i > -1; i--)
            {
                bool contains = false;

                for (int j = 0; j < namedObjectsSetByDerived.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[i].InstanceName == namedObjectsSetByDerived[j].InstanceName &&
                        referencedObjectsBeforeUpdate[i].DefinedByBase)
                    {
                        contains = true;
                        break;
                    }
                }

                for (int j = 0; j < namedObjectsExposedInDerived.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[i].InstanceName == namedObjectsExposedInDerived[j].InstanceName &&
                        referencedObjectsBeforeUpdate[i].DefinedByBase)
                    {
                        contains = true;
                        break;
                    }
                }

                if (!contains)
                {

                    NamedObjectSave nos = referencedObjectsBeforeUpdate[i];

                    string message = "The following object is marked as \"defined by base\" but it is not contained in " +
                        "any base elements\n\n" + nos.ToString() + "\n\nWhat would you like to do?";

                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

                    mbmb.MessageText = message;

                    mbmb.AddButton("Remove " + nos.ToString(), DialogResult.Yes);
                    mbmb.AddButton("Keep it, make it not \"defined by base\"", DialogResult.No);

                    DialogResult result = mbmb.ShowDialog();

                    if (result == DialogResult.Yes)
                    {
                        // We got a NamedObject we should remove
                        namedObjectContainer.NamedObjects.Remove(nos);
                        referencedObjectsBeforeUpdate.RemoveAt(i);
                    }
                    else
                    {
                        nos.DefinedByBase = false;
                        nos.InstantiatedByBase = false;
                    }
                    haveChangesOccurred = true;
                }
            }
            #endregion

            #region Next, see if there are any objects to be added
            for (int i = 0; i < namedObjectsSetByDerived.Count; i++)
            {
                NamedObjectSave namedObjectSetByDerived = namedObjectsSetByDerived[i];

                NamedObjectSave matchingDefinedByBase = null;// contains = false;
                for (int j = 0; j < referencedObjectsBeforeUpdate.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[j].InstanceName == namedObjectSetByDerived.InstanceName &&
                        referencedObjectsBeforeUpdate[j].DefinedByBase)
                    {
                        matchingDefinedByBase = referencedObjectsBeforeUpdate[j];
                        break;
                    }
                }

                if (matchingDefinedByBase == null)
                {
                    AddSetByDerivedNos(namedObjectContainer, namedObjectSetByDerived, false);
                }
                else
                {
                    MatchDerivedToBase(namedObjectSetByDerived, matchingDefinedByBase);
                }
            }

            for (int i = 0; i < namedObjectsExposedInDerived.Count; i++)
            {
                NamedObjectSave namedObjectSetByDerived = namedObjectsExposedInDerived[i];

                NamedObjectSave matchingDefinedByBase = null;// contains = false;
                for (int j = 0; j < referencedObjectsBeforeUpdate.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[j].InstanceName == namedObjectSetByDerived.InstanceName &&
                        referencedObjectsBeforeUpdate[j].DefinedByBase)
                    {
                        matchingDefinedByBase = referencedObjectsBeforeUpdate[j];
                        break;
                    }
                }

                if (matchingDefinedByBase == null)
                {
                    AddSetByDerivedNos(namedObjectContainer, namedObjectSetByDerived, true);
                }
                else
                {
                    MatchDerivedToBase(namedObjectSetByDerived, matchingDefinedByBase);
                }
            }

            #endregion

            return haveChangesOccurred;
        }
        public static List <NamedObjectSave> GetNamedObjectsToBeExposedInDerived(this INamedObjectContainer namedObjectContainer)
        {
            List <NamedObjectSave> namedObjectsToBeExposedInDerived = new List <NamedObjectSave>();

            if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject) && namedObjectContainer.BaseObject != "<NONE>")
            {
                //If this is a Screen
                if ((namedObjectContainer as EntitySave) == null)
                {
                    namedObjectsToBeExposedInDerived.AddRange(
                        ObjectFinder.Self.GetScreenSave(namedObjectContainer.BaseObject).GetNamedObjectsToBeExposedInDerived());
                }
                //Otherwise it's an Entity
                else
                {
                    EntitySave baseEntitySave = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject);

                    if (baseEntitySave == null)
                    {
                        bool inheritsFromFrbType =
                            namedObjectContainer is EntitySave && (namedObjectContainer as EntitySave).InheritsFromFrbType();

                        if (!inheritsFromFrbType)
                        {
                            System.Windows.Forms.MessageBox.Show("The Element\n\n" + namedObjectContainer.ToString() + "\n\nhas a base type\n\n" + namedObjectContainer.BaseObject +
                                                                 "\n\nbut this base type can't be found.  " +
                                                                 "It was probably removed from the project.  You will need to set the base object to NONE.");
                        }
                    }
                    else
                    {
                        namedObjectsToBeExposedInDerived.AddRange(
                            baseEntitySave.GetNamedObjectsToBeExposedInDerived());
                    }
                }
            }

            foreach (NamedObjectSave nos in namedObjectContainer.NamedObjects)
            {
                if (nos.ExposedInDerived)
                {
                    bool isAlreadyThere = false;

                    for (int i = namedObjectsToBeExposedInDerived.Count - 1; i > -1; i--)
                    {
                        if (namedObjectsToBeExposedInDerived[i].InstanceName == nos.InstanceName)
                        {
                            isAlreadyThere = true;
                            break;
                        }
                    }

                    if (!isAlreadyThere)
                    {
                        namedObjectsToBeExposedInDerived.Add(nos);
                    }
                }
                else if (nos.DefinedByBase)
                {
                    // This guy is handling the named object save, so let's remove it from the list

                    for (int i = namedObjectsToBeExposedInDerived.Count - 1; i > -1; i--)
                    {
                        if (namedObjectsToBeExposedInDerived[i].InstanceName == nos.InstanceName)
                        {
                            namedObjectsToBeExposedInDerived.RemoveAt(i);
                        }
                    }
                }
            }

            return(namedObjectsToBeExposedInDerived);
        }
Пример #14
0
        private static void AddSetByDerivedNos(INamedObjectContainer namedObjectContainer,
            NamedObjectSave namedObjectSetByDerived, bool instantiatedByBase)
        {
            NamedObjectSave existingNamedObject = null;

            foreach (NamedObjectSave namedObjectInDerived in namedObjectContainer.NamedObjects)
            {
                if (namedObjectInDerived.InstanceName == namedObjectSetByDerived.InstanceName)
                {
                    existingNamedObject = namedObjectInDerived;
                    break;
                }
            }

            if (existingNamedObject != null)
            {
                existingNamedObject.DefinedByBase = true;
                existingNamedObject.InstantiatedByBase = instantiatedByBase;
            }
            else
            {
                NamedObjectSave namedObjectSave = namedObjectSetByDerived.Clone();

                namedObjectSave.SetDefinedByBaseRecursively(true);
                namedObjectSave.SetInstantiatedByBaseRecursively(instantiatedByBase);

                // This can't be set by derived because an object it inherits from has that already set
                namedObjectSave.SetSetByDerivedRecursively(false);


                namedObjectContainer.NamedObjects.Add(namedObjectSave);
            }
        }
Пример #15
0
        public static NamedObjectSave GetNamedObjectThatIsContainerFor(INamedObjectContainer element, NamedObjectSave containedNamedObject)
        {
            foreach (NamedObjectSave namedObjectSave in element.NamedObjects)
            {
                NamedObjectSave returnValue = GetNamedObjectThatIsContainerFor(namedObjectSave, containedNamedObject);

                if (returnValue != null)
                {
                    return returnValue;
                }
            }

            return null;
        }
Пример #16
0
        private void ReactToNamedObjectChangedInstanceName(NamedObjectSave namedObjectSave, object oldValueAsObject)
        {
            string oldValue = (string)oldValueAsObject;

            #region Fail checks

            string whyItIsntValid;

            NameVerifier.IsNamedObjectNameValid(namedObjectSave.InstanceName, out whyItIsntValid);

            if (!string.IsNullOrEmpty(whyItIsntValid))
            {
                GlueGui.ShowMessageBox(whyItIsntValid);
                namedObjectSave.InstanceName = oldValue;
            }
            #endregion

            else
            {
                IElement currentElement = EditorLogic.CurrentElement;

                string baseObject = ((IElement)EditorLogic.CurrentElement).BaseObject;
                // See if the entity has a base and if the base contains this name
                if (!string.IsNullOrEmpty(baseObject))
                {
                    INamedObjectContainer baseNamedObjectContainer = ObjectFinder.Self.GetNamedObjectContainer(baseObject);

                    NamedObjectSave baseNamedObject = baseNamedObjectContainer.GetNamedObjectRecursively(namedObjectSave.InstanceName);

                    if (baseNamedObject != null)
                    {
                        if (baseNamedObject.SetByDerived)
                        {
                            // There is a base element that has an object with the same
                            // name as the derived element.  The derived doesn't have a same-named
                            // object already, and the base is SetByDerived, so let's setup the derived
                            // to use the base and notify the user.
                            namedObjectSave.DefinedByBase = true;
                            MessageBox.Show("This object has the same name as\n\n" + baseNamedObject.ToString() + "\n\nIt is SetByDerived, " +
                                            "so Glue will use this as the base object for the object " + namedObjectSave.InstanceName);
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("A base object already has an object with this name");
                            namedObjectSave.InstanceName = oldValue;
                        }
                    }
                }

                if (currentElement != null)
                {
                    // See if any named objects in this instance use this for tunneling

                    foreach (CustomVariable customVariable in currentElement.CustomVariables)
                    {
                        if (!string.IsNullOrEmpty(customVariable.SourceObject) && customVariable.SourceObject == oldValue)
                        {
                            MessageBox.Show("Changing the variable " + customVariable.Name + " so it uses " + namedObjectSave.InstanceName + " instead of " + (string)oldValue);

                            customVariable.SourceObject = namedObjectSave.InstanceName;
                        }
                    }

                    // See if any events tunnel to this NOS
                    foreach (EventResponseSave eventResponseSave in currentElement.Events)
                    {
                        if (!string.IsNullOrEmpty(eventResponseSave.SourceObject) && eventResponseSave.SourceObject == oldValue)
                        {
                            MessageBox.Show("Chaing the Event " + eventResponseSave.EventName + " so it uses " + namedObjectSave.InstanceName + " instead of " + oldValue);

                            eventResponseSave.SourceObject = namedObjectSave.InstanceName;
                        }
                    }
                }

                // If this is a layer, see if any other NOS's use this as their Layer
                if (namedObjectSave.IsLayer)
                {
                    List <NamedObjectSave> namedObjectList = EditorLogic.CurrentElement.NamedObjects;

                    string oldLayerName = (string)oldValue;

                    foreach (NamedObjectSave nos in namedObjectList)
                    {
                        nos.ReplaceLayerRecursively(oldLayerName, namedObjectSave.InstanceName);
                    }
                }
            }
        }
        public static bool UpdateNamedObjectsFromBaseType(INamedObjectContainer namedObjectContainer)
        {
            bool haveChangesOccurred = false;

            List <NamedObjectSave> referencedObjectsBeforeUpdate = new List <NamedObjectSave>();

            for (int i = 0; i < namedObjectContainer.NamedObjects.Count; i++)
            {
                if (namedObjectContainer.NamedObjects[i].DefinedByBase)
                {
                    referencedObjectsBeforeUpdate.Add(namedObjectContainer.NamedObjects[i]);
                }
            }

            List <NamedObjectSave> namedObjectsSetByDerived     = new List <NamedObjectSave>();
            List <NamedObjectSave> namedObjectsExposedInDerived = new List <NamedObjectSave>();

            List <INamedObjectContainer> baseElements = new List <INamedObjectContainer>();

            // June 1, 2011:
            // The following code
            // was using AddRange instead
            // of manually looping, but this
            // is only possible in .NET 4.0, and
            // GlueView still uses 3.1.
            // July 24, 2011
            // Before today, this
            // code would loop through
            // all base Entities and search
            // for SetByDerived properties in
            // any NamedObjectSave. This caused
            // bugs.  Basically if you had 3 Elements
            // in an inheritance chain and the one at the
            // very base defined a NOS to be SetByDerived, then
            // anything that inherited directly from the base should
            // be forced to define it.  If it does, then the 3rd Element
            // in the inheritance chain shouldn't have to define it, but before
            // to day it did.  This caused a lot of problems including generated
            // code creating the element twice.
            if (namedObjectContainer is EntitySave)
            {
                if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject))
                {
                    baseElements.Add(ObjectFinder.Self.GetIElement(namedObjectContainer.BaseObject));
                }
                //List<EntitySave> allBase = ((EntitySave)namedObjectContainer).GetAllBaseEntities();
                //foreach (EntitySave baseEntitySave in allBase)
                //{
                //    baseElements.Add(baseEntitySave);
                //}
            }
            else
            {
                if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject))
                {
                    baseElements.Add(ObjectFinder.Self.GetIElement(namedObjectContainer.BaseObject));
                }
                //List<ScreenSave> allBase = ((ScreenSave)namedObjectContainer).GetAllBaseScreens();
                //foreach (ScreenSave baseScreenSave in allBase)
                //{
                //    baseElements.Add(baseScreenSave);
                //}
            }


            foreach (INamedObjectContainer baseNamedObjectContainer in baseElements)
            {
                if (baseNamedObjectContainer != null)
                {
                    namedObjectsSetByDerived.AddRange(baseNamedObjectContainer.GetNamedObjectsToBeSetByDerived());
                    namedObjectsExposedInDerived.AddRange(baseNamedObjectContainer.GetNamedObjectsToBeExposedInDerived());
                }
            }

            #region See if there are any objects to be removed from the derived.
            for (int i = referencedObjectsBeforeUpdate.Count - 1; i > -1; i--)
            {
                bool contains = false;

                for (int j = 0; j < namedObjectsSetByDerived.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[i].InstanceName == namedObjectsSetByDerived[j].InstanceName &&
                        referencedObjectsBeforeUpdate[i].DefinedByBase)
                    {
                        contains = true;
                        break;
                    }
                }

                for (int j = 0; j < namedObjectsExposedInDerived.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[i].InstanceName == namedObjectsExposedInDerived[j].InstanceName &&
                        referencedObjectsBeforeUpdate[i].DefinedByBase)
                    {
                        contains = true;
                        break;
                    }
                }

                if (!contains)
                {
                    NamedObjectSave nos = referencedObjectsBeforeUpdate[i];

                    string message = "The following object is marked as \"defined by base\" but it is not contained in " +
                                     "any base elements\n\n" + nos.ToString() + "\n\nWhat would you like to do?";

                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

                    mbmb.MessageText = message;

                    mbmb.AddButton("Remove " + nos.ToString(), DialogResult.Yes);
                    mbmb.AddButton("Keep it, make it not \"defined by base\"", DialogResult.No);

                    DialogResult result = mbmb.ShowDialog();

                    if (result == DialogResult.Yes)
                    {
                        // We got a NamedObject we should remove
                        namedObjectContainer.NamedObjects.Remove(nos);
                        referencedObjectsBeforeUpdate.RemoveAt(i);
                    }
                    else
                    {
                        nos.DefinedByBase      = false;
                        nos.InstantiatedByBase = false;
                    }
                    haveChangesOccurred = true;
                }
            }
            #endregion

            #region Next, see if there are any objects to be added
            for (int i = 0; i < namedObjectsSetByDerived.Count; i++)
            {
                NamedObjectSave namedObjectSetByDerived = namedObjectsSetByDerived[i];

                NamedObjectSave matchingDefinedByBase = null;// contains = false;
                for (int j = 0; j < referencedObjectsBeforeUpdate.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[j].InstanceName == namedObjectSetByDerived.InstanceName &&
                        referencedObjectsBeforeUpdate[j].DefinedByBase)
                    {
                        matchingDefinedByBase = referencedObjectsBeforeUpdate[j];
                        break;
                    }
                }

                if (matchingDefinedByBase == null)
                {
                    AddSetByDerivedNos(namedObjectContainer, namedObjectSetByDerived, false);
                }
                else
                {
                    MatchDerivedToBase(namedObjectSetByDerived, matchingDefinedByBase);
                }
            }

            for (int i = 0; i < namedObjectsExposedInDerived.Count; i++)
            {
                NamedObjectSave namedObjectSetByDerived = namedObjectsExposedInDerived[i];

                NamedObjectSave matchingDefinedByBase = null;// contains = false;
                for (int j = 0; j < referencedObjectsBeforeUpdate.Count; j++)
                {
                    if (referencedObjectsBeforeUpdate[j].InstanceName == namedObjectSetByDerived.InstanceName &&
                        referencedObjectsBeforeUpdate[j].DefinedByBase)
                    {
                        matchingDefinedByBase = referencedObjectsBeforeUpdate[j];
                        break;
                    }
                }

                if (matchingDefinedByBase == null)
                {
                    AddSetByDerivedNos(namedObjectContainer, namedObjectSetByDerived, true);
                }
                else
                {
                    MatchDerivedToBase(namedObjectSetByDerived, matchingDefinedByBase);
                }
            }

            #endregion

            return(haveChangesOccurred);
        }
 public static NamedObjectSave GetNamedObject(this INamedObjectContainer namedObjectContainer, string namedObjectName)
 {
     return(GetNamedObjectInList(namedObjectContainer.NamedObjects, namedObjectName));
 }
Пример #19
0
        private static CheckResult InheritanceVerificationHelper(ref INamedObjectContainer node, ref string cycleString)
        {
            //Assign the current VerificationId to identify nodes that have been visited
            node.VerificationIndex = VerificationId;

            //Travel upward through the inheritence tree from this object, stopping when either the
            //tree stops, or you reach a node that's already been visited.
            if (!string.IsNullOrEmpty(node.BaseObject))
            {
                INamedObjectContainer baseNode = ObjectFinder.Self.GetNamedObjectContainer(node.BaseObject);

                if (baseNode == null)
                {
                    // We do nothing - the base object for this
                    // Entity doesn't exist, so we'll continue as if this thing doesn't really have
                    // a base Entity.  The user will have to address this in the Glue UI
                }
                else if (baseNode.VerificationIndex != VerificationId)
                {

                    //If baseNode verification failed, add this node's name to the list and return Failed
                    if (InheritanceVerificationHelper(ref baseNode, ref cycleString) == CheckResult.Failed)
                    {
                        cycleString = (node as FlatRedBall.Utilities.INameable).Name + "\n" + cycleString;
                        return CheckResult.Failed;
                    }

                }
                else
                {
                    //If the basenode has already been visited, begin the cycleString and return Failed

                    cycleString = (node as FlatRedBall.Utilities.INameable).Name + "\n" +
                                    (baseNode as FlatRedBall.Utilities.INameable).Name + "\n";

                    return CheckResult.Failed;
                }
            }


            return CheckResult.Passed;
        }