public static void Render(GraphicsDevice GraphicsDevice) { foreach (Button button in buttons) { // Default placement bottom.Width = button.Bounds.Width; bottom.Height = 5; bottom.X = button.Bounds.X; bottom.Y = button.Bounds.Y + button.Bounds.Height - bottom.Height; body.Width = button.Bounds.Width; body.Height = button.Bounds.Height - bottom.Height; body.X = button.Bounds.X; body.Y = button.Bounds.Y; // Mouse is hovering over button if (button.Hover) { body.Color = new Color(152, 227, 227); bottom.Color = new Color(118, 188, 188); } else { body.Color = Color.LightGray; bottom.Color = Color.Silver; } // Mouse is being pressed if (button.Active) { body.Y = button.Bounds.Y + bottom.Height; } bottom.Render(GraphicsDevice); body.Render(GraphicsDevice); } #region Selected Outline vertices[0].Position = new Vector3( buttons[selectedButtonIndex].Bounds.X - outlineThickness, buttons[selectedButtonIndex].Bounds.Y - outlineThickness, 0); vertices[1].Position = new Vector3( buttons[selectedButtonIndex].Bounds.X - outlineThickness * 2, buttons[selectedButtonIndex].Bounds.Y - outlineThickness * 2, 0); vertices[2].Position = new Vector3( vertices[0].Position.X + buttons[selectedButtonIndex].Bounds.Width + outlineThickness * 2, vertices[0].Position.Y, 0); vertices[3].Position = new Vector3( vertices[2].Position.X + outlineThickness, vertices[2].Position.Y - outlineThickness, 0); vertices[4].Position = new Vector3( vertices[2].Position.X, vertices[2].Position.Y + buttons[selectedButtonIndex].Bounds.Height + outlineThickness * 2, 0); vertices[5].Position = new Vector3( vertices[4].Position.X + outlineThickness, vertices[4].Position.Y + outlineThickness, 0); vertices[6].Position = new Vector3( vertices[0].Position.X, vertices[0].Position.Y + buttons[selectedButtonIndex].Bounds.Height + outlineThickness * 2, 0); vertices[7].Position = new Vector3( vertices[6].Position.X - outlineThickness, vertices[6].Position.Y + outlineThickness, 0); // Tying the knot vertices[8].Position = vertices[0].Position; vertices[9].Position = vertices[1].Position; // Render Selected Outline GraphicsDevice.DrawUserPrimitives( PrimitiveType.TriangleStrip, vertices, 0, vertices.Length - 2); #endregion Selected Outline }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { // Needed before Render.Draw(); StaticGlobal.BasicEffect.ApplyCurrentTechnique(); // clear screen GraphicsDevice.Clear(Color.WhiteSmoke); if (Camera.SpectatingCell != null && !Camera.FreeCam) { Camera.Position = Vector2.Lerp(Camera.Position, Camera.SpectatingCell.Position, 0.125f); } RasterizerState rasterizerState; rasterizerState = new RasterizerState(); rasterizerState.FillMode = FillMode.Solid; GraphicsDevice.RasterizerState = rasterizerState; Render.Draw(StaticGlobal.CM, GraphicsDevice); spriteBatch.Begin(); spriteBatch.DrawString(spriteFont, debugMessage, new Vector2(10, 35), Color.Black); if (Camera.SpectatingCell != null && !Camera.FreeCam) { spriteBatch.DrawString(spriteFont, "About current Cell:", new Vector2(10, 80 - 20 * 1), Color.Black); spriteBatch.DrawString(spriteFont, "Energy: " + Math.Floor(Camera.SpectatingCell.Energy).ToString(), new Vector2(10, 80 + 20 * 0), Color.Black); spriteBatch.DrawString(spriteFont, "Family: " + Camera.SpectatingCell.AI.family.ToString(), new Vector2(10, 80 + 20 * 1), Color.Black); spriteBatch.DrawString(spriteFont, "FamilyCount: " + StaticGlobal.Family.FamilyCount(Camera.SpectatingCell.AI.family).ToString(), new Vector2(10, 80 + 20 * 2), Color.Black); spriteBatch.DrawString(spriteFont, "Memory: " + Camera.SpectatingCell.AI.lastMemory.ToString(), new Vector2(10, 80 + 20 * 3), Color.Black); spriteBatch.DrawString(spriteFont, "Points: " + Camera.SpectatingCell.AI.lastMemory.Points.ToString(), new Vector2(10, 80 + 20 * 4), Color.Black); } if (StaticGlobal.CM.Pause) { shadowRectangle.Width = Window.ClientBounds.Width; shadowRectangle.Height = Window.ClientBounds.Height; shadowRectangle.Render(GraphicsDevice); spriteBatch.DrawString(spriteFont, LORE, new Vector2(StaticGlobal.Screen.Area.Center.X - 239, StaticGlobal.Screen.Area.Center.Y - 74), Color.Black); debugRectangle.X = StaticGlobal.Screen.Area.Center.X - 239 - 6; debugRectangle.Y = StaticGlobal.Screen.Area.Center.Y - 74 - 6; debugRectangle.Render(GraphicsDevice); } if (StaticGlobal.CM.Pause) { spriteBatch.DrawString(spriteFont, "Press [Spacebar] to resume the simulation", new Vector2(10, 10 + 25 * 0), Color.White); spriteBatch.DrawString(spriteFont, "Use WASD to enter free-cam mode and move the Camera", new Vector2(10, 10 + 25 * 1), Color.White); spriteBatch.DrawString(spriteFont, "Press [F] to toggle between free-cam mode", new Vector2(10, 10 + 25 * 2), Color.White); spriteBatch.DrawString(spriteFont, "Press [Left Arrow] and [Right Arrow] to switch between which cell you're spectating", new Vector2(10, 10 + 25 * 3), Color.White); spriteBatch.DrawString(spriteFont, "Press [R] to restart the simulation", new Vector2(10, 10 + 25 * 4), Color.White); spriteBatch.DrawString(spriteFont, "Press [ESC] to quit the application", new Vector2(10, Window.ClientBounds.Height - 10 - 25 * 1), Color.White); spriteBatch.DrawString(spriteFont, "Press [Up Arrow] and [Down Arrow] or use [Scrollwheel] to zoom in and out in the simulation", new Vector2(10, Window.ClientBounds.Height - 10 - 25 * 2), Color.White); spriteBatch.DrawString(spriteFont, "Press [F11] to toggle between fullscreen mode and window mode", new Vector2(10, Window.ClientBounds.Height - 10 - 25 * 3), Color.White); } else { spriteBatch.DrawString(spriteFont, "Press [Spacebar] to pause the simulation, see controls, and read the lore", new Vector2(10, 10), Color.Black); } UIElementHandler.Render(GraphicsDevice); spriteBatch.End(); base.Draw(gameTime); }