Example #1
0
 private void DrawThingIcon(Rect rect, Pawn pawn, Thing thing, CompAwesomeInventoryLoadout comp)
 {
     this.DrawThingIcon(rect, thing);
     if (Event.current.button == 1 && Widgets.ButtonInvisible(rect))
     {
         Find.WindowStack.Add(
             new FloatMenu(
                 new List <FloatMenuOption>()
         {
             ContextMenuUtility.OptionForThingOnPawn(pawn, thing, comp),
         }));
     }
 }
        public static void Postfix(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts)
        {
            IntVec3 position = IntVec3.FromVector3(clickPos);

            // Add options for equipment.
            if (pawn.equipment != null)
            {
                List <Thing> things = position.GetThingList(pawn.Map);
                foreach (Thing thing in things)
                {
                    if (thing.TryGetComp <CompEquippable>() != null)
                    {
                        ThingWithComps equipment = (ThingWithComps)thing;

                        if (!SimpleSidearmUtility.IsActive &&
                            equipment.def.IsWeapon &&
                            !MassUtility.WillBeOverEncumberedAfterPickingUp(pawn, equipment, 1) &&
                            !pawn.WorkTagIsDisabled(WorkTags.Violent) &&
                            pawn.CanReach(equipment, PathEndMode.ClosestTouch, Danger.Deadly) &&
                            pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) &&
                            !(pawn.IsQuestLodger() && (!equipment.def.IsWeapon || pawn.equipment.Primary != null)) &&
                            EquipmentUtility.CanEquip(equipment, pawn, out _))
                        {
                            string text3 = UIText.AIEquip.Translate(thing.LabelShort);
                            if (equipment.def.IsRangedWeapon && pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler))
                            {
                                text3 += " " + UIText.EquipWarningBrawler.Translate();
                            }

                            opts.Add(ContextMenuUtility.MakeDecoratedEquipOption(pawn, equipment, text3, () => AddToLoadoutDialog(equipment)));
                        }
                    }
                }
            }

            // Add options for apparel.
            if (pawn.apparel != null)
            {
                Apparel apparel = pawn.Map.thingGrid.ThingAt <Apparel>(position);
                if (apparel != null)
                {
                    if (pawn.CanReach(apparel, PathEndMode.ClosestTouch, Danger.Deadly) &&
                        !apparel.IsBurning() &&
                        !MassUtility.WillBeOverEncumberedAfterPickingUp(pawn, apparel, apparel.stackCount) &&
                        ApparelOptionUtility.CanWear(pawn, apparel))
                    {
                        opts.Add(
                            ContextMenuUtility.MakeDecoratedWearApparelOption(
                                pawn, apparel, UIText.AIForceWear.Translate(apparel.LabelShort), true, () => AddToLoadoutDialog(apparel)));

                        opts.Add(
                            ContextMenuUtility.MakeDecoratedWearApparelOption(
                                pawn, apparel, UIText.AIWear.Translate(apparel.LabelShort), false, () => AddToLoadoutDialog(apparel)));
                    }
                }
            }

            void AddToLoadoutDialog(Thing thing1)
            {
                if (AwesomeInventoryMod.Settings.OpenLoadoutInContextMenu && pawn.UseLoadout(out Loadout.CompAwesomeInventoryLoadout comp))
                {
                    Find.WindowStack.Add(
                        new Dialog_InstantMessage(
                            UIText.AddToLoadout.Translate(comp.Loadout.label) + Environment.NewLine + $"({UIText.DisableWindowInModSetting.TranslateSimple()})"
                            , _size
                            , "Yes".TranslateSimple()
                            , () => ContextMenuUtility.AddToLoadoutDialog(pawn, comp, thing1)
                            , "No".TranslateSimple()));
                }
            }
        }