Exemplo n.º 1
0
        public static void Initialize()
        {
            try
            {
                Assembly smAssembly = Assembly.Load("SkinManagerMod");
                Type     smType     = smAssembly?.GetType("SkinManagerMod.Main");

                if (smType != null)
                {
                    SM_ReplaceTexture = AccessTools.Method(smType, "ReplaceTexture")?.CreateDelegate(typeof(ReplaceTextureDelegate)) as ReplaceTextureDelegate;
                    CarStates         = AccessTools.Field(smType, "trainCarState")?.GetValue(null) as Dictionary <string, string>;
                    SkinGroups        = AccessTools.Field(smType, "skinGroups")?.GetValue(null) as IDictionary;

                    if ((CarStates == null) || (SM_ReplaceTexture == null))
                    {
                        PassengerJobs.ModEntry.Logger.Warning("SkinManager found, but failed to connect to members");
                    }
                    else
                    {
                        Enabled = true;
                        PassengerJobs.ModEntry.Logger.Log("SkinManager integration enabled");

                        SearchForNamedTrains();
                        GetPlainCoachSkinList();
                    }
                }
                else
                {
                    PassengerJobs.ModEntry.Logger.Log("SkinManager not found, skipping integration");
                }
            }
            catch (Exception ex) when(ex is FileNotFoundException || ex is BadImageFormatException)
            {
                PassengerJobs.ModEntry.Logger.Log("SkinManager not found, skipping integration");
            }
            catch (Exception ex)
            {
                PassengerJobs.ModEntry.Logger.Log($"Error while trying to connect with SkinManager:\n{ex.Message}");
            }
        }
