예제 #1
0
        /// <summary>
        /// Generates a loadout from a pawn's current equipment and inventory.  Attempts to put items which fit in Generics that are default/DropExcess into said Generic.
        /// </summary>
        /// <param name="pawn">Pawn to check equipment/inventory on and generate a Loadout from.</param>
        /// <returns>Loadout which was generated based on Pawn's inventory.</returns>
        public static Loadout GenerateLoadoutFromPawn(this Pawn pawn)
        {
            // generate the name for this new pawn based loadout.
            string newName = string.Concat(pawn.Name.ToStringShort, " ", "CE_DefaultLoadoutName".Translate());
            Regex  reNum   = new Regex(@"^(.*?)\d+$");

            if (reNum.IsMatch(newName))
            {
                newName = reNum.Replace(newName, @"$1");
            }
            newName = LoadoutManager.GetUniqueLabel(newName);

            // set basic loadout properties.
            Loadout loadout = new Loadout(newName);

            loadout.defaultLoadout = false;
            loadout.canBeDeleted   = true;

            LoadoutSlot slot = null;

            // grab the pawn's current equipment as a loadoutslot.
            if (pawn.equipment?.Primary != null)
            {
                slot = new LoadoutSlot(pawn.equipment.Primary.def);
                loadout.AddSlot(slot);
            }

            // get a list of generics which are drop only.  Assumes that anything that doesn't fit here is a Specific slot later.
            IEnumerable <LoadoutGenericDef> generics = DefDatabase <LoadoutGenericDef> .AllDefs.Where(gd => gd.defaultCountType == LoadoutCountType.dropExcess);

            // enumerate each item in the pawn's inventory and add appropriate slots.
            foreach (Thing thing in pawn.inventory.innerContainer)
            {
                LoadoutGenericDef foundGeneric = null;
                // first check if it's a generic-able item...
                foreach (LoadoutGenericDef generic in generics)
                {
                    if (generic.lambda(thing.def))
                    {
                        foundGeneric = generic;
                        break;
                    }
                }

                // assign a loadout slot that fits the thing.
                if (foundGeneric != null)
                {
                    slot = new LoadoutSlot(foundGeneric, thing.stackCount);
                }
                else
                {
                    slot = new LoadoutSlot(thing.def, thing.stackCount);
                }

                // add the slot (this also takes care of adding to existing slots)
                loadout.AddSlot(slot);
            }

            // finally check the loadout and make sure that it has sufficient generics like what happens with a new loadout in the management UI.
            foreach (LoadoutGenericDef generic in generics.Where(gd => gd.isBasic))
            {
                slot = loadout.Slots.FirstOrDefault(s => s.genericDef == generic);
                if (slot != null)
                {
                    if (slot.count < slot.genericDef.defaultCount)
                    {
                        slot.count = slot.genericDef.defaultCount;
                    }
                }
                else
                {
                    slot = new LoadoutSlot(generic);
                    loadout.AddSlot(slot);
                }
            }

            return(loadout);
        }
