示例#1
0
        public static void GenerateSelectedElementCode()
        {
            if (EditorLogic.CurrentElement != null)
            {
                CodeWriter.GenerateCode(EditorLogic.CurrentElement);
            }
            else if (EditorLogic.CurrentReferencedFile != null)
            {
                ReferencedFileSave rfs = EditorLogic.CurrentReferencedFile;
                ContentLoadWriter.UpdateLoadGlobalContentCode();

                if (rfs.IsCsvOrTreatedAsCsv)
                {
                    CsvCodeGenerator.GenerateAndSaveDataClass(EditorLogic.CurrentReferencedFile, rfs.CsvDelimiter);
                }
            }

            // Even though we may have generated a Screen/Entity, we still might want to see if we should update
            // CSVs:
            if (EditorLogic.CurrentReferencedFile != null)
            {
                ReferencedFileSave rfs = EditorLogic.CurrentReferencedFile;
                if (rfs.Name.ToLower().EndsWith(".csv"))
                {
                    CsvCodeGenerator.GenerateAndSaveDataClass(EditorLogic.CurrentReferencedFile, rfs.CsvDelimiter);
                }
            }
        }
示例#2
0
        public static void UpdateChangedElements()
        {
            foreach (var element in from entitySave in ProjectManager.GlueProjectSave.Entities
                     where entitySave.HasChanged
                     select entitySave)
            {
                var elementTreeNode = GlueState.Self.Find.ElementTreeNode(element);
                if (elementTreeNode != null)
                {
                    elementTreeNode.UpdateReferencedTreeNodes();
                    CodeWriter.GenerateCode(element);
                }
                element.HasChanged = false;
            }

            foreach (var element in from screenSave in ProjectManager.GlueProjectSave.Screens
                     where screenSave.HasChanged
                     select screenSave)
            {
                var elementTreeNode = GlueState.Self.Find.ElementTreeNode(element);
                if (elementTreeNode != null)
                {
                    elementTreeNode.UpdateReferencedTreeNodes();
                    CodeWriter.GenerateCode(element);
                }
                element.HasChanged = false;
            }

            if (ProjectManager.GlueProjectSave.GlobalContentHasChanged)
            {
                UpdateGlobalContentTreeNodes(true);
                ContentLoadWriter.UpdateLoadGlobalContentCode();
            }
        }
        private void PostMoveActivity()
        {
            PopulateFrom(this.mReferencedFiles);

            ContentLoadWriter.UpdateLoadGlobalContentCode();

            GluxCommands.Self.SaveGlux();
        }
示例#4
0
        internal void ReactToGlobalContentChangedValue(string changedMember, object oldValue, ref bool updateTreeView)
        {
            updateTreeView = false; // currently nothing here will update the UI, so we can save some time with this
            //if (changedMember == "LoadAsynchronously")
            //{
            //    ElementViewWindow.GenerateGlobalContentFileCode();
            //}

            ContentLoadWriter.UpdateLoadGlobalContentCode();
        }
示例#5
0
        private static void AskAndAddAllContainedRfsToGlobalContent(IElement element)
        {
            string message = "Add all contained files in " + element.ToString() + " to Global Content Files?  Files will still be referenced by " + element.ToString();

            DialogResult dialogResult = MessageBox.Show(message, "Add to Global Content?", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (!element.UseGlobalContent)
                {
                    string screenOrEntity = "Screen";

                    if (element is EntitySave)
                    {
                        screenOrEntity = "Entity";
                    }

                    DialogResult result = MessageBox.Show("The " + screenOrEntity + " " + element.ToString() +
                                                          "does not UseGlobalContent.  Would you like " +
                                                          " to set UseGlobalContent to true?", "Set UseGlobalContent to true?", MessageBoxButtons.YesNo);

                    if (result == DialogResult.Yes)
                    {
                        element.UseGlobalContent = true;
                    }
                }

                foreach (ReferencedFileSave rfs in element.ReferencedFiles)
                {
                    bool alreadyExists = false;
                    foreach (ReferencedFileSave existingRfs in ObjectFinder.Self.GlueProject.GlobalFiles)
                    {
                        if (existingRfs.Name.ToLower() == rfs.Name.ToLower())
                        {
                            alreadyExists = true;
                            break;
                        }
                    }

                    if (!alreadyExists)
                    {
                        bool useFullPathAsName = true;
                        ElementCommands.Self.AddReferencedFileToGlobalContent(rfs.Name, useFullPathAsName);
                    }
                }


                ContentLoadWriter.UpdateLoadGlobalContentCode();

                ProjectManager.SaveProjects();
                GluxCommands.Self.SaveGlux();
            }
        }
