コード例 #1
0
        private bool FixContentPipelineProjectValues(List <ReferencedFileSave> rfsList, ProjectBase contentProjectBase)
        {
            bool hasMadeChanges = false;

            if (contentProjectBase != null)
            {
                foreach (ReferencedFileSave rfs in rfsList)
                {
                    var item = contentProjectBase.GetItem(rfs.Name);


                    if (item != null)
                    {
                        if (rfs.UseContentPipeline)
                        {
                            if (rfs.TextureFormat == Microsoft.Xna.Framework.Content.Pipeline.Processors.TextureProcessorOutputFormat.DxtCompressed &&
                                !item.HasMetadata("ProcessorParameters_TextureProcessorOutputFormat"))
                            {
                                hasMadeChanges = true;
                                // Gotta make this thing use the DxtCompression
                                ContentPipelineHelper.UpdateTextureFormatFor(rfs);
                            }
                        }
                    }
                }
            }

            return(hasMadeChanges);
        }
コード例 #2
0
        private static void AddFileToContentProject(ProjectBase project, bool useContentPipeline, bool shouldLink, string fileToAddAbsolute)
        {
            string relativeFileName = FileManager.MakeRelative(
                fileToAddAbsolute,
                FileManager.GetDirectory(project.ContentProject.FullFileName) + project.ContentProject.ContentDirectory);

            if (relativeFileName.StartsWith(ProjectManager.ContentDirectoryRelative))
            {
                relativeFileName = relativeFileName.Substring(ProjectManager.ContentDirectoryRelative.Length);
            }

            if (!useContentPipeline && project.ContentProject.IsFilePartOfProject(fileToAddAbsolute, BuildItemMembershipType.CompileOrContentPipeline))
            {
                ReferencedFileSave rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(fileToAddAbsolute);

                if (rfs != null)
                {
                    rfs.UseContentPipeline = false;
                    ContentPipelineHelper.ReactToUseContentPipelineChange(rfs);
                }
            }
            else if (useContentPipeline && project.ContentProject.IsFilePartOfProject(fileToAddAbsolute, BuildItemMembershipType.CopyIfNewer))
            {
                ReferencedFileSave rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(fileToAddAbsolute);

                if (rfs != null)
                {
                    rfs.UseContentPipeline = true;
                    ContentPipelineHelper.ReactToUseContentPipelineChange(rfs);
                }
            }
            else
            {
                project.ContentProject.AddContentBuildItem(
                    fileToAddAbsolute,
                    shouldLink ? SyncedProjectRelativeType.Linked : SyncedProjectRelativeType.Contained,
                    useContentPipeline);
            }

            PluginManager.ReceiveOutput("Added " + relativeFileName + $" to {project.Name} as content");
        }
