using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FarseerXNADemo3.Screens
{
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using FarseerXNABase.ScreenSystem;
using Microsoft.Xna.Framework.Input;
using FarseerXNABase.Controls;
public class HighScoreScreen : GameScreen
{
#region Properties & Variables
private ContentManager _content;
private Rectangle _viewport;
private Texture2D _background;
private ScrollingPanelControl pnl;
#endregion
#region Initialization and Load
public HighScoreScreen()
{
TransitionOnTime = TimeSpan.FromSeconds(0.5);
TransitionOffTime = TimeSpan.FromSeconds(0.5);
this.EnabledGestures = ScrollTracker.GesturesNeeded;
}
public override void LoadContent()
{
if (_content == null)
_content = new ContentManager(ScreenManager.Game.Services, "Content");
_background = ScreenManager.ContentManager.Load<Texture2D>("texture");
UpdateScreen();
ScreenManager.Camera.ProjectionUpdated += UpdateScreen;
//Add Header
Color ForegroundColor = new Color(0, 128, 192);
pnl = new ScrollingPanelControl();
int i = 10;
pnl.AddChild(new TextControl("HIGHSCORE", ScreenManager.SpriteFonts.GameSpriteFont, ForegroundColor,
new Vector2(_viewport.Width / 2 - ScreenManager.SpriteFonts.GameSpriteFont.MeasureString("HIGHSCORE").X / 2, i)));
i += 60;
//Add Titles
pnl.AddChild(new TextControl("PLAYER", ScreenManager.SpriteFonts.GameSpriteMediumFont, ForegroundColor, new Vector2(30, i)));
pnl.AddChild(new TextControl("SCORE", ScreenManager.SpriteFonts.GameSpriteMediumFont, ForegroundColor, new Vector2(200, i)));
pnl.AddChild(new TextControl("DATE", ScreenManager.SpriteFonts.GameSpriteMediumFont, ForegroundColor, new Vector2(400, i)));
i += 45;
//Add Random scores
Random r = new Random();
for (int j = 0; j < 50; j++)
{
pnl.AddChild(new TextControl(j.ToString(), ScreenManager.SpriteFonts.GameSpriteMediumFont, ForegroundColor, new Vector2(30, i)));
pnl.AddChild(new TextControl(r.Next(10000, 99999).ToString(), ScreenManager.SpriteFonts.GameSpriteMediumFont, ForegroundColor, new Vector2(200, i)));
pnl.AddChild(new TextControl(DateTime.Now.Subtract(TimeSpan.FromDays(r.Next(1, 30))).ToString("dd MMM yyyy HH:MM"), ScreenManager.SpriteFonts.GameSpriteMediumFont, ForegroundColor, new Vector2(400, i)));
i += 30;
}
base.LoadContent();
}
public override void UnloadContent()
{
_content.Unload();
}
private void UpdateScreen()
{
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
_viewport = new Rectangle(0, 0, viewport.Width, viewport.Height);
}
#endregion
#region Game Methods
public override void HandleInput(InputHelper input)
{
pnl.HandleInput(input);
base.HandleInput(input);
}
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
{
// Allows popup to be closed by back button
if (this.IsActive && GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
{
this.ExitScreen();
}
pnl.Update(gameTime);
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
}
public override void Draw(GameTime gameTime)
{
ScreenManager.SpriteBatch.Begin();
ScreenManager.SpriteBatch.Draw(_background, _viewport, Color.White);
ScreenManager.SpriteBatch.End();
Control.BatchDraw(pnl, ScreenManager.GraphicsDevice, ScreenManager.SpriteBatch, Vector2.Zero, gameTime);
}
#endregion
}
}