예제 #1
0
        public static PicRef Create(MemberSpriteBitmap mb, string name)
        {
            PicRef pr = new PicRef(name, (MemberSpriteBitmap)mb);

            pr.Offset = new EPoint();
            return(pr);
        }
예제 #2
0
        public static PicRef GetOrCreate(string name)
        {
            PicRef pr = PicRef.Get(name);

            if (pr != null)
            {
                return(pr);
            }
            return(PicRef.Create(name));
        }
예제 #3
0
 private void PostConstructor(string originalName)
 {
     PicRef._numCreated++;
     if (originalName == null)
     {
         originalName = "Unnamed" + PicRef._numCreated;
     }
     this._originalName = originalName;
     this._offset       = new EPoint();
     this._sourceRect   = new ERectangle();
     PicRef.AddPicture(this);
 }
예제 #4
0
        public static void ScanMediaDirectories()
        {
            //Look for files ending with .xml in all Media paths
            string[] paths = Endogine.AppSettings.Instance["Paths.Media"];

            if (paths != null)
            {
                foreach (string path in paths)
                {
                    PicRef.ScanDirectory(path);
                }
            }
        }
예제 #5
0
        public void Init(string defaultDirectory)
        {
            m_dirInfo = new DirectoryInfo(defaultDirectory);

            m_aMembers         = new ArrayList();
            m_hashToMember     = new Hashtable();
            this._nameToMember = new Hashtable();

//			m_dtMembers = new DataTable();
//			m_dtMembers.Columns.Add("Name", typeof(System.String));
//			m_dtMembers.Columns.Add("Hash", typeof(System.Int32));

            PicRef.ScanMediaDirectories();
        }
예제 #6
0
        public static void ScanDirectory(string path)
        {
            PicRef.Prepare();

            if (!Endogine.Files.FileFinder.ContainsRoot(path))
            {
                DirectoryInfo di = new DirectoryInfo(path);
                if (!di.Exists)
                {
                    di = new DirectoryInfo(Endogine.AppSettings.BaseDirectory + "\\" + path);
                    if (!di.Exists)
                    {
                        throw new Exception("ScanDirectory: " + path + " doesn't exists");
                    }
                }
                path = di.FullName;
            }
            if (!path.EndsWith("\\"))
            {
                path += "\\";
            }

            FileInfo[] files = Endogine.Files.FileFinder.GetFiles(path + "*.xml");
            foreach (FileInfo file in files)
            {
                //Find files with the same name, but a different file extension - those are probably media files.
                //TODO: Not only bitmaps - this goes for all types of media, they come in media+resource pairs.
                string     mediaFile          = file.FullName.Remove(file.FullName.Length - 3, 3) + "*";
                FileInfo[] probableMediaFiles = Endogine.Files.FileFinder.GetFiles(mediaFile);

                foreach (FileInfo probableFile in probableMediaFiles)
                {
                    if (probableFile.Name.EndsWith("xml"))
                    {
                        continue;
                    }
                    PicRef.LoadPicRef(probableFile.FullName);
                    break;
                }
            }

            FileInfo[] filesGif = Endogine.Files.FileFinder.GetFiles(path + "*.gif");
            foreach (FileInfo file in filesGif)
            {
                //TODO: check if already loaded (had xml fork)
                PicRef.LoadPicRef(file.FullName);
            }
        }
예제 #7
0
        public static List <PicRef> CreatePicRefs(string fileName, int numFramesOnX, int numFramesTotal)
        {
            if (fileName.IndexOf("\\") > 0)
            {
                fileName = fileName.Remove(0, fileName.LastIndexOf("\\") + 1);
            }
            int index = fileName.LastIndexOf(".");

            if (index > 0)
            {
                fileName = fileName.Remove(index);
            }

            MemberSpriteBitmap mb = (MemberSpriteBitmap)EH.Instance.CastLib.GetOrCreate(fileName);

            return(PicRef.CreatePicRefs(mb, numFramesOnX, numFramesTotal));
        }