예제 #2
0
        protected override void FillTab()
        {
            // get the inventory comp
            CompInventory comp = SelPawn.TryGetComp <CompInventory>();

            // set up rects
            Rect listRect = new Rect(
                _margin,
                _topPadding,
                size.x - 2 * _margin,
                size.y - _topPadding - _margin);

            if (comp != null)
            {
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(CE_ConceptDefOf.CE_InventoryWeightBulk, KnowledgeAmount.FrameDisplayed);

                // adjust rects if comp found
                listRect.height -= (_margin / 2 + _barHeight) * 2;
                Rect weightRect = new Rect(_margin, listRect.yMax + _margin / 2, listRect.width, _barHeight);
                Rect bulkRect   = new Rect(_margin, weightRect.yMax + _margin / 2, listRect.width, _barHeight);

                // draw bars
                Utility_Loadouts.DrawBar(bulkRect, comp.currentBulk, comp.capacityBulk, "CE_Bulk".Translate(), SelPawn.GetBulkTip());
                Utility_Loadouts.DrawBar(weightRect, comp.currentWeight, comp.capacityWeight, "CE_Weight".Translate(), SelPawn.GetWeightTip());

                // draw text overlays on bars
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleCenter;

                string currentBulk  = CE_StatDefOf.CarryBulk.ValueToString(comp.currentBulk, CE_StatDefOf.CarryBulk.toStringNumberSense);
                string capacityBulk = CE_StatDefOf.CarryBulk.ValueToString(comp.capacityBulk, CE_StatDefOf.CarryBulk.toStringNumberSense);
                Widgets.Label(bulkRect, currentBulk + "/" + capacityBulk);

                string currentWeight  = comp.currentWeight.ToString("0.#");
                string capacityWeight = CE_StatDefOf.CarryWeight.ValueToString(comp.capacityWeight, CE_StatDefOf.CarryWeight.toStringNumberSense);
                Widgets.Label(weightRect, currentWeight + "/" + capacityWeight);

                Text.Anchor = TextAnchor.UpperLeft;
            }

            // start drawing list (rip from ITab_Pawn_Gear)

            GUI.BeginGroup(listRect);
            Text.Font = GameFont.Small;
            GUI.color = Color.white;
            Rect outRect  = new Rect(0f, 0f, listRect.width, listRect.height);
            Rect viewRect = new Rect(0f, 0f, listRect.width - 16f, _scrollViewHeight);

            Widgets.BeginScrollView(outRect, ref _scrollPosition, viewRect);
            float num = 0f;

            TryDrawComfyTemperatureRange(ref num, viewRect.width);
            if (ShouldShowOverallArmor(SelPawnForGear))
            {
                Widgets.ListSeparator(ref num, viewRect.width, "OverallArmor".Translate());
                TryDrawOverallArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Blunt, "ArmorBlunt".Translate(), " " + "CE_MPa".Translate());
                TryDrawOverallArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Sharp, "ArmorSharp".Translate(), "CE_mmRHA".Translate());
                TryDrawOverallArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Heat, "ArmorHeat".Translate(), "%");
            }
            if (ShouldShowEquipment(SelPawnForGear))
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Equipment".Translate());
                foreach (ThingWithComps current in SelPawnForGear.equipment.AllEquipmentListForReading)
                {
                    DrawThingRow(ref num, viewRect.width, current);
                }
            }
            if (ShouldShowApparel(SelPawnForGear))
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Apparel".Translate());
                foreach (Apparel current2 in from ap in SelPawnForGear.apparel.WornApparel
                         orderby ap.def.apparel.bodyPartGroups[0].listOrder descending
                         select ap)
                {
                    DrawThingRow(ref num, viewRect.width, current2);
                }
            }
            if (ShouldShowInventory(SelPawnForGear))
            {
                // get the loadout so we can make a decision to show a button.
                bool    showMakeLoadout = false;
                Loadout curLoadout      = SelPawnForGear.GetLoadout();
                if (SelPawnForGear.IsColonist && (curLoadout == null || curLoadout.Slots.NullOrEmpty()) && (SelPawnForGear.inventory.innerContainer.Any() || SelPawnForGear.equipment?.Primary != null))
                {
                    showMakeLoadout = true;
                }

                if (showMakeLoadout)
                {
                    num += 3;        // Make a little room for the button.
                }
                float buttonY = num; // Could be accomplished with seperator being after the button...

                Widgets.ListSeparator(ref num, viewRect.width, "Inventory".Translate());

                // only offer this button if the pawn has no loadout or has the default loadout and there are things/equipment...
                if (showMakeLoadout)
                {
                    Rect loadoutButtonRect = new Rect(viewRect.width / 2, buttonY, viewRect.width / 2, 26f); // button is half the available width...
                    if (Widgets.ButtonText(loadoutButtonRect, "CE_MakeLoadout".Translate()))
                    {
                        Loadout loadout = SelPawnForGear.GenerateLoadoutFromPawn();
                        LoadoutManager.AddLoadout(loadout);
                        SelPawnForGear.SetLoadout(loadout);

                        // Opening this window is the same way as if from the assign tab so should be correct.
                        Find.WindowStack.Add(new Dialog_ManageLoadouts(SelPawnForGear.GetLoadout()));
                    }
                }

                workingInvList.Clear();
                workingInvList.AddRange(SelPawnForGear.inventory.innerContainer);
                for (int i = 0; i < workingInvList.Count; i++)
                {
                    DrawThingRow(ref num, viewRect.width, workingInvList[i].GetInnerIfMinified(), true);
                }
            }
            if (Event.current.type == EventType.Layout)
            {
                _scrollViewHeight = num + 30f;
            }
            Widgets.EndScrollView();
            GUI.EndGroup();
            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
        }
