public override IEnumerable <KeyValuePair <_Condition, Func <Vector3, Pawn, Thing, List <FloatMenuOption> > > > GetFloatMenus() { List <KeyValuePair <_Condition, Func <Vector3, Pawn, Thing, List <FloatMenuOption> > > > FloatMenus = new List <KeyValuePair <_Condition, Func <Vector3, Pawn, Thing, List <FloatMenuOption> > > >(); _Condition curCondition = new _Condition(_ConditionType.IsType, typeof(ThingWithComps)); Func <Vector3, Pawn, Thing, List <FloatMenuOption> > curFunc = delegate(Vector3 clickPos, Pawn pawn, Thing curThing) { List <FloatMenuOption> opts = new List <FloatMenuOption>(); if (curThing is ThingWithComps groundThing && groundThing.GetComp <CompInstalledPart>() is CompInstalledPart groundPart) { if (pawn.equipment != null) { //Remove "Equip" option from right click. if (groundThing.GetComp <CompEquippable>() != null) { var optToRemove = opts.FirstOrDefault((x) => x.Label.Contains(groundThing.Label)); if (optToRemove != null) { opts.Remove(optToRemove); } } string text = "CompInstalledPart_Install".Translate(); opts.Add(new FloatMenuOption(text, delegate { CompProperties_InstalledPart props = groundPart.Props; if (props != null) { if (props.allowedToInstallOn != null && props.allowedToInstallOn.Count > 0) { SoundDefOf.TickTiny.PlayOneShotOnCamera(null); Find.Targeter.BeginTargeting(new TargetingParameters { canTargetPawns = true, canTargetBuildings = true, mapObjectTargetsMustBeAutoAttackable = false, validator = delegate(TargetInfo targ) { if (!targ.HasThing) { return(false); } return(props.allowedToInstallOn.Contains(targ.Thing.def)); } }, delegate(LocalTargetInfo target) { groundThing.SetForbidden(false); groundPart.GiveInstallJob(pawn, target.Thing); }, null, null, null); } else { Log.ErrorOnce("CompInstalledPart :: allowedToInstallOn list needs to be defined in XML.", 3242); } } }, MenuOptionPriority.Default, null, null, 29f, null, null)); } } return(opts); }; KeyValuePair <_Condition, Func <Vector3, Pawn, Thing, List <FloatMenuOption> > > curSec = new KeyValuePair <_Condition, Func <Vector3, Pawn, Thing, List <FloatMenuOption> > >(curCondition, curFunc); FloatMenus.Add(curSec); return(FloatMenus); }
// RimWorld.FloatMenuMakerMap public static void AddHumanlikeOrders_PostFix(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts) { IntVec3 c = IntVec3.FromVector3(clickPos); foreach (Thing current in c.GetThingList(pawn.Map)) { //Handler for things on the ground if (current is ThingWithComps groundThing) { if (groundThing != null && pawn != null && pawn != groundThing) { CompInstalledPart groundPart = groundThing.GetComp <CompInstalledPart>(); if (groundPart != null) { if (pawn.equipment != null) { //Remove "Equip" option from right click. if (groundThing.GetComp <CompEquippable>() != null) { var optToRemove = opts.FirstOrDefault((x) => x.Label.Contains(groundThing.Label)); if (optToRemove != null) { opts.Remove(optToRemove); } } string text = "CompInstalledPart_Install".Translate(); opts.Add(new FloatMenuOption(text, delegate { CompProperties_InstalledPart props = groundPart.Props; if (props != null) { if (props.allowedToInstallOn != null && props.allowedToInstallOn.Count > 0) { SoundDefOf.TickTiny.PlayOneShotOnCamera(null); Find.Targeter.BeginTargeting(new TargetingParameters { canTargetPawns = true, canTargetBuildings = true, mapObjectTargetsMustBeAutoAttackable = false, validator = delegate(TargetInfo targ) { if (!targ.HasThing) { return(false); } return(props.allowedToInstallOn.Contains(targ.Thing.def)); } }, delegate(LocalTargetInfo target) { groundThing.SetForbidden(false); groundPart.GiveInstallJob(pawn, target.Thing); }, null, null, null); } else { Log.ErrorOnce("CompInstalledPart :: allowedToInstallOn list needs to be defined in XML.", 3242); } } }, MenuOptionPriority.Default, null, null, 29f, null, null)); } } } //Handler character with installed parts if (current is Pawn targetPawn) { if (targetPawn != null && pawn != null && pawn != targetPawn) { //Handle installed weapons if (targetPawn.equipment != null) { if (targetPawn.equipment.Primary != null) { CompInstalledPart installedEq = targetPawn.equipment.Primary.GetComp <CompInstalledPart>(); if (installedEq != null) { string text = "CompInstalledPart_Uninstall".Translate(targetPawn.equipment.Primary.LabelShort); opts.Add(new FloatMenuOption(text, delegate { SoundDefOf.TickTiny.PlayOneShotOnCamera(null); installedEq.GiveUninstallJob(pawn, targetPawn); }, MenuOptionPriority.Default, null, null, 29f, null, null)); } } } //Handle installed apparel if (targetPawn.apparel != null) { if (targetPawn.apparel.WornApparel != null && targetPawn.apparel.WornApparelCount > 0) { List <Apparel> installedApparel = targetPawn.apparel.WornApparel.FindAll((x) => x.GetComp <CompInstalledPart>() != null); if (installedApparel != null && installedApparel.Count > 0) { foreach (Apparel ap in installedApparel) { string text = "CompInstalledPart_Uninstall".Translate(ap.LabelShort); opts.Add(new FloatMenuOption(text, delegate { SoundDefOf.TickTiny.PlayOneShotOnCamera(null); ap.GetComp <CompInstalledPart>().GiveUninstallJob(pawn, targetPawn); }, MenuOptionPriority.Default, null, null, 29f, null, null)); } } } } } } } } }