public Generate(Build bb) { InitializeComponent(); if (Main.config.AppSettings.Settings.AllKeys.Contains("locktest")) bool.TryParse(Main.config.AppSettings.Settings["locktest"].Value, out noLocked); if (Main.config.AppSettings.Settings.AllKeys.Contains("testgray")) bool.TryParse(Main.config.AppSettings.Settings["testgray"].Value, out grayLocked); if (Main.config.AppSettings.Settings.AllKeys.Contains("testGen")) int.TryParse(Main.config.AppSettings.Settings["testGen"].Value, out buildsGen); if (Main.config.AppSettings.Settings.AllKeys.Contains("testShow")) int.TryParse(Main.config.AppSettings.Settings["testShow"].Value, out buildsShow); // master has given Gener a Build? build = bb; Label label = null; TextBox textBox = null; // cool clicky thing var sorter = new ListViewSort(); // sort decending on POINTS sorter.OnColumnClick(0, false); listView1.ListViewItemSorter = sorter; // place controls in a nice grid-like manner int x, y; y = 20; foreach (string stat in statNames) { x = 25; label = new Label(); label.Name = stat + "Label"; label.Location = new Point(x, y); label.Size = new Size(40, 20); label.Text = stat; groupBox1.Controls.Add(label); x += 45; textBox = new TextBox(); textBox.Name = stat + "Worth"; textBox.Location = new Point(x, y); textBox.Size = new Size(40, 20); if (build.Sort[stat] != 0) textBox.Text = build.Sort[stat].ToString(); textBox.TextChanged += textBox_TextChanged; groupBox1.Controls.Add(textBox); y += 22; listView1.Columns.Add(stat).Width = 80; } foreach (string extra in extraNames) { x = 25; label = new Label(); label.Name = extra + "Label"; label.Location = new Point(x, y); label.Size = new Size(40, 20); label.Text = extra; groupBox1.Controls.Add(label); x += 45; textBox = new TextBox(); textBox.Name = extra + "Worth"; textBox.Location = new Point(x, y); textBox.Size = new Size(40, 20); if (build.Sort.ExtraGet(extra) != 0) textBox.Text = build.Sort.ExtraGet(extra).ToString(); textBox.TextChanged += textBox_TextChanged; groupBox1.Controls.Add(textBox); y += 22; listView1.Columns.Add(extra).Width = 80; } toolStripStatusLabel1.Text = "Generating..."; building = true; toolStripProgressBar1.Maximum = buildsShow * 2; Task.Factory.StartNew(() => { // Allow the window to draw before destroying the CPU Thread.Sleep(100); // Disregard locked, but honor equippedness checking build.GenRunes(Main.data, noLocked, Main.useEquipped); // generate 5000 builds build.GenBuilds(buildsGen, 0, (s) => { }, (d) => { Invoke((MethodInvoker)delegate { toolStripProgressBar1.Value = (int)(d * buildsShow); }); }); if (build.loads == null) { toolStripStatusLabel1.Text = "Error: no builds"; return; } int num = 0; var takenLoads = build.loads.Take(buildsShow); int tbuilds = takenLoads.Count(); // pick the top 100 // Believe it or not, putting 100 into the list takes a *lot* longer than making 5000 foreach (var b in takenLoads) { ListViewItem li = new ListViewItem(); var Cur = b.GetStats(); double pts = GetPoints(Cur, (str, i)=> { li.SubItems.Add(str); }); // put the sum points into the first item li.SubItems[0].Text = pts.ToString("0.##"); li.Tag = b; if (grayLocked && b.Current.runes.Any(r => r.Locked)) li.ForeColor = Color.Gray; Invoke((MethodInvoker)delegate { // put the thing in on the main thread and bump the progress bar listView1.Items.Add(li); num++; toolStripProgressBar1.Value = buildsShow + (int)(buildsShow * num / (double)tbuilds); }); } Invoke((MethodInvoker)delegate { toolStripStatusLabel1.Text = "Generated " + listView1.Items.Count + " builds"; building = false; }); }); }