private void fetchButton_Click(object sender, RoutedEventArgs e) { dfConnection.ConnectAndFetch(); if (dfConnection.unitList != null) { UnitList.Clear(); for (int i = 0; i < dfConnection.unitList.creature_list.Count; i++) { RemoteFortressReader.UnitDefinition unit = dfConnection.unitList.creature_list[i]; Creature listedCreature = new Creature(); listedCreature.Index = i; listedCreature.unitDefinition = unit; if ((listedCreature.flags1 & UnitFlags.UnitFlags1.dead) == UnitFlags.UnitFlags1.dead) { continue; } if ((listedCreature.flags1 & UnitFlags.UnitFlags1.forest) == UnitFlags.UnitFlags1.forest) { continue; } UnitList.Add(listedCreature); } CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(unitListView.ItemsSource); view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); view.SortDescriptions.Add(new SortDescription("Race", ListSortDirection.Ascending)); view.Filter = UnitlistFilter; } if (DFConnection.creatureRawList != null) { RaceList.Clear(); for (int raceIndex = 0; raceIndex < DFConnection.creatureRawList.creature_raws.Count; raceIndex++) { var raceRaw = DFConnection.creatureRawList.creature_raws[raceIndex]; for (int casteIndex = 0; casteIndex < raceRaw.caste.Count; casteIndex++) { var casteRaw = raceRaw.caste[casteIndex]; RemoteFortressReader.UnitDefinition fakeUnit = new RemoteFortressReader.UnitDefinition(); fakeUnit.race = new RemoteFortressReader.MatPair() { mat_type = raceIndex, mat_index = casteIndex }; string name = casteRaw.caste_name[0]; switch (casteRaw.gender) { case 0: name += " ♀"; break; case 1: name += " ♂"; break; //case -1: // name += " ⚪"; // break; default: break; } name = TI.ToTitleCase(name); fakeUnit.name = name; Creature fakeCreature = new Creature() { unitDefinition = fakeUnit }; RaceList.Add(fakeCreature); } } CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(raceListView.ItemsSource); view.SortDescriptions.Add(new SortDescription("Race", ListSortDirection.Ascending)); view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); view.Filter = UnitlistFilter; } }