using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using CodeImp.DoomBuilder.Config; using CodeImp.DoomBuilder.Editing; using CodeImp.DoomBuilder.Geometry; using CodeImp.DoomBuilder.Map; using CodeImp.DoomBuilder.Windows; namespace CodeImp.DoomBuilder.GZBuilder.Windows { public partial class ThingStatisticsForm : DelayedForm { private static Size size = Size.Empty; private static Point location = Point.Empty; public ThingStatisticsForm() { InitializeComponent(); //apply window size and location if (!size.IsEmpty && !location.IsEmpty) { this.StartPosition = FormStartPosition.Manual; this.Size = size; this.Location = location; } setup(); } private void setup() { Dictionary thingcounts = new Dictionary(); Dictionary thingtitles = new Dictionary(); Dictionary thingclasses = new Dictionary(); dataGridView.Rows.Clear(); foreach(ThingTypeInfo ti in General.Map.Data.ThingTypes) { thingcounts.Add(ti.Index, 0); thingtitles.Add(ti.Index, ti.Title); thingclasses.Add(ti.Index, ti.ClassName); } foreach(Thing t in General.Map.Map.Things) { if (thingcounts.ContainsKey(t.Type)) { thingcounts[t.Type]++; } else { thingcounts.Add(t.Type, 1); thingtitles.Add(t.Type, "Unknown thing"); thingclasses.Add(t.Type, "-"); } } //add rows foreach (KeyValuePair group in thingcounts) { if (hideUnused.Checked && group.Value == 0) continue; DataGridViewRow row = new DataGridViewRow(); row.Cells.Add(new DataGridViewTextBoxCell { Value = group.Key }); //type row.Cells.Add(new DataGridViewTextBoxCell { Value = thingtitles[group.Key] }); //title row.Cells.Add(new DataGridViewTextBoxCell { Value = thingclasses[group.Key] }); //class row.Cells.Add(new DataGridViewTextBoxCell { Value = group.Value }); //count dataGridView.Rows.Add(row); } dataGridView.Sort(ThingType, ListSortDirection.Ascending); } private static List getThingsByType(int type) { List list = new List(); foreach (Thing t in General.Map.Map.Things) { if (t.Type == type) list.Add(t); } return list; } private static void showSelection(List points) { RectangleF area = MapSet.CreateEmptyArea(); // Make a view area from the points foreach (Vector2D p in points) area = MapSet.IncreaseArea(area, p); // Make the area square, using the largest side if (area.Width > area.Height) { float delta = area.Width - area.Height; area.Y -= delta * 0.5f; area.Height += delta; } else { float delta = area.Height - area.Width; area.X -= delta * 0.5f; area.Width += delta; } // Add padding area.Inflate(100f, 100f); // Zoom to area ClassicMode editmode = (General.Editing.Mode as ClassicMode); editmode.CenterOnArea(area, 0.6f); } private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex == -1) return; if (e.Button == MouseButtons.Left) { //select List list = getThingsByType((int)dataGridView.Rows[e.RowIndex].Cells[0].Value); if (list.Count > 0) { General.Map.Map.ClearSelectedThings(); List points = new List(); foreach (Thing t in list) { t.Selected = true; Vector2D p = t.Position; points.Add(p); points.Add(p + new Vector2D(t.Size * 2.0f, t.Size * 2.0f)); points.Add(p + new Vector2D(t.Size * 2.0f, -t.Size * 2.0f)); points.Add(p + new Vector2D(-t.Size * 2.0f, t.Size * 2.0f)); points.Add(p + new Vector2D(-t.Size * 2.0f, -t.Size * 2.0f)); } General.Map.Map.Update(); General.Editing.ChangeMode("ThingsMode"); showSelection(points); } } else if (e.Button == MouseButtons.Right) { //edit List list = getThingsByType((int)dataGridView.Rows[e.RowIndex].Cells[0].Value); if (list.Count > 0) { General.MainWindow.ShowEditThings(list); General.Map.Map.Update(); setup(); } } } private void hideUnused_CheckedChanged(object sender, EventArgs e) { setup(); } private void apply_Click(object sender, EventArgs e) { this.Close(); } private void ThingStatisticsForm_FormClosing(object sender, FormClosingEventArgs e) { size = this.Size; location = this.Location; } } }