Exemple #1
0
        /// <summary>
        /// Load textures for a given pack
        /// </summary>
        private static void LoadTextures(ContentPack pack)
        {
            //List of texture file names
            List<string> Files = null;
            //Base directory for all textures
            string BaseDirectory;
            Texture2D Texture = null;

            //Get the files name list for the pack, and the directory to it for loading
            if (pack.Embedded)
            {
                Files = DirSearch(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Content\\Content Packs\\" + pack.Name, System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Content\\Content Packs\\" + pack.Name + "\\textures", ".xnb");
                BaseDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Content\\Content Packs\\" + pack.Name + "\\textures\\";
            }
            else
            {
                Files = DirSearch(IO.Directories["Content Packs"] + Game.ContentPackName, IO.Directories["Content Packs"] + Game.ContentPackName + "\\textures", ".png");
                BaseDirectory = IO.Directories["Content Packs"] + Game.ContentPackName + "\\textures\\";
            }

            //For each file name, load it from disk;
            for (int i = 0; i < Files.Count; i++)
            {
                //Remove the full path to return the name of the file
                string name = GetName(Files[i], BaseDirectory, i);

                if (pack.Embedded)
                    Texture = Game.TextureLoader.Content.Load<Texture2D>("Content\\Content Packs\\Default\\textures\\" + name);
                else
                    Texture = Game.TextureLoader.FromFile(Files[i]);

                //Add it to the dictionary
                if (Textures.ContainsKey(name))
                    Textures[name] = Texture;
                else
                    Textures.Add(name, Texture);
            }
        }
Exemple #2
0
 /// <summary>
 /// Loads a pack into the game
 /// </summary>
 /// <param name="pack">ContentPack to load</param>
 public static void LoadPack(ContentPack pack)
 {
     //Clear all memory in case we are reloading
     Textures.Clear();
     if (!pack.Embedded) //If extenal pack, first load default
         LoadTextures(IO.ContentPacks[0]);
     LoadTextures(pack);
 }
Exemple #3
0
        /// <summary>
        /// Finds content packs and loads the selected one
        /// </summary>
        public static void LoadContentPacks(Game game)
        {
            try
            {
                //Load Content Packs
                List<string> dirs = new List<string>();
                //Load embedded pack directories from Content folder
                dirs.Add(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Content\\Content Packs\\Default");
                //Load packs from Zarknorth folder
                dirs.AddRange(Directory.GetDirectories(Directories["Content Packs"]).ToList<string>());

                //Foreach directory
                for (int x = 0; x < dirs.Count(); x++)
                {
                    string dir = dirs[x];

                    //Load the packs xml data
                    XmlDocument doc = new XmlDocument();
                    doc.Load(dir + "\\pack.xml");

                    //Create the new pack and set it's data
                    ContentPack pack = new ContentPack();
                    pack.Name = doc.ChildNodes[1].ChildNodes[0].ChildNodes[0].Value;
                    pack.Description = doc.ChildNodes[1].ChildNodes[1].ChildNodes[0].Value;
                    pack.Version = doc.ChildNodes[1].ChildNodes[2].ChildNodes[0].Value;
                    pack.Author = doc.ChildNodes[1].ChildNodes[3].ChildNodes[0].Value;
                    pack.Path = dir;
                    pack.Embedded = pack.Name == "Default";

                    //If an embedded pack, load from ContentManager, else FromStream
                    if (pack.Embedded)
                        pack.Icon = Game.TextureLoader.Content.Load<Texture2D>("Content\\Content Packs\\" + pack.Name + "\\icon");
                    else
                        using (FileStream fileStream = new FileStream(dir + "\\icon.png", FileMode.Open))
                            pack.Icon = Texture2D.FromStream(game.GraphicsDevice, fileStream);

                    //Add the pack
                    ContentPacks.Add(pack);

                    //If this pack is the current pack, set the game's data to it, so it is aware of the pack to use
                    if (pack.Name == Game.ContentPackName)
                    {
                        Game.ContentPackIndex = x;
                        Game.ContentPackData = pack;
                    }
                }
                //Load the current pack
                ContentPack.LoadPack(Game.ContentPackData);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
        }