Пример #1
0
 public static void CreateCaravanTransferableWidgets(List <TransferableOneWay> transferables
                                                     , out TransferableOneWayWidget itemsTransfer, string sourceLabel, string destLabel, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreCorpsesGearAndInventoryMass)
 {
     itemsTransfer = new TransferableOneWayWidget(from x in transferables
                                                  //where x.ThingDef.category != ThingCategory.Pawn
                                                  select x, sourceLabel, destLabel, thingCountTip, true, ignorePawnInventoryMass, false, availableMassGetter, 24f, ignoreCorpsesGearAndInventoryMass, true);
 }
Пример #2
0
        public static void Postfix(List <TransferableOneWay> transferables, ref TransferableOneWayWidget pawnsTransfer, ref TransferableOneWayWidget itemsTransfer, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly)
        {
            List <TransferableOneWay> modifiedTransferables = transferables.Where((TransferableOneWay x) => x.ThingDef.category != ThingCategory.Pawn).ToList();

            modifiedTransferables = modifiedTransferables.Where(x => !x.ThingDef.IsWithinCategory(ThingCategoryDef.Named("RoadEquipment"))).ToList();
            itemsTransfer         = new TransferableOneWayWidget(modifiedTransferables, null, null, thingCountTip, drawMass: true, ignorePawnInventoryMass, includePawnsMassInMassUsage: false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, drawMarketValue: true, drawEquippedWeapon: false, drawNutritionEatenPerDay: false, drawItemNutrition: true, drawForagedFoodPerDay: false, drawDaysUntilRot: true);
        }
 public static void CreateCaravanTransferableWidgets_NewTmp(List <TransferableOneWay> transferables, out TransferableOneWayWidget pawnsTransfer, out TransferableOneWayWidget itemsTransfer, out TransferableOneWayWidget foodAndMedicineTransfer, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly = false)
 {
     pawnsTransfer = new TransferableOneWayWidget(null, null, null, thingCountTip, drawMass: true, ignorePawnInventoryMass, includePawnsMassInMassUsage: false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, drawMarketValue: true, drawEquippedWeapon: true, drawNutritionEatenPerDay: true, drawItemNutrition: false, drawForagedFoodPerDay: true, drawDaysUntilRot: false, playerPawnsReadOnly);
     AddPawnsSections(pawnsTransfer, transferables);
     itemsTransfer           = new TransferableOneWayWidget(transferables.Where((TransferableOneWay x) => GetTransferableCategory(x) == TransferableCategory.Item), null, null, thingCountTip, drawMass: true, ignorePawnInventoryMass, includePawnsMassInMassUsage: false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, drawMarketValue: true, drawEquippedWeapon: false, drawNutritionEatenPerDay: false, drawItemNutrition: true, drawForagedFoodPerDay: false, drawDaysUntilRot: true);
     foodAndMedicineTransfer = new TransferableOneWayWidget(transferables.Where((TransferableOneWay x) => GetTransferableCategory(x) == TransferableCategory.FoodAndMedicine), null, null, thingCountTip, drawMass: true, ignorePawnInventoryMass, includePawnsMassInMassUsage: false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, drawMarketValue: true, drawEquippedWeapon: false, drawNutritionEatenPerDay: false, drawItemNutrition: true, drawForagedFoodPerDay: false, drawDaysUntilRot: true);
 }
Пример #4
0
        private void CalculateAndRecacheTransferables()
        {
            this.transferables = new List <TransferableOneWay>();
            this.AddPawnsToTransferables();
            this.AddItemsToTransferables();
            IEnumerable <TransferableOneWay> enumerable = null;
            string text             = null;
            string destinationLabel = null;
            string text2            = "FormCaravanColonyThingCountTip".Translate();
            bool   flag             = true;
            IgnorePawnsInventoryMode ignorePawnInventoryMass = IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload;
            bool         flag2 = true;
            Func <float> availableMassGetter = () => this.MassCapacity - this.MassUsage;
            int          tile = this.map.Tile;

            this.pawnsTransfer = new TransferableOneWayWidget(enumerable, text, destinationLabel, text2, flag, ignorePawnInventoryMass, flag2, availableMassGetter, 0f, false, tile, true, true, true, false, true, false, false);
            CaravanUIUtility.AddPawnsSections(this.pawnsTransfer, this.transferables);
            enumerable = from x in this.transferables
                         where x.ThingDef.category != ThingCategory.Pawn
                         select x;

            text2                   = null;
            destinationLabel        = null;
            text                    = "FormCaravanColonyThingCountTip".Translate();
            flag2                   = true;
            ignorePawnInventoryMass = IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload;
            flag                    = true;
            availableMassGetter     = (() => this.MassCapacity - this.MassUsage);
            tile                    = this.map.Tile;
            this.itemsTransfer      = new TransferableOneWayWidget(enumerable, text2, destinationLabel, text, flag2, ignorePawnInventoryMass, flag, availableMassGetter, 0f, false, tile, true, false, false, true, false, true, false);
            this.CountToTransferChanged();
        }
