// Signals the CompStripChecker and toggles the designation if required internal static void SetShouldStrip(bool shouldStrip, CompStripChecker c, Pawn SelPawnForGear, ThingWithComps holder) { // is it not marked yet? if (CompStripChecker.getFirstMarked(SelPawnForGear) == null) { var designation = holder.Map?.designationManager.DesignationOn(holder, DesignationDefOf.Strip); bool stripping = designation != null; // | - | 🡓 | 🡓 | - // shouldStrip | t | f | t | f // stripping | t | t | f | f // AddDesignation | f | f | t | f // RemoveDesignation | f | t | f | f if (shouldStrip != stripping) { if (stripping) { holder.Map.designationManager.RemoveDesignation(designation); } else { holder.Map.designationManager.AddDesignation(new Designation(holder, DesignationDefOf.Strip)); } } } c.ShouldStrip = shouldStrip; }
static void Postfix(Thing thing, IntVec3 dropCell, Map map, ThingPlaceMode mode, Thing resultingThing, Action <Thing, int> placedAction, Predicate <IntVec3> nearPlaceValidator) { CompStripChecker UChecker = resultingThing.TryGetComp <CompStripChecker>(); if (UChecker != null) { UChecker.ShouldStrip = false; } }
public static bool Prefix(ITab_Pawn_Gear __instance, ref float y, ref float width, Thing thing, ref bool inventory) { Pawn SelPawnForGear = Traverse.Create(__instance).Property("SelPawnForGear").GetValue<Pawn>(); Corpse corpse = SelPawnForGear.Corpse; inventory = inventory && corpse == null; if (SelPawnForGear.Downed || corpse != null || SelPawnForGear.IsPrisoner && SelPawnForGear.guest.PrisonerIsSecure) { CompStripChecker c = CompStripChecker.GetChecker(thing, false); if (c == null) { width -= 24f; return true; } ThingWithComps holder = corpse == null ? SelPawnForGear : (ThingWithComps)corpse; Rect rect = new Rect(0f, y, width, 28f); Rect rect2 = new Rect(rect.width - 24f, y, 24f, 24f); if (c.ShouldStrip) { TooltipHandler.TipRegion(rect2, "StripThingCancel".Translate()); //weird shenanigans with colors var cl = GUI.color; if (Widgets.ButtonImage(rect2, ContentFinder<Texture2D>.Get("UI/Icons/Strip_Thing_Cancel"), hColor)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); c.ShouldStrip = false; if (CompStripChecker.getFirstMarked(SelPawnForGear) == null && holder.Map != null) { Designation d = holder.Map.designationManager.DesignationOn(holder, DesignationDefOf.Strip); if (d != null) holder.Map.designationManager.RemoveDesignation(d); } } GUI.color = cl; } else { TooltipHandler.TipRegion(rect2, "StripThing".Translate()); if (Widgets.ButtonImage(rect2, ContentFinder<Texture2D>.Get("UI/Icons/Strip_Thing"))) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); bool b = CompStripChecker.getFirstMarked(SelPawnForGear) == null && holder.Map.designationManager.DesignationOn(holder, DesignationDefOf.Strip) == null; c.ShouldStrip = true; if (b) holder.Map.designationManager.AddDesignation(new Designation(holder, DesignationDefOf.Strip)); } } width -= 24f; } return true; }
// Sends the ThingWithComps parent for reference on write // Retrieves CompStripChecker from the parent on read static void SyncWorkerForCompStripChecker(SyncWorker sw, ref CompStripChecker comp) { if (sw.isWriting) { sw.Write(comp.parent); } else { comp = sw.Read <ThingWithComps>().GetComp <CompStripChecker>(); } }
static void Postfix(ThingWithComps __instance) { if (Scribe.mode == LoadSaveMode.LoadingVars) { bool a = false; Scribe_Values.Look(ref a, "NonUnoPinataShouldStrip", defaultValue: false); if (a) { CompStripChecker.GetChecker(__instance, a); } } }
public static void DrawThingRow(Pawn pawn, ref float y, ref float width, Thing thing, ref bool inventory) { Corpse corpse = pawn.Corpse; inventory = inventory && corpse == null; //if (pawn.Downed || corpse != null || pawn.IsPrisoner && pawn.guest.PrisonerIsSecure) //if(StrippableUtility.CanBeStrippedByColony(pawn)) if (corpse != null || StrippableUtility.CanBeStrippedByColony(pawn)) { CompStripChecker c = CompStripChecker.GetChecker(thing, false); if (c == null) { width -= 24f; return; } ThingWithComps holder = corpse == null ? pawn : (ThingWithComps)corpse; Rect rect = new Rect(0f, y, width, 28f); Rect rect2 = new Rect(rect.width - 24f, y, 24f, 24f); if (c.ShouldStrip) { TooltipHandler.TipRegion(rect2, "StripThingCancel".Translate()); //weird shenanigans with colors var cl = GUI.color; if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Strip_Thing_Cancel"), hColor)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); SetShouldStrip(false, c, pawn, holder); } GUI.color = cl; } else { TooltipHandler.TipRegion(rect2, "StripThing".Translate()); if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Strip_Thing"))) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); SetShouldStrip(true, c, pawn, holder); } } width -= 24f; } return; }
static bool doStripCorpse(RecipeDef def, Thing thing) { if (!def.autoStripCorpses) { IStrippable strippable = thing as IStrippable; Corpse corpse = thing as Corpse; Pawn pawn; if (corpse == null) { pawn = thing as Pawn; } else { pawn = corpse.InnerPawn; } int val = 0; if (pawn != null) { if (Settings.strip_inventory) { val += 1; } if (Settings.strip_equipment) { val += 2; } if (Settings.strip_apparel) { val += 4; } if (!CompStripChecker.MarkAll(pawn, true, val)) { val = 0; } } return(strippable != null && thing.MapHeld != null && (val != 0 || thing.MapHeld.designationManager.DesignationOn(thing, DesignationDefOf.Strip) != null)); } else { return(true); } }
static bool Prefix(Designation __instance) { //return true; // designation gets removed before stripping is happened, so it doesn't work as intended if (__instance.def == DesignationDefOf.Strip && __instance.target.HasThing) { Corpse c = __instance.target.Thing as Corpse; if (c != null) { if (c.InnerPawn != null) { CompStripChecker.MarkAll(c.InnerPawn, false); } } else { CompStripChecker.MarkAll((Pawn)__instance.target.Thing, false); } return(false); } return(true); }
static public CompStripChecker GetChecker(Thing thing, bool InitShouldStrip = false) { if (!(thing is ThingWithComps) && !thing.GetType().IsSubclassOf(typeof(ThingWithComps))) { return(null); } ThingWithComps TWC = (ThingWithComps)thing; if (TWC.AllComps == null) { return(null); } CompStripChecker thingComp = thing.TryGetComp <CompStripChecker>(); if (thingComp == null) { thingComp = (CompStripChecker)Activator.CreateInstance(typeof(CompStripChecker)); thingComp.parent = TWC; TWC.AllComps.Add(thingComp); } thingComp.ShouldStrip = thingComp.ShouldStrip || InitShouldStrip; return(thingComp); }
static bool Prefix(Pawn __instance) { return(__instance.GetCaravan() != null || !CompStripChecker.TryDropMarked(__instance)); }