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

namespace Slayter
{
    public class GameScreen: Screen
    {
        public Map Bground;
        public override Background BGROUND { get { return Bground; } }
        public GameScreen(Game1 game,String background,String csv)
            : base(game)
        {
            Bground = new Map(game.Content.Load<Texture2D>(background), new Rectangle(0, 0, 640, 480), csv,this);
            drawables.Add(Bground);
            clickables.Add(Bground);
            Bground.addForbidden(3);
            Bground.addForbidden(1);


            //Texture2D tab_background = game.Content.Load<Texture2D>("tab_background");
            Texture2D tab_background = game.Content.Load<Texture2D>("TabClear");


            Background tab_Object = new Background(tab_background, new Rectangle(0, 480, tab_background.Width, tab_background.Height));
            drawables.Add(tab_Object);

            Texture2D NewDayButton = game.Content.Load<Texture2D>("NextHero_button");
            Rectangle rect = new Rectangle(game.Window.ClientBounds.Width - NewDayButton.Width - 40, 515, NewDayButton.Width, NewDayButton.Height);
            ClickableObject button_ClickableObject = new ClickableObject(NewDayButton, rect, delegate(MouseState state, ClickableObject o) { if (!this.hero.heroIsMoving) { player.ChangeHero(); } });
            drawables.Add(button_ClickableObject);
            clickables.Add(button_ClickableObject);

            Texture2D NewDayButton2 = game.Content.Load<Texture2D>("FinishMove_button");
            Rectangle rect2= new Rectangle(rect.X, rect.Y+60, NewDayButton2.Width, NewDayButton2.Height);
            ClickableObject button_ClickableObject2 = new ClickableObject(NewDayButton2, rect2, delegate(MouseState state, ClickableObject o) { if (!this.hero.heroIsMoving) { hero.NewDay(); UpdateText(); } });
            drawables.Add(button_ClickableObject2);
            clickables.Add(button_ClickableObject2);

            MiniMap bg = new MiniMap(Bground,new Rectangle(30,505,160,120));
            drawables.Add(bg);
            clickables.Add(bg);

            Texture2D Frame = game.Content.Load<Texture2D>("frame");
            Background r = new Background(Frame,new Rectangle(3,482,Frame.Width,Frame.Height));
            drawables.Add(r);

            Texture2D InfoBox = game.Content.Load<Texture2D>("InfoBox");
            Background info = new Background(InfoBox, new Rectangle(230, 488, InfoBox.Width+55, InfoBox.Height+4));
            drawables.Add(info);

            moves = new Text(game.Content.Load<SpriteFont>("font"), "M: ", new Vector2(info.Rect.X+20, info.Rect.Y+10));
            gold = new Text(game.Content.Load<SpriteFont>("font"), "G: ", new Vector2(info.Rect.X+20, info.Rect.Y + 30));
            time = new Text(game.Content.Load<SpriteFont>("font"), "D: ", new Vector2(info.Rect.X+20, info.Rect.Y + 50));
        }

        public virtual void AddPlayer(Game1 game,Player player)
        {
            this.player = player;
            hero = player.currentHero;
            drawables.Add(player);
            drawables.Add(moves);
            drawables.Add(gold);
            drawables.Add(time);
            Bground.setHero(game,hero);
            UpdateText();
        }

        public virtual void changeHero()
        {
            hero = player.currentHero;
            Bground.setHero(parent, hero);
            UpdateText();
        }
            

        public void updateKeyboard(Game1 game,KeyboardState keyboard)
        {
            this.Bground.Move(game, keyboard);
        }

        public void addHeroToMap(Hero h)
        {
            Bground.addHeroOnMap(h); ;
        }

        public void RemoveHeroFromMap(Hero h)
        {
            Bground.removeHeroFromMap(h);
        }
    }
}
