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

namespace Sentience
{
    public partial class FormOptions: Form
    {
        public FormOptions()
        {
            InitializeComponent();

            Settings = Properties.Settings.Default;

            LoadSettings();
        }

        Properties.Settings Settings;

        private void LoadSettings()
        {
            chkShowConsole.Checked = Settings.ShowConsole;
            chkBlockLabels.Checked = Settings.ShowBlockLabels;
            chkFixErrors.Checked = Settings.FixPathErrors;

            cmbHeuristic.Items.Clear();

            String[] heuristicNames = Enum.GetNames(typeof(Heuristics));

            for (int i = 0; i < heuristicNames.Length; i++)
                cmbHeuristic.Items.Add(heuristicNames[i]);

            cmbHeuristic.SelectedIndex = (int)Settings.Heuristic;

            numConnDistance.Value = (decimal)Settings.ConnectionDistance;
            numViewDistance.Value = (decimal)Settings.ViewDistance;
            numMovementSpeed.Maximum = Defaults.MaxMovementSpeed - 1;
            numMovementSpeed.Value = (decimal)Settings.MovementSpeed;

            chkBlockTeamComm.Checked = Settings.BlockTeamCommunication;
        }

        private void ApplySettings()
        {
            Settings.ShowConsole = chkShowConsole.Checked;
            Settings.ShowBlockLabels = chkBlockLabels.Checked;
            Settings.FixPathErrors = chkFixErrors.Checked;

            Settings.Heuristic = (Heuristics)Enum.Parse(typeof(Heuristics), cmbHeuristic.SelectedItem.ToString());

            Settings.ConnectionDistance = (float)numConnDistance.Value;
            Settings.ViewDistance = (float)numViewDistance.Value;
            Settings.MovementSpeed = (int)numMovementSpeed.Value;

            Settings.BlockTeamCommunication = chkBlockTeamComm.Checked;

            Settings.Save();
        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            ApplySettings();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            ApplySettings();
        }
    }
}
