Beispiel #1
0
        public NamedObjectSave AddNewNamedObjectToSelectedElement(AddObjectViewModel addObjectViewModel)
        {
            MembershipInfo membershipInfo = NamedObjectSaveExtensionMethodsGlue.GetMemberMembershipInfo(addObjectViewModel.ObjectName);

            var newNos = NamedObjectSaveExtensionMethodsGlue.AddNewNamedObjectToSelectedElement(addObjectViewModel.ObjectName, membershipInfo, false);

            if (addObjectViewModel.SourceClassType != NoType && !string.IsNullOrEmpty(addObjectViewModel.SourceClassType))
            {
                newNos.SourceType      = addObjectViewModel.SourceType;
                newNos.SourceClassType = addObjectViewModel.SourceClassType;
                newNos.SourceFile      = addObjectViewModel.SourceFile;
                newNos.SourceName      = addObjectViewModel.SourceNameInFile;
                newNos.UpdateCustomProperties();

                EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes();
            }
            else if (!string.IsNullOrEmpty(addObjectViewModel.SourceFile))
            {
                newNos.SourceType = addObjectViewModel.SourceType;
                newNos.SourceFile = addObjectViewModel.SourceFile;
                newNos.SourceName = addObjectViewModel.SourceNameInFile;
                newNos.UpdateCustomProperties();

                EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes();
            }

            newNos.SourceClassGenericType = addObjectViewModel.SourceClassGenericType;

            var ati = newNos.GetAssetTypeInfo();

            if (ati != null && ati.DefaultPublic)
            {
                newNos.HasPublicProperty = true;
            }

            var currentEntity = GlueState.Self.CurrentElement as EntitySave;

            if (currentEntity != null && currentEntity.CreatedByOtherEntities && currentEntity.PooledByFactory)
            {
                bool wasAnythingAdded =
                    FlatRedBall.Glue.Factories.FactoryManager.AddResetVariablesFor(newNos);

                if (wasAnythingAdded)
                {
                    PluginManager.ReceiveOutput("Added reset variables for " + newNos);
                }
            }

            PluginManager.ReactToNewObject(newNos);
            MainGlueWindow.Self.PropertyGrid.Refresh();
            PropertyGridHelper.UpdateNamedObjectDisplay();
            ElementViewWindow.GenerateSelectedElementCode();

            // it may already be selected, so force select it
            MainGlueWindow.Self.ElementTreeView.SelectedNode = null;
            MainGlueWindow.Self.ElementTreeView.SelectedNode = GlueState.Self.Find.NamedObjectTreeNode(newNos);
            GluxCommands.Self.SaveGlux();

            return(newNos);
        }
