/// <summary> /// Updates the "Entity Class" <see cref="ListView"/> with the current "Category" and /// "Filter" choices.</summary> /// <param name="select"> /// <c>true</c> to select the previously selected item, if any, or else the first item in /// the "Entity Class" <see cref="ListView"/>; <c>false</c> to not select any item.</param> private void UpdateClasses(bool select) { // remember selected item, if any BuildListItem selectedItem = null; if (select) { int index = ClassList.SelectedIndex; if (index >= 0) { selectedItem = (BuildListItem)ClassList.Items[index]; } } // clear Entity Class list view ClassList.Items.Clear(); // get all buildable classes for current category var classes = this._faction.GetBuildableClasses(CurrentCategory); // quit if no buildable classes if (classes == null || classes.Count == 0) { return; } // get current filter settings bool?showSite = SiteToggle.IsChecked; bool?showPlace = PlaceToggle.IsChecked; foreach (EntityClass entityClass in classes.Values) { // get all place targets for entity class IList <PointI> targets; this._classTargets.TryGetValue(entityClass.Id, out targets); // Site filter: skip classes without this place target if (showSite == true && (targets == null || !targets.Contains(this._selectedSite))) { continue; } // Can Place filter: skip classes with or without place targets if ((showPlace == true && targets == null) || (showPlace == false && targets != null)) { continue; } ClassList.Items.Add(new BuildListItem(entityClass)); } // show current & build counts ShowClassCounts(); // select remembered or first item, if any if (select && ClassList.Items.Count > 0) { if (selectedItem != null) { for (int i = 0; i < ClassList.Items.Count; i++) { var item = (BuildListItem)ClassList.Items[i]; if (item.EntityClass == selectedItem.EntityClass) { ClassList.SelectedIndex = i; ClassList.ScrollIntoView(item); break; } } } if (ClassList.SelectedIndex < 0) { ClassList.SelectedIndex = 0; } } }