public static Texture2D LoadShapeTexture(string name, bool isTemp, TextureShape shape, float[] shapeParms) { var dics = isTemp ? TextureTempDics : TextureDics; Texture2D tex = null; bool reload = false; lock (dics) { if (dics != null && (!dics.TryGetValue(name, out tex) || tex != null && tex.IsDisposed)) { reload = true; if (tex != null) { dics.Remove(name); } } } if (reload) { tex = GameTools.CreateShapeTexture(shape, Color.White, shapeParms); lock (dics) { if (tex == null) { dics.Add(name, null); } else { dics.Add(name, tex); } } } return(tex); }
public static void DrawShape(string name, TextureShape shape, float[] shapeParms, Vector2 pos, Color color, Vector2 scale, Rectangle?source = null, bool isTemp = true) { Texture2D tex = LoadShapeTexture(name, isTemp, shape, shapeParms); if (tex != null && !tex.IsDisposed) { Session.Current.SpriteBatch.Draw(tex, pos, source, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); } }
static Texture2D LoadTexture(string name, bool isUser, bool isTemp, TextureShape shape, float[] shapeParms) { var dics = isTemp ? TextureTempDics : TextureDics; Texture2D tex = null; bool reload = false; lock (dics) { if (dics != null && (!dics.TryGetValue(name, out tex) || tex != null && tex.IsDisposed)) { reload = true; if (tex != null) { dics.Remove(name); } } } if (reload) { string res = ""; if (isUser) { res = name; } else { //res = "Textures" + Platform.Current.GetSlash + name; res = name; if (!name.Contains(".")) { TextureRecs rec = Session.TextureRecs.FirstOrDefault(te => te.Key.Split('#')[0] == name).Value; res = res + "." + rec.Ext; } else { } } tex = Platform.Current.LoadTexture(res, isUser); GameTools.ProcessTextureShape(tex, shape, shapeParms); lock (dics) { if (tex == null) { dics.Add(name, null); } else { dics.Add(name, tex); } } } return(tex); }
public static Texture2D CreateShapeTexture(TextureShape shape, Color color, float[] shapeParms) { Texture2D tex = null; if (shape == TextureShape.Circle) { int radius = Convert.ToInt32(shapeParms[0]); int width = radius * 2; int height = radius * 2; int radius2 = radius * radius; Microsoft.Xna.Framework.Color[] bits = new Microsoft.Xna.Framework.Color[width * height]; Vector2 center = new Vector2(radius, radius); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { var dis2 = (i - center.X) * (i - center.X) + (j - center.Y) * (j - center.Y); if (dis2 <= radius2) { bits[i + j * width] = color; } else { bits[i + j * width] = Microsoft.Xna.Framework.Color.FromNonPremultiplied(0, 0, 0, 0); } } } tex = new Texture2D(Platform.GraphicsDevice, width, height); tex.SetData(bits); } return(tex); }
public static void DrawPic(Person person, Rectangle pos, Color color, bool isUser = false, bool isTemp = true, TextureShape shape = TextureShape.None, float[] shapeParams = null, float depth = 0f, string type = "", bool IsPic = true) { int m = 0; if (type == "m" || type == "t") { m = 1; } else if (type == "e") { m = 3; } else if (type == "L") { m = 2; } type = (type == "s") ? "s" : ""; string name = $@"Content/Textures/GameComponents/PersonPortrait/Images/Default/{person.PictureIndexString}{type}.jpg"; if (person.PictureIndex > Convert.ToInt32(person.PictureIndex)) { string pictureIndex2 = string.Format("{0:N2}", person.PictureIndex); pictureIndex2 = (pictureIndex2.Substring(pictureIndex2.Length - 2, 2)).TrimStart('0'); name = $@"Content/Textures/GameComponents/PersonPortrait/Images/Default/{pictureIndex2}{type}.jpg"; name = name.Replace("Default", "Default/" + Convert.ToInt32(person.PictureIndex)); } else if (m != 2 && type != "") { person.PictureIndexString = person.PictureIndex.ToString(); name = $@"Content/Textures/GameComponents/PersonPortrait/Images/Default/{Convert.ToInt32(person.PictureIndexString)}{type}.jpg"; } if (person.PictureIndexModString != null) { name = name.Replace("Content", "MODs/" + person.PictureIndexModString); } if (m == 2 && person.BGkind == 1) { name = $@"Content/Textures/GameComponents/PersonPortrait/Images/BG/{Convert.ToInt32(person.PictureIndex)}.jpg"; } if (!String.IsNullOrEmpty(name)) { Texture2D pic = LoadAvatar(name, isUser, isTemp, shape, shapeParams); if (pic != null) { if (m == 2) { //if (pic.Height > 240 && pic.Height<= 640) //{ // pos.Height = pic.Height; // pos.Width = pic.Width; //} //else if ( pic.Height > 640) //{ pos.Height = 640; //if (pic.Height > pic.Width) //{ // pos.Height = (pos.Width * pic.Height) / pic.Width; //} //if (pic.Height < pic.Width) //{ pos.Width = (pos.Height * pic.Width) / pic.Height; //} //} } else if (m == 3) { if (pic.Height > 640) { pos.Height = 640; pos.Width = (pos.Height * pic.Width) / pic.Height; } else { pos.Height = pic.Height; pos.Width = pic.Width; } } else if (m == 1 && pic.Height != pic.Width) { if (pic.Height > pic.Width + 80) { //pos.Y = 16; pos.Height = (pos.Width * pic.Height) / pic.Width; pos.Y = pos.Y + pos.Width - pos.Height; } if (pic.Height < pic.Width) { pos.Width = (pos.Height * pic.Width) / pic.Height; pos.X = pos.X + pos.Height - pos.Width; } depth = 0.198f; } if (pic != null && !pic.IsDisposed) { if (Scale != Vector2.One) { pos = new Rectangle(Convert.ToInt16(pos.X * Scale.X), Convert.ToInt16(pos.Y * Scale.Y), Convert.ToInt16(pos.Width * Scale.X), Convert.ToInt16(pos.Height * Scale.Y)); } Session.Current.SpriteBatch.Draw(pic, pos, null, color, 0f, Vector2.Zero, SpriteEffects.None, depth); } } } }
public static void DrawAvatar(string name, Rectangle pos, Color color, bool isUser = false, bool isTemp = true, TextureShape shape = TextureShape.None, float[] shapeParams = null, float depth = 0f) { if (!String.IsNullOrEmpty(name)) { Texture2D tex = LoadAvatar(name, isUser, isTemp, shape, shapeParams); if (tex != null && !tex.IsDisposed) { if (Scale != Vector2.One) { pos = new Rectangle(Convert.ToInt16(pos.X * Scale.X), Convert.ToInt16(pos.Y * Scale.Y), Convert.ToInt16(pos.Width * Scale.X), Convert.ToInt16(pos.Height * Scale.Y)); } Session.Current.SpriteBatch.Draw(tex, pos, null, color, 0f, Vector2.Zero, SpriteEffects.None, depth); } } }
public static void DrawAvatar(string name, Vector2 pos, Color color, float scale, bool isUser = false, bool isTemp = true, TextureShape shape = TextureShape.None, float[] shapeParams = null) { if (!String.IsNullOrEmpty(name)) { Texture2D tex = LoadAvatar(name, isUser, isTemp, shape, shapeParams); if (tex != null && !tex.IsDisposed) { Session.Current.SpriteBatch.Draw(tex, pos, null, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); } } }
public static void DrawGeneralAvatar(string id, Vector2 pos, float alpha, float?scale = null, bool isTemp = true, TextureShape shape = TextureShape.None, float[] shapeParams = null) { if (String.IsNullOrEmpty(id)) { CacheManager.DrawAvatar(@"Avatars\General\Custom.jpg", pos + new Vector2(3, 3), Color.White * alpha, scale == null ? 1f : (float)scale, false, isTemp, shape, shapeParams); } else if (id.StartsWith("Avatar")) { if (!id.Contains(".")) { id = id + ".jpg"; } CacheManager.DrawAvatar(id, pos + new Vector2(3, 3), Color.White * alpha, scale == null ? 0.5f : 0.5f * (float)scale, true, isTemp, shape, shapeParams); } else { if (id.Contains('-')) { id = id.Split('-')[1]; } CacheManager.DrawAvatar(@"Avatars\General\" + id + ".jpg", pos + new Vector2(3, 3), Color.White * alpha, scale == null ? 1f : (float)scale, false, isTemp, shape, shapeParams); } }
//public static Texture2D LoadTempTexture(string name) //{ // return Platform.Current.LoadTexture(name, false); //} public static Texture2D LoadAvatar(string name, bool isUser, bool isTemp, TextureShape shape, float[] shapeParms) { return(LoadTexture(name, isUser, isTemp, shape, shapeParms)); }
public static void ProcessTextureShape(Texture2D tex, TextureShape shape, float[] shapeParms) { if (shape == TextureShape.Circle) { Microsoft.Xna.Framework.Color[] bits = new Microsoft.Xna.Framework.Color[tex.Width * tex.Height]; tex.GetData(bits); int radius = tex.Width / 2; // Convert.ToInt32(shapeParms[0]); int radius2 = radius * radius; Vector2 center = new Vector2(tex.Width / 2, tex.Height / 2); for (int i = 0; i < tex.Width; i++) { for (int j = 0; j < tex.Height; j++) { var dis2 = (i - center.X) * (i - center.X) + (j - center.Y) * (j - center.Y); if (dis2 <= radius2) { } else { bits[i + j * tex.Width] = Microsoft.Xna.Framework.Color.FromNonPremultiplied(0, 0, 0, 0); } } } //tex = new Texture2D(tex.GraphicsDevice, tex.Width, tex.Height); tex.SetData(bits); //for (int i=0; i < bits.Length; i++) //{ // var color = bits[i]; // bits[i] = new Microsoft.Xna.Framework.Color(color.R, color.G, color.B, 0f); // bits[i] * 0f; //} //Vector2[] overlapedArea = new Vector2[] { }; //foreach (Vector2 pixel in overlapedArea) //{ // int x = (int)(pixel.X); // int y = (int)(pixel.Y); // bits[x + y * tex.Width] = Microsoft.Xna.Framework.Color.FromNonPremultiplied(0, 0, 0, 0); //} //// Colour the entire texture transparent first. //for (int i = 0; i < data.Length; i++) // data[i] = Color.TransparentWhite; //// Work out the minimum step necessary using trigonometry + sine approximation. //double angleStep = 1f / radius; //for (double angle = 0; angle < Math.PI * 2; angle += angleStep) //{ // // Use the parametric definition of a circle: http://en.wikipedia.org/wiki/Circle#Cartesian_coordinates // int x = (int)Math.Round(radius + radius * Math.Cos(angle)); // int y = (int)Math.Round(radius + radius * Math.Sin(angle)); // data[y * outerRadius + x + 1] = Color.White; //} //tex = new Texture2D(tex.GraphicsDevice, tex.Width, tex.Height); //tex.SetData(bits); } }
public void Update(string name, ResourceManager res) { if (string.IsNullOrEmpty(name)) { Name = name; Texture = res.NullTexture; Coordinates = DefaultCoordinates; FrameCount = 1; } if (Name != name) { Texture = null; frameanim = null; shape = null; } Name = name; if (shape == null && frameanim == null && Texture != null) { if (Texture == null || Texture.IsDisposed) { Texture = res.FindTexture(name) as Texture2D; } } else if (shape == null) { if (res.TryGetShape(name, out shape)) { Texture = (Texture2D)res.FindTexture(shape.Texture); Coordinates = new[] { new Vector2(shape.Dimensions.X, shape.Dimensions.Y), new Vector2(shape.Dimensions.X + shape.Dimensions.Width, shape.Dimensions.Y), new Vector2(shape.Dimensions.X, shape.Dimensions.Y + shape.Dimensions.Height), new Vector2(shape.Dimensions.X + shape.Dimensions.Width, shape.Dimensions.Y + shape.Dimensions.Height) }; } else if (res.TryGetFrameAnimation(name, out frameanim)) { Texture = res.FindTexture(name + "_0") as Texture2D; Coordinates = new Vector2[frameanim.FrameCount * 4]; for (int i = 0; i < frameanim.FrameCount; i++) { var j = (i * 4); var rect = frameanim.Frames[i]; var uv1 = new Vector2(rect.UV1.X, 1 - rect.UV1.Y); var uv2 = new Vector2(rect.UV2.X, 1 - rect.UV2.Y); Coordinates[j] = uv1; Coordinates[j + 1] = new Vector2(uv2.X, uv1.Y); Coordinates[j + 2] = new Vector2(uv1.X, uv2.Y); Coordinates[j + 3] = uv2; } FrameCount = frameanim.FrameCount; } else { Texture = res.FindTexture(name) as Texture2D; Coordinates = DefaultCoordinates; } } }