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 ChooseSize : Form
    {
        public int width;
        public int height;

        public ChooseSize(int width, int height)
        {
            InitializeComponent();
            this.width = width;
            this.height = height;
            textBox1.Text = width.ToString();
            textBox2.Text = height.ToString();
        }

        private void ChooseSize_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                int num = int.Parse(textBox1.Text);
                if (num >= 0 && num <= Map.MAP_WIDTH_MAX)
                {
                    width = num;
                }
                else if (num > Map.MAP_WIDTH_MAX)
                {
                    width = Map.MAP_WIDTH_MAX;
                }
                textBox1.Text = width.ToString();
            }
            catch (Exception)
            {
                textBox1.Text = width.ToString();
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            try
            {
                int num = int.Parse(textBox2.Text);
                if (num >= 0 && num <= Map.MAP_HEIGHT_MAX)
                {
                    height = num;
                }
                else if (num > Map.MAP_HEIGHT_MAX)
                {
                    height = Map.MAP_WIDTH_MAX;
                }
                textBox2.Text = height.ToString();
            }
            catch (Exception)
            {
                textBox2.Text = height.ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool error = false;
            try
            {
                int num = int.Parse(textBox1.Text);
                if (num < 16)
                {
                    width = 16;
                    error = true;
                }
                textBox1.Text = width.ToString();
            }
            catch (Exception)
            {
                textBox1.Text = width.ToString();
            }

            try
            {
                int num = int.Parse(textBox2.Text);
                if (num < 16)
                {
                    height = 16;
                    error = true;
                }
                textBox2.Text = height.ToString();
            }
            catch (Exception)
            {
                textBox2.Text = height.ToString();
            }

            if (error)
                MessageBox.Show("Minimum value for width & height is 16.", "Error");
        }
    }
}