예제 #3
0
        public override void DoWindowContents(Rect canvas)
        {
            // fix weird zooming bug
            Text.Font = GameFont.Small;

            // SET UP RECTS
            // top buttons
            Rect selectRect = new Rect(0f, 0f, canvas.width * .2f, _topAreaHeight);
            Rect newRect    = new Rect(selectRect.xMax + _margin, 0f, canvas.width * .2f, _topAreaHeight);
            Rect copyRect   = new Rect(newRect.xMax + _margin, 0f, canvas.width * .2f, _topAreaHeight);
            Rect deleteRect = new Rect(copyRect.xMax + _margin, 0f, canvas.width * .2f, _topAreaHeight);

            // main areas
            Rect nameRect = new Rect(
                0f,
                _topAreaHeight + _margin * 2,
                (canvas.width - _margin) / 2f,
                24f);

            Rect slotListRect = new Rect(
                0f,
                nameRect.yMax + _margin,
                (canvas.width - _margin) / 2f,
                canvas.height - _topAreaHeight - nameRect.height - _barHeight * 2 - _margin * 5);

            Rect weightBarRect = new Rect(slotListRect.xMin, slotListRect.yMax + _margin, slotListRect.width, _barHeight);
            Rect bulkBarRect   = new Rect(weightBarRect.xMin, weightBarRect.yMax + _margin, weightBarRect.width, _barHeight);

            Rect sourceButtonRect = new Rect(
                slotListRect.xMax + _margin,
                _topAreaHeight + _margin * 2,
                (canvas.width - _margin) / 2f,
                24f);

            Rect selectionRect = new Rect(
                slotListRect.xMax + _margin,
                sourceButtonRect.yMax + _margin,
                (canvas.width - _margin) / 2f,
                canvas.height - 24f - _topAreaHeight - _margin * 3);

            LoadoutManager.SortLoadouts();
            List <Loadout> loadouts = LoadoutManager.Loadouts.Where(l => !l.defaultLoadout).ToList();

            // DRAW CONTENTS
            // buttons
            // select loadout
            if (Widgets.ButtonText(selectRect, "CE_SelectLoadout".Translate()))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();

                if (loadouts.Count == 0)
                {
                    options.Add(new FloatMenuOption("CE_NoLoadouts".Translate(), null));
                }
                else
                {
                    for (int i = 0; i < loadouts.Count; i++)
                    {
                        int local_i = i;
                        options.Add(new FloatMenuOption(loadouts[i].LabelCap, delegate
                                                        { CurrentLoadout = loadouts[local_i]; }));
                    }
                }

                Find.WindowStack.Add(new FloatMenu(options));
            }
            // create loadout
            if (Widgets.ButtonText(newRect, "CE_NewLoadout".Translate()))
            {
                Loadout loadout = new Loadout();
                loadout.AddBasicSlots();
                LoadoutManager.AddLoadout(loadout);
                CurrentLoadout = loadout;
            }
            // copy loadout
            if (CurrentLoadout != null && Widgets.ButtonText(copyRect, "CE_CopyLoadout".Translate()))
            {
                CurrentLoadout = CurrentLoadout.Copy();
                LoadoutManager.AddLoadout(CurrentLoadout);
            }
            // delete loadout
            if (loadouts.Any(l => l.canBeDeleted) && Widgets.ButtonText(deleteRect, "CE_DeleteLoadout".Translate()))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();

                for (int i = 0; i < loadouts.Count; i++)
                {
                    int local_i = i;

                    // don't allow deleting the default loadout
                    if (!loadouts[i].canBeDeleted)
                    {
                        continue;
                    }
                    options.Add(new FloatMenuOption(loadouts[i].LabelCap,
                                                    delegate
                    {
                        if (CurrentLoadout == loadouts[local_i])
                        {
                            CurrentLoadout = LoadoutManager.DefaultLoadout;
                        }
                        LoadoutManager.RemoveLoadout(loadouts[local_i]);
                    }));
                }

                Find.WindowStack.Add(new FloatMenu(options));
            }

            // draw notification if no loadout selected
            if (CurrentLoadout == null)
            {
                Text.Anchor = TextAnchor.MiddleCenter;
                GUI.color   = Color.grey;
                Widgets.Label(canvas, "CE_NoLoadoutSelected".Translate());
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperLeft;

                // and stop further drawing
                return;
            }

            // name
            DrawNameField(nameRect);

            // source selection
            DrawSourceSelection(sourceButtonRect);

            // selection area
            DrawSlotSelection(selectionRect);

            // current slots
            DrawSlotList(slotListRect);

            // bars
            if (CurrentLoadout != null)
            {
                Utility_Loadouts.DrawBar(weightBarRect, CurrentLoadout.Weight, Utility_Loadouts.medianWeightCapacity, "CE_Weight".Translate(), CurrentLoadout.GetWeightTip());
                Utility_Loadouts.DrawBar(bulkBarRect, CurrentLoadout.Bulk, Utility_Loadouts.medianBulkCapacity, "CE_Bulk".Translate(), CurrentLoadout.GetBulkTip());
                // draw text overlays on bars
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleCenter;
                var currentBulk  = CE_StatDefOf.CarryBulk.ValueToString(CurrentLoadout.Bulk, CE_StatDefOf.CarryBulk.toStringNumberSense);
                var capacityBulk = CE_StatDefOf.CarryBulk.ValueToString(Utility_Loadouts.medianBulkCapacity, CE_StatDefOf.CarryBulk.toStringNumberSense);
                Widgets.Label(bulkBarRect, currentBulk + "/" + capacityBulk);
                Widgets.Label(weightBarRect, CurrentLoadout.Weight.ToString("0.#") + "/" + Utility_Loadouts.medianWeightCapacity.ToStringMass());
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperLeft;
            }
            // done!
        }