Beispiel #2
0
        public static NamedObjectSave AddNewNamedObjectTo(string objectName, MembershipInfo membershipInfo,
                                                          IElement element, NamedObjectSave namedObjectSave, bool raisePluginResponse = true)
        {
            NamedObjectSave namedObject = new NamedObjectSave();

            namedObject.InstanceName = objectName;

            namedObject.DefinedByBase = membershipInfo == MembershipInfo.ContainedInBase;

            #region Adding to a NamedObject (PositionedObjectList)

            if (namedObjectSave != null)
            {
                AddNamedObjectToCurrentNamedObjectList(namedObject);
            }
            #endregion

            else if (element != null)
            {
                AddExistingNamedObjectToElement(element, namedObject, true);
            }


            if (raisePluginResponse)
            {
                PluginManager.ReactToNewObject(namedObject);
            }
            MainGlueWindow.Self.PropertyGrid.Refresh();
            ElementViewWindow.GenerateSelectedElementCode();
            GluxCommands.Self.SaveGlux();

            return(namedObject);
        }
        private static void UseFullScreenClick(object sender, EventArgs e)
        {
            EditorLogic.CurrentNamedObject.DestinationRectangle = null;

            ElementViewWindow.GenerateSelectedElementCode();
            GluxCommands.Self.SaveGlux();
            MainGlueWindow.Self.PropertyGrid.Refresh();
        }
        private void DoneButton_Click(object sender, EventArgs e)
        {
            this.Close();

            ElementViewWindow.GenerateSelectedElementCode();

            GlueCommands.Self.GenerateCodeCommands.GenerateCustomClassesCode();

            GlueCommands.Self.GenerateCodeCommands.GenerateGlobalContentCode();
        }
        private static void UseCustomRectangleClick(object sender, EventArgs e)
        {
            FloatRectangle rectangle = new FloatRectangle(0, 0,
                                                          ProjectManager.GlueProjectSave.ResolutionWidth,
                                                          ProjectManager.GlueProjectSave.ResolutionHeight);

            EditorLogic.CurrentNamedObject.DestinationRectangle = rectangle;

            ElementViewWindow.GenerateSelectedElementCode();
            GluxCommands.Self.SaveGlux();
            MainGlueWindow.Self.PropertyGrid.Refresh();
        }
        public static NamedObjectSave AddNewNamedObjectToSelectedElement(string objectName, MembershipInfo membershipInfo, bool raisePluginResponse = true)
        {
            NamedObjectSave namedObject = new NamedObjectSave();

            namedObject.InstanceName = objectName;

            namedObject.DefinedByBase = membershipInfo == MembershipInfo.ContainedInBase;

            #region Adding to a NamedObject (PositionedObjectList)

            if (EditorLogic.CurrentNamedObject != null)
            {
                AddNamedObjectToCurrentNamedObjectList(namedObject);
            }
            #endregion

            #region else adding to Screen

            else if (EditorLogic.CurrentScreenTreeNode != null)
            {
                ScreenTreeNode screenTreeNode =
                    EditorLogic.CurrentScreenTreeNode;
                AddNewNamedObjectToElementTreeNode(screenTreeNode, namedObject, true);
            }

            #endregion

            #region else adding to an Entity
            else if (EditorLogic.CurrentEntityTreeNode != null)
            {
                EntityTreeNode entityTreeNode =
                    EditorLogic.CurrentEntityTreeNode;

                AddNewNamedObjectToElementTreeNode(entityTreeNode, namedObject, true);
            }
            #endregion


            if (raisePluginResponse)
            {
                PluginManager.ReactToNewObject(namedObject);
            }
            MainGlueWindow.Self.PropertyGrid.Refresh();
            ElementViewWindow.GenerateSelectedElementCode();
            GluxCommands.Self.SaveGlux();

            return(namedObject);
        }
        private static void SetDefaultClick(object sender, EventArgs e)
        {
            // set default, reset default, set to default, reset to default
            if (mHighlightedCustomVariable != null)
            {
                mHighlightedCustomVariable.DefaultValue = null;
                GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();
            }
            else if (EditorLogic.CurrentStateSave != null)
            {
                StateSave stateSave = EditorLogic.CurrentStateSave;

                string valueToChange = MainGlueWindow.Self.PropertyGrid.SelectedGridItem.Label;
                if (valueToChange.Contains(" set"))
                {
                    valueToChange = valueToChange.Substring(0, valueToChange.IndexOf(" set"));
                }
                for (int i = stateSave.InstructionSaves.Count - 1; i > -1; i--)
                {
                    if (stateSave.InstructionSaves[i].Member == valueToChange)
                    {
                        stateSave.InstructionSaves.RemoveAt(i);
                        break;
                    }
                }
            }
            else if (EditorLogic.CurrentCustomVariable != null)
            {
                EditorLogic.CurrentCustomVariable.DefaultValue = null;
                GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();
            }
            else
            {
                NamedObjectSave currentNamedObject = EditorLogic.CurrentNamedObject;

                string variableToSet = MainGlueWindow.Self.PropertyGrid.SelectedGridItem.Label;

                SetVariableToDefault(currentNamedObject, variableToSet);
            }

            ElementViewWindow.GenerateSelectedElementCode();

            GluxCommands.Self.SaveGlux();

            MainGlueWindow.Self.PropertyGrid.Refresh();
        }
