/// <summary> Unit filtering logic. </summary> private void FilterUnits(object sender, FilterEventArgs e) { // If filters aren't supported, return everything if (UnitDetails == null || UnitDetails.Count() == 0) { e.Accepted = true; return; } // Look up character metadata var character = e.Item as string; var unit = UnitDetails.Where(u => u.name == character).FirstOrDefault(); if (unit == null) { e.Accepted = false; return; } // Apply selected filter switch (SelectedFilter) { // Handle generic filters case "All": e.Accepted = true; break; case "Light Side": e.Accepted = unit.forceAlignment == goh_ui.UnitDetails.ALIGNMENT_LIGHT; break; case "Dark Side": e.Accepted = unit.forceAlignment == goh_ui.UnitDetails.ALIGNMENT_DARK; break; // Handle tag-based filters default: e.Accepted = unit.categoryIdList.Contains(SelectedFilter); break; } }
/// <summary> Rebuild unit list. </summary> public void BuildUnitList() { if (Members == null) { Units = null; return; } Units = new ObservableCollection <string>(); // Use UnitDetails if available, since it can contain units not found // in any player's roster. if (UnitDetails != null && UnitDetails.Count() > 0) { foreach (var name in UnitDetails.Where(u => u.combatType == goh_ui.UnitDetails.COMBATTYPE_CHARACTER).Select(u => u.name).OrderBy(x => x)) { Units.Add(name); } return; } // If UnitDetails not available, derive a list by combining the members' rosters. var units = Members.Select(m => m.Roster.Where(u => u.combatType == goh_ui.UnitDetails.COMBATTYPE_CHARACTER) .Select(c => c.name)) // map each member to an array of unit names .SelectMany(x => x) // flatten list .Distinct() // de-duplicate .OrderBy(x => x); // sort alphabetically foreach (var unit in units) { Units.Add(unit); } }