using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WTD_Editor
{
    public partial class ChooseTower : Form
    {
        public int selected;
        public int pal;
        private bool refresh;
        public bool dark;

        public ChooseTower(int sel, int pal, bool dark)
        {
            InitializeComponent();
            selected = sel;
            this.pal = pal;
            this.dark = dark;
            checkBox1.Checked = dark;
            refresh = false;
            string[] pall = Enum.GetNames(typeof(Map.T_PAL));
            comboBox1.DataSource = pall;
            comboBox1.Text = Enum.GetName(typeof(Map.T_PAL), pal);
            refresh = true;
            refreshTower();
        }

        private void ChooseTower_Load(object sender, EventArgs e)
        {
            
        }

        private void refreshTower()
        {
            Bitmap gfx = null;
            switch (pal)
            {
                case (int)Map.T_PAL.NORMAL:
                    gfx = WTD_Editor.Properties.Resources.t_all_normal;
                    break;
//                case (int)Map.T_PAL.DARK:
//                    gfx = WTD_Editor.Properties.Resources.t_all_dark;
//                    break;
                case (int)Map.T_PAL.FROZEN:
                    gfx = WTD_Editor.Properties.Resources.t_all_frozen;
                    break;
                case (int)Map.T_PAL.POISON:
                    gfx = WTD_Editor.Properties.Resources.t_all_poison;
                    break;
            }
            pictureBox1.Image = gfx;
            pictureBox1.Location = new Point(0, -32 * selected);
            pictureBox2.Image = gfx;
            pictureBox2.Location = new Point(0, 0);
            pictureBox3.Image = gfx;
            pictureBox3.Location = new Point(32, -256);
            pictureBox4.Image = gfx;
            pictureBox4.Location = new Point(64, -512);
            pictureBox5.Image = gfx;
            pictureBox5.Location = new Point(96, -768);
            pictureBox6.Image = gfx;
            pictureBox6.Location = new Point(128, -1024);
            pictureBox7.Image = gfx;
            pictureBox7.Location = new Point(160, -1280);
            pictureBox8.Image = gfx;
            pictureBox8.Location = new Point(192, -1536);
            pictureBox9.Image = gfx;
            pictureBox9.Location = new Point(224, -1792);
        
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (refresh)
            {
                pal = (int)Enum.Parse(typeof(Map.T_PAL), comboBox1.Text); ;
                refreshTower();
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            selected = ((this.PointToClient(Cursor.Position).Y - panel2.Location.Y) / 32) % Map.TOTAL_TOWERS;
            refreshTower();
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            selected = ((this.PointToClient(Cursor.Position).Y - panel2.Location.Y + 256) / 32) % Map.TOTAL_TOWERS;
            refreshTower();
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            selected = ((this.PointToClient(Cursor.Position).Y - panel2.Location.Y + 512) / 32) % Map.TOTAL_TOWERS;
            refreshTower();
        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            selected = ((this.PointToClient(Cursor.Position).Y - panel2.Location.Y + 768) / 32) % Map.TOTAL_TOWERS;
            refreshTower();

        }

        private void pictureBox6_Click(object sender, EventArgs e)
        {
            selected = ((this.PointToClient(Cursor.Position).Y - panel2.Location.Y + 1024) / 32) % Map.TOTAL_TOWERS;
            refreshTower();
        }

        private void pictureBox7_Click(object sender, EventArgs e)
        {
            selected = ((this.PointToClient(Cursor.Position).Y - panel2.Location.Y + 1280) / 32) % Map.TOTAL_TOWERS;
            refreshTower();
        }

        private void pictureBox8_Click(object sender, EventArgs e)
        {
            selected = ((this.PointToClient(Cursor.Position).Y - panel2.Location.Y + 1536) / 32) % Map.TOTAL_TOWERS;
            refreshTower();
        }

        private void pictureBox9_Click(object sender, EventArgs e)
        {
            selected = ((this.PointToClient(Cursor.Position).Y - panel2.Location.Y + 1792) / 32) % Map.TOTAL_TOWERS;
            refreshTower();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            dark = checkBox1.Checked;

            // TODO : display the dark variation

        }

    }
}