internal static void filterAnimals(ref SettingHandle <DictAnimalRecordHandler> setting, List <ThingDef> allAnimals, SettingHandle <float> filter = null) { if (setting.Value == null) { setting.Value = new DictAnimalRecordHandler(); } Dictionary <String, AnimalRecord> selection = new Dictionary <string, AnimalRecord>(); foreach (ThingDef animal in allAnimals) { bool shouldSelect = false; if (filter != null) { float mass = animal.race.baseBodySize; shouldSelect = mass >= filter.Value; } AnimalRecord value = null; bool found = setting.Value.InnerList.TryGetValue(animal.defName, out value); if (found && value.isException) { selection.Add(animal.defName, value); } else if (found) { selection.Add(animal.defName, new AnimalRecord(shouldSelect, false, animal.label)); } else { addNewAnimal(animal, selection, shouldSelect, setting.Name); } } selection = selection.OrderBy(d => d.Value.label).ToDictionary(d => d.Key, d => d.Value); setting.Value.InnerList = selection; }
internal static bool CustomDrawer_MatchingAnimals_active(Rect wholeRect, SettingHandle <DictAnimalRecordHandler> setting, List <ThingDef> allAnimals, SettingHandle <float> filter = null, string yesText = "Is a mount", string noText = "Is not a mount") { drawBackground(wholeRect, background); GUI.color = Color.white; Rect leftRect = new Rect(wholeRect); leftRect.width = leftRect.width / 2; leftRect.height = wholeRect.height - TextMargin + BottomMargin; leftRect.position = new Vector2(leftRect.position.x, leftRect.position.y); Rect rightRect = new Rect(wholeRect); rightRect.width = rightRect.width / 2; leftRect.height = wholeRect.height - TextMargin + BottomMargin; rightRect.position = new Vector2(rightRect.position.x + leftRect.width, rightRect.position.y); DrawLabel(yesText, leftRect, TextMargin); DrawLabel(noText, rightRect, TextMargin); leftRect.position = new Vector2(leftRect.position.x, leftRect.position.y + TextMargin); rightRect.position = new Vector2(rightRect.position.x, rightRect.position.y + TextMargin); int iconsPerRow = 1; if (setting.Value == null) { setting.Value = new DictAnimalRecordHandler(); } Dictionary <String, AnimalRecord> selection = new Dictionary <string, AnimalRecord>(); for (int i = 0; i < allAnimals.Count; i++) { bool shouldSelect = false; if (filter != null) { float mass = allAnimals[i].race.baseBodySize; shouldSelect = mass >= filter.Value; } AnimalRecord value = null; bool found = setting.Value.InnerList.TryGetValue(allAnimals[i].defName, out value); if (found && value.isException) { selection.Add(allAnimals[i].defName, value); } else { selection.Add(allAnimals[i].defName, new AnimalRecord(shouldSelect, false)); } } bool change = false; int numSelected = 0; foreach (KeyValuePair <String, AnimalRecord> item in selection) { if (item.Value.isSelected) { numSelected++; } } int biggerRows = Math.Max(numSelected / iconsPerRow, (selection.Count - numSelected) / iconsPerRow); setting.CustomDrawerHeight = (biggerRows * rowHeight) + ((biggerRows) * BottomMargin) + TextMargin; int indexLeft = 0; int indexRight = 0; foreach (KeyValuePair <String, AnimalRecord> item in selection) { Rect rect = item.Value.isSelected ? leftRect : rightRect; int index = item.Value.isSelected ? indexLeft : indexRight; if (item.Value.isSelected) { indexLeft++; } else { indexRight++; } int collum = (index % iconsPerRow); int row = (index / iconsPerRow); bool interacted = DrawTileForAnimal(item, rect, new Vector2(0, rowHeight * row + row * BottomMargin), index); if (interacted) { change = true; item.Value.isSelected = !item.Value.isSelected; item.Value.isException = !item.Value.isException; } } if (change) { setting.Value.InnerList = selection; } return(change); }
//Constructor public UserControlAddPetViewModel(DBConnect db) { Connection = db; newPet = new AnimalRecord(); }