Beispiel #8
0
        public void RemoveReferencedFile(ReferencedFileSave referencedFileToRemove, List <string> additionalFilesToRemove, bool regenerateCode)
        {
            var isContained = GlueState.Self.Find.IfReferencedFileSaveIsReferenced(referencedFileToRemove);

            /////////////////////////Early Out//////////////////////////////
            if (!isContained)
            {
                return;
            }
            ////////////////////////End Early Out/////////////////////////////



            // There are some things that need to happen:
            // 1.  Remove the ReferencedFileSave from the Glue project (GLUX)
            // 2.  Remove the GUI item
            // 3.  Remove the item from the Visual Studio project.
            IElement container = referencedFileToRemove.GetContainer();

            #region Remove the file from the current Screen or Entity if there is a current Screen or Entity

            if (container != null)
            {
                // The referenced file better be a globally referenced file


                if (!container.ReferencedFiles.Contains(referencedFileToRemove))
                {
                    throw new ArgumentException();
                }
                else
                {
                    container.ReferencedFiles.Remove(referencedFileToRemove);
                }
                // Ask about any NamedObjects that reference this file.
                for (int i = container.NamedObjects.Count - 1; i > -1; i--)
                {
                    var nos = container.NamedObjects[i];
                    if (nos.SourceType == SourceType.File && nos.SourceFile == referencedFileToRemove.Name)
                    {
                        MainGlueWindow.Self.Invoke(() =>
                        {
                            // Ask the user what to do here - remove it?  Keep it and not compile?
                            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                            mbmb.MessageText           = "The object\n" + nos.ToString() + "\nreferences the file\n" + referencedFileToRemove.Name +
                                                         "\nWhat would you like to do?";
                            mbmb.AddButton("Remove this object", DialogResult.Yes);
                            mbmb.AddButton("Keep it (object will not be valid until changed)", DialogResult.No);

                            var result = mbmb.ShowDialog();

                            if (result == DialogResult.Yes)
                            {
                                container.NamedObjects.RemoveAt(i);
                            }
                        });
                    }
                    nos.ResetVariablesReferencing(referencedFileToRemove);
                }

                MainGlueWindow.Self.Invoke(() =>
                {
                    if (EditorLogic.CurrentScreenTreeNode != null)
                    {
                        EditorLogic.CurrentScreenTreeNode.UpdateReferencedTreeNodes();
                    }
                    else if (EditorLogic.CurrentEntityTreeNode != null)
                    {
                        EditorLogic.CurrentEntityTreeNode.UpdateReferencedTreeNodes();
                    }
                    if (regenerateCode)
                    {
                        ElementViewWindow.GenerateSelectedElementCode();
                    }
                });
            }
            #endregion

            #region else, the file is likely part of the GlobalContentFile

            else
            {
                ProjectManager.GlueProjectSave.GlobalFiles.Remove(referencedFileToRemove);
                ProjectManager.GlueProjectSave.GlobalContentHasChanged = true;

                // Much faster to just remove the tree node.  This was done
                // to reuse code and make things reactive, but this has gotten
                // slow on bigger projects.
                //ElementViewWindow.UpdateGlobalContentTreeNodes(false); // don't save here because projects will get saved below

                Action refreshUiAction = () =>
                {
                    TreeNode treeNode = GlueState.Self.Find.ReferencedFileSaveTreeNode(referencedFileToRemove);
                    if (treeNode != null)
                    {
                        // treeNode can be null if the user presses delete + enter really really fast, stacking 2 remove
                        // actions
                        if (treeNode.Tag != referencedFileToRemove)
                        {
                            throw new Exception("Error removing the tree node - the selected tree node doesn't reference the file being removed");
                        }

                        treeNode.Parent.Nodes.Remove(treeNode);
                    }
                };

                MainGlueWindow.Self.Invoke((MethodInvoker) delegate
                {
                    refreshUiAction();
                }
                                           );


                GlobalContentCodeGenerator.UpdateLoadGlobalContentCode();

                List <IElement> elements = ObjectFinder.Self.GetAllElementsReferencingFile(referencedFileToRemove.Name);

                foreach (IElement element in elements)
                {
                    if (regenerateCode)
                    {
                        CodeWriter.GenerateCode(element);
                    }
                }
            }

            #endregion


            // November 10, 2015
            // I feel like this may
            // have been old code before
            // we had full dependency tracking
            // in Glue. This file should only be
            // removed from the project if nothing
            // else references it, including no entities.
            // This code does just entities/screens/global
            // content, but doesn't check the full dependency
            // tree. I think we can just remove it and depend on
            // the code below.
            // Actually, removing this seems to cause problems - files
            // that should be removed aren't. So instead we'll chnage the
            // call to use the dependency tree:
            // replace:

            List <string> referencedFiles =
                GlueCommands.Self.FileCommands.GetAllReferencedFileNames().Select(item => item.ToLowerInvariant()).ToList();

            string absoluteToLower   = GlueCommands.Self.GetAbsoluteFileName(referencedFileToRemove).ToLowerInvariant();
            string relativeToProject = FileManager.MakeRelative(absoluteToLower, GlueState.Self.ContentDirectory);

            bool isReferencedByOtherContent = referencedFiles.Contains(relativeToProject);

            if (isReferencedByOtherContent == false)
            {
                additionalFilesToRemove.Add(referencedFileToRemove.GetRelativePath());

                string itemName     = referencedFileToRemove.GetRelativePath();
                string absoluteName = ProjectManager.MakeAbsolute(referencedFileToRemove.Name, true);

                // I don't know why we were removing the file from the ProjectBase - it should
                // be from the Content project
                //ProjectManager.RemoveItemFromProject(ProjectManager.ProjectBase, itemName);
                ProjectManager.RemoveItemFromProject(ProjectManager.ProjectBase.ContentProject, itemName, performSave: false);

                foreach (ProjectBase syncedProject in ProjectManager.SyncedProjects)
                {
                    ProjectManager.RemoveItemFromProject(syncedProject.ContentProject, absoluteName);
                }
            }



            if (ProjectManager.IsContent(referencedFileToRemove.Name))
            {
                UnreferencedFilesManager.Self.RefreshUnreferencedFiles(false);
                foreach (var file in UnreferencedFilesManager.LastAddedUnreferencedFiles)
                {
                    additionalFilesToRemove.Add(file.FilePath);
                }
            }

            ReactToRemovalIfCsv(referencedFileToRemove, additionalFilesToRemove);

            GluxCommands.Self.SaveGlux();
        }
