using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Penguloon.Scenes; using System; namespace Penguloon.Controls { public static class Alert { static Texture2D background; private static bool active = false; private static float posY = 0f; private static string text_; private const int maxY = 50; private const int speed = 3000; private static float posX = 0; private static SceneBase scene_; private static bool movingUp = false; private static bool bottomReached = false; private static DateTime bottomReachedTime; private static int displayTimeMS_ = 0; private static SpriteFont font; public static void Show(string text, int displayTimeMS, SceneBase scene) { text_ = text; scene_ = scene; displayTimeMS_ = displayTimeMS; font = ContentManager.GetFont(StaticUIValues.MenuFont); posX = (StaticUIValues.ScreenViewport.X / 2) - (StaticUIValues.AlertSize.X / 2); background = ContentManager.GetTexture("UI/alertBackground"); posY = -StaticUIValues.AlertSize.Y; active = true; } public static void Draw(float deltaTime) { if (!active) return; scene_.Main.SpriteBatch.Draw(background, destinationRectangle: new Microsoft.Xna.Framework.Rectangle((int)posX, (int)posY, (int)StaticUIValues.AlertSize.X, (int)StaticUIValues.AlertSize.Y)); scene_.DrawText(font, text_, new Vector2(posX, posY), StaticUIValues.AlertSize, TextAllignment.CenterMiddle, Color.White, Color.Black, 2); } public static void Update(float deltaTime) { if (!active) return; if (movingUp) { posY -= (speed * deltaTime); // we done here if (posY < -StaticUIValues.AlertSize.Y) { movingUp = false; bottomReached = false; active = false; } return; } if (bottomReached) { if ((DateTime.Now - bottomReachedTime).TotalMilliseconds > displayTimeMS_) { movingUp = true; } return; } if (posY < maxY) { posY += (speed * deltaTime); } else { bottomReachedTime = DateTime.Now; bottomReached = true; } } } }