public Cube(Vector2 origin, Vector3 gridPos, Texture2D southwestTex, Texture2D southeastTex, Texture2D topTex, GraphicsDeviceManager graphics, SpriteSheetInfo spriteSheetInfo) { this.southwestTex = southwestTex; this.southeastTex = southeastTex; this.topTex = topTex; this.origin = origin; this.gridPos = gridPos; this.position = origin + Game1.world.twoDToIso(new Point((int)(gridPos.X * southwestTex.Width), (int)(gridPos.Y * southwestTex.Height * .65f))).ToVector2(); this.position.Y -= gridPos.Z * southwestTex.Height * .65F; this.graphics = graphics; this.spriteSheetInfo = spriteSheetInfo; this.highLight = false; this.invert = false; southwest = new Sprite(southwestTex); southwest.position = position; southwest.position.X -= (int)Math.Floor((double)southwest.tex.Width / 2); // - 1; southwest.position.Y += (int)Math.Floor((double)southwest.tex.Height / 2); // - 1; southwest.origin = new Vector2(southwestTex.Width / 2, southwestTex.Height / 2); southwest.scale = 1f; southwest.rotation = 180; // enables collision by moving the rectangle to the proper space /*southwest.rectangle.X = (int)position.X; * southwest.rectangle.Y = (int)position.Y; * southwest.rectangle.Width = southwest.tex.Width; * southwest.rectangle.Height = southwest.tex.Height;*/ southeast = new Sprite(southeastTex); southeast.position = position; southeast.position.X += (int)Math.Floor((double)southwest.tex.Width / 2); // - 1; southeast.position.Y += (int)Math.Floor((double)southwest.tex.Height / 2); // - 1; southeast.origin = new Vector2(southeastTex.Width / 2, southeastTex.Height / 2); southeast.scale = 1f; southeast.rotation = 180; // enables collision by moving the rectangle to the proper space /*southeast.rectangle.X = (int)position.X; * southeast.rectangle.Y = (int)position.Y; * southeast.rectangle.Width = southeast.tex.Width; * southeast.rectangle.Height = southeast.tex.Height; * southeast.rectangle.*/ top = new Sprite(topTex); top.position = position; top.origin = new Vector2(topTex.Width / 2, topTex.Height / 2); top.scale = 1f; // enables collision by moving the rectangle to the proper space top.rectangle.X = (int)position.X; top.rectangle.Y = (int)position.Y; top.rectangle.Width = top.tex.Width; top.rectangle.Height = top.tex.Height; topPoly = new Polygon(); /*Vector2 topOfDiamond = new Vector2(top.position.X + top.tex.Width / 2 + top.origin.X, top.position.Y + top.origin.Y); * Vector2 bottomOfDiamond = new Vector2(top.position.X + top.tex.Width / 2 + top.origin.X, top.position.Y + top.tex.Height + top.origin.Y); * Vector2 leftOfDiamond = new Vector2(top.position.X + top.origin.X, top.position.Y + top.tex.Height / 2 + top.origin.Y); * Vector2 rightOfDiamond = new Vector2(top.position.X + top.tex.Width + top.origin.X, top.position.Y + top.tex.Height / 2 + top.origin.Y); * topPoly.Lines.Add(new PolyLine(leftOfDiamond, topOfDiamond)); * topPoly.Lines.Add(new PolyLine(topOfDiamond, rightOfDiamond)); * topPoly.Lines.Add(new PolyLine(rightOfDiamond, bottomOfDiamond)); * topPoly.Lines.Add(new PolyLine(bottomOfDiamond, leftOfDiamond));*/ /*if (gridPos == new Vector3(8, 8, 1)) { * Console.WriteLine("Cube Top Rect:" + top.rectangle + " Pos:" + top.position + " Origin:" + top.origin); * }*/ text = new TextItem(World.fontManager["InfoFont"], "X: " + gridPos.X + " Y: " + gridPos.Y + " Z: " + gridPos.Z); text.position = position; /*if (gridPos == new Vector3(8, 8, 1)) * { * // add random transparent colors * rectangleTex = Game1.world.textureConverter.GenRectangle(top.rectangle.Width, top.rectangle.Height, Color.Red); // top.rectangle.Width, top.rectangle.Height, Color.Black); * rectangleSprite = new Sprite(rectangleTex, graphics, spriteSheetInfo); * rectangleSprite.position = new Vector2(top.position.X, top.position.Y); * rectangleSprite.origin = top.origin; * Console.WriteLine("pos:" + rectangleSprite.position); * }*/ /*highlightTex = Game1.world.textureConverter.highlightTex(topTex); * highlight = new Sprite(highlightTex); * highlight.origin = top.origin; * highlight.position = top.position;*/ }
public void PositionBelow(TextItem textItem, float margin = 10.0f) { position = new Vector2(textItem.position.X, textItem.position.Y + textItem.TextSize.Y + margin); }
public void PositionRight(TextItem textItem, float margin = 10) { position = new Vector2(textItem.position.X + textItem.TextSize.X + margin, textItem.position.Y); }
public Descriptor(Polygon poly, String text, Sprite refSprite = null) { this.poly = poly; this.refSprite = refSprite; int leftMost = int.MaxValue; int rightMost = int.MinValue; int topMost = int.MaxValue; int bottomMost = int.MinValue; foreach (PolyLine l in poly.Lines) { leftMost = (int)Math.Min(l.Start.X, leftMost); rightMost = (int)Math.Max(l.Start.X, rightMost); topMost = (int)Math.Min(l.Start.Y, topMost); bottomMost = (int)Math.Max(l.Start.Y, bottomMost); leftMost = (int)Math.Min(l.End.X, leftMost); rightMost = (int)Math.Max(l.End.X, rightMost); topMost = (int)Math.Min(l.End.Y, topMost); bottomMost = (int)Math.Max(l.End.Y, bottomMost); } textItems = new List <TextItem>(); textItems.Add(new TextItem(World.fontManager["Trajanus Roman 24"], text)); TextItem textItem = textItems.ToArray()[0]; textItem.origin = Vector2.Zero; textItem.color = Color.White; width = textItem.rectangle.Width + 20; height = textItem.rectangle.Height * 4; Vector2 topLeft = new Vector2(leftMost, topMost - 5 - height); Vector2 bottomLeft = new Vector2(leftMost, bottomMost + 5); Vector2 topRight = new Vector2(rightMost - width, topMost - 5 - height); Vector2 bottomRight = new Vector2(rightMost - width, bottomMost + 5); if (!(textInBounds(topLeft) || textInBounds(bottomLeft) || textInBounds(topRight) || textInBounds(bottomRight))) { int lines = 1; while (true) { lines++; String[] splitText = text.Split(); List <String> stringLines = new List <String>(); int i = 0; int l = 1; String temp = ""; int tempChars = 0; foreach (String s in splitText) { temp += s + " "; tempChars += s.Length; if (tempChars >= (text.Length / lines) * l || splitText.Length - 1 == i) { stringLines.Add(temp); temp = ""; l++; } i++; } textItems.Clear(); width = 0; height = 0; int k = 0; foreach (String s in stringLines) { textItems.Add(new TextItem(World.fontManager["Trajanus Roman 24"], s)); TextItem tempTextItem = textItems.ToArray()[k]; tempTextItem.origin = Vector2.Zero; tempTextItem.color = Color.White; width = Math.Max(width, tempTextItem.rectangle.Width + 20); height += textItem.rectangle.Height * 4; k++; } topLeft = new Vector2(leftMost, topMost - 5 - height); bottomLeft = new Vector2(leftMost, bottomMost + 5); topRight = new Vector2(rightMost - width, topMost - 5 - height); bottomRight = new Vector2(rightMost - width, bottomMost + 5); if (textInBounds(topLeft) || textInBounds(bottomLeft) || textInBounds(topRight) || textInBounds(bottomRight) || lines > 10) { break; } } } if (textInBounds(topLeft)) { //Console.WriteLine("Chose topLeft"); pos = topLeft; } else if (textInBounds(bottomLeft)) { //Console.WriteLine("Chose bottomLeft"); pos = bottomLeft; } else if (textInBounds(topRight)) { //Console.WriteLine("Chose topRight"); pos = topRight; } else if (textInBounds(bottomRight)) { //Console.WriteLine("Chose bottomRight"); pos = bottomRight; } else { pos = Vector2.Zero; } /*if (pos.X + width > 1920) * { * Console.WriteLine("Right: " + (int)(pos.X + width)); * }*/ for (int i = 0; i < textItems.Count; i++) { TextItem t = textItems.ToArray()[i]; t.position = pos + new Vector2(0, i * t.rectangle.Height * 4); t.position.Y += (t.rectangle.Height * 4) / 2 - 3; t.position.X += 10; } backing = new Sprite(Game1.world.textureConverter.GenBorderedRectangle(width, height, new Color(75, 75, 75))); backing.origin = Vector2.Zero; backing.position = pos; trigger = false; }