public FontsCollection(Game game, XElement xml, IOOperation op, IOContent type)
     : base(game) {
     fonts = new List<FontPack>();
     links = new Hashtable();
     Game.Components.Add(this);
     ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(xml, op, type));
 }
        /// <summary>
        /// Creates texturepacks and adds them to the packs list.
        /// </summary>
        private void LoadTexturePacks(IODataPack ioDataPack)
        {
            XElement    xml         = ioDataPack.Xml;
            IOContent   contentType = ioDataPack.Type;
            IOOperation operation   = ioDataPack.Operation;

            int totalFiles  = FileCount(xml);
            int loadedFiles = 0;
            int progress    = 0;

            OnStart(this, new IOEventArgs(progress, operation, contentType));
            IEnumerable <XElement> xmlPacks = from element in xml.Elements() select element;

            foreach (XElement xmlData in xmlPacks)
            {
                int    id     = Convert.ToInt32(xmlData.Element("id").Value);
                int    count  = Convert.ToInt32(xmlData.Element("frames").Value);
                string folder = xmlData.Element("folder").Value;
                string name   = xmlData.Element("name").Value;
                packs.Add(CreateTexturePack(id, name, folder, count, ref loadedFiles, ref totalFiles, contentType, operation));
                links.Add(name, packs.Count - 1);
                links.Add(id, packs.Count - 1);
                OnNewPack(this, new IOEventArgs(progress, operation, contentType));
            }
            OnComplete(this, new IOEventArgs(progress, operation, contentType));
        }
示例#3
0
        private void LoadFonts(IODataPack ioDataPack)
        {
            XElement    xml         = ioDataPack.Xml;
            IOContent   contentType = ioDataPack.Type;
            IOOperation operation   = ioDataPack.Operation;

            int    fileCount   = xml.Elements("font").Count();
            int    filesLoaded = 0;
            double progress    = (double)filesLoaded / (double)fileCount * 100;

            OnStart(this, new IOEventArgs(0, ioDataPack.Operation, ioDataPack.Type));
            foreach (XElement element in xml.Elements("font"))
            {
                SpriteFont font = Game.Content.Load <SpriteFont>(element.Element("resource").Value);
                int        id   = Convert.ToInt32(element.Element("id").Value);
                string     name = element.Element("name").Value;
                fonts.Add(new FontPack(font, id, name));
                links.Add(id, fonts.Count - 1);
                links.Add(name, fonts.Count - 1);
                filesLoaded++;
                progress = (double)filesLoaded / (double)fileCount * 100;
                OnProgress(this, new IOEventArgs(progress, ioDataPack.Operation, ioDataPack.Type));
            }
            OnComplete(this, new IOEventArgs(progress, ioDataPack.Operation, ioDataPack.Type));
        }
示例#4
0
 public FontsCollection(Game game, XElement xml, IOOperation op, IOContent type)
     : base(game)
 {
     fonts = new List <FontPack>();
     links = new Hashtable();
     Game.Components.Add(this);
     ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(xml, op, type));
 }
 /// <summary>
 /// Creates a new GraphicsCollection and starts loading the textures from the received XML.
 /// </summary>
 public GraphicsCollection(Game game, XElement _xml, IOContent type, IOOperation op)
     : base(game)
 {
     packs = new List <TexturePack>();
     links = new Hashtable();
     Game.Components.Add(this);
     ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(_xml, op, type));
 }
示例#6
0
 public IOEventArgs(double progress, IOOperation op,IOContent c) {
     progressPercent = progress;
     content = c;
     operation = op;
 }
 public void AddFontsFromXml(XElement xml, IOOperation op, IOContent type) {
     ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(xml, op, type));
 }
示例#8
0
 public void AddFontsFromXml(XElement xml, IOOperation op, IOContent type)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(xml, op, type));
 }
示例#9
0
 public IOEventArgs(double progress, IOOperation op, IOContent c)
 {
     progressPercent = progress;
     content         = c;
     operation       = op;
 }
 /// <summary>
 /// Creates a new GraphicsCollection and starts loading the textures from the received XML.
 /// </summary>
 public GraphicsCollection(Game game, XElement _xml, IOContent type, IOOperation op)
     : base(game) {
     packs = new List<TexturePack>();
     links = new Hashtable();
     Game.Components.Add(this);
     ThreadPool.QueueUserWorkItem(new WaitCallback(Load), new IODataPack(_xml, op, type));
 }
 public IODataPack(XElement _xml, IOOperation op,IOContent _type){
     xml = _xml;
     type = _type;
     operation = op;
 }
 /// <summary>
 /// Loads a pack of textures and returns a new TexturePack.
 /// </summary>
 /// <param name="id">The id of the TexturePack returned.</param>
 /// <param name="name">The name of the TexturePack returned.</param>
 /// <param name="folder">The path of the TexturePack returned.</param>
 /// <param name="count">The number of frames.</param>
 private TexturePack CreateTexturePack(int id, string name, string folder, int count, ref int loadedFiles, ref int totalFiles, IOContent contentType, IOOperation operation) {
     List<Texture2D> temp = new List<Texture2D>(count);
     for (int i = 0; i < count; i++) {
         string path = folder + "//" + (10000 + i).ToString();
         Texture2D tex = Game.Content.Load<Texture2D>(path);
         //Thread.Sleep(500);
         loadedFiles++;
         double progress = (double)loadedFiles/(double)totalFiles*100;
         OnProgress(this, new IOEventArgs(progress,operation, contentType));
         temp.Add(tex);
     }
     return new TexturePack(name, id, temp);
 }
 public IODataPack(XElement _xml, IOOperation op, IOContent _type)
 {
     xml       = _xml;
     type      = _type;
     operation = op;
 }
        /// <summary>
        /// Loads a pack of textures and returns a new TexturePack.
        /// </summary>
        /// <param name="id">The id of the TexturePack returned.</param>
        /// <param name="name">The name of the TexturePack returned.</param>
        /// <param name="folder">The path of the TexturePack returned.</param>
        /// <param name="count">The number of frames.</param>
        private TexturePack CreateTexturePack(int id, string name, string folder, int count, ref int loadedFiles, ref int totalFiles, IOContent contentType, IOOperation operation)
        {
            List <Texture2D> temp = new List <Texture2D>(count);

            for (int i = 0; i < count; i++)
            {
                string    path = folder + "//" + (10000 + i).ToString();
                Texture2D tex  = Game.Content.Load <Texture2D>(path);
                //Thread.Sleep(500);
                loadedFiles++;
                double progress = (double)loadedFiles / (double)totalFiles * 100;
                OnProgress(this, new IOEventArgs(progress, operation, contentType));
                temp.Add(tex);
            }
            return(new TexturePack(name, id, temp));
        }