Пример #5
0
 private void CalculateAndRecacheTransferables()
 {
     transferables = new List <TransferableOneWay>();
     AddItemsToTransferables();
     itemsTransfer = new TransferableOneWayWidget(transferables, null, null, null, true, IgnorePawnsInventoryMode.IgnoreIfAssignedToUnloadOrPlayerPawn);
     CountToTransferChanged();
 }
Пример #6
0
        public static void AddPawnsSections(TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            IEnumerable <TransferableOneWay> source = transferables.Where((TransferableOneWay x) => x.ThingDef.category == ThingCategory.Pawn);

            widget.AddSection("ColonistsSection".Translate(), source.Where((TransferableOneWay x) => ((Pawn)x.AnyThing).IsFreeColonist));
            widget.AddSection("PrisonersSection".Translate(), source.Where((TransferableOneWay x) => ((Pawn)x.AnyThing).IsPrisoner));
            widget.AddSection("CaptureSection".Translate(), source.Where((TransferableOneWay x) => ((Pawn)x.AnyThing).Downed && CaravanUtility.ShouldAutoCapture((Pawn)x.AnyThing, Faction.OfPlayer)));
            widget.AddSection("AnimalsSection".Translate(), source.Where((TransferableOneWay x) => ((Pawn)x.AnyThing).RaceProps.Animal));
        }
Пример #7
0
 /// <summary>
 /// Create new Widget for VehicleCaravan with <paramref name="transferables"/>
 /// </summary>
 /// <param name="transferables"></param>
 /// <param name="pawnsTransfer"></param>
 /// <param name="vehiclesTransfer"></param>
 /// <param name="itemsTransfer"></param>
 /// <param name="thingCountTip"></param>
 /// <param name="ignorePawnInventoryMass"></param>
 /// <param name="availableMassGetter"></param>
 /// <param name="ignoreSpawnedCorpsesGearAndInventoryMass"></param>
 /// <param name="tile"></param>
 /// <param name="playerPawnsReadOnly"></param>
 public static void CreateVehicleCaravanTransferableWidgets(List <TransferableOneWay> transferables, out TransferableOneWayWidget pawnsTransfer, out TransferableVehicleWidget vehiclesTransfer, out TransferableOneWayWidget itemsTransfer, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly = false)
 {
     pawnsTransfer    = new TransferableOneWayWidget(null, null, null, thingCountTip, true, ignorePawnInventoryMass, false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, true, true, true, false, true, false, playerPawnsReadOnly);
     vehiclesTransfer = new TransferableVehicleWidget(null, null, null, thingCountTip, true, ignorePawnInventoryMass, false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, true, false, false, playerPawnsReadOnly);
     AddVehicleAndPawnSections(pawnsTransfer, vehiclesTransfer, transferables);
     itemsTransfer = new TransferableOneWayWidget(from x in transferables
                                                  where x.ThingDef.category != ThingCategory.Pawn
                                                  select x, null, null, thingCountTip, true, ignorePawnInventoryMass, false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, true, false, false, true, false, true, false);
 }
Пример #8
0
        public static void AddSectionPrefix(TransferableOneWayWidget __instance, string title, IEnumerable <TransferableOneWay> transferables)
        {
            List <TransferableOneWay> tmp = transferables.ToList();

            for (int i = 0; i < tmp.Count; i++)
            {
                Dialog_LoadShipCargo.RemoveExistingTransferable(tmp[i], Find.VisibleMap);
                //tmp[i].AdjustTo(tmp[i].GetMinimum());
            }
        }