示例#6
0
        public static void GenerateSelectedElementAndDerivedCode()
        {
            if (EditorLogic.CurrentScreenTreeNode != null)
            {
                CodeGeneratorIElement.GenerateElementAndDerivedCode(EditorLogic.CurrentScreenSave);
            }
            else if (EditorLogic.CurrentEntityTreeNode != null)
            {
                CodeGeneratorIElement.GenerateElementAndDerivedCode(EditorLogic.CurrentEntitySave);
            }
            else if (EditorLogic.CurrentReferencedFile != null)
            {
                ContentLoadWriter.UpdateLoadGlobalContentCode();

                // Vic asks - do we have to do anything else here?  I don't think so...
            }
        }
        private void ListBox_DragDrop(object sender, DragEventArgs e)
        {
            Point point = ListBox.PointToClient(new Point(e.X, e.Y));
            int   index = this.ListBox.IndexFromPoint(point);

            if (index < 0)
            {
                index = this.ListBox.Items.Count - 1;
            }
            ReferencedFileSave data = e.Data.GetData(typeof(ReferencedFileSave)) as ReferencedFileSave;

            this.ListBox.Items.Remove(data);
            mReferencedFiles.Remove(data);
            this.ListBox.Items.Insert(index, data);
            mReferencedFiles.Insert(index, data);

            ContentLoadWriter.UpdateLoadGlobalContentCode();

            GluxCommands.Self.SaveGlux();
        }
示例#8
0
        public void RemoveReferencedFile(ReferencedFileSave referencedFileToRemove, List <string> additionalFilesToRemove, bool regenerateCode)
        {
            // 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.

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

            IElement container = referencedFileToRemove.GetContainer();

            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(false);
                    }
                    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.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();
                }
                                           );


                ContentLoadWriter.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();
        }
