Ejemplo n.º 1
0
 private static string GetTextureFormatTag(ReferencedFileSave rfs)
 {
     if (rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().RuntimeTypeName == "Texture2D")
     {
         return("ProcessorParameters_TextureFormat");
     }
     else
     {
         return("ProcessorParameters_TextureProcessorOutputFormat");
     }
 }
Ejemplo n.º 2
0
        public static void ReactToUseContentPipelineChange(ReferencedFileSave rfs)
        {
            TaskManager.Self.AddSync(() =>
            {
                List <string> filesInModifiedRfs = new List <string>();
                bool shouldRemoveAndAdd          = false;


                ProjectBase projectBase = ProjectManager.ContentProject;
                if (projectBase == null)
                {
                    projectBase = ProjectManager.ProjectBase;
                }


                AddOrRemoveIndividualRfs(rfs, filesInModifiedRfs, ref shouldRemoveAndAdd, projectBase);

                if (shouldRemoveAndAdd)
                {
                    List <ReferencedFileSave> rfses = new List <ReferencedFileSave>();
                    rfses.Add(rfs);
                    bool usesContentPipeline = rfs.UseContentPipeline || rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().MustBeAddedToContentPipeline;
                    AddAndRemoveModifiedRfsFiles(rfses, filesInModifiedRfs, projectBase, usesContentPipeline);

                    GlueCommands.Self.ProjectCommands.SaveProjects();
                }
            }, "Reacting to changing UseContentPipeline");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the presence of the RFS in the main project.  If the RFS has project specific files, then those
        /// files are updated in the appropriate synced project.
        /// </summary>
        /// <remarks>
        /// This method does not update synced projects if the synced projects use the same file.  The reason is because
        /// this is taken care of when the projects are saved later on.
        /// </remarks>
        /// <param name="referencedFileSave">The RFS representing the file to update membership on.</param>
        /// <returns>Whether anything was added to any projects.</returns>
        public bool UpdateFileMembershipInProject(ReferencedFileSave referencedFileSave)
        {
            var assetTypeInfo = referencedFileSave.GetAssetTypeInfo();

            bool shouldSkip = assetTypeInfo != null && assetTypeInfo.ExcludeFromContentProject;

            bool wasAnythingAdded = false;

            if (!shouldSkip)
            {
                bool useContentPipeline = referencedFileSave.UseContentPipeline || (assetTypeInfo != null && assetTypeInfo.MustBeAddedToContentPipeline);

                wasAnythingAdded = UpdateFileMembershipInProject(GlueState.Self.CurrentMainProject, referencedFileSave.GetRelativePath(), useContentPipeline, false);

                foreach (ProjectSpecificFile projectSpecificFile in referencedFileSave.ProjectSpecificFiles)
                {
                    wasAnythingAdded |= UpdateFileMembershipInProject(ProjectManager.GetProjectByName(projectSpecificFile.ProjectName), projectSpecificFile.FilePath, useContentPipeline, true);
                }
                if (wasAnythingAdded)
                {
                    int m = 3;
                }
            }
            return(wasAnythingAdded);
        }
Ejemplo n.º 4
0
        private static GeneralResponse HandleDroppingFileOnObjectInSameElement(TreeNode targetNode, ReferencedFileSave referencedFileSave)
        {
            // Dropping the file on an object. If the object's type matches the named object's
            // entire file, ask the user if they want to make the object come from the file...
            var rfsAti         = referencedFileSave.GetAssetTypeInfo();
            var namedObject    = ((NamedObjectSave)targetNode.Tag);
            var namedObjectAti = namedObject.GetAssetTypeInfo();

            var response = GeneralResponse.SuccessfulResponse;

            var shouldAskAboutChangingObjectToBeFromFile =
                rfsAti == namedObjectAti && rfsAti != null;


            if (shouldAskAboutChangingObjectToBeFromFile)
            {
                var dialogResult = MessageBox.Show(
                    $"Would you like to set the object {namedObject.InstanceName} to be created from the file {referencedFileSave.Name}?",
                    $"Set {namedObject.InstanceName} to be from file?",
                    MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    namedObject.SourceType = SourceType.File;
                    namedObject.SourceFile = referencedFileSave.Name;
                    namedObject.SourceName = $"Entire File ({rfsAti.RuntimeTypeName})";

                    // This might be the case if the base is SetbyDerived.
                    if (namedObject.Instantiate == false)
                    {
                        // If an entire object is dropped on this, it's likely that the user wants to create (aka instantiate)
                        // the object using the entire file. The user may not realize that the object is set to not initialize,
                        // so let's ask them and offer to set Initialize to true
                        string message = $"The object {namedObject.InstanceName} has its 'Instantiate' variable set to 'false'. " +
                                         $"This needs to be set to 'true' for the object to be created from the file. Set it to true?";

                        var setToTrueResponse = MessageBox.Show(message,
                                                                "Set Instantiate to true?",
                                                                MessageBoxButtons.YesNo);

                        if (setToTrueResponse == DialogResult.Yes)
                        {
                            namedObject.Instantiate = true;
                        }
                    }

                    GlueCommands.Self.GluxCommands.SaveGluxTask();
                    GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCodeTask();
                }
            }
            else
            {
                response.Fail(
                    $"The object {namedObject.InstanceName} cannot be entirely set from {referencedFileSave.Name}." +
                    $"To set this object from an object contained within the file, select the object and change its source values.");
            }

            return(response);
        }
Ejemplo n.º 5
0
        private static bool GetIfFileCanBeReloaded(ReferencedFileSave item)
        {
            var extension     = FileManager.GetExtension(item.Name);
            var assetTypeInfo = item.GetAssetTypeInfo();

            return(item.IsCsvOrTreatedAsCsv ||
                   assetTypeInfo?.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Graphics.Animation.AnimationChainList");
        }
Ejemplo n.º 6
0
        public static void UpdateTextureFormatFor(ReferencedFileSave rfs)
        {
            string absoluteName = ProjectManager.MakeAbsolute(rfs.Name, true);

            bool usesContentPipeline = rfs.UseContentPipeline || rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().MustBeAddedToContentPipeline;

            string parameterTag = GetTextureFormatTag(rfs);
            string valueToSet   = rfs.TextureFormat.ToString();

            SetParameterOnBuildItems(absoluteName, parameterTag, valueToSet);
        }
        public static void RenameReferencedFile(string oldName, string newName, ReferencedFileSave rfs, IElement container)
        {
            string oldDirectory        = FileManager.GetDirectory(oldName);
            string newDirectory        = FileManager.GetDirectory(newName);
            string newFileNameAbsolute = ProjectManager.MakeAbsolute(newName);
            string instanceName        = FileManager.RemovePath(FileManager.RemoveExtension(newName));
            string whyIsntValid;

            if (oldDirectory != newDirectory)
            {
                MessageBox.Show("The old file was located in \n" + oldDirectory + "\n" +
                                "The new file is located in \n" + newDirectory + "\n" +
                                "Currently Glue does not support changing directories.", "Warning");

                rfs.SetNameNoCall(oldName);
            }
            else if (NameVerifier.IsReferencedFileNameValid(instanceName, rfs.GetAssetTypeInfo(), rfs, container, out whyIsntValid) == false)
            {
                MessageBox.Show(whyIsntValid);
                rfs.SetNameNoCall(oldName);
            }
            else
            {
                bool shouldMove     = true;
                bool shouldContinue = true;

                CheckForExistingFileOfSameName(oldName, rfs, newFileNameAbsolute, ref shouldMove, ref shouldContinue);

                if (shouldContinue)
                {
                    MoveFileIfNecessary(oldName, newName, shouldMove);

                    string rfsType = rfs.RuntimeType;
                    if (rfsType != null && rfsType.Contains("."))
                    {
                        // We dont want the fully qualified type.
                        rfsType = FileManager.GetExtension(rfsType);
                    }
                    UpdateObjectsUsingFile(container, oldName, rfs, rfsType);

                    RegenerateCodeAndUpdateUiAccordingToRfsRename(oldName, newName, rfs);

                    UpdateBuildItemsForRenamedRfs(oldName, newName);

                    AdjustDataFilesIfIsCsv(oldName, rfs);

                    GluxCommands.Self.SaveGlux();

                    ProjectManager.SaveProjects();
                }
            }
        }
        bool IsRfsOfUnqualifiedRuntimeType(ReferencedFileSave rfs, string unqualifiedRuntimeType)
        {
            AssetTypeInfo ati = rfs.GetAssetTypeInfo();

            if (ati != null)
            {
                return(ati.RuntimeTypeName == unqualifiedRuntimeType);
            }
            else
            {
                return(false);
            }
        }
        bool IsRfsOfType(ReferencedFileSave rfs, Type type)
        {
            AssetTypeInfo ati = rfs.GetAssetTypeInfo();

            if (ati != null)
            {
                return(ati.QualifiedRuntimeTypeName.QualifiedType == type.FullName);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 10
0
        private static bool AddOrRemoveIndividualRfs(ReferencedFileSave rfs, List <string> filesInModifiedRfs, ref bool shouldRemoveAndAdd, ProjectBase projectBase)
        {
            List <ProjectBase> projectsAlreadyModified = new List <ProjectBase>();

            bool usesContentPipeline = rfs.UseContentPipeline || rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().MustBeAddedToContentPipeline;

            if (rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().MustBeAddedToContentPipeline&& rfs.UseContentPipeline == false)
            {
                rfs.UseContentPipeline = true;
                MessageBox.Show("The file " + rfs.Name + " must use the content pipeline");
            }
            else
            {
                string absoluteName = ProjectManager.MakeAbsolute(rfs.Name, true);

                shouldRemoveAndAdd = usesContentPipeline && !projectBase.IsFilePartOfProject(absoluteName, BuildItemMembershipType.CompileOrContentPipeline) ||
                                     !usesContentPipeline && !projectBase.IsFilePartOfProject(absoluteName, BuildItemMembershipType.CopyIfNewer);

                if (shouldRemoveAndAdd)
                {
                    projectBase.RemoveItem(absoluteName);
                    projectBase.AddContentBuildItem(absoluteName, SyncedProjectRelativeType.Contained, usesContentPipeline);
                    projectsAlreadyModified.Add(projectBase);

                    #region Loop through all synced projects and add or remove the file referenced by the RFS

                    foreach (ProjectBase syncedProject in ProjectManager.SyncedProjects)
                    {
                        ProjectBase syncedContentProjectBase = syncedProject;
                        if (syncedProject.ContentProject != null)
                        {
                            syncedContentProjectBase = syncedProject.ContentProject;
                        }

                        if (!projectsAlreadyModified.Contains(syncedContentProjectBase))
                        {
                            projectsAlreadyModified.Add(syncedContentProjectBase);
                            syncedContentProjectBase.RemoveItem(absoluteName);

                            if (syncedContentProjectBase.SaveAsAbsoluteSyncedProject)
                            {
                                syncedContentProjectBase.AddContentBuildItem(absoluteName, SyncedProjectRelativeType.Contained, usesContentPipeline);
                            }
                            else
                            {
                                syncedContentProjectBase.AddContentBuildItem(absoluteName, SyncedProjectRelativeType.Linked, usesContentPipeline);
                            }
                        }
                    }
                    #endregion

                    List <string> filesReferencedByAsset =
                        FileReferenceManager.Self.GetFilesReferencedBy(absoluteName, EditorObjects.Parsing.TopLevelOrRecursive.Recursive);

                    for (int i = 0; i < filesReferencedByAsset.Count; i++)
                    {
                        if (!filesInModifiedRfs.Contains(filesReferencedByAsset[i]))
                        {
                            filesInModifiedRfs.Add(filesReferencedByAsset[i]);
                        }
                    }
                }
            }
            return(usesContentPipeline);
        }
Ejemplo n.º 11
0
        private static void MoveReferencedFile(TreeNode treeNodeMoving, TreeNode targetNode)
        {
            var response = GeneralResponse.SuccessfulResponse;

            while (targetNode != null && targetNode.IsReferencedFile())
            {
                targetNode = targetNode.Parent;
            }
            // If the user drops a file on a Screen or Entity, let's allow them to
            // complete the operation on the Files node
            if (targetNode is BaseElementTreeNode)
            {
                targetNode = ((BaseElementTreeNode)targetNode).FilesTreeNode;
            }

            ReferencedFileSave referencedFileSave = treeNodeMoving.Tag as ReferencedFileSave;

            if (!targetNode.IsFilesContainerNode() &&
                !targetNode.IsFolderInFilesContainerNode() &&
                !targetNode.IsFolderForGlobalContentFiles() &&
                !targetNode.IsNamedObjectNode() &&
                !targetNode.IsRootNamedObjectNode())
            {
                response.Fail(@"Can't drop this file here");
            }
            else if (!string.IsNullOrEmpty(referencedFileSave.SourceFile) ||
                     referencedFileSave.SourceFileCache.Count != 0)
            {
                response.Fail("Can't move the file\n\n" + referencedFileSave.Name + "\n\nbecause it has source-referencing files.  These sources will be broken " +
                              "if the file is moved.  You will need to manually move the file, modify the source references, remove this file, then add the newly-created file.");
            }

            if (response.Succeeded)
            {
                if (targetNode.IsGlobalContentContainerNode())
                {
                    if (targetNode.GetContainingElementTreeNode() == null)
                    {
                        string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true);
                        MoveReferencedFileToDirectory(referencedFileSave, targetDirectory);
                    }
                    else
                    {
                        DragAddFileToGlobalContent(treeNodeMoving, referencedFileSave);
                        // This means the user wants to add the file
                        // to global content.
                    }
                }
                else if (targetNode.IsFolderForGlobalContentFiles())
                {
                    string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true);
                    MoveReferencedFileToDirectory(referencedFileSave, targetDirectory);
                }
                else if (targetNode.IsRootNamedObjectNode())
                {
                    AddObjectViewModel viewModel = new AddObjectViewModel();
                    viewModel.SourceType = SourceType.File;
                    viewModel.SourceFile = (treeNodeMoving.Tag as ReferencedFileSave).Name;
                    GlueCommands.Self.DialogCommands.ShowAddNewObjectDialog(viewModel);
                }
                else if (targetNode.IsNamedObjectNode() &&
                         // dropping on an object in the same element
                         targetNode.GetContainingElementTreeNode() == treeNodeMoving.GetContainingElementTreeNode())
                {
                    response = HandleDroppingFileOnObjectInSameElement(targetNode, referencedFileSave);
                }

                //if (targetNode.IsFolderInFilesContainerNode() || targetNode.IsFilesContainerNode())
                else
                {
                    // See if we're moving the RFS from one Element to another
                    IElement container = ObjectFinder.Self.GetElementContaining(referencedFileSave);
                    TreeNode elementTreeNodeDroppingIn = targetNode.GetContainingElementTreeNode();
                    IElement elementDroppingIn         = null;
                    if (elementTreeNodeDroppingIn != null)
                    {
                        // User didn't drop on an entity, but instead on a node within the entity.
                        // Let's check if it's a subfolder. If so, we need to tell the user that we
                        // can't add the file in a subfolder.

                        if (targetNode.IsFolderInFilesContainerNode())
                        {
                            response.Message = "Shared files cannot be added to subfolders, so it will be added directly to \"Files\"";
                        }

                        elementDroppingIn = elementTreeNodeDroppingIn.Tag as IElement;
                    }

                    if (container != elementDroppingIn)
                    {
                        // Make sure the target element is not named the same as the file itself.
                        // For example, dropping a file called Level1.tmx in a screen called Level1.
                        // This will not compile so we shouldn't allow it.

                        var areNamedTheSame = elementDroppingIn.GetStrippedName() == referencedFileSave.GetInstanceName();

                        if (areNamedTheSame)
                        {
                            response.Fail($"The file {referencedFileSave.GetInstanceName()} has the same name as the target screen. it will not be added since this is not allowed.");
                        }

                        if (response.Succeeded)
                        {
                            ElementViewWindow.SelectedNode = targetNode;

                            string absoluteFileName = ProjectManager.MakeAbsolute(referencedFileSave.Name, true);
                            string creationReport;
                            string errorMessage;

                            var newlyCreatedFile = ElementCommands.Self.CreateReferencedFileSaveForExistingFile(elementDroppingIn, null, absoluteFileName,
                                                                                                                PromptHandleEnum.Prompt,
                                                                                                                referencedFileSave.GetAssetTypeInfo(),
                                                                                                                out creationReport,
                                                                                                                out errorMessage);

                            ElementViewWindow.UpdateChangedElements();

                            if (!String.IsNullOrEmpty(errorMessage))
                            {
                                MessageBox.Show(errorMessage);
                            }
                            else if (newlyCreatedFile != null)
                            {
                                GlueCommands.Self.TreeNodeCommands.SelectTreeNode(newlyCreatedFile);
                            }
                        }
                    }
                    else
                    {
                        // Not moving into or out of an element
                        string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true);
                        MoveReferencedFileToDirectory(referencedFileSave, targetDirectory);
                    }
                }
            }

            if (!string.IsNullOrEmpty(response.Message))
            {
                MessageBox.Show(response.Message);
            }
        }
        private void UpdateIncludedAndExcluded(ReferencedFileSave instance)
        {
            ResetToDefault();

            AssetTypeInfo ati = instance.GetAssetTypeInfo();


            ExcludeMember(nameof(ReferencedFileSave.InvalidFileNameCharacters));
            ExcludeMember(nameof(ReferencedFileSave.ToStringDelegate));
            ExcludeMember(nameof(ReferencedFileSave.Properties));

            ContainerType containerType = instance.GetContainerType();

            if (containerType == ContainerType.Entity)
            {
                // We do this because this is set automatically if the Entity is unique
                ExcludeMember(nameof(ReferencedFileSave.IsSharedStatic));

                // We do this because whether the objects from a file are manually updated or not
                // should be up to the entity, not the source file.
                ExcludeMember(nameof(ReferencedFileSave.IsManuallyUpdated));
            }

            if (containerType == ContainerType.Entity || ati == null || ati.QualifiedRuntimeTypeName.QualifiedType != "Microsoft.Xna.Framework.Media.Song")
            {
                ExcludeMember(nameof(ReferencedFileSave.DestroyOnUnload));
            }

            #region Extension-based additions/removals
            string extension = FileManager.GetExtension(instance.Name);

            if (extension != "csv" && !instance.TreatAsCsv)
            {
                ExcludeMember(nameof(ReferencedFileSave.CreatesDictionary));
                ExcludeMember(nameof(ReferencedFileSave.IsDatabaseForLocalizing));
                ExcludeMember(nameof(ReferencedFileSave.UniformRowType));
            }
            else
            {
                IncludeMember(nameof(ReferencedFileSave.UniformRowType), typeof(ReferencedFileSave), new AvailablePrimitiveTypeArraysStringConverter());
            }

            if ((extension != "txt" && extension != "csv") ||
                (extension == "txt" && instance.TreatAsCsv == false)
                )
            {
                ExcludeMember(nameof(ReferencedFileSave.CsvDelimiter));
            }

            if (extension != "txt")
            {
                ExcludeMember(nameof(ReferencedFileSave.TreatAsCsv));
            }

            if (extension == "png")
            {
                Attribute[] fileDetailsCategoryAttribute = new Attribute[] {
                    new CategoryAttribute("File Details")
                };
                IncludeMember("ImageWidth", typeof(int), null, GetImageWidth, null, fileDetailsCategoryAttribute);
                IncludeMember("ImageHeight", typeof(int), null, GetImageHeight, null, fileDetailsCategoryAttribute);
            }

            if (extension == "emix")
            {
                Attribute[] fileDetailsCategoryAttribute = new Attribute[] {
                    new CategoryAttribute("File Details")
                };

                IncludeMember("EquilibriumParticleCount", typeof(float), null, GetEquilibriumParticleCount, null, fileDetailsCategoryAttribute);
                IncludeMember("BurstParticleCount", typeof(float), null, GetBurstParticleCount, null, fileDetailsCategoryAttribute);
            }

            #endregion

            AddProjectSpecificFileMember();


            if (!instance.LoadedAtRuntime)
            {
                ExcludeMember(nameof(ReferencedFileSave.IsSharedStatic));
                ExcludeMember(nameof(ReferencedFileSave.IsManuallyUpdated));
                ExcludeMember(nameof(ReferencedFileSave.LoadedOnlyWhenReferenced));
                ExcludeMember(nameof(ReferencedFileSave.HasPublicProperty));
                ExcludeMember("InstanceName");
                ExcludeMember(nameof(ReferencedFileSave.IncludeDirectoryRelativeToContainer));
            }

            if (ati == null || string.IsNullOrEmpty(ati.MakeManuallyUpdatedMethod))
            {
                ExcludeMember(nameof(ReferencedFileSave.IsManuallyUpdated));
            }

            if (!instance.GetCanUseContentPipeline())
            {
                ExcludeMember(nameof(ReferencedFileSave.UseContentPipeline));
            }
            if (!instance.UseContentPipeline || ati.QualifiedRuntimeTypeName.QualifiedType != "Microsoft.Xna.Framework.Graphics.Texture2D")
            {
                ExcludeMember("TextureFormat");
            }

            IncludeMember("OpensWith", typeof(ReferencedFileSave), new AvailableApplicationsStringConverters());

            bool shouldShowRuntimeType = instance.LoadedAtRuntime;
            if (shouldShowRuntimeType)
            {
                IncludeMember("RuntimeType", typeof(ReferencedFileSave), new AvailableRuntimeTypeConverter()
                {
                    ReferencedFileSave = instance
                });
            }
            else
            {
                ExcludeMember(nameof(ReferencedFileSave.RuntimeType));
            }

            if (string.IsNullOrEmpty(instance.SourceFile))
            {
                ExcludeMember(nameof(ReferencedFileSave.SourceFile));
                ExcludeMember(nameof(ReferencedFileSave.BuildTool));
                ExcludeMember(nameof(ReferencedFileSave.AdditionalArguments));
                ExcludeMember(nameof(ReferencedFileSave.ConditionalCompilationSymbols));
            }
            else
            {
            }
        }
Ejemplo n.º 13
0
        private string GetRawDialogTreeLoadCode(IElement element, NamedObjectSave namedObject, ReferencedFileSave referencedFile, string contentManager)
        {
            var fileName = ReferencedFileSaveCodeGenerator.GetFileToLoadForRfs(referencedFile, referencedFile.GetAssetTypeInfo());

            return($"{referencedFile.GetInstanceName()} = DialogTreePlugin.SaveClasses.DialogTreeRaw.RootObject.FromJson(\"{fileName}\");");
        }