Exemplo n.º 2
0
        public static void MakeSceneRelativeAndSave(Scene scene, string fileName, string contentManager, List<string> filesToMakeDotDotRelative,
            ReplaceTextureDelegate replaceTextureDelegate, SaveSceneDelegate saveDelegate)
        {
            if(replaceTextureDelegate == null)
            {
                replaceTextureDelegate = DefaultReplaceTexture;
            }

            mTexturesNotRelative.Clear();
            mAnimationChainListsNotRelative.Clear();
            mFntFilesNotRelative.Clear();
			mModelsNotRelative.Clear();
            mExtraFilesToCopy.Clear();

            mSaveDelegate = saveDelegate;
            mLastFileName = fileName;
            mContentManager = contentManager;

            string pathOfFile = FileManager.GetDirectory(fileName);

            #region Find any not-relative Sprites

            foreach (Sprite s in scene.Sprites)
            {
                if (s.Texture == null)
                    continue;

                string textureFileName = s.Texture.SourceFile();

                if (!FileManager.IsRelativeTo(textureFileName, pathOfFile) &&
                    !mTexturesNotRelative.Contains(s.Texture))
                {
                    mTexturesNotRelative.Add(s.Texture);
                }

                if (s.AnimationChains != null && string.IsNullOrEmpty(s.AnimationChains.Name) == false &&
                    !FileManager.IsRelativeTo(s.AnimationChains.Name, pathOfFile) &&
                    !mAnimationChainListsNotRelative.Contains(s.AnimationChains))
                {
                    mAnimationChainListsNotRelative.Add(s.AnimationChains);
                }
            }

            #endregion

            #region Find any not-relative SpriteGrids

            foreach (SpriteGrid sg in scene.SpriteGrids)
            {
                List<Texture2D> usedTextures = sg.GetUsedTextures();
                foreach (Texture2D texture in usedTextures)
                {
                    if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(texture))
                    {
                        mTexturesNotRelative.Add(texture);
                    }
                }
            }

            #endregion

            #region Find any not-relative SpriteFrames

            foreach (SpriteFrame sf in scene.SpriteFrames)
            {
                if (!FileManager.IsRelativeTo(sf.Texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(sf.Texture))
                {
                    mTexturesNotRelative.Add(sf.Texture);
                }
            }

            #endregion

            #region Find any not-relative Fonts (Text objects)

            foreach (Text t in scene.Texts)
            {
                BitmapFont bitmapFont = t.Font;

                if (bitmapFont == TextManager.DefaultFont)
                    continue;

                foreach (Texture2D texture in bitmapFont.Textures)
                {
                    if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) &&
                        !mTexturesNotRelative.Contains(texture))
                    {
                        mTexturesNotRelative.Add(texture);
                    }
                }
                if (!FileManager.IsRelativeTo(bitmapFont.FontFile, pathOfFile) &&
                    !mFntFilesNotRelative.Contains(bitmapFont.FontFile))
                {
                    mFntFilesNotRelative.Add(bitmapFont.FontFile);
                }

            }

            #endregion

			#region Find any non-relative PositionedModels

			foreach (PositionedModel positionedModel in scene.PositionedModels)
			{
				if (!FileManager.IsRelativeTo(positionedModel.ModelFileName, pathOfFile) &&
					!mModelsNotRelative.Contains(positionedModel.ModelFileName))
				{
					mModelsNotRelative.Add(positionedModel.ModelFileName);
				}

#if !FRB_MDX
                // Extra files which won't be re-referenced
                foreach (SourceReferencingFile extraFile in positionedModel.ExtraFiles)
                {
                    if (!FileManager.IsRelativeTo(extraFile.DestinationFile, pathOfFile) &&
                        !mExtraFilesToCopy.Contains(extraFile.DestinationFile))
                    {
                        mExtraFilesToCopy.Add(extraFile.DestinationFile);

                    }
                }
#endif

			}

			#endregion

            #region Loop through all AnimationChains and add any missing files

            foreach (AnimationChainList acl in mAnimationChainListsNotRelative)
            {
                foreach (AnimationChain chain in acl)
                {
                    foreach (AnimationFrame frame in chain)
                    {
                        Texture2D texture = frame.Texture;

                        if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) &&
                            !mTexturesNotRelative.Contains(texture))
                        {
                            mTexturesNotRelative.Add(texture);
                        }
                    }
                }
            }

            #endregion

            mLastFileName = fileName;
            mContentManager = contentManager;
            mSaveDelegate = saveDelegate;


            #region If there are files which are not relative, show the multi button message box

            SceneSaving = scene;
            mReplaceTextureDelegate = replaceTextureDelegate;

            string message = "The file\n\n" + fileName +
                "\n\nreferences the following which are not relative:";


            CopyTexturesMultiButtonMessageBox mbmb = new CopyTexturesMultiButtonMessageBox();
            mbmb.Text = message;
            mbmb.SaveClick += CopyAssetsToFileFolder;

            //mbmb.AddButton("Make all references relative using \"..\\\"", MakeSceneRelativeWithDotDots);
            //mbmb.AddButton("Copy textures to relative and reference copies.", new GuiMessage(CopyAssetsToFileFolder));

            foreach (Texture2D texture in mTexturesNotRelative)
            {
                mbmb.AddItem(texture.SourceFile());
            }

            foreach (AnimationChainList animationChainList in mAnimationChainListsNotRelative)
            {
                mbmb.AddItem(animationChainList.Name);
            }
            foreach (string s in mFntFilesNotRelative)
            {
                mbmb.AddItem(s);
            }
			foreach (string s in mModelsNotRelative)
			{
				mbmb.AddItem(s);
			}

            foreach (string s in mExtraFilesToCopy)
            {
                mbmb.AddItem(s);
            }


            //mbmb.FilesToMakeDotDotRelative = filesToMakeDotDotRelative;
            if (filesToMakeDotDotRelative.Count != mbmb.ItemsCount) 
            {
                mbmb.FilesMarkedDotDotRelative = filesToMakeDotDotRelative;
                GuiManager.AddDominantWindow(mbmb);
            }
            else
            {
                saveDelegate(fileName, true);
            }

            #endregion

        }