示例#9
0
        public void ReactToPropertyChanged(string variableNameAsDisplayed, object oldValue, string variableName, string parentGridItemName)
        {
            var mPropertyGrid = MainGlueWindow.Self.PropertyGrid;


            bool updateTreeView = true;

            #region EventResponseSave
            if (EditorLogic.CurrentEventResponseSave != null)
            {
                Container.Get <EventResponseSaveSetVariableLogic>().ReactToChange(
                    variableNameAsDisplayed, oldValue, GlueState.Self.CurrentEventResponseSave, GlueState.Self.CurrentElement);
            }

            #endregion

            #region State

            else if (EditorLogic.CurrentStateSave != null)
            {
                Container.Get <StateSaveSetVariableLogic>().ReactToStateSaveChangedValue(
                    EditorLogic.CurrentStateSave, EditorLogic.CurrentStateSaveCategory, variableNameAsDisplayed, oldValue, EditorLogic.CurrentElement, ref updateTreeView);
            }

            #endregion

            #region StateCategory

            else if (EditorLogic.CurrentStateSaveCategory != null)
            {
                Container.Get <StateSaveCategorySetVariableLogic>().ReactToStateSaveCategoryChangedValue(
                    EditorLogic.CurrentStateSaveCategory, variableNameAsDisplayed, oldValue, EditorLogic.CurrentElement, ref updateTreeView);
            }

            #endregion

            #region NamedObject

            else if (EditorLogic.CurrentNamedObject != null)
            {
                Container.Get <NamedObjectSetVariableLogic>().ReactToNamedObjectChangedValue(
                    variableNameAsDisplayed, parentGridItemName, oldValue);
            }

            #endregion

            #region ReferencedFile

            else if (EditorLogic.CurrentReferencedFile != null)
            {
                Container.Get <ReferencedFileSaveSetVariableLogic>().ReactToChangedReferencedFile(
                    variableNameAsDisplayed, oldValue, ref updateTreeView);
            }

            #endregion

            #region CustomVariable

            else if (EditorLogic.CurrentCustomVariable != null)
            {
                Container.Get <CustomVariableSaveSetVariableLogic>().ReactToCustomVariableChangedValue(
                    variableNameAsDisplayed, EditorLogic.CurrentCustomVariable, oldValue);
            }
            else if (mPropertyGrid.SelectedObject != null && mPropertyGrid.SelectedObject is PropertyGridDisplayer &&
                     EditorLogic.CurrentElement != null && EditorLogic.CurrentElement.GetCustomVariableRecursively(variableName) != null)
            {
                Container.Get <CustomVariableSaveSetVariableLogic>().ReactToCustomVariableChangedValue(
                    variableName, EditorLogic.CurrentElement.GetCustomVariableRecursively(variableName), oldValue);
            }
            #endregion

            // Check Entities and Screens after checking variables and objects
            #region Entity
            else if (EditorLogic.CurrentEntitySave != null)
            {
                Container.Get <EntitySaveSetVariableLogic>().ReactToEntityChangedValue(variableNameAsDisplayed, oldValue);
            }

            #endregion

            #region ScreenSave

            else if (EditorLogic.CurrentScreenSave != null)
            {
                Container.Get <ScreenSaveSetVariableLogic>().ReactToScreenChangedValue(variableNameAsDisplayed, oldValue);
            }

            #endregion

            #region Global content container node

            else if (EditorLogic.CurrentTreeNode.Root().IsGlobalContentContainerNode())
            {
                Container.Get <GlobalContentSetVariableLogic>().ReactToGlobalContentChangedValue(
                    variableNameAsDisplayed, oldValue, ref updateTreeView);
            }

            #endregion


            PluginManager.ReactToChangedProperty(variableNameAsDisplayed, oldValue);

            if (EditorLogic.CurrentElement != null)
            {
                CodeGeneratorIElement.GenerateElementDerivedAndReferenced(EditorLogic.CurrentElement);
            }
            else if (EditorLogic.CurrentReferencedFile != null)
            {
                ContentLoadWriter.UpdateLoadGlobalContentCode();
            }

            // UpdateCurrentObjectReferencedTreeNodes
            // kicks off a save by default.  Therefore
            // we don't need to call SaveProjects if UpdateCurrentObjectReferencedTreeNodes
            // is called.
            if (updateTreeView)
            {
                ElementViewWindow.UpdateCurrentObjectReferencedTreeNodes();
            }
            else
            {
                ProjectManager.SaveProjects();
            }

            mPropertyGrid.Refresh();

            GluxCommands.Self.SaveGlux();

            // Vic says:  This was intented to refresh the variables at one point
            // but this is a messy feature.  I think we should just refresh the entire
            // glux whenever a change is made now that it's async
            //RemotingManager.RefreshVariables(false);
        }
        private static 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

                    #region Moving on to a Layer

                    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();
                        }
                    }

                    #endregion

                    #region Moving on to a PositionedObjectList

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


                if (succeeded)
                {
                    if (EditorLogic.CurrentElement != null)
                    {
                        ElementViewWindow.GenerateSelectedElementCode();
                    }
                    else
                    {
                        ContentLoadWriter.UpdateLoadGlobalContentCode();
                    }
                    ProjectManager.SaveProjects();
                    GluxCommands.Self.SaveGlux();
                }
            }
        }
        private static void DragAddFileToGlobalContent(TreeNode treeNodeMoving, ReferencedFileSave referencedFileSave)
        {
            if (referencedFileSave.GetContainerType() == ContainerType.None)
            {
                // This means the user dragged a file from global content onto the global content tree node -
                // we shouldn't do anything here.  It's not a valid operation, but at the same time, it may have
                // happened accidentally and we don't want to burden the user with popups.
            }
            else
            {
                bool isAlreadyPartOfReferencedFiles = false;
                // If the file is already part of GlobalContent, then warn the user and do nothing
                foreach (ReferencedFileSave fileInGlobalContent in ObjectFinder.Self.GlueProject.GlobalFiles)
                {
                    if (fileInGlobalContent.Name == referencedFileSave.Name)
                    {
                        isAlreadyPartOfReferencedFiles = true;
                        break;
                    }
                }


                if (isAlreadyPartOfReferencedFiles)
                {
                    MessageBox.Show("The file\n\n" + referencedFileSave.Name + "\n\nis already a Global Content File");
                }
                else
                {
                    // If we got here, that means that the file that
                    // the user is dragging in to Global Content Files
                    // can be added to Global Content Files; however, the
                    // owner of the file may not be using global content.  We
                    // should ask the user if the containing IElement should use
                    // global content
                    IElement container = referencedFileSave.GetContainer();



                    if (!container.UseGlobalContent)
                    {
                        string screenOrEntity = "Screen";

                        if (container is EntitySave)
                        {
                            screenOrEntity = "Entity";
                        }

                        DialogResult result = MessageBox.Show("The " + screenOrEntity + " " + container.ToString() +
                                                              "does not UseGlobalContent.  Would you like " +
                                                              " to set UseGlobalContent to true?", "Set UseGlobalContent to true?", MessageBoxButtons.YesNo);

                        if (result == DialogResult.Yes)
                        {
                            container.UseGlobalContent = true;
                        }
                    }

                    bool useFullPathAsName = true;
                    ElementCommands.Self.AddReferencedFileToGlobalContent(referencedFileSave.Name, useFullPathAsName);

                    ContentLoadWriter.UpdateLoadGlobalContentCode();

                    ProjectManager.SaveProjects();
                    GluxCommands.Self.SaveGlux();
                }
            }
        }
        private static void MoveReferencedFileToDirectory(ReferencedFileSave referencedFileSave, string targetDirectory)
        {
            // Things to do:
            // 1 Move the TreeNode from one parent TreeNode to another UPDATE:  We will just refresh the UI for the Element or GlobalContent
            // 2 Move the file from one folder to another
            // 3 Remove the BuildItems from the project and add them back in the VisualStudio project
            // 4 Change the ReferencedFileSave's name
            // 5 Re-generate the containing Element (Screen or Entity)
            // 6 Save everything

            string oldNodeText = referencedFileSave.Name.Replace("/", "\\");



            string newNodeText = FlatRedBall.IO.FileManager.MakeRelative(targetDirectory, ProjectManager.ProjectBase.GetAbsoluteContentFolder()) + FileManager.RemovePath(referencedFileSave.Name);

            newNodeText = newNodeText.Replace("/", "\\");

            string oldFileName = ProjectManager.MakeAbsolute(referencedFileSave.Name, true);
            string targetFile  = targetDirectory + FileManager.RemovePath(oldFileName);

            bool canMove = true;

            // There's so much error checking and validation that we
            // could/should do here, but man, I just can't spend forever
            // on it because I need to get the game I'm working on moving forward
            // But I'm going to at least improve it a little bit by having the referenced
            // files get copied over.
            Dictionary <string, string> mOldNewDependencyFileDictionary = new Dictionary <string, string>();
            List <string> referencedFiles  = ContentParser.GetFilesReferencedByAsset(oldFileName, TopLevelOrRecursive.Recursive);
            string        oldDirectoryFull = FileManager.GetDirectory(oldFileName);

            foreach (string file in referencedFiles)
            {
                string relativeToRfs = FileManager.MakeRelative(file, FileManager.GetDirectory(oldFileName));

                string targetReferencedFileName = targetDirectory + relativeToRfs;

                mOldNewDependencyFileDictionary.Add(file, targetReferencedFileName);

                if (!FileManager.IsRelativeTo(targetReferencedFileName, targetDirectory))
                {
                    MessageBox.Show("The file\n\n" + file + "\n\nis not relative to the file being moved, so it cannot be moved.  You must manually move these files and manually update the file reference.");
                    canMove = false;
                    break;
                }
            }


            if (canMove && File.Exists(targetFile))
            {
                MessageBox.Show("There is already a file by this name located in the directory you're trying to move to.");
                canMove = false;
            }
            if (canMove)
            {
                foreach (KeyValuePair <string, string> kvp in mOldNewDependencyFileDictionary)
                {
                    if (File.Exists(kvp.Value))
                    {
                        MessageBox.Show("Can't move the file because a dependency will be moved to\n\n" + kvp.Value + "\n\nand a file already exists there.");
                        canMove = false;
                        break;
                    }
                }
            }

            if (canMove)
            {
                // 1 Move the TreeNode from one parent TreeNode to another
                //treeNodeMoving.Parent.Nodes.Remove(treeNodeMoving);
                //targetNode.Nodes.Add(treeNodeMoving);
                // This is updated at the bottom of this method



                // 2 Move the file from one folder to another
                File.Move(oldFileName, targetFile);
                foreach (KeyValuePair <string, string> kvp in mOldNewDependencyFileDictionary)
                {
                    File.Move(kvp.Key, kvp.Value);
                }


                // 3 Remove the BuildItems from the project and add them back in the VisualStudio project
                ProjectBase projectBase = ProjectManager.ProjectBase;
                if (ProjectManager.ContentProject != null)
                {
                    projectBase = ProjectManager.ContentProject;
                }

                ProjectManager.RemoveItemFromProject(projectBase, oldNodeText, false);
                projectBase.AddContentBuildItem(targetFile);
                foreach (KeyValuePair <string, string> kvp in mOldNewDependencyFileDictionary)
                {
                    string fileFileRelativeToProject = FileManager.MakeRelative(kvp.Key, projectBase.Directory);

                    ProjectManager.RemoveItemFromProject(projectBase, fileFileRelativeToProject, false);
                    projectBase.AddContentBuildItem(kvp.Value);
                }
                // TODO:  This should also check to see if something else is referencing this content.
                // I'm going to write it to not make this check now since I'm just getting the initial system set up



                // 4 Change the ReferencedFileSave's name
                referencedFileSave.SetNameNoCall(newNodeText.Replace("\\", "/"));
                // No need for this, it'll get updated automatically
                // treeNodeMoving.Text = newNodeText;



                // 5 Re-generate the containing Element (Screen or Entity)
                if (EditorLogic.CurrentElement != null)
                {
                    CodeWriter.GenerateCode(EditorLogic.CurrentElement);
                }
                else
                {
                    ContentLoadWriter.UpdateLoadGlobalContentCode();
                }


                // The new 1:  Update
                if (EditorLogic.CurrentElement != null)
                {
                    EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes();
                }
                else
                {
                    ElementViewWindow.UpdateGlobalContentTreeNodes(false);
                }


                // 6 Save everything
                GluxCommands.Self.SaveGlux();
                ProjectManager.SaveProjects();
            }
        }
