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 Core; using Azimuth; namespace UI.Winforms.Prsn828 { public partial class Settings : Form { public Species chosen; public List TheSpecies { get { List temp = new List(); foreach (SpeciesItem s in SpeciesList.Items) { temp.Add(s.species); } return temp; } set { SpeciesList.Items.Clear(); foreach (Species s in value) { SpeciesList.Items.Add(new SpeciesItem(s)); } } } public Scalar TheHeight { get { return Double.Parse(HeightText.Text); } set { HeightText.Text = value + ""; } } public Scalar TheWidth { get { return Double.Parse(WidthText.Text); } set { WidthText.Text = value + ""; } } public Settings() { InitializeComponent(); chosen = new Species("."); TheHeight = 400; TheWidth = 400; } private void SpeciesChooser_FileOk(object sender, CancelEventArgs e) { } private void AddSpecies_Click(object sender, EventArgs e) { OpenSpecies.ShowDialog(); foreach(string s in OpenSpecies.FileNames) SpeciesList.Items.Add(new SpeciesItem(s)); } protected class SpeciesItem : ListViewItem { public Species species { get; protected set; } public SpeciesItem(string FileName) : base() { species = new Species(FileName); Text = species.Name; } public SpeciesItem(Species s) : base() { species = s; Text = species.Name; } } private void MutationMultiplier_Scroll(object sender, EventArgs e) { } private void RemoveSpecies_Click(object sender, EventArgs e) { foreach (SpeciesItem item in SpeciesList.Items) { if (item.Selected) { item.Remove(); } } } private void SelectAll_Click(object sender, EventArgs e) { foreach (SpeciesItem item in SpeciesList.Items) { item.Selected = true; } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void SpeciesName_Click(object sender, EventArgs e) { } private void SpeciesList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { chosen = ((SpeciesItem)(e.Item)).species; SpeciesProperties.SetItemChecked(0, chosen.IsVegitable); SpeciesProperties.SetItemChecked(1, chosen.DisableMutation); SpeciesProperties.SetItemChecked(2, chosen.DisableVoluntaryMotion); SpeciesProperties.SetItemChecked(3, chosen.DisableDNAExecution); SpeciesProperties.SetItemChecked(4, chosen.DisableVision); SpeciesProperties.SetItemChecked(5, chosen.DisableAsexualReproduction); SpeciesProperties.SetItemChecked(6, chosen.DisableSexualReproduction); PopulationChooser.Value = chosen.InitialPopulation; EnergyChooser.Value = chosen.InitialEnergy; } private void SpeciesProperties_ItemCheck(object sender, ItemCheckEventArgs e) { switch (e.Index) { case(0): chosen.IsVegitable = e.NewValue.Equals(CheckState.Checked); break; case (1): chosen.DisableMutation = e.NewValue.Equals(CheckState.Checked); break; case (2): chosen.DisableVoluntaryMotion = e.NewValue.Equals(CheckState.Checked); break; case (3): chosen.DisableDNAExecution = e.NewValue.Equals(CheckState.Checked); break; case (4): chosen.DisableVision = e.NewValue.Equals(CheckState.Checked); break; case (5): chosen.DisableAsexualReproduction = e.NewValue.Equals(CheckState.Checked); break; case (6): chosen.DisableSexualReproduction = e.NewValue.Equals(CheckState.Checked); break; } } private void PopulationChooser_ValueChanged(object sender, EventArgs e) { chosen.InitialPopulation = (int)PopulationChooser.Value; } private void EnergyChooser_ValueChanged(object sender, EventArgs e) { chosen.InitialEnergy = (int)EnergyChooser.Value; } private void ChooseColor_Click(object sender, EventArgs e) { SpeciesColorChooser.ShowDialog(); Color c = SpeciesColorChooser.Color; chosen.SpeciesColor = new Microsoft.Xna.Framework.Graphics.Color(c.R, c.G, c.B, c.A); } private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e) { } private void SpeciesMutations_Click(object sender, EventArgs e) { SpeciesMutationSettings m = new SpeciesMutationSettings(ref chosen); m.Show(); } private void asNewToolStripMenuItem_Click(object sender, EventArgs e) { SaveSettings.ShowDialog(); getSettings().Save(SaveSettings.FileName); } private void loadToolStripMenuItem_Click(object sender, EventArgs e) { LoadSettings.ShowDialog(); Core.Settings set = new Core.Settings(); set.Load(LoadSettings.FileName); setup(set); } private void setup(Core.Settings set) { TheHeight = set.Height; TheWidth = set.Width; TheSpecies = set.Species; } public Core.Settings getSettings() { Core.Settings set = new Core.Settings(); set.Height = TheHeight; set.Width = TheWidth; set.Species = TheSpecies; return set; } } }