Пример #9
0
 private void CalculateAndRecacheTransferables()
 {
     this.transferables = new List <TransferableOneWay>();
     this.AddPawnsToTransferables();
     this.AddItemsToTransferables();
     this.pawnsTransfer = new TransferableOneWayWidget(null, Faction.OfPlayer.Name, this.TransportersLabelShort, "FormCaravanColonyThingCountTip".Translate(), true, false, true, () => this.MassCapacity - this.MassUsage, 24f, false, true);
     CaravanUIUtility.AddPawnsSections(this.pawnsTransfer, this.transferables);
     this.itemsTransfer = new TransferableOneWayWidget(from x in this.transferables
                                                       where x.ThingDef.category != ThingCategory.Pawn
                                                       select x, Faction.OfPlayer.Name, this.TransportersLabelShort, "FormCaravanColonyThingCountTip".Translate(), true, false, true, () => this.MassCapacity - this.MassUsage, 24f, false, true);
     this.CountToTransferChanged();
 }
Пример #10
0
        public static float addMountSelector(TransferableOneWayWidget widget, float num, Rect rect, TransferableOneWay trad)
        {
            float buttonWidth = 150f;


            Pawn pawn = trad.AnyThing as Pawn;

            if (pawn == null)
            {
                return(num); //not an animal, return;
            }



            Rect buttonRect = new Rect(num - buttonWidth, 0f, buttonWidth, rect.height);


            //Reflection is needed here to access the private struct inside TransferableOneWayWidget
            Type  sectionType = Traverse.Create(widget).Type("Section").GetValue <Type>();
            IList sections    = Traverse.Create(widget).Field("sections").GetValue <IList>();

            object section = sections[0]; //section 0 only yields pawns, which are needed in this case

            List <TransferableOneWay> cachedTransferables = sectionType.GetField("cachedTransferables").GetValue(section) as List <TransferableOneWay>;

            List <Pawn> pawns = new List <Pawn>();

            if (cachedTransferables != null)
            {
                foreach (TransferableOneWay tow in cachedTransferables)
                {
                    //Log.Message(tow.AnyThing.Label);
                    Pawn towPawn = tow.AnyThing as Pawn;
                    if (towPawn != null)
                    {
                        pawns.Add(tow.AnyThing as Pawn);
                    }
                }
                //It quacks like a duck, so it is one!
            }
            setSelectedForCaravan(pawn, trad);
            if (pawn.RaceProps.Animal && pawns.Count > 0)
            {
                handleAnimal(num, buttonRect, pawn, pawns, trad);
            }
            else
            {
                return(num);
            }


            return(num - buttonWidth);
        }
        public static void Postfix(List <TransferableOneWay> transferables, ref TransferableOneWayWidget pawnsTransfer,
                                   ref TransferableOneWayWidget itemsTransfer, string thingCountTip,
                                   IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter,
                                   bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly)
        {
            var modifiedTransferables = transferables.Where(x => x.ThingDef.category != ThingCategory.Pawn).ToList();

            modifiedTransferables = modifiedTransferables
                                    .Where(x => !x.ThingDef.IsWithinCategory(ThingCategoryDef.Named("RoadEquipment"))).ToList();
            itemsTransfer = new TransferableOneWayWidget(modifiedTransferables, null, null, thingCountTip, true,
                                                         ignorePawnInventoryMass, false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile,
                                                         true, false, false, true, false, true);
        }
Пример #12
0
        static void Postfix(ref TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            IEnumerable <TransferableOneWay> mechs = from x in transferables
                                                     where x.ThingDef.category == ThingCategory.Pawn &&
                                                     ((Pawn)x.AnyThing).RaceProps.IsMechanoid &&
                                                     ((Pawn)x.AnyThing).IsHacked()
                                                     select x;

            widget.AddSection("WTH_MechanoidsSection".Translate(), mechs);
            if (mechs != null && mechs.Count() > 0)
            {
                LessonAutoActivator.TeachOpportunity(WTH_DefOf.WTH_Caravanning, OpportunityType.Important);
            }
        }
