public DecisionPopupComponent(int locationX, int locationY, string title, string text, SpriteData image, DecisionPopupChoice[] decisions) { this.locationX = locationX; this.locationY = locationY; this.decisions = decisions; this.title = title; this.text = text; this.image = image; this.visible = true; PerformDrag(0, 0); //Trigger the drag code }
/// <summary> /// Creates a Decision Popup Component from a game event /// </summary> /// <param name="locationX"></param> /// <param name="locationY"></param> /// <param name="gameEvent"></param> public DecisionPopupComponent(int locationX, int locationY, GameEvent gameEvent) { this.locationX = locationX; this.locationY = locationY; this.decisions = gameEvent.EventChoices.Select(ec => new DecisionPopupChoice(ec.Text,ec.InternalAction,ec.Action,ec.Agrs)).ToArray(); this.text = gameEvent.Text; this.title = gameEvent.Title; this.image = gameEvent.Image; this.visible = true; PerformDrag(0, 0); }
/// <summary> /// Clones the Sprite Data /// </summary> /// <param name="clone"></param> public SpriteData(SpriteData clone) { this.path = clone.path; this.sourceRectangle = clone.sourceRectangle; this.ColorFilter = clone.ColorFilter; }
/// <summary> /// Adds a local sprite to the lists, provided they are in a 50x50 grid /// </summary> /// <param name="name"></param> /// <param name="x"></param> /// <param name="y"></param> private static void AddLocalSprite(LocalSpriteName name, string filePath, int x, int y) { const int GRIDSIZE = 50; localSprites[(int)name] = new SpriteData(filePath, new Rectangle(x*GRIDSIZE, y *GRIDSIZE, GRIDSIZE, GRIDSIZE)); }
/// <summary> /// Draws the prepared grid onto the screen /// </summary> /// <param name="blocks"></param> void DrawGrid(IEnumerable<InterfaceBlock> blocks) { Rectangle rec = new Rectangle(0, 0, TILEWIDTH, TILEHEIGHT); Rectangle itemRec = new Rectangle(0, 0, TILEWIDTH - 5, TILEHEIGHT - 5); //Set the default texture in case we don't find it Texture2D defTex = new Texture2D(GraphicsDevice, 1, 1); defTex.SetData(new[] { Color.White }); foreach (InterfaceBlock block in blocks) { //find the location and put it in there rec.X = block.InterfaceX * TILEWIDTH; rec.Y = block.InterfaceY * TILEHEIGHT; //Start with the tile try { foreach (SpriteData tileGraphic in block.TileGraphics.Reverse()) { if (tileGraphic != null) { if (tileGraphic.sourceRectangle == null) { spriteBatch.Draw(this.game.Content.Load<Texture2D>(tileGraphic.path), rec, block.IsOld ? Color.DarkGray : (tileGraphic.ColorFilter.HasValue ? tileGraphic.ColorFilter.Value : Color.White)); } else { //part of a tileset spriteBatch.Draw(this.game.Content.Load<Texture2D>(tileGraphic.path), rec, tileGraphic.sourceRectangle, block.IsOld ? Color.DarkGray : (tileGraphic.ColorFilter.HasValue ? tileGraphic.ColorFilter.Value : Color.White)); } } } } catch { //texture not found, lets draw the default spriteBatch.Draw(defTex, rec, Color.Green); } //now draw the items try { SpriteData[] graphics = new SpriteData[block.ItemGraphics.Length + block.ActorGraphics.Length]; block.ItemGraphics.CopyTo(graphics, 0); block.ActorGraphics.CopyTo(graphics, block.ItemGraphics.Length); if (graphics.Length != 0) { foreach (SpriteData itemGraphic in graphics) { if (itemGraphic != null) { if (itemGraphic.GetType().Equals(typeof(TextSpriteData))) { TextSpriteData data = (TextSpriteData)itemGraphic; //Write it in the screen spriteBatch.DrawString(font, data.Text, rec, Alignment.Right | Alignment.Bottom, data.Colour); } else { if (itemGraphic.sourceRectangle == null) { spriteBatch.Draw(this.game.Content.Load<Texture2D>(itemGraphic.path), rec, block.IsOld ? greyedOutColour : itemGraphic.ColorFilter.HasValue ? itemGraphic.ColorFilter.Value : Color.White); } else { //part of a tileset spriteBatch.Draw(this.game.Content.Load<Texture2D>(itemGraphic.path), rec, itemGraphic.sourceRectangle, block.IsOld ? greyedOutColour : (itemGraphic.ColorFilter.HasValue ? itemGraphic.ColorFilter.Value : Color.White)); } } } } } } catch { //texture not found, lets draw the default spriteBatch.Draw(defTex, rec, Color.Blue); } } }
public static void Draw(this SpriteBatch batch, ContentManager content, SpriteData data, Rectangle drawRect, Color colour) { batch.Draw(content.Load<Texture2D>(data.path),drawRect,data.sourceRectangle,colour); }