コード例 #3
0
        internal void ReactToChangedReferencedFile(string changedMember, object oldValue, ref bool updateTreeView)
        {
            ReferencedFileSave rfs = GlueState.Self.CurrentReferencedFileSave;



            #region Opens With

            if (changedMember == "OpensWith")
            {
                if (rfs.OpensWith == "New Application...")
                {
                    string newApplication = EditorData.FileAssociationSettings.SetApplicationForExtension(null, "New Application...");

                    if (!string.IsNullOrEmpty(newApplication))
                    {
                        rfs.OpensWith = newApplication;
                    }
                    else
                    {
                        rfs.OpensWith = "<DEFAULT>";
                    }
                }
            }

            #endregion

            #region Name

            else if (changedMember == "Name")
            {
                if ((string)oldValue != rfs.Name && ProjectManager.GlueProjectSave != null)
                {
                    if ((string)oldValue != null)
                    {
                        RenameReferencedFile((string)oldValue, rfs.Name, rfs, GlueState.Self.CurrentElement);
                    }
                }
            }

            #endregion

            #region LoadedAtRuntime

            if (changedMember == "LoadedAtRuntime")
            {
                updateTreeView = false;
            }

            #endregion

            #region Loaded only when referenced

            else if (changedMember == "LoadedOnlyWhenReferenced")
            {
                updateTreeView = false;
                if (rfs.LoadedOnlyWhenReferenced)
                {
                    // We need to make this public, or else it won't work on WP7 and Silverlight.
                    // Update - The preferred method to get access to this stuff by string is either
                    // GetMember or GetStaticMember, so there's no reason to force this stuff as public
                    // when LoadedWhenReferenced is set to true.
                    //rfs.HasPublicProperty = true;
                }
            }

            #endregion

            #region Has public property

            else if (changedMember == "HasPublicProperty")
            {
                updateTreeView = false;
                // GetMember and GetStaticMember
                // make it so we no longer require
                // the member to be public.
                //if (rfs.LoadedOnlyWhenReferenced && !rfs.HasPublicProperty)
                //{
                //    System.Windows.Forms.MessageBox.Show("This file must have a public property if it " +
                //        "is \"Loaded Only When Referenced\" so that it can be accessed through reflection " +
                //        "on non-PC platforms.");

                //    rfs.HasPublicProperty = true;
                //}

                //if (rfs.ContainerType == ContainerType.None && rfs.HasPublicProperty == false)
                //{
                //    System.Windows.Forms.MessageBox.Show("Global content must be public so custom code can access it.");
                //    rfs.HasPublicProperty = true;
                //}
            }

            #endregion

            #region IsSharedStatic

            else if (changedMember == "IsSharedStatic")
            {
                updateTreeView = false;
                // If this is made IsSharedStatic, that means that the file will not be added to managers
                // We should see if any named objects reference this and notify the user
                List <NamedObjectSave> namedObjects = EditorLogic.CurrentElement.NamedObjects;

                foreach (NamedObjectSave namedObject in namedObjects)
                {
                    if (namedObject.SourceType == SourceType.File && namedObject.SourceFile == rfs.Name && namedObject.AddToManagers == false)
                    {
                        DialogResult result = MessageBox.Show("The object " + namedObject.InstanceName + " references this file.  " +
                                                              "Shared files are not added to the engine, but since the object has its AddToManagers also set to false " +
                                                              "the content in this file will not be added to managers.  Would you like to set the object's AddToManagers to " +
                                                              "true?", "Add to managers?", MessageBoxButtons.YesNo);

                        if (result == DialogResult.Yes)
                        {
                            namedObject.AddToManagers = true;
                        }
                    }
                }
            }

            #endregion

            #region IsDatabaseForLocalizing

            else if (changedMember == "IsDatabaseForLocalizing")
            {
                updateTreeView = false;
                bool oldValueAsBool = (bool)oldValue;
                bool newValue       = rfs.IsDatabaseForLocalizing;

                if (newValue)
                {
                    TaskManager.Self.AddSync(() => RemoveCodeForCsv(rfs), "Removing old CSV");
                }
                else
                {
                    CsvCodeGenerator.GenerateAndSaveDataClass(rfs, rfs.CsvDelimiter);
                }

                // Let's revert the change just to see if
                // things have changed project-wide, and if
                // have to tell the user to re-generate all code.
                rfs.IsDatabaseForLocalizing = oldValueAsBool;
                ObjectFinder.Self.GlueProject.UpdateIfTranslationIsUsed();
                bool oldProjectLocalization = ObjectFinder.Self.GlueProject.UsesTranslation;

                rfs.IsDatabaseForLocalizing = newValue;
                ObjectFinder.Self.GlueProject.UpdateIfTranslationIsUsed();
                bool newProjectLocalization = ObjectFinder.Self.GlueProject.UsesTranslation;



                if (oldProjectLocalization != newProjectLocalization)
                {
                    MessageBox.Show("Because of the change to the \"Is Database For Localizing\" the generated code for the entire project is likely out of date." +
                                    "We recommend closing and re-opening the project in Glue to cause a full regeneration.", "Generated code is out of date");
                }
            }

            #endregion

            #region UseContentPipeline

            else if (changedMember == "UseContentPipeline")
            {
                ContentPipelineHelper.ReactToUseContentPipelineChange(rfs);

                // Make sure that
                // all other RFS's
                // that use this file
                // get changed too.
                List <ReferencedFileSave> matchingRfses = ObjectFinder.Self.GetMatchingReferencedFiles(rfs);

                foreach (ReferencedFileSave rfsToUpdate in matchingRfses)
                {
                    rfsToUpdate.UseContentPipeline = rfs.UseContentPipeline;
                    // No need to
                    // call this method
                    // because there's only
                    // one file in the project
                    // even though there's multiple
                    // ReferencedFileSaves, and this
                    // method just modifies the content
                    // project.
                    //ContentPipelineHelper.ReactToUseContentPipelineChange(rfsToUpdate);

                    IElement container = rfsToUpdate.GetContainer();

                    if (container != null)
                    {
                        CodeWriter.GenerateCode(container);
                    }
                    else
                    {
                        GlueCommands.Self.GenerateCodeCommands.GenerateGlobalContentCode();
                    }
                }


                updateTreeView = false;
            }

            #endregion

            #region TextureFormat

            else if (changedMember == "TextureFormat")
            {
                ContentPipelineHelper.UpdateTextureFormatFor(rfs);

                // See the UseContentPipeline section for comments on what this
                // code does.
                List <ReferencedFileSave> matchingRfses = ObjectFinder.Self.GetMatchingReferencedFiles(rfs);
                foreach (ReferencedFileSave rfsToUpdate in matchingRfses)
                {
                    rfsToUpdate.TextureFormat = rfs.TextureFormat;
                    IElement container = rfsToUpdate.GetContainer();

                    if (container != null)
                    {
                        CodeWriter.GenerateCode(container);
                    }
                    else
                    {
                        GlueCommands.Self.GenerateCodeCommands.GenerateGlobalContentCode();
                    }
                }


                updateTreeView = false;
            }

            #endregion

            #region IncludeDirectoryRelativeToContainer

            else if (changedMember == "IncludeDirectoryRelativeToContainer")
            {
                if (rfs.GetContainerType() == ContainerType.None)
                {
                    // This RFS
                    // is in GlobalContent
                    // so we need to find all
                    // RFS's that use this RFS
                    // and regenerate them
                    List <IElement> elements = ObjectFinder.Self.GetAllElementsReferencingFile(rfs.Name);

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

            #endregion

            #region AdditionalArguments

            else if (changedMember == "AdditionalArguments")
            {
                rfs.PerformExternalBuild(runAsync: true);
            }

            #endregion

            #region CreatesDictionary

            else if (changedMember == "CreatesDictionary")
            {
                // This could change things like the constants added to the code file, so let's generate the code now.
                GlueCommands.Self.GenerateCodeCommands.GenerateCurrentCsvCode();
            }

            #endregion
        }
コード例 #4
0
        void ContentPipelineChange(bool useContentPipeline, CurrentElementOrAll currentOrAll)
        {
            TextureProcessorOutputFormat?textureFormat = null;

            if (useContentPipeline)
            {
                MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                mbmb.MessageText = "How should the texture formats be set?";
                mbmb.AddButton("Set to DXT Compression", DialogResult.Yes);
                mbmb.AddButton("Set to Color", DialogResult.OK);
                mbmb.AddButton("Do nothing", DialogResult.No);

                DialogResult result = mbmb.ShowDialog(Form1.Self);

                switch (result)
                {
                case DialogResult.Yes:
                    textureFormat = TextureProcessorOutputFormat.DxtCompressed;
                    break;

                case DialogResult.OK:
                    textureFormat = TextureProcessorOutputFormat.Color;
                    break;

                case DialogResult.No:
                    // do nothing, leave it to null
                    break;
                }
            }

            InitializationWindow initWindow = new InitializationWindow();

            initWindow.Show(Form1.Self);
            initWindow.Message = "Performing Operation...";


            List <ReferencedFileSave> allRfses = new List <ReferencedFileSave>();

            if (currentOrAll == CurrentElementOrAll.CurrentElement)
            {
                IElement element = EditorLogic.CurrentElement;
                allRfses.AddRange(element.ReferencedFiles);
            }
            else
            {
                allRfses.AddRange(ObjectFinder.Self.GetAllReferencedFiles());
            }

            int totalRfs = allRfses.Count;

            //int count = 0;

            initWindow.SubMessage = "Removing/adding files as appropriate";
            Application.DoEvents();

            foreach (ReferencedFileSave rfs in allRfses)
            {
                if (rfs.GetAssetTypeInfo() != null && rfs.GetAssetTypeInfo().MustBeAddedToContentPipeline)
                {
                    rfs.UseContentPipeline = true;
                }
                else
                {
                    rfs.UseContentPipeline = useContentPipeline;
                }
            }

            ContentPipelineHelper.ReactToUseContentPipelineChange(allRfses);

            if (useContentPipeline)
            {
                initWindow.SubMessage = "Updating texture formats";
                Application.DoEvents();

                foreach (ReferencedFileSave rfs in allRfses)
                {
                    if (textureFormat.HasValue)
                    {
                        rfs.TextureFormat = textureFormat.Value;
                    }

                    ContentPipelineHelper.UpdateTextureFormatFor(rfs);
                }
            }

            initWindow.SubMessage = "Refreshing UI";
            Application.DoEvents();
            if (EditorLogic.CurrentElement != null)
            {
                GlueCommands.RefreshCommands.RefreshUiForSelectedElement();
            }

            initWindow.SubMessage = "Generating Code";
            Application.DoEvents();

            if (currentOrAll == CurrentElementOrAll.CurrentElement)
            {
                GlueCommands.GenerateCodeCommands.GenerateCurrentElementCode();
            }
            else
            {
                GlueCommands.GenerateCodeCommands.GenerateAllCode();
            }

            GlueCommands.GluxCommands.SaveGlux();

            GlueCommands.ProjectCommands.SaveProjects();


            initWindow.Close();
        }