Exemplo n.º 3
0
        public static void MakeSceneRelativeAndSave(Scene scene, string fileName, string contentManager, List <string> filesToMakeDotDotRelative,
                                                    ReplaceTextureDelegate replaceTextureDelegate, SaveSceneDelegate saveDelegate)
        {
            if (replaceTextureDelegate == null)
            {
                replaceTextureDelegate = DefaultReplaceTexture;
            }

            mTexturesNotRelative.Clear();
            mAnimationChainListsNotRelative.Clear();
            mFntFilesNotRelative.Clear();
            mModelsNotRelative.Clear();
            mExtraFilesToCopy.Clear();

            mSaveDelegate   = saveDelegate;
            mLastFileName   = fileName;
            mContentManager = contentManager;

            string pathOfFile = FileManager.GetDirectory(fileName);

            #region Find any not-relative Sprites

            foreach (Sprite s in scene.Sprites)
            {
                if (s.Texture == null)
                {
                    continue;
                }

                string textureFileName = s.Texture.SourceFile();

                if (!FileManager.IsRelativeTo(textureFileName, pathOfFile) &&
                    !mTexturesNotRelative.Contains(s.Texture))
                {
                    mTexturesNotRelative.Add(s.Texture);
                }

                if (s.AnimationChains != null && string.IsNullOrEmpty(s.AnimationChains.Name) == false &&
                    !FileManager.IsRelativeTo(s.AnimationChains.Name, pathOfFile) &&
                    !mAnimationChainListsNotRelative.Contains(s.AnimationChains))
                {
                    mAnimationChainListsNotRelative.Add(s.AnimationChains);
                }
            }

            #endregion

            #region Find any not-relative SpriteGrids

            foreach (SpriteGrid sg in scene.SpriteGrids)
            {
                List <Texture2D> usedTextures = sg.GetUsedTextures();
                foreach (Texture2D texture in usedTextures)
                {
                    if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(texture))
                    {
                        mTexturesNotRelative.Add(texture);
                    }
                }
            }

            #endregion

            #region Find any not-relative SpriteFrames

            foreach (SpriteFrame sf in scene.SpriteFrames)
            {
                if (!FileManager.IsRelativeTo(sf.Texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(sf.Texture))
                {
                    mTexturesNotRelative.Add(sf.Texture);
                }
            }

            #endregion

            #region Find any not-relative Fonts (Text objects)

            foreach (Text t in scene.Texts)
            {
                BitmapFont bitmapFont = t.Font;

                if (bitmapFont == TextManager.DefaultFont)
                {
                    continue;
                }

                foreach (Texture2D texture in bitmapFont.Textures)
                {
                    if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) &&
                        !mTexturesNotRelative.Contains(texture))
                    {
                        mTexturesNotRelative.Add(texture);
                    }
                }
                if (!FileManager.IsRelativeTo(bitmapFont.FontFile, pathOfFile) &&
                    !mFntFilesNotRelative.Contains(bitmapFont.FontFile))
                {
                    mFntFilesNotRelative.Add(bitmapFont.FontFile);
                }
            }

            #endregion

            #region Find any non-relative PositionedModels

            foreach (PositionedModel positionedModel in scene.PositionedModels)
            {
                if (!FileManager.IsRelativeTo(positionedModel.ModelFileName, pathOfFile) &&
                    !mModelsNotRelative.Contains(positionedModel.ModelFileName))
                {
                    mModelsNotRelative.Add(positionedModel.ModelFileName);
                }

#if !FRB_MDX
                // Extra files which won't be re-referenced
                foreach (SourceReferencingFile extraFile in positionedModel.ExtraFiles)
                {
                    if (!FileManager.IsRelativeTo(extraFile.DestinationFile, pathOfFile) &&
                        !mExtraFilesToCopy.Contains(extraFile.DestinationFile))
                    {
                        mExtraFilesToCopy.Add(extraFile.DestinationFile);
                    }
                }
#endif
            }

            #endregion

            #region Loop through all AnimationChains and add any missing files

            foreach (AnimationChainList acl in mAnimationChainListsNotRelative)
            {
                foreach (AnimationChain chain in acl)
                {
                    foreach (AnimationFrame frame in chain)
                    {
                        Texture2D texture = frame.Texture;

                        if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) &&
                            !mTexturesNotRelative.Contains(texture))
                        {
                            mTexturesNotRelative.Add(texture);
                        }
                    }
                }
            }

            #endregion

            mLastFileName   = fileName;
            mContentManager = contentManager;
            mSaveDelegate   = saveDelegate;


            #region If there are files which are not relative, show the multi button message box

            SceneSaving             = scene;
            mReplaceTextureDelegate = replaceTextureDelegate;

            string message = "The file\n\n" + fileName +
                             "\n\nreferences the following which are not relative:";


            CopyTexturesMultiButtonMessageBox mbmb = new CopyTexturesMultiButtonMessageBox();
            mbmb.Text       = message;
            mbmb.SaveClick += CopyAssetsToFileFolder;

            //mbmb.AddButton("Make all references relative using \"..\\\"", MakeSceneRelativeWithDotDots);
            //mbmb.AddButton("Copy textures to relative and reference copies.", new GuiMessage(CopyAssetsToFileFolder));

            foreach (Texture2D texture in mTexturesNotRelative)
            {
                mbmb.AddItem(texture.SourceFile());
            }

            foreach (AnimationChainList animationChainList in mAnimationChainListsNotRelative)
            {
                mbmb.AddItem(animationChainList.Name);
            }
            foreach (string s in mFntFilesNotRelative)
            {
                mbmb.AddItem(s);
            }
            foreach (string s in mModelsNotRelative)
            {
                mbmb.AddItem(s);
            }

            foreach (string s in mExtraFilesToCopy)
            {
                mbmb.AddItem(s);
            }


            //mbmb.FilesToMakeDotDotRelative = filesToMakeDotDotRelative;
            if (filesToMakeDotDotRelative.Count != mbmb.ItemsCount)
            {
                mbmb.FilesMarkedDotDotRelative = filesToMakeDotDotRelative;
                GuiManager.AddDominantWindow(mbmb);
            }
            else
            {
                saveDelegate(fileName, true);
            }

            #endregion
        }