using System; using System.Collections.Generic; using System.Net; using System.IO; using System.Threading; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace MrAG { public class Overlay { public class GamerServicesOverlayException : Exception{ public GamerServicesOverlayException(string msg): base(msg){ } } private class NoticeSystem { public class Popup { public byte MsgID = 0; public byte Icon; public string Title; public string Message; public short DisplayTime = 6000; public double ScrollInTime = 1500; private Texture2D PrevImg; private double CreateTime; public Popup(byte icon, string text){ Icon = icon; Title = ""; Message = text; CreateTime = DateTime.Now.TimeOfDay.TotalMilliseconds; } public Popup(byte icon, string title, string text){ Icon = icon; Title = title; Message = text; CreateTime = DateTime.Now.TimeOfDay.TotalMilliseconds; if (icon == 1) { PrevImg = Gamerservices.GetAvatar(title); } } public bool Draw(SpriteBatch sb, int y){ double restime = Math.Abs(DateTime.Now.TimeOfDay.TotalMilliseconds - CreateTime); if (restime > DisplayTime) return true; int x = 0; int alpha = 255; if (restime < DisplayTime - ScrollInTime + 1){ restime = Math.Min(restime, ScrollInTime); alpha = (int)Math.Min((restime / ScrollInTime) * 256.0, 256); x = WindowWidth - alpha; }else{ restime -= DisplayTime - ScrollInTime; alpha = (int)Math.Min((restime / ScrollInTime) * 256.0, 256); x = WindowWidth - 256 + alpha; alpha = 256 - alpha; } sb.Draw(NoticeTexture, new Rectangle(x - 10, y, 256, 56), new Color(255, 255, 255, alpha)); if (PrevImg != null) sb.Draw(PrevImg, new Rectangle(x - 7, y + 3, 50, 50), new Color(255, 255, 255, alpha)); sb.DrawString(NoticeFont_Title, Title, new Vector2(x + 50, y + 4), new Color(0, 0, 0, alpha)); sb.DrawString(NoticeFont_Text, Message, new Vector2(x + 50, y + 25), new Color(0, 0, 0, alpha)); return false; } } public static List Popups = new List(); } private static bool EnableNotices; private static SpriteFont NoticeFont_Title; private static SpriteFont NoticeFont_Text; private static Texture2D NoticeTexture; //private static Texture2D[] NoticeTypes; private static byte CurrentMessageID; public static Delegate OnNotice; public static int WindowWidth = 0; public static void LoadContent(Microsoft.Xna.Framework.Content.ContentManager man, string MrAGContentPath, int windowwidth){ try{ NoticeFont_Title = man.Load(MrAGContentPath + "/notice_title"); NoticeFont_Text = man.Load(MrAGContentPath + "/notice_text"); NoticeTexture = man.Load(MrAGContentPath + "/notice_background"); }catch{ throw new GamerServicesOverlayException("Could not find overlay files: " + man.RootDirectory + "/" + MrAGContentPath + "/notice_*****"); } WindowWidth = windowwidth; } public static void AddNotice(byte type, string title, string message){ NoticeSystem.Popups.Add(new NoticeSystem.Popup(type, title, message)); CurrentMessageID++; NoticeSystem.Popups[NoticeSystem.Popups.Count - 1].MsgID = CurrentMessageID; } public static void AddNotice(byte type, string message){ NoticeSystem.Popups.Add(new NoticeSystem.Popup(type, "", message)); CurrentMessageID++; NoticeSystem.Popups[NoticeSystem.Popups.Count - 1].MsgID = CurrentMessageID; } public static void InitilizeSystem(bool noticesenabled){ EnableNotices = noticesenabled; if (noticesenabled) NoticeSystem.Popups.Add(new NoticeSystem.Popup(0, "Notice", "Your now online.\nUse alt + ctrl + del for MrAG overlay")); } public static void Close(){ } public static void Draw(SpriteBatch sb){ lock (NoticeSystem.Popups){ for (int i = 0; i < NoticeSystem.Popups.Count; i++){ if (NoticeSystem.Popups[i].Draw(sb, 12 + (i * 68))){ NoticeSystem.Popups.RemoveAt(i); i--; } } } } } }