﻿using System.Collections.Generic;
using System.Linq;
using SFML.Graphics;

namespace GuiTestingCon.GUI
{
    public class Credits : ScreenObject
    {
        private Button Bnlogin;

        public Credits(ScreenManager sm, int x, int y, int width, int height)
        {
            ScreenRect = new System.Drawing.Rectangle(x, y, width, height);
            Screen = sm;
            Position = new Vector2(x, y);
            Draggable = false;

            Images.Add("Background", new Image("Images/Gui/Background/creditsbg.png"));
            sprite = new Sprite(Images["Background"]);

            Initialize();
        }

        private void Initialize()
        {
            Bnlogin = new Button(this, 5, 535, 140, 59, "Back", "Backhov", "Backclick", 1);

            Bnlogin.OnClick += new Button.OnClickEvent(Bnlogin_OnClick);

            AddControl(Bnlogin);

            Screen.AddScreen("CreditPanel", this);
            Screen.ChangeFocus(this);
        }

        public void Bnlogin_OnClick()
        {
            this.Images["Background"].Dispose();
            this.sprite.Dispose();
            Screen.RemoveScreen(this);
            var l = new MainMenu(Screen, 0, 0, 800, 600);
        }

        public override void Draw()
        {
            sprite.Position = Position;
            Screen.Window.Draw(sprite);

            foreach (KeyValuePair<string, GuiObject> kvp in Controls)
            {
                if (kvp.Value.Visible == true)
                {
                    kvp.Value.Draw();
                }
            }
        }

        public override void MouseButtonPressed(object sender, SFML.Window.MouseButtonEventArgs e)
        {
            foreach (KeyValuePair<string, GuiObject> kvp in Controls.ToList())
            {
                if (Screen.IsMouseOver(kvp.Value.ScreenRect))
                {
                    kvp.Value.MouseButtonPressed(sender, e);
                }
            }
        }
    }
}