Beispiel #9
0
        private static EntitySave CreateEntityAndObjects(AddEntityWindow window, string entityName, string directory)
        {
            var gluxCommands = GlueCommands.Self.GluxCommands;

            var newElement = gluxCommands.EntityCommands.AddEntity(
                directory + entityName, is2D: true);

            GlueState.Self.CurrentElement = newElement;

            if (window.SpriteChecked)
            {
                AddObjectViewModel addObjectViewModel = new AddObjectViewModel();
                addObjectViewModel.ObjectName      = "SpriteInstance";
                addObjectViewModel.SourceClassType = "Sprite";
                addObjectViewModel.SourceType      = SourceType.FlatRedBallType;
                gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel);
                GlueState.Self.CurrentElement = newElement;
            }

            if (window.TextChecked)
            {
                AddObjectViewModel addObjectViewModel = new AddObjectViewModel();
                addObjectViewModel.ObjectName      = "TextInstance";
                addObjectViewModel.SourceClassType = "Text";
                addObjectViewModel.SourceType      = SourceType.FlatRedBallType;
                gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel);
                GlueState.Self.CurrentElement = newElement;
            }

            if (window.CircleChecked)
            {
                AddObjectViewModel addObjectViewModel = new AddObjectViewModel();
                addObjectViewModel.ObjectName      = "CircleInstance";
                addObjectViewModel.SourceClassType = "Circle";
                addObjectViewModel.SourceType      = SourceType.FlatRedBallType;
                gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel);
                GlueState.Self.CurrentElement = newElement;
            }

            if (window.AxisAlignedRectangleChecked)
            {
                AddObjectViewModel addObjectViewModel = new AddObjectViewModel();
                addObjectViewModel.ObjectName      = "AxisAlignedRectangleInstance";
                addObjectViewModel.SourceClassType = "AxisAlignedRectangle";
                addObjectViewModel.SourceType      = SourceType.FlatRedBallType;
                gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel);
                GlueState.Self.CurrentElement = newElement;
            }

            // There are a few important things to note about this function:
            // 1. Whenever gluxCommands.AddNewNamedObjectToSelectedElement is called, Glue performs a full
            //    refresh and save. The reason for this is that gluxCommands.AddNewNamedObjectToSelectedElement
            //    is the standard way to add a new named object to an element, and it may be called by other parts
            //    of the code (and plugins) that expect the add to be a complete set of logic (add, refresh, save, etc).
            //    This is less efficient than adding all of them and saving only once, but that would require a second add
            //    method, which would add complexity. For now, we deal with the slower calls because it's not really noticeable.
            // 2. Some actions, like adding Points to a polygon, are done after the polygon is created and added, and that requires
            //    an additional save. Therefore, we do one last save/refresh at the end of this method in certain situations.
            //    Again, this is less efficient than if we performed just a single call, but a single call would be more complicated.
            //    because we'd have to suppress all the other calls.
            bool needsRefreshAndSave = false;

            if (window.PolygonChecked)
            {
                AddObjectViewModel addObjectViewModel = new AddObjectViewModel();
                addObjectViewModel.ObjectName      = "PolygonInstance";
                addObjectViewModel.SourceClassType = "Polygon";
                addObjectViewModel.SourceType      = SourceType.FlatRedBallType;

                var nos = gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel);
                CustomVariableInNamedObject instructions = null;
                instructions = nos.GetCustomVariable("Points");
                if (instructions == null)
                {
                    instructions        = new CustomVariableInNamedObject();
                    instructions.Member = "Points";
                    nos.InstructionSaves.Add(instructions);
                }
                var points = new List <Vector2>();
                points.Add(new Vector2(-16, 16));
                points.Add(new Vector2(16, 16));
                points.Add(new Vector2(16, -16));
                points.Add(new Vector2(-16, -16));
                points.Add(new Vector2(-16, 16));
                instructions.Value = points;


                needsRefreshAndSave = true;

                GlueState.Self.CurrentElement = newElement;
            }

            if (window.IVisibleChecked)
            {
                newElement.ImplementsIVisible = true;
                needsRefreshAndSave           = true;
            }

            if (window.IClickableChecked)
            {
                newElement.ImplementsIClickable = true;
                needsRefreshAndSave             = true;
            }

            if (window.IWindowChecked)
            {
                newElement.ImplementsIWindow = true;
                needsRefreshAndSave          = true;
            }

            if (window.ICollidableChecked)
            {
                newElement.ImplementsICollidable = true;
                needsRefreshAndSave = true;
            }

            if (needsRefreshAndSave)
            {
                MainGlueWindow.Self.PropertyGrid.Refresh();
                ElementViewWindow.GenerateSelectedElementCode();
                GluxCommands.Self.SaveGlux();
            }

            return(newElement);
        }