예제 #4
0
        protected override void FillTab()
        {
            // get the inventory comp
            CompInventory comp = SelPawn.TryGetComp <CompInventory>();

            // set up rects
            Rect listRect = new Rect(
                _margin,
                _topPadding,
                size.x - 2 * _margin,
                size.y - _topPadding - _margin);

            if (comp != null)
            {
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(CE_ConceptDefOf.CE_InventoryWeightBulk, KnowledgeAmount.FrameDisplayed);

                // adjust rects if comp found
                listRect.height -= (_margin / 2 + _barHeight) * 2;
                Rect weightRect = new Rect(_margin, listRect.yMax + _margin / 2, listRect.width, _barHeight);
                Rect bulkRect   = new Rect(_margin, weightRect.yMax + _margin / 2, listRect.width, _barHeight);

                Utility_Loadouts.DrawBar(bulkRect, comp.currentBulk, comp.capacityBulk, "CE_Bulk".Translate(), SelPawn.GetBulkTip());
                Utility_Loadouts.DrawBar(weightRect, comp.currentWeight, comp.capacityWeight, "CE_Weight".Translate(), SelPawn.GetWeightTip());
            }

            // start drawing list (rip from ITab_Pawn_Gear)

            GUI.BeginGroup(listRect);
            Text.Font = GameFont.Small;
            GUI.color = Color.white;
            Rect outRect  = new Rect(0f, 0f, listRect.width, listRect.height);
            Rect viewRect = new Rect(0f, 0f, listRect.width - 16f, _scrollViewHeight);

            Widgets.BeginScrollView(outRect, ref _scrollPosition, viewRect);
            float num = 0f;

            TryDrawComfyTemperatureRange(ref num, viewRect.width);
            if (SelPawnForGear.apparel != null)
            {
                bool flag = false;
                TryDrawAverageArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Blunt, "ArmorBlunt".Translate(), ref flag);
                TryDrawAverageArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Sharp, "ArmorSharp".Translate(), ref flag);
                TryDrawAverageArmor(ref num, viewRect.width, StatDefOf.ArmorRating_Heat, "ArmorHeat".Translate(), ref flag);
            }
            if (SelPawnForGear.equipment != null)
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Equipment".Translate());
                foreach (ThingWithComps current in SelPawnForGear.equipment.AllEquipmentListForReading)
                {
                    DrawThingRow(ref num, viewRect.width, current);
                }
            }
            if (SelPawnForGear.apparel != null)
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Apparel".Translate());
                foreach (Apparel current2 in from ap in SelPawnForGear.apparel.WornApparel
                         orderby ap.def.apparel.bodyPartGroups[0].listOrder descending
                         select ap)
                {
                    DrawThingRow(ref num, viewRect.width, current2);
                }
            }
            if (SelPawnForGear.inventory != null)
            {
                // get the loadout so we can make a decision to show a button.
                bool    showMakeLoadout = false;
                Loadout curLoadout      = SelPawnForGear.GetLoadout();
                if (SelPawnForGear.IsColonist && (curLoadout == null || curLoadout.Slots.NullOrEmpty()) && (SelPawnForGear.inventory.innerContainer.Any() || SelPawnForGear.equipment?.Primary != null))
                {
                    showMakeLoadout = true;
                }

                if (showMakeLoadout)
                {
                    num += 3;        // Make a little room for the button.
                }
                float buttonY = num; // Could be accomplished with seperator being after the button...

                Widgets.ListSeparator(ref num, viewRect.width, "Inventory".Translate());

                // only offer this button if the pawn has no loadout or has the default loadout and there are things/equipment...
                if (showMakeLoadout)
                {
                    Rect loadoutButtonRect = new Rect(viewRect.width / 2, buttonY, viewRect.width / 2, 26f);     // button is half the available width...
                    if (Widgets.ButtonText(loadoutButtonRect, "Make Loadout"))
                    {
                        Loadout loadout = SelPawnForGear.GenerateLoadoutFromPawn();
                        LoadoutManager.AddLoadout(loadout);
                        SelPawnForGear.SetLoadout(loadout);

                        // UNDONE ideally we'd open the assign (MainTabWindow_OutfitsAndLoadouts) tab as if the user clicked on it here.
                        // (ProfoundDarkness) But I have no idea how to do that just yet.  The attempts I made seem to put the RimWorld UI into a bit of a bad state.
                        //                     ie opening the tab like the dialog below.
                        //                    Need to understand how RimWorld switches tabs and see if something similar can be done here
                        //                     (or just remove the unfinished marker).

                        // Opening this window is the same way as if from the assign tab so should be correct.
                        Find.WindowStack.Add(new Dialog_ManageLoadouts(SelPawnForGear.GetLoadout()));
                    }
                }

                workingInvList.Clear();
                workingInvList.AddRange(SelPawnForGear.inventory.innerContainer);
                for (int i = 0; i < workingInvList.Count; i++)
                {
                    DrawThingRow(ref num, viewRect.width, workingInvList[i].GetInnerIfMinified(), true);
                }
            }
            if (Event.current.type == EventType.Layout)
            {
                _scrollViewHeight = num + 30f;
            }
            Widgets.EndScrollView();
            GUI.EndGroup();
            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
        }
예제 #5
0
 /// <summary>
 /// Makes it convenient to fetch a pawn's holdTracker (List of HoldRecords).
 /// </summary>
 /// <param name="pawn">Pawn to fetch the records for.</param>
 /// <returns>List of HoldRecords otherwise known as the Pawn's holdTracker.</returns>
 public static List <HoldRecord> GetHoldRecords(this Pawn pawn)
 {
     return(LoadoutManager.GetHoldRecords(pawn));
 }