示例#13
0
        private void PerformGluxLoad(string projectFileName, string glueProjectFile)
        {
            SetInitWindowText("Loading .glux");


            bool succeeded = true;

            succeeded = DeserializeGluxXmlInternal(projectFileName, glueProjectFile);

            if (succeeded)
            {
                // This seems to take some time (like 1 second). Can we possibly
                // make it faster by having it chek Game1.cs first? Why is this so slow?
                ProjectManager.FindGameClass();

                AvailableAssetTypes.Self.AdditionalExtensionsToTreatAsAssets.Clear();

                IdentifyAdditionalAssetTypes();

                SetInitWindowText("Finding and fixing .glux errors");
                ProjectManager.GlueProjectSave.FixErrors(true);
                ProjectManager.GlueProjectSave.RemoveInvalidStatesFromNamedObjects(true);

                FixProjectErrors();

                SetUnsetValues();



                ProjectManager.LoadOrCreateProjectSpecificSettings(FileManager.GetDirectory(projectFileName));

                SetInitWindowText("Notifying plugins of project...");


                // The project specific settings are needed before the plugins do their thing...
                PluginManager.ReactToLoadedGluxEarly(ProjectManager.GlueProjectSave);

                // and after that's done we can validate that the build tools are there
                BuildToolAssociationManager.Self.ProjectSpecificBuildTools.ValidateBuildTools(FileManager.GetDirectory(projectFileName));

                ProjectManager.GlueProjectSave.UpdateIfTranslationIsUsed();

                Section.GetAndStartContextAndTime("Add items");

                SetInitWindowText("Creating project view...");


                AddEmptyTreeItems();

                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("RefreshSourceFileCache");

                // This has to be done before the tree nodes are created.  The reason is because a user
                // may create a ReferencedFileSave using a source type, but not check in the built file.
                // Glue depends on the built file being there, so we gotta build to make sure that file gets
                // generated.
                // Update on May 4, 2011:  This should be done AFTER BuildAllOutOfDateFiles because Refreshing
                // source file cache requires looking at all referenced files, and this requires the files existing
                // so that dependencies can be tracked.
                // Update May 4, 2011 Part 2:  The SourceFileCache is used when building files.  So instead, the refreshing
                // of the source file cache will also build a file if it encounters a missing file.  This should greatly reduce
                // popup count.
                SetInitWindowText("Refreshing Source File Cache...");
                RefreshSourceFileCache();

                SetInitWindowText("Checking for additional missing files...");

                SetInitWindowText("Building out of date external files...");
                BuildAllOutOfDateFiles();
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("RefreshGlobalContentDirectory");

                SetInitWindowText("Refreshing global content dictionary...");
                ReferencedFileSaveCodeGenerator.RefreshGlobalContentDictionary();
                ContentLoadWriter.SuppressGlobalContentDictionaryRefresh = true;

                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("Screens");

                SetInitWindowText("Creating tree nodes...");

                CreateScreenTreeNodes();
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("Entities");

                CreateEntityTreeNodes();
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("SortEntities");



                ElementViewWindow.SortEntities();

                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("PrepareSyncedProjects");

                PrepareSyncedProjects(projectFileName);

                mLastLoadedFilename = projectFileName;
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("MakeGeneratedItemsNested");

                // This should happen after loading synced projects
                MakeGeneratedItemsNested();
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("GlobalContent");


                #region Update GlobalContent UI and code

                SetInitWindowText("Updating global content");

                ElementViewWindow.UpdateGlobalContentTreeNodes(false);

                // Screens and Entities have the membership of their files
                // automatically updated when the tree nodes are created. This
                // is bad. GlobalContent does this better by requiring the call
                // to be explicitly made:
                UpdateGlobalContentFileProjectMembership();

                ContentLoadWriter.UpdateLoadGlobalContentCode();

                #endregion
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("Startup");

                SetInitWindowText("Setting StartUp Screen");


                #region Set the Startup Screen

                if (!string.IsNullOrEmpty(ProjectManager.GlueProjectSave.StartUpScreen))
                {
                    TreeNode startUpTreeNode = GlueState.Self.Find.ScreenTreeNode(ProjectManager.GlueProjectSave.StartUpScreen);

                    ElementViewWindow.StartUpScreen = startUpTreeNode;

                    if (startUpTreeNode == null)
                    {
                        ProjectManager.GlueProjectSave.StartUpScreen = "";
                    }
                }

                #endregion

                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("Performance code");


                FactoryCodeGenerator.AddGeneratedPerformanceTypes();
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("CSV generation");

                CsvCodeGenerator.RegenerateAllCsvs();
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("PluginManager Init");

                PluginManager.Initialize(false);

                SetInitWindowText("Notifying Plugins of startup");


                PluginManager.ReactToLoadedGlux(ProjectManager.GlueProjectSave, glueProjectFile, SetInitWindowText);
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("GenerateAllCode");
                SetInitWindowText("Generating all code");
                GlueCommands.Self.GenerateCodeCommands.GenerateAllCode();
                Section.EndContextAndTime();
                ContentLoadWriter.SuppressGlobalContentDictionaryRefresh = false;
            }
        }
        static void GenerateAllCodeSync(object throwaway)
        {
            var glueProject = FlatRedBall.Glue.Plugins.ExportedImplementations.GlueState.Self.CurrentGlueProject;

            CameraSetupCodeGenerator.UpdateOrAddCameraSetup();

            CameraSetupCodeGenerator.CallSetupCamera(ProjectManager.GameClassFileName, true);

            //Parallel.For(0, layer.data[0].tiles.Count, (count) =>
            PluginManager.ReceiveOutput("Starting to generate all code...");
            PluginManager.ReceiveOutput("Starting to generate all Screens");

            // make sure the user hasn't exited the program

            foreach (var screen in glueProject.Screens)
            {
                #region Check for exiting the function becuase Glue is closing

                if (ProjectManager.WantsToClose)
                {
                    PluginManager.ReceiveOutput("Stopping generation because the project is closing");
                    return;
                }

                #endregion


                CodeWriter.GenerateCode(screen);
            }

            PluginManager.ReceiveOutput("Done generating Screens, starting Entities");

            // not sure which is faster:
            // Currently the referenced file dictionary makes this not work well:
            //Parallel.ForEach(GlueState.Self.CurrentGlueProject.Entities, (entity) =>
            //    {
            //        CodeWriter.GenerateCode(entity);
            //    });

            // Let's make this thread safe:
            IEnumerable <EntitySave> entityList = null;
            lock (glueProject.Entities)
            {
                entityList = glueProject.Entities.Where(item => true).ToList();
            }

            foreach (var entity in entityList)
            {
                #region Check for exiting the function becuase Glue is closing

                if (ProjectManager.WantsToClose)
                {
                    PluginManager.ReceiveOutput("Stopping generation because the project is closing");
                    return;
                }

                #endregion

                CodeWriter.GenerateCode(entity);
            }



            PluginManager.ReceiveOutput("Done generating Entities, starting GlobalContent");

            #region Check for exiting the function becuase Glue is closing

            if (ProjectManager.WantsToClose)
            {
                PluginManager.ReceiveOutput("Stopping generation because the project is closing");
                return;
            }

            #endregion

            ContentLoadWriter.UpdateLoadGlobalContentCode();



            #region Check for exiting the function becuase Glue is closing

            if (ProjectManager.WantsToClose)
            {
                PluginManager.ReceiveOutput("Stopping generation because the project is closing");
                return;
            }

            #endregion

            CsvCodeGenerator.GenerateAllCustomClasses(glueProject);

            PluginManager.ReceiveOutput("Done with all generation");
        }
 public void GenerateGlobalContentCode()
 {
     ContentLoadWriter.UpdateLoadGlobalContentCode();
 }