Пример #13
0
        public static void Postfix(ref TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            RoadsOfTheRim.DebugLog("DEBUG AddPawnsSection: ");
            List <TransferableOneWay> source = new List <TransferableOneWay>();

            foreach (TransferableOneWay tow in transferables)
            {
                if (tow.ThingDef.IsWithinCategory(ThingCategoryDef.Named("RoadEquipment")))
                {
                    source.Add(tow);
                    RoadsOfTheRim.DebugLog("Found an ISR2G");
                }
            }
            widget.AddSection("RoadsOfTheRim_RoadEquipment".Translate(), source);
        }
 private void CalculateAndRecacheTransferables()
 {
     transferables = new List <TransferableOneWay>();
     AddPawnsToTransferables();
     AddItemsToTransferables();
     pawnsTransfer = new TransferableOneWayWidget(null, Faction.OfPlayer.Name, TransportersLabelCap,
                                                  "FormCaravanColonyThingCountTip".Translate(), true, IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload,
                                                  true, () => MassCapacity - MassUsage, 24f, false, map.Tile, true);
     CaravanUIUtility.AddPawnsSections(pawnsTransfer, transferables);
     itemsTransfer = new TransferableOneWayWidget(from x in transferables
                                                  where x.ThingDef.category != ThingCategory.Pawn
                                                  select x, Faction.OfPlayer.Name, TransportersLabelCap,
                                                  "FormCaravanColonyThingCountTip".Translate(), true, IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload,
                                                  true, () => MassCapacity - MassUsage, 24f, false, map.Tile, true);
     CountToTransferChanged();
 }
Пример #15
0
        public static void CreateCaravanTransferableWidgets(List <TransferableOneWay> transferables, out TransferableOneWayWidget pawnsTransfer, out TransferableOneWayWidget itemsTransfer, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly = false)
        {
            IEnumerable <TransferableOneWay> transferables2 = null;
            string sourceLabel                 = null;
            string destinationLabel            = null;
            bool   drawMass                    = true;
            bool   includePawnsMassInMassUsage = false;

            pawnsTransfer = new TransferableOneWayWidget(transferables2, sourceLabel, destinationLabel, thingCountTip, drawMass, ignorePawnInventoryMass, includePawnsMassInMassUsage, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, true, true, true, false, true, false, playerPawnsReadOnly);
            CaravanUIUtility.AddPawnsSections(pawnsTransfer, transferables);
            transferables2 = from x in transferables
                             where x.ThingDef.category != ThingCategory.Pawn
                             select x;
            string sourceLabel2 = null;

            destinationLabel = null;
            bool drawMass2 = true;
            bool includePawnsMassInMassUsage2 = false;

            itemsTransfer = new TransferableOneWayWidget(transferables2, sourceLabel2, destinationLabel, thingCountTip, drawMass2, ignorePawnInventoryMass, includePawnsMassInMassUsage2, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile, true, false, false, true, false, true, false);
        }
        static void Postfix(TransferableOneWayWidget __instance, ref bool anythingChanged)
        {
            //Reflection is needed here to access the private struct inside TransferableOneWayWidget
            Type  sectionType = Traverse.Create(__instance).Type("Section").GetValue <Type>();
            IList sections    = Traverse.Create(__instance).Field("sections").GetValue <IList>();

            foreach (object s in sections)
            {
                List <TransferableOneWay> tf = sectionType.GetField("cachedTransferables").GetValue(s) as List <TransferableOneWay>;
            }
            if (sections.Count < 4)
            {
                return;
            }
            object section = sections[3]; //section 3 only yields animals, which are needed in this case

            List <TransferableOneWay> cachedTransferables = sectionType.GetField("cachedTransferables").GetValue(section) as List <TransferableOneWay>;

            if (cachedTransferables != null)
            {
                foreach (TransferableOneWay tow in cachedTransferables)
                {
                    Pawn towPawn = tow.AnyThing as Pawn;
                    if (towPawn == null)
                    {
                        continue;
                    }
                    if (tow.CountToTransfer == -1)
                    {
                        ExtendedPawnData PawnData = GiddyUpCore.Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(towPawn);
                        if (PawnData.selectedForCaravan == true)
                        {
                            anythingChanged = true;
                            Traverse.Create(tow).Property("CountToTransfer").SetValue(1);
                        }
                    }
                }
            }
        }