예제 #6
0
        /// <summary>
        /// Find an item that should be dropped from the pawn's inventory and how much to drop.
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="dropThing">The thing which should be dropped.</param>
        /// <param name="dropCount">The amount to drop.</param>
        /// <returns>bool, true indicates that the out variables are filled with something to do work on (drop).</returns>
        // NOTE (ProfoundDarkness): Ended up doing this by nibbling away at the pawn's inventory (or dictionary representation of ThingDefs/Count).
        //  Probably not efficient but was easier to handle atm.
        static public bool GetExcessThing(this Pawn pawn, out Thing dropThing, out int dropCount)
        {
            //(ProfoundDarkness) Thanks to erdelf on the RimWorldMod discord for helping me figure out some dictionary stuff and C# concepts related to 'Primitives' (pass by Value).
            CompInventory     inventory = pawn.TryGetComp <CompInventory>();
            Loadout           loadout   = pawn.GetLoadout();
            List <HoldRecord> records   = LoadoutManager.GetHoldRecords(pawn);

            dropThing = null;
            dropCount = 0;

            if (inventory == null || inventory.container == null || loadout == null || loadout.Slots.NullOrEmpty())
            {
                return(false);
            }

            Dictionary <ThingDef, Integer> listing = GetStorageByThingDef(pawn);

            // iterate over specifics and generics and Chip away at the dictionary.
            foreach (LoadoutSlot slot in loadout.Slots)
            {
                if (slot.thingDef != null && listing.ContainsKey(slot.thingDef))
                {
                    listing[slot.thingDef].value -= slot.count;
                    if (listing[slot.thingDef].value <= 0)
                    {
                        listing.Remove(slot.thingDef);
                    }
                }
                if (slot.genericDef != null)
                {
                    List <ThingDef> killKeys     = new List <ThingDef>();
                    int             desiredCount = slot.count;
                    // find dictionary entries which corespond to covered slot.
                    foreach (ThingDef def in listing.Keys.Where(td => slot.genericDef.lambda(td)))
                    {
                        listing[def].value -= desiredCount;
                        if (listing[def].value <= 0)
                        {
                            desiredCount = 0 - listing[def].value;
                            killKeys.Add(def); // the thing in inventory is exausted, forget about it.
                        }
                        else
                        {
                            break; // we have satisifed this loadout so no need to keep enumerating.
                        }
                    }
                    // cleanup dictionary.
                    foreach (ThingDef def in killKeys)
                    {
                        listing.Remove(def);
                    }
                }
            }

            // if there is something left in the dictionary, that is what is to be dropped.
            // Complicated by the fact that we now consider ammo in guns as part of the inventory...
            if (listing.Any())
            {
                if (records != null && !records.NullOrEmpty())
                {
                    // look at each remaining 'uneaten' thingdef in pawn's inventory.
                    foreach (ThingDef def in listing.Keys)
                    {
                        HoldRecord rec = records.FirstOrDefault(r => r.thingDef == def);
                        if (rec == null)
                        {
                            // the item we have extra of has no HoldRecord, drop it.
                            dropThing = inventory.container.FirstOrDefault(t => t.def == def);
                            if (dropThing != null)
                            {
                                dropCount = listing[def].value > dropThing.stackCount ? dropThing.stackCount : listing[def].value;
                                return(true);
                            }
                        }
                        else if (rec.count < listing[def].value)
                        {
                            // the item we have extra of HAS a HoldRecord but the amount carried is above the limit of the HoldRecord, drop extra.
                            dropThing = pawn.inventory.innerContainer.FirstOrDefault(t => t.def == def);
                            if (dropThing != null)
                            {
                                dropCount = listing[def].value - rec.count;
                                dropCount = dropCount > dropThing.stackCount ? dropThing.stackCount : dropCount;
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    foreach (ThingDef def in listing.Keys)
                    {
                        dropThing = inventory.container.FirstOrDefault(t => t.GetInnerIfMinified().def == def);
                        if (dropThing != null)
                        {
                            dropCount = listing[def].value > dropThing.stackCount ? dropThing.stackCount : listing[def].value;
                            return(true);
                        }
                    }
                }
            } // else
            return(false);
        }
예제 #7
0
        /* (ProfoundDarkness) I've intentionally left some code remarked in the following code because it's a useful guide on how to create
         * and maintain the transpilers that will do nearly identical changes to RimWorld's code for the other 2 PawnColumnWorkers.
         */
        public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
        {
            if (pawn.outfits == null)
            {
                return;
            }
            //changed: int num = Mathf.FloorToInt((rect.width - 4f) * 0.714285731f);
            int num = Mathf.FloorToInt((rect.width - 4f) - IconSize);
            //changed: int num2 = Mathf.FloorToInt((rect.width - 4f) * 0.2857143f);
            int   num2 = Mathf.FloorToInt(IconSize);
            float num3 = rect.x;
            //added:
            float num4 = rect.y + ((rect.height - IconSize) / 2);

            // Reduce width if we're adding a clear forced button
            bool somethingIsForced = pawn.HoldTrackerAnythingHeld();
            Rect loadoutButtonRect = new Rect(num3, rect.y + 2f, (float)num, rect.height - 4f);

            if (somethingIsForced)
            {
                loadoutButtonRect.width -= 4f + (float)num2;
            }

            // Main loadout button
            string label = pawn.GetLoadout().label.Truncate(loadoutButtonRect.width, null);

            if (Widgets.ButtonText(loadoutButtonRect, label, true, false, true))
            {
                LoadoutManager.SortLoadouts();
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (Loadout loadout in LoadoutManager.Loadouts)
                {
                    // need to create a local copy for delegate
                    Loadout localLoadout = loadout;
                    options.Add(new FloatMenuOption(localLoadout.LabelCap, delegate
                    {
                        pawn.SetLoadout(localLoadout);
                    }, MenuOptionPriority.Default, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(options));
            }

            // Clear forced button
            num3 += loadoutButtonRect.width;
            num3 += 4f;
            //changed: Rect forcedHoldRect = new Rect(num3, rect.y + 2f, (float)num2, rect.height - 4f);
            Rect forcedHoldRect = new Rect(num3, num4, (float)num2, (float)num2);

            if (somethingIsForced)
            {
                //changed: if (Widgets.ButtonText(forcedHoldRect, "ClearForcedApparel".Translate(), true, false, true)) // "Clear forced" is sufficient and that's what this is at the moment.
                if (Widgets.ButtonImage(forcedHoldRect, ClearImage))
                {
                    pawn.HoldTrackerClear(); // yes this will also delete records that haven't been picked up and thus not shown to the player...
                }
                TooltipHandler.TipRegion(forcedHoldRect, new TipSignal(delegate
                {
                    string text = "CE_ForcedHold".Translate() + ":\n";
                    foreach (HoldRecord rec in LoadoutManager.GetHoldRecords(pawn))
                    {
                        if (!rec.pickedUp)
                        {
                            continue;
                        }
                        text = text + "\n   " + rec.thingDef.LabelCap + " x" + rec.count;
                    }
                    return(text);
                }, pawn.GetHashCode() * 613));
                num3 += (float)num2;
                num3 += 4f;
            }

            //changed: Rect assignTabRect = new Rect(num3, rect.y + 2f, (float)num2, rect.height - 4f);
            Rect assignTabRect = new Rect(num3, num4, (float)num2, (float)num2);

            //changed: if (Widgets.ButtonText(assignTabRect, "AssignTabEdit".Translate(), true, false, true))
            if (Widgets.ButtonImage(assignTabRect, EditImage))
            {
                Find.WindowStack.Add(new Dialog_ManageLoadouts(pawn.GetLoadout()));
            }
            // Added this next line.
            TooltipHandler.TipRegion(assignTabRect, new TipSignal(textGetter("CE_Loadouts"), pawn.GetHashCode() * 613));
            num3 += (float)num2;
        }
예제 #8
0
        public static void HoldTrackerClear(this Pawn pawn)
        {
            List <HoldRecord> recs = LoadoutManager.GetHoldRecords(pawn);

            recs.Clear();
        }
예제 #9
0
        protected override void DrawPawnRow(Rect rect, Pawn p)
        {
            // available space for row
            Rect rowRect = new Rect(rect.x + 165f, rect.y, rect.width - 165f, rect.height);

            // response button rect
            Vector2 responsePos = new Vector2(rowRect.xMin, rowRect.yMin + (rowRect.height - 24f) / 2f);

            // offset rest of row for that button, so we don't have to mess with all the other rect calculations
            rowRect.xMin += 24f + _margin;

            // label + buttons for outfit
            Rect outfitRect = new Rect(rowRect.xMin,
                                       rowRect.yMin,
                                       rowRect.width * (1f / 4f) + (_margin + _buttonSize) / 2f,
                                       rowRect.height);

            Rect labelOutfitRect = new Rect(outfitRect.xMin,
                                            outfitRect.yMin,
                                            outfitRect.width - _margin * 3 - _buttonSize * 2,
                                            outfitRect.height)
                                   .ContractedBy(_margin / 2f);
            Rect editOutfitRect = new Rect(labelOutfitRect.xMax + _margin,
                                           outfitRect.yMin + ((outfitRect.height - _buttonSize) / 2),
                                           _buttonSize,
                                           _buttonSize);
            Rect forcedOutfitRect = new Rect(labelOutfitRect.xMax + _buttonSize + _margin * 2,
                                             outfitRect.yMin + ((outfitRect.height - _buttonSize) / 2),
                                             _buttonSize,
                                             _buttonSize);

            // drucg policy
            Rect drugRect = new Rect(outfitRect.xMax,
                                     rowRect.yMin,
                                     rowRect.width * (1f / 4f) - (_margin + _buttonSize) / 2f,
                                     rowRect.height);
            Rect labelDrugRect = new Rect(drugRect.xMin,
                                          drugRect.yMin,
                                          drugRect.width - _margin * 2 - _buttonSize,
                                          drugRect.height)
                                 .ContractedBy(_margin / 2f);
            Rect editDrugRect = new Rect(labelDrugRect.xMax + _margin,
                                         drugRect.yMin + ((drugRect.height - _buttonSize) / 2),
                                         _buttonSize,
                                         _buttonSize);

            // label + button for loadout
            Rect loadoutRect = new Rect(drugRect.xMax,
                                        rowRect.yMin,
                                        rowRect.width * (1f / 4f) - (_margin + _buttonSize) / 2f,
                                        rowRect.height);
            Rect labelLoadoutRect = new Rect(loadoutRect.xMin,
                                             loadoutRect.yMin,
                                             loadoutRect.width - _margin * 3 - _buttonSize * 2,
                                             loadoutRect.height)
                                    .ContractedBy(_margin / 2f);
            Rect editLoadoutRect = new Rect(labelLoadoutRect.xMax + _margin,
                                            loadoutRect.yMin + ((loadoutRect.height - _buttonSize) / 2),
                                            _buttonSize,
                                            _buttonSize);
            Rect forcedHoldRect = new Rect(labelLoadoutRect.xMax + _buttonSize + _margin * 2,
                                           loadoutRect.yMin + ((loadoutRect.height - _buttonSize) / 2),
                                           _buttonSize,
                                           _buttonSize);

            // fight or flight button
            HostilityResponseModeUtility.DrawResponseButton(responsePos, p);

            // weight + bulk indicators
            Rect weightRect = new Rect(loadoutRect.xMax, rowRect.yMin, rowRect.width * (1f / 8f) - _margin, rowRect.height).ContractedBy(_margin / 2f);
            Rect bulkRect   = new Rect(weightRect.xMax + _margin, rowRect.yMin, rowRect.width * (1f / 8f) - _margin, rowRect.height).ContractedBy(_margin / 2f);

            // OUTFITS
            // main button
            if (Widgets.ButtonText(labelOutfitRect, p.outfits.CurrentOutfit.label, true, false))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (Outfit current in Current.Game.outfitDatabase.AllOutfits)
                {
                    // need to create a local copy for delegate
                    Outfit localOut = current;
                    options.Add(new FloatMenuOption(localOut.label, delegate
                    {
                        p.outfits.CurrentOutfit = localOut;
                    }, MenuOptionPriority.Default, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(options, optionalTitle, false));
            }

            // edit button
            TooltipHandler.TipRegion(editOutfitRect, "CE_EditX".Translate("CE_outfit".Translate() + " " + p.outfits.CurrentOutfit.label));
            if (Widgets.ButtonImage(editOutfitRect, _iconEdit))
            {
                Text.Font = GameFont.Small;
                Find.WindowStack.Add(new Dialog_ManageOutfits(p.outfits.CurrentOutfit));
            }

            // clear forced button
            if (p.outfits.forcedHandler.SomethingIsForced)
            {
                TooltipHandler.TipRegion(forcedOutfitRect, "ClearForcedApparel".Translate());
                if (Widgets.ButtonImage(forcedOutfitRect, _iconClearForced))
                {
                    p.outfits.forcedHandler.Reset();
                }
                TooltipHandler.TipRegion(forcedOutfitRect, new TipSignal(delegate
                {
                    string text = "ForcedApparel".Translate() + ":\n";
                    foreach (Apparel current2 in p.outfits.forcedHandler.ForcedApparel)
                    {
                        text = text + "\n   " + current2.LabelCap;
                    }
                    return(text);
                }, p.GetHashCode() * 612));
            }

            // DRUG POLICY
            // main button
            string textDrug = p.drugs.CurrentPolicy.label;

            if (p.story != null && p.story.traits != null)
            {
                Trait trait = p.story.traits.GetTrait(TraitDefOf.DrugDesire);
                if (trait != null)
                {
                    textDrug = textDrug + " (" + trait.Label + ")";
                }
            }
            if (Widgets.ButtonText(labelDrugRect, textDrug, true, false, true))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (DrugPolicy current in Current.Game.drugPolicyDatabase.AllPolicies)
                {
                    DrugPolicy localAssignedDrugs = current;
                    list.Add(new FloatMenuOption(current.label, delegate
                    {
                        p.drugs.CurrentPolicy = localAssignedDrugs;
                    }, MenuOptionPriority.Default, null, null, 0f, null));
                }
                Find.WindowStack.Add(new FloatMenu(list));
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.DrugPolicies, KnowledgeAmount.Total);
            }


            // edit button
            TooltipHandler.TipRegion(editDrugRect, "CE_EditX".Translate("CE_drugs".Translate() + " " + p.drugs.CurrentPolicy.label));
            if (Widgets.ButtonImage(editDrugRect, _iconEdit))
            {
                Text.Font = GameFont.Small;
                Find.WindowStack.Add(new Dialog_ManageDrugPolicies(p.drugs.CurrentPolicy));
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.DrugPolicies, KnowledgeAmount.Total);
            }

            // LOADOUTS
            // main button
            if (Widgets.ButtonText(labelLoadoutRect, p.GetLoadout().LabelCap, true, false))
            {
                LoadoutManager.SortLoadouts();
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (Loadout loadout in LoadoutManager.Loadouts)
                {
                    // need to create a local copy for delegate
                    Loadout localLoadout = loadout;
                    options.Add(new FloatMenuOption(localLoadout.LabelCap, delegate
                    {
                        p.SetLoadout(localLoadout);
                    }, MenuOptionPriority.Default, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(options, optionalTitle, false));
            }

            // edit button
            TooltipHandler.TipRegion(editLoadoutRect, "CE_EditX".Translate("CE_loadout".Translate() + " " + p.GetLoadout().LabelCap));
            if (Widgets.ButtonImage(editLoadoutRect, _iconEdit))
            {
                Find.WindowStack.Add(new Dialog_ManageLoadouts(p.GetLoadout()));
            }

            // clear forced held button
            if (p.HoldTrackerAnythingHeld())
            {
                TooltipHandler.TipRegion(forcedHoldRect, "ClearForcedApparel".Translate()); // "Clear forced" is sufficient and that's what this is at the moment.
                if (Widgets.ButtonImage(forcedHoldRect, _iconClearForced))                  // also can re-use the icon for clearing forced at the moment.
                {
                    p.HoldTrackerClear();                                                   // yes this will also delete records that haven't been picked up and thus not shown to the player...
                }
                TooltipHandler.TipRegion(forcedHoldRect, new TipSignal(delegate
                {
                    string text = "CE_ForcedHold".Translate() + ":\n";
                    foreach (HoldRecord rec in LoadoutManager.GetHoldRecords(p))
                    {
                        if (!rec.pickedUp)
                        {
                            continue;
                        }
                        text = text + "\n   " + rec.thingDef.LabelCap + " x" + rec.count;
                    }
                    return(text);
                }, p.GetHashCode() * 613));
            }

            // STATUS BARS
            // fetch the comp
            CompInventory comp = p.TryGetComp <CompInventory>();

            if (comp != null)
            {
                Utility_Loadouts.DrawBar(bulkRect, comp.currentBulk, comp.capacityBulk, "", p.GetBulkTip());
                Utility_Loadouts.DrawBar(weightRect, comp.currentWeight, comp.capacityWeight, "", p.GetWeightTip());
            }
        }
예제 #10
0
        /// <summary>
        /// Refreshes the cached bulk and weight. Call this whenever items are added/removed from inventory
        /// </summary>
        public void UpdateInventory()
        {
            if (parentPawn == null)
            {
                Log.Error("CompInventory on non-pawn " + parent.ToString());
                return;
            }
            float newBulk   = 0f;
            float newWeight = 0f;

            // Add equipped weapon
            if (parentPawn.equipment != null && parentPawn.equipment.Primary != null)
            {
                GetEquipmentStats(parentPawn.equipment.Primary, out newWeight, out newBulk);
            }

            // Add apparel
            if (parentPawn.apparel != null && parentPawn.apparel.WornApparelCount > 0)
            {
                foreach (Thing apparel in parentPawn.apparel.WornApparel)
                {
                    float apparelBulk   = apparel.GetStatValue(CE_StatDefOf.WornBulk);
                    float apparelWeight = apparel.GetStatValue(StatDefOf.Mass);
                    newBulk   += apparelBulk;
                    newWeight += apparelWeight;
                    if (apparelBulk > 0 && parentPawn != null && parentPawn.IsColonist && parentPawn.Spawned)
                    {
                        LessonAutoActivator.TeachOpportunity(CE_ConceptDefOf.CE_WornBulk, OpportunityType.GoodToKnow);
                    }
                }
            }

            // Add inventory items
            if (parentPawn.inventory != null && parentPawn.inventory.innerContainer != null)
            {
                ammoListCached.Clear();
                meleeWeaponListCached.Clear();
                rangedWeaponListCached.Clear();

                List <HoldRecord> recs = LoadoutManager.GetHoldRecords(parentPawn);
                foreach (Thing thing in parentPawn.inventory.innerContainer)
                {
                    // Check for weapons
                    ThingWithComps eq     = thing as ThingWithComps;
                    CompEquippable compEq = thing.TryGetComp <CompEquippable>();
                    if (eq != null && compEq != null)
                    {
                        if (eq.def.IsRangedWeapon)
                        {
                            rangedWeaponListCached.Add(eq);
                        }
                        else
                        {
                            meleeWeaponListCached.Add(eq);
                        }
                        // Calculate equipment weight
                        float eqWeight;
                        float eqBulk;
                        GetEquipmentStats(eq, out eqWeight, out eqBulk);
                        newWeight += eqWeight * thing.stackCount;
                        newBulk   += eqBulk * thing.stackCount;
                    }
                    else
                    {
                        // Add item weight
                        newBulk   += thing.GetStatValue(CE_StatDefOf.Bulk) * thing.stackCount;
                        newWeight += thing.GetStatValue(StatDefOf.Mass) * thing.stackCount;
                    }
                    // Update ammo list
                    if (thing.def is AmmoDef)
                    {
                        ammoListCached.Add(thing);
                    }
                    if (recs != null)
                    {
                        HoldRecord rec = recs.FirstOrDefault(hr => hr.thingDef == thing.def);
                        if (rec != null && !rec.pickedUp)
                        {
                            rec.pickedUp = true;
                        }
                    }
                }
            }
            currentBulkCached   = newBulk;
            currentWeightCached = newWeight;
        }
예제 #11
0
 public Tracker(List <HoldRecord> newRecs)
 {
     uniqueID = LoadoutManager.GetUniqueTrackerID();
     _recs    = newRecs;
 }
예제 #12
0
 public Tracker()
 {
     // this constructor is also used by the scribe.
     uniqueID = LoadoutManager.GetUniqueTrackerID();
     _recs    = new List <HoldRecord>();
 }
        /* (ProfoundDarkness) I've intentionally left some code remarked in the following code because it's a useful guide on how to create
         * and maintain the transpilers that will do nearly identical changes to RimWorld's code for the other 2 PawnColumnWorkers.
         */
        public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
        {
            if (pawn.outfits == null)
            {
                return;
            }
            //changed: int num = Mathf.FloorToInt((rect.width - 4f) * 0.714285731f);
            int num = Mathf.FloorToInt((rect.width - 4f) - IconSize);
            //changed: int num2 = Mathf.FloorToInt((rect.width - 4f) * 0.2857143f);
            int   num2 = Mathf.FloorToInt(IconSize);
            float num3 = rect.x;
            //added:
            float num4          = rect.y + ((rect.height - IconSize) / 2);
            float equipNowWidth = "CE_UpdateLoadoutNow".Translate().GetWidthCached();

            // Reduce width if we're adding a clear forced button
            bool somethingIsForced = pawn.HoldTrackerAnythingHeld();
            Rect loadoutRect       = new Rect(num3, rect.y + 2f, (float)num, rect.height - 4f);

            if (somethingIsForced)
            {
                loadoutRect.width -= 4f + (float)num2;
            }

            // Main loadout button
            Rect mainLoadoutButton = pawn.Spawned ? loadoutRect.LeftPartPixels(loadoutRect.width - equipNowWidth - 16) : loadoutRect;

            mainLoadoutButton.xMax -= 2;
            string label = pawn.GetLoadout().label.Truncate(mainLoadoutButton.width, null);

            Widgets.Dropdown <Pawn, Loadout>(mainLoadoutButton, pawn, (Pawn p) => p.GetLoadout(), new Func <Pawn, IEnumerable <Widgets.DropdownMenuElement <Loadout> > >(Button_GenerateMenu), label, null, null, null, null, true);

            if (pawn.Spawned)
            {
                Rect forceEquipNow = loadoutRect.RightPartPixels(equipNowWidth + 12);
                if (Widgets.ButtonText(forceEquipNow, "CE_UpdateLoadoutNow".Translate()))
                {
                    Job           job       = JobGiver_UpdateLoadout.GetUpdateLoadoutJob(pawn);
                    CompInventory inventory = pawn.TryGetComp <CompInventory>();
                    if (inventory != null)
                    {
                        inventory.ForcedLoadoutUpdate = job != null;
                    }
                    if (job != null)
                    {
                        pawn.jobs.StopAll(false, true);
                        pawn.jobs.StartJob(job, JobCondition.InterruptForced, tag: JobTag.ChangingApparel);
                    }
                }
            }

            // Clear forced button
            num3 += loadoutRect.width;
            num3 += 4f;
            //changed: Rect forcedHoldRect = new Rect(num3, rect.y + 2f, (float)num2, rect.height - 4f);
            Rect forcedHoldRect = new Rect(num3, num4, (float)num2, (float)num2);

            if (somethingIsForced)
            {
                if (Widgets.ButtonImage(forcedHoldRect, ClearImage))
                {
                    pawn.HoldTrackerClear(); // yes this will also delete records that haven't been picked up and thus not shown to the player...
                }
                TooltipHandler.TipRegion(forcedHoldRect, new TipSignal(delegate
                {
                    string text = "CE_ForcedHold".Translate() + ":\n";
                    foreach (HoldRecord rec in LoadoutManager.GetHoldRecords(pawn))
                    {
                        if (!rec.pickedUp)
                        {
                            continue;
                        }
                        text = text + "\n   " + rec.thingDef.LabelCap + " x" + rec.count;
                    }
                    return(text);
                }, pawn.GetHashCode() * 613));
                num3 += (float)num2;
                num3 += 4f;
            }

            //changed: Rect assignTabRect = new Rect(num3, rect.y + 2f, (float)num2, rect.height - 4f);
            Rect assignTabRect = new Rect(num3, num4, (float)num2, (float)num2);

            //changed: if (Widgets.ButtonText(assignTabRect, "AssignTabEdit".Translate(), true, false, true))
            if (Widgets.ButtonImage(assignTabRect, EditImage))
            {
                Find.WindowStack.Add(new Dialog_ManageLoadouts(pawn.GetLoadout()));
            }
            // Added this next line.
            TooltipHandler.TipRegion(assignTabRect, new TipSignal(textGetter("CE_Loadouts"), pawn.GetHashCode() * 613));
            num3 += (float)num2;
        }