Beispiel #10
0
        public TreeNode MoveEntityOn(EntityTreeNode treeNodeMoving, TreeNode targetNode)
        {
            TreeNode newTreeNode = null;

            #region Moving the Entity into (or out of) a directory
            if (targetNode.IsDirectoryNode() || targetNode.IsRootEntityNode())
            {
                MoveEntityToDirectory(treeNodeMoving, targetNode);
            }

            #endregion

            #region Moving an Entity onto another element to create an instance

            else if (targetNode.IsEntityNode() || targetNode.IsScreenNode() || targetNode.IsRootNamedObjectNode())
            {
                bool isValidDrop = true;
                // Make sure that we don't drop an Entity into its own Objects
                if (targetNode.IsRootNamedObjectNode())
                {
                    if (treeNodeMoving == targetNode.GetContainingElementTreeNode())
                    {
                        isValidDrop = false;
                    }
                }
                if (isValidDrop)
                {
                    newTreeNode = MoveEntityOntoElement(treeNodeMoving, targetNode, newTreeNode);
                }
            }

            #endregion

            #region Moving an Entity onto a NamedObject (currently supports only Lists)

            else if (targetNode.IsNamedObjectNode())
            {
                // Allow drop only if it's a list or Layer
                NamedObjectSave targetNamedObjectSave = targetNode.Tag as NamedObjectSave;

                if (!targetNamedObjectSave.IsList && !targetNamedObjectSave.IsLayer)
                {
                    MessageBox.Show("The target is not a List or Layer so we can't add an Object to it.", "Target not valid");
                }
                if (targetNamedObjectSave.IsLayer)
                {
                    TreeNode parent = targetNode.Parent;

                    newTreeNode = MoveEntityOn(treeNodeMoving, parent);

                    // this created a new NamedObjectSave.  Let's put that on the Layer
                    DragDropManager.Self.MoveNamedObject(newTreeNode, targetNode);
                }
                else
                {
                    // Make sure that the two types match
                    string listType = targetNamedObjectSave.SourceClassGenericType;

                    bool isOfTypeOrInherits =
                        listType == treeNodeMoving.EntitySave.Name ||
                        treeNodeMoving.EntitySave.InheritsFrom(listType);

                    if (isOfTypeOrInherits == false)
                    {
                        MessageBox.Show("The target list type is of type\n\n" +
                                        listType +
                                        "\n\nBut the Entity is of type\n\n" +
                                        treeNodeMoving.EntitySave.Name +
                                        "\n\nCould not add an instance to the list", "Could not add instance");
                    }
                    else
                    {
                        NamedObjectSave namedObject = new NamedObjectSave();
                        namedObject.InstanceName =
                            FileManager.RemovePath(treeNodeMoving.EntitySave.Name) + "1";

                        StringFunctions.MakeNameUnique <NamedObjectSave>(
                            namedObject, targetNamedObjectSave.ContainedObjects);

                        // Not sure if we need to set this or not, but I think
                        // any instance added to a list will not be defined by base
                        namedObject.DefinedByBase = false;

                        NamedObjectSaveExtensionMethodsGlue.AddNamedObjectToCurrentNamedObjectList(namedObject);

                        ElementViewWindow.GenerateSelectedElementCode();
                        // Don't save the Glux, the caller of this method will take care of it
                        // GluxCommands.Self.SaveGlux();
                    }
                }
            }

            #endregion

            else if (targetNode.IsGlobalContentContainerNode())
            {
                AskAndAddAllContainedRfsToGlobalContent(treeNodeMoving.SaveObject);
            }

            return(newTreeNode);
        }
