public override bool Equals(object obj) { if (!(obj is LibraryGraphicPair)) { return(false); } LibraryGraphicPair other = (LibraryGraphicPair)obj; return(other.GraphicNumber == GraphicNumber && other.LibraryNumber == LibraryNumber); }
public int CompareTo(object other) { if (!(other is LibraryGraphicPair)) { return(-1); } LibraryGraphicPair rhs = (LibraryGraphicPair)other; if (rhs.LibraryNumber == LibraryNumber && rhs.GraphicNumber == GraphicNumber) { return(0); } return(-1); }
/// <summary> /// Returns a byte array of image data from a single image within an endless online *.egf file /// Image is specified by the library file (GFXTypes) and the resourceName (number) /// </summary> /// <param name="resourceVal">Name (number) of the image resource</param> /// <param name="file">File type to load from</param> /// <param name="transparent">Whether or not to make the background black color transparent</param> /// <param name="reloadFromFile">True to force reload the gfx from the gfx file, false to use the in-memory cache</param> /// <returns>Texture2D containing the image from the *.egf file</returns> public static Texture2D TextureFromResource(GFXTypes file, int resourceVal, bool transparent = false, bool reloadFromFile = false) { Texture2D ret; LibraryGraphicPair key = new LibraryGraphicPair((int)file, 100 + resourceVal); if (!reloadFromFile && cache.ContainsKey(key)) { return(cache[key]); } if (cache.ContainsKey(key) && reloadFromFile) { if (cache[key] != null) { cache[key].Dispose(); } cache.Remove(key); } using (System.IO.MemoryStream mem = new System.IO.MemoryStream()) { using (Bitmap i = BitmapFromResource(file, resourceVal, transparent)) i.Save(mem, System.Drawing.Imaging.ImageFormat.Png); ret = Texture2D.FromStream(device, mem); } //need to double-check that the key isn't already in the cache: // multiple threads can enter this method simultaneously //avoiding a lock because this method is used for every graphic if (!cache.ContainsKey(key)) { cache.Add(key, ret); } return(ret); }
/// <summary> /// Returns a byte array of image data from a single image within an endless online *.egf file /// Image is specified by the library file (GFXTypes) and the resourceName (number) /// </summary> /// <param name="resourceVal">Name (number) of the image resource</param> /// <param name="file">File type to load from</param> /// <param name="transparent">Whether or not to make the background black color transparent</param> /// <param name="reloadFromFile">True to force reload the gfx from the gfx file, false to use the in-memory cache</param> /// <returns>Texture2D containing the image from the *.egf file</returns> public static Texture2D TextureFromResource(GFXTypes file, int resourceVal, bool transparent = false, bool reloadFromFile = false) { Texture2D ret; LibraryGraphicPair key = new LibraryGraphicPair((int)file, 100 + resourceVal); if (!reloadFromFile && cache.ContainsKey(key)) { return cache[key]; } if (cache.ContainsKey(key) && reloadFromFile) { if (cache[key] != null) cache[key].Dispose(); cache.Remove(key); } using (System.IO.MemoryStream mem = new System.IO.MemoryStream()) { using (Bitmap i = BitmapFromResource(file, resourceVal, transparent)) i.Save(mem, System.Drawing.Imaging.ImageFormat.Png); ret = Texture2D.FromStream(device, mem); } //need to double-check that the key isn't already in the cache: // multiple threads can enter this method simultaneously //avoiding a lock because this method is used for every graphic if(!cache.ContainsKey(key)) cache.Add(key, ret); return ret; }