Пример #17
0
        /// <summary>
        /// Create sections in VehicleCaravan dialog for proper listing
        /// </summary>
        /// <param name="pawnWidget"></param>
        /// <param name="vehicleWidget"></param>
        /// <param name="transferables"></param>
        public static void AddVehicleAndPawnSections(TransferableOneWayWidget pawnWidget, TransferableVehicleWidget vehicleWidget, List <TransferableOneWay> transferables)
        {
            IEnumerable <TransferableOneWay> source = from x in transferables
                                                      where x.ThingDef.category == ThingCategory.Pawn
                                                      select x;

            vehicleWidget.AddSection("VehiclesTab".Translate(), from x in source
                                     where x.AnyThing is VehiclePawn vehicle && vehicle.CanMove
                                     select x);
            pawnWidget.AddSection("ColonistsSection".Translate(), from x in source
                                  where ((Pawn)x.AnyThing).IsFreeColonist
                                  select x);
            pawnWidget.AddSection("PrisonersSection".Translate(), from x in source
                                  where ((Pawn)x.AnyThing).IsPrisoner
                                  select x);
            pawnWidget.AddSection("CaptureSection".Translate(), from x in source
                                  where ((Pawn)x.AnyThing).Downed && CaravanUtility.ShouldAutoCapture((Pawn)x.AnyThing, Faction.OfPlayer)
                                  select x);
            pawnWidget.AddSection("AnimalsSection".Translate(), from x in source
                                  where ((Pawn)x.AnyThing).RaceProps.Animal
                                  select x);
            vehicleWidget.AvailablePawns = source.Where(x => x.AnyThing is Pawn pawn && !(pawn is VehiclePawn) && pawn.IsColonistPlayerControlled).ToList();
        }
Пример #18
0
        public static void CreateCaravanTransferableWidgets(List <TransferableOneWay> transferables, out TransferableOneWayWidget pawnsTransfer, out TransferableOneWayWidget itemsTransfer, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly = false)
        {
            IEnumerable <TransferableOneWay> transferables2 = null;
            string sourceLabel                             = null;
            string destinationLabel                        = null;
            bool   drawMass                                = true;
            bool   includePawnsMassInMassUsage             = false;
            bool   ignoreSpawnedCorpseGearAndInventoryMass = ignoreSpawnedCorpsesGearAndInventoryMass;
            bool   playerPawnsReadOnly2                    = playerPawnsReadOnly;

            pawnsTransfer = new TransferableOneWayWidget(transferables2, sourceLabel, destinationLabel, thingCountTip, drawMass, ignorePawnInventoryMass, includePawnsMassInMassUsage, availableMassGetter, 0f, ignoreSpawnedCorpseGearAndInventoryMass, tile, drawMarketValue: true, drawEquippedWeapon: true, drawNutritionEatenPerDay: true, drawItemNutrition: false, drawForagedFoodPerDay: true, drawDaysUntilRot: false, playerPawnsReadOnly2);
            AddPawnsSections(pawnsTransfer, transferables);
            transferables2 = from x in transferables
                             where x.ThingDef.category != ThingCategory.Pawn
                             select x;
            string sourceLabel2 = null;

            destinationLabel     = null;
            playerPawnsReadOnly2 = true;
            ignoreSpawnedCorpseGearAndInventoryMass = false;
            includePawnsMassInMassUsage             = ignoreSpawnedCorpsesGearAndInventoryMass;
            itemsTransfer = new TransferableOneWayWidget(transferables2, sourceLabel2, destinationLabel, thingCountTip, playerPawnsReadOnly2, ignorePawnInventoryMass, ignoreSpawnedCorpseGearAndInventoryMass, availableMassGetter, 0f, includePawnsMassInMassUsage, tile, drawMarketValue: true, drawEquippedWeapon: false, drawNutritionEatenPerDay: false, drawItemNutrition: true, drawForagedFoodPerDay: false, drawDaysUntilRot: true);
        }
 public static void CreateCaravanTransferableWidgets(List <TransferableOneWay> transferables, out TransferableOneWayWidget pawnsTransfer, out TransferableOneWayWidget itemsTransfer, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass, Func <float> availableMassGetter, bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly = false)
 {
     CreateCaravanTransferableWidgets_NewTmp(transferables, out pawnsTransfer, out itemsTransfer, out var _, thingCountTip, ignorePawnInventoryMass, availableMassGetter, ignoreSpawnedCorpsesGearAndInventoryMass, tile, playerPawnsReadOnly);
 }