Beispiel #11
0
        public void MoveNamedObject(TreeNode treeNodeMoving, TreeNode targetNode)
        {
            if (targetNode != null)
            {
                NamedObjectSave targetNos = targetNode.Tag as NamedObjectSave;
                NamedObjectSave movingNos = treeNodeMoving.Tag as NamedObjectSave;

                bool succeeded = false;
                if (targetNode == null)
                {
                    // Didn't move on to anything
                }
                else if (targetNode.IsRootNamedObjectNode())
                {
                    succeeded = MoveObjectOnObjectsRoot(treeNodeMoving, targetNode, movingNos, succeeded);
                }
                else if (targetNode.IsRootCustomVariablesNode())
                {
                    MoveObjectOnRootCustomVariablesNode(treeNodeMoving, targetNode);
                }
                else if (targetNode.Tag is IElement)
                {
                    succeeded = DragDropNosIntoElement(movingNos, targetNode.Tag as IElement);
                }
                else if (targetNode.IsRootEventsNode())
                {
                    succeeded = DragDropNosOnRootEventsNode(treeNodeMoving, targetNode);
                }
                else if (targetNos != null && targetNos.SourceType == SourceType.FlatRedBallType)
                {
                    string targetClassType = targetNos.SourceClassType;

                    #region Failure cases

                    if (string.IsNullOrEmpty(targetClassType))
                    {
                        MessageBox.Show("The target Object does not have a defined type.  This operation is not valid");
                    }

                    #endregion

                    else if (targetClassType == "Layer")
                    {
                        // Only allow this if the NOS's are on the same object
                        if (ObjectFinder.Self.GetElementContaining(movingNos) ==
                            ObjectFinder.Self.GetElementContaining(targetNos))
                        {
                            succeeded         = true;
                            movingNos.LayerOn = targetNos.InstanceName;
                            MainGlueWindow.Self.PropertyGrid.Refresh();
                        }
                    }

                    else if (targetClassType == "ShapeCollection")
                    {
                        succeeded = HandleDropOnShapeCollection(treeNodeMoving, targetNode, targetNos, movingNos);
                    }

                    else if (targetClassType == "PositionedObjectList<T>")
                    {
                        succeeded = HandleDropOnList(treeNodeMoving, targetNode, targetNos, movingNos);
                    }
                }
                else
                {
                    MessageBox.Show("Invalid movement");
                }


                if (succeeded)
                {
                    if (EditorLogic.CurrentElement != null)
                    {
                        ElementViewWindow.GenerateSelectedElementCode();
                    }
                    else
                    {
                        GlobalContentCodeGenerator.UpdateLoadGlobalContentCode();
                    }
                    ProjectManager.SaveProjects();
                    GluxCommands.Self.SaveGlux();
                }
            }
        }
        public void SetResetVariablesForEntitySave(EntitySave entitySave)
        {
            // set reset variables
            bool hasNamedObjectEntities = false;

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

            #region Loop through the NamedObjects to identify which variables should be added
            foreach (NamedObjectSave nos in entitySave.NamedObjects)
            {
                hasNamedObjectEntities |= AddResetVariablesFor(skippedNoses, nos);
            }

            // let's make sure to get all the NOS's that are defined in base types too:
            foreach (var element in entitySave.GetAllBaseEntities())
            {
                foreach (NamedObjectSave nos in element.NamedObjects)
                {
                    if (!nos.DefinedByBase && !nos.SetByDerived)
                    {
                        hasNamedObjectEntities |= AddResetVariablesFor(skippedNoses, nos);
                    }
                }
            }

            if (skippedNoses.Count != 0)
            {
                string message = "Couldn't add reset variables for the following objects.  This may cause pooling to behave improperly for these objects:";

                foreach (NamedObjectSave skipped in skippedNoses)
                {
                    message += "\n " + skipped.InstanceName;
                }

                MessageBox.Show(message);
            }
            #endregion

            #region See if there are any variables to add

            bool areAnyVariablesBeingAdded = false;

            foreach (KeyValuePair <NamedObjectSave, List <string> > kvp in mResetVariablesToAdd)
            {
                NamedObjectSave nos       = kvp.Key;
                List <string>   variables = kvp.Value;

                // reverse loop here because we're removing from the list
                for (int i = variables.Count - 1; i > -1; i--)
                {
                    string variable = variables[i];

                    if (nos.VariablesToReset.Contains(variable))
                    {
                        variables.Remove(variable);
                    }
                    else
                    {
                        areAnyVariablesBeingAdded = true;
                    }
                }
            }
            #endregion

            #region If there are any variables, ask the user if resetting should be added

            if (areAnyVariablesBeingAdded)
            {
                DialogResult result = MessageBox.Show("Glue will add some best-guess variables to be reset " +
                                                      "to the objects in your Entity.  Existing variables will be preserved.  You may " +
                                                      "need to manually add additional variables depending on the logic contained in your Entity." +
                                                      "\n\nAdd variables?", "Add Variables for " + entitySave.Name + "?", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    foreach (KeyValuePair <NamedObjectSave, List <string> > kvp in mResetVariablesToAdd)
                    {
                        NamedObjectSave nos       = kvp.Key;
                        List <string>   variables = kvp.Value;

                        foreach (string s in variables)
                        {
                            Plugins.PluginManager.ReceiveOutput("Added reset variable " + s + " in object " + nos);
                        }


                        nos.VariablesToReset.AddRange(variables);
                    }
                }

                GluxCommands.Self.SaveGlux();

                ElementViewWindow.GenerateSelectedElementCode();
            }
            else
            {
                Plugins.PluginManager.ReceiveOutput("No reset variables added to " + entitySave);
            }

            #endregion

            #region As the user if Glue should reset variables for all NamedObjects which are Entities

            if (hasNamedObjectEntities)
            {
                DialogResult result = MessageBox.Show(
                    "Would you like to set reset variables for all contained objects which reference Entities inside " + entitySave.Name + "?  This " +
                    "action is recommended.", "Reset objects referencing Entities?", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    foreach (NamedObjectSave nos in entitySave.NamedObjects)
                    {
                        if (nos.SourceType == SourceType.Entity)
                        {
                            EntitySave containedEntitySave = nos.GetReferencedElement() as EntitySave;

                            if (containedEntitySave != null)
                            {
                                SetResetVariablesForEntitySave(containedEntitySave);
                            }
                        }
                    }
                }
            }
            #endregion

            #region Check for inheritance and ask if all derived Entities should have their variables reset too

            List <EntitySave> inheritingEntities = ObjectFinder.Self.GetAllEntitiesThatInheritFrom(entitySave);

            if (inheritingEntities.Count != 0)
            {
                string message =
                    "Would you like to set reset variables for Entities which inherit from " + entitySave.Name + "?  " +
                    "The following Entities will be modified:\n\n";

                foreach (EntitySave inheritingEntity in inheritingEntities)
                {
                    message += inheritingEntity.Name + "\n";
                }

                message += "\nThis " +
                           "action is recommended.";

                DialogResult result = MessageBox.Show(message,
                                                      "Reset Entites inheriting from this?", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    foreach (EntitySave inheritingEntity in inheritingEntities)
                    {
                        SetResetVariablesForEntitySave(inheritingEntity);
                    }
                }
            }

            #endregion

            foreach (NamedObjectSave nos in entitySave.NamedObjects)
            {
                StringFunctions.RemoveDuplicates(nos.VariablesToReset);
            }

            CodeWriter.GenerateCode(entitySave);

            foreach (var element in entitySave.GetAllBaseEntities())
            {
                CodeWriter.GenerateCode(element);
            }

            GluxCommands.Self.SaveGlux();
        }