public override ActivationResult Activate(Designator designator, Map map) { int hitCountThings = 0; int hitCountTiles = 0; var manager = map.designationManager; foreach (var des in manager.allDesignations.ToArray()) { // skip planning designation, as so does cancel if (des.def == null || !des.def.designateCancelable || des.def == DesignationDefOf.Plan) { continue; } if (des.target.Thing != null) { hitCountThings++; } else { hitCountTiles++; } manager.RemoveDesignation(des); } return(ActivationResult.SuccessMessage("Designator_context_cancel_desig_msg".Translate(hitCountThings, hitCountTiles))); }
public static ActivationResult SelectSimilarWithFilter(Designator designator, Map map, string successMessageKey, string failureMessageKey, Predicate <Thing> filter = null) { var des = (Designator_SelectSimilar)designator; des = (Designator_SelectSimilar)des.PickUpReverseDesignator(); if (Find.Selector.NumSelected == 0) { return(ActivationResult.Failure(failureMessageKey)); } des.ReindexSelectionConstraints(); // find things to select var thingsToSelect = new List <Thing>(); foreach (var thing in map.listerThings.AllThings) { if (thing != null && (filter == null || filter(thing)) && des.CanDesignateThing(thing).Accepted) { thingsToSelect.Add(thing); } } // sort by distance to camera var cameraCenter = Current.CameraDriver.MapPosition; thingsToSelect.SortBy(t => t.Position.DistanceTo(cameraCenter)); // do selection var hitCount = 0; var limitWasHit = false; foreach (var thing in thingsToSelect) { if (!des.SelectionLimitAllowsAdditionalThing()) { limitWasHit = true; break; } if (des.TrySelectThing(thing)) { hitCount++; } } return(limitWasHit ? ActivationResult.SuccessMessage((successMessageKey + "_part").Translate(hitCount, thingsToSelect.Count)) : ActivationResult.Success(successMessageKey, hitCount)); }