using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using System.Drawing;
using Microsoft.DirectX.Direct3D;

namespace Obligatorisk
{
    public class Model
    {
        private Engine theEngine;
        private List<Keys> pressedKeys;
        private Ground ground;

        #region  3D-models (Frank & Kasper) 2. Maj
        private Car theCar;
        #region Car Property
        public Car TheCar
        {
            get { return theCar; }
            //set { theCar = value; }
        }
        #endregion

        List<ModelComponent> modelList;
        #region modelList Property
        public List<ModelComponent> ModelList
        {
            get { return modelList; }
            //set { modelList = value; }
        }
        #endregion

        //#region 3D-model Car (Morten) 27. April.
        //private Car AudiA4;
        //#endregion
        //#region  3D-models (Jon) 20. april
        //private Airtower airtower;
        //private Airtower airtower_2;
        //private Airtower airtower_3;
        //private Airtower airtower_4;

        //private Comtower comtower;
        //private Comtower comtower_2;
        //private Comtower comtower_3;
        //private Comtower comtower_4;

        //private House house;
        //private House house_2;
        //private House house_3;
        //private House house_4;
        //#endregion
        #endregion

        public Model(Engine anEngine)
        {
            theEngine = anEngine;
            this.pressedKeys = new List<Keys>();
            this.ground = new Ground(this.theEngine.GetDevice());
            #region  3D-models (Frank & Kasper) 2. Maj

            this.modelList = new List<ModelComponent>();


            // TODO: load from file....
            // FileLoadCreaterClass ting kunne være en løsning?
            // switch på object type, opret object med de korrekte parmetre, return object
            

            // MODELS SKAL OPDATERES SÅ DE STÅR PÅ DERES WORLD KOORDINAT FOR POKKER DA, DELETANTER!
            #region Car
            this.theCar = new Car(this, this.theEngine.GetDevice(), new Vector3(5, 0, 0));
            this.modelList.Add(this.theCar);
            #endregion

            #region Buildings
            // Absurt lag i det alle objekter bliver enabled.
            // Ved ikke om det er fordi den rendere noget der ikke kan ses, og derved er unødvendigt at renderer.
            this.modelList.Add(new Airtower(this, theEngine.GetDevice(), new Vector3(20, 0, 0)));
            //this.modelList.Add(new Airtower(this, theEngine.GetDevice(), new Vector3(30, 0, 0)));
            //this.modelList.Add(new Airtower(this, theEngine.GetDevice(), new Vector3(20, 0, 20)));
            //this.modelList.Add(new Airtower(this, theEngine.GetDevice(), new Vector3(80, 0, 6)));

            this.modelList.Add(new Comtower(this, theEngine.GetDevice(), new Vector3(60, 0, 0)));
            this.modelList.Add(new Comtower(this, theEngine.GetDevice(), new Vector3(60, 0, 30)));
            //this.modelList.Add(new Comtower(this, theEngine.GetDevice(), new Vector3(-20, 0, 70)));
            //this.modelList.Add(new Comtower(this, theEngine.GetDevice(), new Vector3(40, 0, 50)));

            this.modelList.Add(new House(this, theEngine.GetDevice(), new Vector3(120, 0, 0)));
            //this.modelList.Add(new House(this, theEngine.GetDevice(), new Vector3(-70, 0, 35)));
            //this.modelList.Add(new House(this, theEngine.GetDevice(), new Vector3(30, 0, 50)));
            //this.modelList.Add(new House(this, theEngine.GetDevice(), new Vector3(20, 0, 90)));
            #endregion
            


            //#region 3D-model Car (Morten) 27. April.
            //this.AudiA4 = new Car(this, this.theEngine.GetDevice(), new Vector3(5,0,0));
            //#endregion
            //#region  3D-models  (Jon) 20. april
            //airtower = new Airtower(this, theEngine.GetDevice(), new Vector3(30, 0, 0));
            //airtower_2 = new Airtower(this, theEngine.GetDevice(), new Vector3(-40, 0, 0));
            //airtower_3 = new Airtower(this, theEngine.GetDevice(), new Vector3(-90, 0, 20));
            //airtower_4 = new Airtower(this, theEngine.GetDevice(), new Vector3(80, 0, 6));

            //comtower = new Comtower(this, theEngine.GetDevice(), new Vector3(60, 0, 0));
            //comtower_2 = new Comtower(this, theEngine.GetDevice(), new Vector3(60, 0, 30));
            //comtower_3 = new Comtower(this, theEngine.GetDevice(), new Vector3(-20, 0, 70));
            //comtower_4 = new Comtower(this, theEngine.GetDevice(), new Vector3(40, 0, 50));

            //house = new House(this, theEngine.GetDevice(), new Vector3(-10, 0, 50));
            //house_2 = new House(this, theEngine.GetDevice(), new Vector3(-70, 0, 35));
            //house_3 = new House(this, theEngine.GetDevice(), new Vector3(30, 0, 50));
            //house_4 = new House(this, theEngine.GetDevice(), new Vector3(20, 0, 90));
            //#endregion
            #endregion
        }

        public void Render()
        {
            ground.Render();
            #region  3D-models (Frank & Kasper) 2. Maj
            foreach (ModelComponent model in this.modelList)
            {
                model.Render();
            }
            //#region 3D-model Car (Morten) 27. April.
            //AudiA4.Render();
            //#endregion        
            //#region  3D-models  (Jon) 20. april
            //airtower.Render();
            //airtower_2.Render();
            //airtower_3.Render();
            //airtower_4.Render();
            //comtower.Render();
            //comtower_2.Render();
            //comtower_3.Render();
            //comtower_4.Render();
            //house.Render();
            //house_2.Render();
            //house_3.Render();
            //house_4.Render();
            //#endregion
            #endregion
        }

        public void UpdateModel()
        {
            #region  3D-models (Frank & Kasper) 2. Maj
            foreach (ModelComponent model in this.modelList)
            {
                model.Update();
            }
            #endregion
            //AudiA4.Update();
        }
        
        public List<Keys> PressedKeys
        {
            set { this.pressedKeys = value; }
            get { return this.pressedKeys; }
        }
    }
}