예제 #8
0
        //public Endogine.BitmapHelpers.PixelManipulatorBase PixelManipulator
        //{
        //    get {return this.Member.PixelManipulator;}
        //    set {this.Member.PixelManipulator = null;}
        //}
        //public Endogine.BitmapHelpers.Canvas Canvas
        //{
        //    get {return this.Member.C
        //}

        /// <summary>
        /// Look for a resource in this order: Animation, FrameSet, PicRef, Member.
        /// </summary>
        /// <param name="name"></param>
        public void SetGraphics(string name)
        {
            //EH.Instance.CastLib.Animations[name];

            Endogine.Animation.BhAnimator an = (Endogine.Animation.BhAnimator) this["_anim"];

            List <string> fs = EH.Instance.CastLib.FrameSets[name];

            if (fs != null)
            {
                if (an != null)
                {
                    an.FrameSet = name;
                }
                else
                {
                    an = new Endogine.Animation.BhAnimator(this, name);
                }
                return;
            }

            PicRef pr = PicRef.Get(name);

            if (pr != null)
            {
                if (an != null)
                {
                    an.Dispose();
                }
                this.PicRef = pr;
                return;
            }

            MemberBase mb = EH.Instance.CastLib.GetByName(name);

            if (mb != null && mb is MemberSpriteBitmap)
            {
                this.Member = (MemberSpriteBitmap)mb;
                return;
            }

            this.MemberName = name;
        }
예제 #9
0
        public static List <PicRef> CreatePicRefs(Endogine.ResourceManagement.MemberBitmapBase mb, int numFramesOnX, int numFramesTotal)
        {
            List <string> animRefs     = new List <string>();
            List <PicRef> picRefs      = new List <PicRef>();
            int           numFramesOnY = numFramesTotal / numFramesOnX;
            EPoint        frameSize    = new EPoint(mb.Size.X / numFramesOnX, mb.Size.Y / numFramesOnY);

            for (int i = 0; i < numFramesTotal; i++)
            {
                string picRefName = mb.Name + "_" + i;
                int    x          = i % numFramesOnX;
                int    y          = i / numFramesOnX;
                PicRef pr         = PicRef.Create((MemberSpriteBitmap)mb, picRefName);
                pr.SourceRectangle = new ERectangle(x * frameSize.X, y * frameSize.Y, frameSize.X, frameSize.Y);
                picRefs.Add(pr);
                animRefs.Add(picRefName);
            }

            EH.Instance.CastLib.FrameSets.AddFrameSet(mb.Name, animRefs);

            return(picRefs);
        }
예제 #10
0
        public static void LoadPicRef(string bitmapFilename)
        {
            FileInfo bitmapFile = new FileInfo(bitmapFilename);

            PicRef.Prepare();

            if (_originalsToMerged.ContainsValue(bitmapFile.FullName))
                return;
            //				throw new Exception("This tiled bitmap has already been loaded: "+bitmapFile.FullName);

            //For now, load the bitmap immediately. The retrieval process for each PicRef seems to be very slow.
            MemberSpriteBitmap mb = new MemberSpriteBitmap(bitmapFilename);

            XmlDocument doc = new XmlDocument();
            string xmlFile = bitmapFile.FullName.Substring(0, bitmapFile.FullName.Length-bitmapFile.Extension.Length) + ".xml";
            if (File.Exists(xmlFile))
            {
                doc.Load(xmlFile);
                if (doc["root"]["Files"] != null)
                {
                    List<string> fileOrder = new List<string>();
                    foreach (XmlNode node in doc["root"]["Files"])
                    {
                        string originalFile = node.Attributes["value"].InnerXml;
                        fileOrder.Add(originalFile);
                        //remove file extension:
                        int index = originalFile.LastIndexOf(".");
                        if (index > 0)
                            originalFile = originalFile.Remove(index, originalFile.Length - index);
                        //							if (_originalsToMerged.Contains(originalFile)
                        //if (originalFile == "object01_0000")
                        //	EH.Put("Jks");
                        //_originalsToMerged.Add(originalFile, bitmapFile.FullName);

                        PicRef picture = new PicRef(originalFile, mb);
                        picture.SourceRectangle = new ERectangle(node["Rect"].Attributes["value"].InnerXml);
                        picture.Offset = new EPoint(node["Offset"].Attributes["value"].InnerXml);
                    }

                    //TODO: ATM, nothing is done with the animation information in here.
                    //Should be stored in a global animation collection -
                    //accessed by [
                    if (doc["root"]["Animations"] != null)
                    {
                        foreach (XmlNode node in doc["root"]["Animations"])
                        {
                            System.Collections.ArrayList anim = Endogine.Animation.AnimationHelpers.ParseAnimationString(node.Attributes["value"].InnerXml);
                            List<string> animPics = new List<string>();
                            foreach (int frame in anim)
                                animPics.Add(fileOrder[frame]);
                            EH.Instance.CastLib.FrameSets.AddFrameSet(node.Name, animPics);
                        }
                    }
                }
            }
        }
