using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GhostArena6
{
    class HighScoreScreen : GameScreen
    {
        private HighScoreList _list;
        private SpriteFont _titleFont;
        private Texture2D _buttonB;

        public HighScoreScreen()
        {
            //load high score list
            _list = new HighScoreList();

            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }

        public override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                _titleFont = ScreenManager.Content.Load<SpriteFont>("Content/scorestitle");
                _buttonB = ScreenManager.Content.Load<Texture2D>("Content/ButtonB");
            }

            base.LoadGraphicsContent(loadAllContent);
        }

        public override void HandleInput(InputState input, GameTime gameTime)
        {
            if (input.CurrentGamePadState.Buttons.B == Microsoft.Xna.Framework.Input.ButtonState.Pressed && input.LastGamePadState.Buttons.B == Microsoft.Xna.Framework.Input.ButtonState.Released)
                this.ExitScreen();

            base.HandleInput(input, gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            Vector2 textPosition;

            ScreenManager.GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 0, 0);

            Color color = new Color(0, 255, 0, TransitionAlpha);

            ScreenManager.SpriteBatch.Begin();

            //draw title
            Vector2 titleSize = _titleFont.MeasureString("High Scores");
            textPosition = new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2 - titleSize.X / 2, 5);

            ScreenManager.SpriteBatch.DrawString(_titleFont, "High Scores", textPosition, color);

            color = new Color(255, 255, 255, TransitionAlpha);

            //draw header
            textPosition = new Vector2(50, 100);
            ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, "Date", textPosition, color);
            ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, "Score", textPosition + new Vector2(250,0), color);
            ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, "Level", textPosition + new Vector2(400, 0), color);

            int count = 0;

            //loop through list and draw each item
            foreach (HighScore item in _list.Scores)
            {
                textPosition = new Vector2(50, 150 + 50 * count);

                ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, item.Date, textPosition, color);
                ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, item.Score.ToString(), textPosition + new Vector2(250, 0), color);
                ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, item.Level.ToString(), textPosition + new Vector2(400, 0), color);

                count++;
            }

            ScreenManager.SpriteBatch.Draw(_buttonB, new Rectangle(800, 700, 48, 48), Color.White);
            ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, "Back", new Vector2(855, 700), Color.White);

            ScreenManager.SpriteBatch.End();

            if (TransitionPosition > 0)
                ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
        }
    }
}