Пример #20
0
        private static List <Pawn> PawnsInCurrentSections; // For Giddy-up! Caravan compatibility
        public static bool AddPawnsSections(TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            PawnsInCurrentSections = new List <Pawn>(); // For Giddy-up! Caravan compatibility

            // Get all pawns from the list of transferables
            List <Pawn> pawns = new List <Pawn>();
            Dictionary <Pawn, TransferableOneWay> pawnThing = new Dictionary <Pawn, TransferableOneWay>();

            foreach (TransferableOneWay thing in transferables)
            {
                if (thing.ThingDef.category == ThingCategory.Pawn)
                {
                    Pawn pawn = (Pawn)thing.AnyThing;
                    pawns.Add(pawn);
                    pawnThing[pawn] = thing;
                }
            }

            List <PawnGroup> pawnGroups = TacticUtils.AllPawnGroups;

            pawnGroups.Reverse(); // Reverse the list because it iterates in the wrong direction

            // Create a HashSet to sort out all the ungrouped pawns
            HashSet <Pawn> ungroupedPawns = new HashSet <Pawn>(pawns);

            foreach (PawnGroup pawnGroup in pawnGroups)
            {
                if (pawnGroup.pawns != null && pawnGroup.pawns.Count > 0)
                {
                    // Remove grouped pawns from the ungroupedPawns HashSet
                    ungroupedPawns.ExceptWith(from pawn in pawnGroup.pawns select pawn);

                    // Get only the group's pawns that are in the current list of transferables
                    List <TransferableOneWay> sectionTranferables = new List <TransferableOneWay>();
                    foreach (Pawn pawn in pawnGroup.pawns)
                    {
                        if (pawns.Contains(pawn) && pawnThing.ContainsKey(pawn) && pawn.IsFreeColonist)
                        {
                            sectionTranferables.Add(pawnThing[pawn]);
                            if (!PawnsInCurrentSections.Contains(pawn))
                            {
                                PawnsInCurrentSections.Add(pawn); // For Giddy-up! Caravan compatibility
                            }
                        }
                    }

                    if (sectionTranferables.Count > 0)
                    {
                        // Add a new section containing all pawns within the group
                        widget.AddSection(pawnGroup.curGroupName ?? "", from pawn in sectionTranferables select pawn);
                    }
                }
            }

            if (ungroupedPawns.Count > 0)
            {
                // Create a section containing all the ungrouped pawns
                widget.AddSection("Ungrouped " + "ColonistsSection".Translate().ToLower(), from pawn in ungroupedPawns
                                  where pawn.IsFreeColonist
                                  select pawnThing[pawn]);
                foreach (Pawn pawn in ungroupedPawns)
                {
                    if (pawn.IsFreeColonist && !PawnsInCurrentSections.Contains(pawn))
                    {
                        PawnsInCurrentSections.Add(pawn); // For Giddy-up! Caravan compatibility
                    }
                }
            }

            // We then return to vanilla code (slightly tweaked), commenting out the Colonists section of course

            /*
             * widget.AddSection("ColonistsSection".Translate(), from pawn in pawns
             *                                                where pawn.IsFreeColonist
             *                                                select pawnThing[pawn]);
             */

            widget.AddSection("PrisonersSection".Translate(), from pawn in pawns
                              where pawn.IsPrisoner
                              select pawnThing[pawn]);

            widget.AddSection("CaptureSection".Translate(), from pawn in pawns
                              where pawn.Downed && CaravanUtility.ShouldAutoCapture(pawn, Faction.OfPlayer)
                              select pawnThing[pawn]);

            widget.AddSection("AnimalsSection".Translate(), from pawn in pawns
                              where pawn.RaceProps.Animal
                              select pawnThing[pawn]);
            return(false);
        }
        public static bool AddPawnsSections(TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            if (ModCompatibility.GiddyUpCaravanIsActive)
            {
                PawnsInCurrentSections = new List <Pawn>();
            }

            // Get all pawns from the list of transferables
            List <Pawn> pawns = new List <Pawn>();
            Dictionary <Pawn, TransferableOneWay> pawnTransferable = new Dictionary <Pawn, TransferableOneWay>();

            foreach (TransferableOneWay transferable in transferables)
            {
                if (transferable.ThingDef.category == ThingCategory.Pawn)
                {
                    Pawn pawn = (Pawn)transferable.AnyThing;
                    pawns.Add(pawn);
                    pawnTransferable[pawn] = transferable;
                }
            }

            List <PawnGroup> pawnGroups = TacticUtils.AllPawnGroups;

            pawnGroups.Reverse(); // Reverse the list because it iterates in the wrong direction

            // Create a HashSet to sort out all the ungrouped pawns
            HashSet <Pawn> ungroupedPawns = new HashSet <Pawn>(pawns);

            foreach (PawnGroup pawnGroup in pawnGroups)
            {
                if (!(pawnGroup.pawns is null) && pawnGroup.pawns.Count > 0)
                {
                    // Remove grouped pawns from the ungroupedPawns HashSet
                    ungroupedPawns.ExceptWith(from pawn in pawnGroup.pawns select pawn);

                    // Get only the group's pawns that are in the current list of transferables
                    List <Pawn> sectionPawns = new List <Pawn>();
                    sectionPawns.AddRange(from pawn in pawnGroup.pawns
                                          where pawns.Contains(pawn)
                                          select pawn);

                    if (ModCompatibility.GiddyUpCaravanIsActive)
                    {
                        PawnsInCurrentSections.AddRange(from pawn in sectionPawns.Except(PawnsInCurrentSections)
                                                        where pawn.IsFreeNonSlaveColonist
                                                        select pawn);
                    }

                    // Add a new section containing all pawns within the group
                    if (sectionPawns.Any(pawn => pawn.IsFreeNonSlaveColonist))
                    {
                        widget.AddSection(pawnGroup.curGroupName, from pawn in sectionPawns
                                          where pawn.IsFreeNonSlaveColonist
                                          select pawnTransferable[pawn]);
                    }

                    // Add a new section containing all slave pawns within the group
                    if (ModsConfig.IdeologyActive && sectionPawns.Any(pawn => pawn.IsSlave))
                    {
                        widget.AddSection("TG.GroupSlavesSection".Translate(pawnGroup.curGroupName), from pawn in sectionPawns
                                          where pawn.IsSlave
                                          select pawnTransferable[pawn]);
                    }
                }
            }

            // Create a section containing all the ungrouped pawns
            if (ungroupedPawns.Any(pawn => pawn.IsFreeNonSlaveColonist))
            {
                widget.AddSection("TG.UngroupedColonistsSection".Translate(), from pawn in ungroupedPawns
                                  where pawn.IsFreeNonSlaveColonist
                                  select pawnTransferable[pawn]);

                if (ModCompatibility.GiddyUpCaravanIsActive)
                {
                    PawnsInCurrentSections.AddRange(from pawn in ungroupedPawns.Except(PawnsInCurrentSections)
                                                    where pawn.IsFreeNonSlaveColonist
                                                    select pawn);
                }
            }

            // Create a section containing all the ungrouped slave pawns
            if (ModsConfig.IdeologyActive && ungroupedPawns.Any(pawn => pawn.IsSlave))
            {
                widget.AddSection("TG.UngroupedSlavesSection".Translate(), from pawn in ungroupedPawns
                                  where pawn.IsSlave
                                  select pawnTransferable[pawn]);
            }


            // We then return to vanilla code

            /*
             * widget.AddSection("ColonistsSection".Translate(), from pawn in pawns
             *                                                where pawn.IsFreeNonSlaveColonist
             *                                                select pawnTransferable[pawn]);
             *
             * if (ModsConfig.IdeologyActive)
             * {
             *  widget.AddSection("SlavesSection".Translate(), from pawn in pawns
             *                                                 where pawn.IsSlave
             *                                                 select pawnTransferable[pawn]);
             * }
             */

            widget.AddSection("PrisonersSection".Translate(), from pawn in pawns
                              where pawn.IsPrisoner
                              select pawnTransferable[pawn]);

            widget.AddSection("CaptureSection".Translate(), from pawn in pawns
                              where pawn.Downed && CaravanUtility.ShouldAutoCapture(pawn, Faction.OfPlayer)
                              select pawnTransferable[pawn]);

            widget.AddSection("AnimalsSection".Translate(), from pawn in pawns
                              where pawn.RaceProps.Animal
                              select pawnTransferable[pawn]);
            return(false);
        }
Пример #22
0
 private void CreateCaravanItemsWidget(List <TransferableOneWay> transferables, out TransferableOneWayWidget itemsTransfer, string thingCountTip, IgnorePawnsInventoryMode ignorePawnInventoryMass,
                                       Func <float> availableMassGetter, bool ignoreSpawnedCorpsesGearAndInventoryMass, int tile, bool playerPawnsReadOnly = false)
 {
     itemsTransfer = new TransferableOneWayWidget(transferables, null, null, thingCountTip, true, ignorePawnInventoryMass, false, availableMassGetter, 0f, ignoreSpawnedCorpsesGearAndInventoryMass, tile,
                                                  true, false, false, true, false, true, false);
 }