예제 #11
0
 public static PicRef Create(MemberSpriteBitmap mb, string name)
 {
     PicRef pr = new PicRef(name, (MemberSpriteBitmap)mb);
     pr.Offset = new EPoint();
     return pr;
 }
예제 #12
0
 public static void AddPicture(PicRef p)
 {
     PicRef.Prepare();
     PicRef._pictures.Add(p.OriginalName, p);
     PicRef._originalsToMerged.Add(p.OriginalName, p.Member.Name);
 }
예제 #13
0
        public static PicRef Create(string fileName)
        {
            MemberSpriteBitmap mb = (MemberSpriteBitmap)EH.Instance.CastLib.GetOrCreate(fileName);

            return(PicRef.Create(mb, fileName));
        }
예제 #14
0
 public static void AddPicture(PicRef p)
 {
     PicRef.Prepare();
     PicRef._pictures.Add(p.OriginalName, p);
     PicRef._originalsToMerged.Add(p.OriginalName, p.Member.Name);
 }
예제 #15
0
        public static void LoadPicRef(string bitmapFilename)
        {
            FileInfo bitmapFile = new FileInfo(bitmapFilename);

            PicRef.Prepare();

            if (_originalsToMerged.ContainsValue(bitmapFile.FullName))
            {
                return;
            }
//				throw new Exception("This tiled bitmap has already been loaded: "+bitmapFile.FullName);

            //For now, load the bitmap immediately. The retrieval process for each PicRef seems to be very slow.
            MemberSpriteBitmap mb = new MemberSpriteBitmap(bitmapFilename);

            XmlDocument doc     = new XmlDocument();
            string      xmlFile = bitmapFile.FullName.Substring(0, bitmapFile.FullName.Length - bitmapFile.Extension.Length) + ".xml";

            if (File.Exists(xmlFile))
            {
                doc.Load(xmlFile);
                if (doc["root"]["Files"] != null)
                {
                    List <string> fileOrder = new List <string>();
                    foreach (XmlNode node in doc["root"]["Files"])
                    {
                        string originalFile = node.Attributes["value"].InnerXml;
                        fileOrder.Add(originalFile);
                        //remove file extension:
                        int index = originalFile.LastIndexOf(".");
                        if (index > 0)
                        {
                            originalFile = originalFile.Remove(index, originalFile.Length - index);
                        }
                        //							if (_originalsToMerged.Contains(originalFile)
                        //if (originalFile == "object01_0000")
                        //	EH.Put("Jks");
                        //_originalsToMerged.Add(originalFile, bitmapFile.FullName);

                        PicRef picture = new PicRef(originalFile, mb);
                        picture.SourceRectangle = new ERectangle(node["Rect"].Attributes["value"].InnerXml);
                        picture.Offset          = new EPoint(node["Offset"].Attributes["value"].InnerXml);
                    }

                    //TODO: ATM, nothing is done with the animation information in here.
                    //Should be stored in a global animation collection -
                    //accessed by [
                    if (doc["root"]["Animations"] != null)
                    {
                        foreach (XmlNode node in doc["root"]["Animations"])
                        {
                            System.Collections.ArrayList anim = Endogine.Animation.AnimationHelpers.ParseAnimationString(node.Attributes["value"].InnerXml);
                            List <string> animPics            = new List <string>();
                            foreach (int frame in anim)
                            {
                                animPics.Add(fileOrder[frame]);
                            }
                            EH.Instance.CastLib.FrameSets.AddFrameSet(node.Name, animPics);
                        }
                    }
                }
            }
        }