protected void AssignEquipmentToPawn(InventoryRecord record, Pawn pawn)
        {
            Thing thing = this.FindClosestValidThing(record, pawn);

            if (thing == null)
            {
                Messages.Message("EdB.Inventory.Equipment.Error".Translate(), MessageSound.Negative);
                SoundDefOf.DesignateFailed.PlayOneShotOnCamera();
                return;
            }
            Thing   thing2  = (thing.def.equipmentType == EquipmentType.None) ? null : thing;
            Apparel apparel = thing as Apparel;

            if (thing2 != null)
            {
                thing2.SetForbidden(false, true);
                Job job = new Job(JobDefOf.Equip, new TargetInfo(thing2));
                job.playerForced = true;
                pawn.drafter.TakeOrderedJob(job);
            }
            else if (apparel != null)
            {
                apparel.SetForbidden(false, true);
                Job job2 = new Job(JobDefOf.Wear, new TargetInfo(apparel));
                job2.playerForced = true;
                pawn.drafter.TakeOrderedJob(job2);
            }
            SoundDefOf.ColonistOrdered.PlayOneShotOnCamera();
            this.manager.TakeInventory();
        }
示例#2
0
        protected void PrepareBuildingRecord(InventoryRecord record)
        {
            ThingDef thingDef = record.thingDef;

            if (thingDef.entityDefToBuild == null)
            {
                record.texture = thingDef.uiIcon;
            }
            else
            {
                record.texture = thingDef.entityDefToBuild.uiIcon;
            }
            if (thingDef.graphic != null)
            {
                record.proportions = new Vector2(thingDef.graphic.drawSize.x / thingDef.graphic.drawSize.y, 1f);
                float num           = (thingDef.graphic.drawSize.x <= thingDef.graphic.drawSize.y) ? thingDef.graphic.drawSize.y : thingDef.graphic.drawSize.x;
                float num2          = (float)((thingDef.size.x <= thingDef.size.z) ? thingDef.size.z : thingDef.size.x);
                float num3          = 0.5f;
                float num4          = 1.75f;
                float num5          = num / num2;
                float buildingScale = (num5 - num3) / num4 + num3;
                record.buildingScale = buildingScale;
            }
            else
            {
                record.proportions   = new Vector2(1f, 1f);
                record.buildingScale = 1f;
            }
            if (record.stuffDef != null)
            {
                record.color = ((record.stuffDef.graphic == null) ? Color.white : record.stuffDef.graphic.color);
            }
        }
        protected Thing FindClosestValidThing(InventoryRecord record, Pawn pawn)
        {
            List <EquippableThing> list = this.manager.EquippableThings[new InventoryRecordKey(record.thingDef, record.stuffDef)];

            foreach (EquippableThing current in list)
            {
                Thing thing2 = current.thing;
                current.distance = (pawn.Position - thing2.Position).LengthHorizontalSquared;
            }
            IEnumerable <Thing> enumerable = from thing in list
                                             orderby thing.distance
                                             select thing.thing;

            foreach (Thing current2 in enumerable)
            {
                if (pawn.CanReach(current2, PathEndMode.ClosestTouch, Danger.Deadly, false))
                {
                    if (pawn.CanReserveAndReach(new TargetInfo(current2), PathEndMode.ClosestTouch, Danger.Deadly, 1))
                    {
                        return(current2);
                    }
                }
            }
            return(null);
        }
示例#4
0
 protected void PrepareRecord(InventoryRecord record)
 {
     if (record.thingDef.building != null)
     {
         this.PrepareBuildingRecord(record);
     }
     this.PrepareInventoryResolver(record);
     this.PrepareInventoryCounters(record);
 }
示例#5
0
        protected void PrepareInventoryResolver(InventoryRecord record)
        {
            ThingDef          thingDef = record.thingDef;
            InventoryResolver resolver;

            if (this.inventoryResolvers.TryGetValue(thingDef.defName, out resolver))
            {
                record.resolver = resolver;
            }
        }
示例#6
0
        protected void Count(Thing thing)
        {
            if (thing == null)
            {
                return;
            }
            InventoryRecord  inventoryRecord = null;
            bool             flag            = false;
            InventoryCounter inventoryCounter;

            if (this.thingCounters.TryGetValue(thing.def, out inventoryCounter))
            {
                inventoryRecord = inventoryCounter.CountThing(thing, this.allRecords, this.state, out flag);
            }
            if (inventoryRecord == null)
            {
                inventoryRecord = this.defaultInventoryCounter.CountThing(thing, this.allRecords, this.state, out flag);
            }
            if (inventoryRecord == null)
            {
                return;
            }
            if (flag)
            {
                this.equippableThings.Add(new InventoryRecordKey(inventoryRecord.thingDef, inventoryRecord.stuffDef), thing);
            }
            Dictionary <InventoryRecordKey, InventoryRecord> dictionary;

            if (this.categorizedRecords.TryGetValue(inventoryRecord.type, out dictionary))
            {
                InventoryRecordKey key = new InventoryRecordKey(inventoryRecord.thingDef, inventoryRecord.stuffDef);
                if (!dictionary.ContainsKey(key))
                {
                    dictionary.Add(key, inventoryRecord);
                }
            }
        }
示例#7
0
        public InventoryRecord CountThing(Thing thing, Dictionary <InventoryRecordKey, InventoryRecord> recordLookup, InventoryState state, out bool equippable)
        {
            equippable = false;
            if (thing == null)
            {
                Log.Warning("Tried to count a null thing");
                return(null);
            }
            ThingDef thingDef = thing.def;

            if (thingDef == null)
            {
                Log.Warning("Failed to count thing.  Its definition is null.");
                return(null);
            }
            ThingDef thingDef2 = null;

            if (thingDef.building != null && thingDef.entityDefToBuild != null)
            {
                thingDef2 = thingDef;
                thingDef  = (thingDef.entityDefToBuild as ThingDef);
                if (thingDef == null)
                {
                    return(null);
                }
            }
            Thing thing2 = thing.GetInnerIfMinified();

            if (thing2 == thing)
            {
                thing2 = null;
            }
            if (thing2 != null)
            {
                thing    = thing2;
                thingDef = thing2.def;
                if (thingDef == null)
                {
                    return(null);
                }
            }
            InventoryRecord inventoryRecord = null;

            if (!recordLookup.TryGetValue(new InventoryRecordKey(thingDef, thing.Stuff), out inventoryRecord))
            {
                if (thing.Stuff == null)
                {
                    Log.Warning("Did not find record for " + thingDef.defName);
                }
                else
                {
                    Log.Warning("Did not find record for " + thingDef.defName + " made out of " + thing.Stuff.defName);
                }
                return(null);
            }
            if (inventoryRecord.type == InventoryType.UNKNOWN)
            {
                return(null);
            }
            if (thingDef2 == null && thing2 == null)
            {
                inventoryRecord.count += thing.stackCount;
            }
            else
            {
                inventoryRecord.unfinishedCount += thing.stackCount;
            }
            if (thingDef.building == null)
            {
                TextureColorPair textureColorPair = MaterialResolver.Resolve(thing);
                inventoryRecord.texture = textureColorPair.texture;
                inventoryRecord.color   = thing.DrawColor;
            }
            else
            {
                inventoryRecord.color = thing.DrawColor;
            }
            if (thingDef.equipmentType != EquipmentType.None || thingDef.apparel != null)
            {
                bool flag  = thing.SelectableNow();
                bool flag2 = this.reservedThings.Contains(thing);
                if (flag && !flag2)
                {
                    if (inventoryRecord.availableCount == -1)
                    {
                        inventoryRecord.availableCount = thing.stackCount;
                    }
                    else
                    {
                        inventoryRecord.availableCount += thing.stackCount;
                    }
                    equippable = true;
                }
                else if (inventoryRecord.availableCount == -1)
                {
                    inventoryRecord.availableCount = 0;
                }
                if (flag2)
                {
                    inventoryRecord.reservedCount++;
                }
            }
            return(inventoryRecord);
        }
示例#8
0
        protected void PrepareAllDefinitions()
        {
            this.schematicDef = DefDatabase <ThingCategoryDef> .GetNamedSilentFail("Schematic");

            Dictionary <StuffCategoryDef, HashSet <ThingDef> > dictionary = new Dictionary <StuffCategoryDef, HashSet <ThingDef> >();

            foreach (ThingDef current in DefDatabase <ThingDef> .AllDefs)
            {
                if (current.IsStuff && current.stuffProps != null)
                {
                    foreach (StuffCategoryDef current2 in current.stuffProps.categories)
                    {
                        HashSet <ThingDef> hashSet = null;
                        if (!dictionary.TryGetValue(current2, out hashSet))
                        {
                            hashSet = new HashSet <ThingDef>();
                            dictionary.Add(current2, hashSet);
                        }
                        hashSet.Add(current);
                    }
                }
            }
            foreach (ThingDef current3 in DefDatabase <ThingDef> .AllDefs)
            {
                if (current3.MadeFromStuff)
                {
                    if (current3.stuffCategories != null)
                    {
                        foreach (StuffCategoryDef current4 in current3.stuffCategories)
                        {
                            HashSet <ThingDef> hashSet2;
                            if (dictionary.TryGetValue(current4, out hashSet2))
                            {
                                foreach (ThingDef current5 in hashSet2)
                                {
                                    try
                                    {
                                        InventoryRecord inventoryRecord = new InventoryRecord();
                                        inventoryRecord.thingDef = current3;
                                        inventoryRecord.stuffDef = current5;
                                        inventoryRecord.count    = 0;
                                        inventoryRecord.color    = new Color(1f, 1f, 1f);
                                        inventoryRecord.texture  = null;
                                        this.PrepareBuildingRecord(inventoryRecord);
                                        this.allRecords[new InventoryRecordKey(current3, current5)] = inventoryRecord;
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error(string.Concat(new string[]
                                        {
                                            "Failed to prepare thing definitions for EdB Interface inventory dialog.  Failed on ",
                                            current3.defName,
                                            " with ",
                                            current5.defName,
                                            " stuff"
                                        }));
                                        throw ex;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        InventoryRecord inventoryRecord2 = new InventoryRecord();
                        inventoryRecord2.thingDef = current3;
                        inventoryRecord2.stuffDef = null;
                        inventoryRecord2.count    = 0;
                        inventoryRecord2.color    = new Color(1f, 1f, 1f);
                        inventoryRecord2.texture  = null;
                        this.PrepareBuildingRecord(inventoryRecord2);
                        this.allRecords[new InventoryRecordKey(current3, null)] = inventoryRecord2;
                    }
                    catch (Exception ex2)
                    {
                        Log.Error("Failed to prepare thing definitions for EdB Interface inventory dialog.  Failed on " + current3.defName);
                        throw ex2;
                    }
                }
            }
        }
示例#9
0
 protected void PrepareInventoryCounters(InventoryRecord record)
 {
 }
        protected Vector2 DrawResources(float width, List <InventoryRecord> records, Vector2 position, Vector2 iconSize, Vector2 offset, Vector2 slotSize, InventoryPreferences prefs)
        {
            if (this.equipmentAssignmentFloatMenu != null && Find.WindowStack[0] != this.equipmentAssignmentFloatMenu)
            {
                this.equipmentAssignmentFloatMenu = null;
            }
            Vector2 result = new Vector2(position.x, position.y);

            foreach (InventoryRecord current in records)
            {
                if (current.count != 0 || (current.compressedCount != 0 && prefs.CompressedStorage.Value) || (current.unfinishedCount != 0 && prefs.IncludeUnfinished.Value))
                {
                    if (result.x + slotSize.x > width)
                    {
                        result.y += slotSize.y;
                        result.y += InventoryTab.SlotRowPadding;
                        result.x  = InventoryTab.SectionPaddingSides;
                    }
                    if (current.texture != null)
                    {
                        Vector2 vector = new Vector2(0f, 0f);
                        if (current.thingDef.apparel != null && current.thingDef.apparel.LastLayer == ApparelLayer.Overhead)
                        {
                            vector.y += 10f;
                        }
                        Rect rect = new Rect(result.x + offset.x + vector.x, result.y + offset.y + vector.y, iconSize.x, iconSize.y);
                        GUI.color = current.color;
                        if (current.thingDef.building == null)
                        {
                            GUI.DrawTexture(rect, current.thingDef.uiIcon);
                            if (current.availableCount > 0 && this.equipmentAssignmentFloatMenu == null && Widgets.InvisibleButton(rect) && Event.current.button == 1)
                            {
                                List <FloatMenuOption> list = new List <FloatMenuOption>();
                                foreach (Pawn current2 in Find.ListerPawns.FreeColonists)
                                {
                                    if (current2.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                                    {
                                        InventoryRecord assignedRecord = current;
                                        Pawn            assignedPawn   = current2;
                                        list.Add(new FloatMenuOption(current2.LabelBaseShort, delegate
                                        {
                                            this.AssignEquipmentToPawn(assignedRecord, assignedPawn);
                                        }, MenuOptionPriority.Medium, null, null));
                                    }
                                }
                                this.equipmentAssignmentFloatMenu = new FloatMenu(list, "EdB.Inventory.Equipment.Assign".Translate(), false, false);
                                Find.WindowStack.Add(this.equipmentAssignmentFloatMenu);
                            }
                        }
                        else
                        {
                            if (current.texture == null)
                            {
                                Log.Warning("No texture for building: " + current.thingDef.defName);
                            }
                            Widgets.DrawTextureFitted(rect, current.texture as Texture2D, current.buildingScale, current.proportions, new Rect(0f, 0f, 1f, 1f));
                        }
                        if (this.equipmentAssignmentFloatMenu == null)
                        {
                            string tooltipText = GenLabel.ThingLabel(current.thingDef, current.stuffDef, 1).CapitalizeFirst() + (string.IsNullOrEmpty(current.thingDef.description) ? string.Empty : ("\n\n" + current.thingDef.description));
                            if (current.availableCount > -1)
                            {
                                tooltipText = string.Concat(new string[]
                                {
                                    tooltipText,
                                    "\n\n",
                                    "EdB.Inventory.Equipment.Equipped".Translate(new object[]
                                    {
                                        current.count - current.reservedCount - current.availableCount
                                    }),
                                    "\n",
                                    "EdB.Inventory.Equipment.Reserved".Translate(new object[]
                                    {
                                        current.reservedCount
                                    }),
                                    "\n",
                                    "EdB.Inventory.Equipment.Available".Translate(new object[]
                                    {
                                        current.availableCount
                                    })
                                });
                            }
                            TipSignal tip = new TipSignal(tooltipText, tooltipText.GetHashCode());
                            TooltipHandler.TipRegion(rect, tip);
                        }
                        Text.Anchor = TextAnchor.UpperCenter;
                        GUI.color   = Color.white;
                        Text.Font   = GameFont.Tiny;
                        string label;
                        if (prefs.IncludeUnfinished.Value && current.thingDef.building != null)
                        {
                            label = string.Empty + current.count + ((current.unfinishedCount <= 0) ? string.Empty : (" / " + (current.count + current.unfinishedCount)));
                        }
                        else if (prefs.CompressedStorage.Value && current.compressedCount > 0)
                        {
                            label = string.Concat(new object[]
                            {
                                string.Empty,
                                current.count,
                                " / ",
                                current.count + current.compressedCount
                            });
                        }
                        else
                        {
                            label = string.Empty + current.count;
                        }
                        Widgets.Label(new Rect(result.x, result.y + slotSize.y - InventoryTab.LabelOffset.y, slotSize.x, slotSize.y), label);
                        result.x += slotSize.x;
                    }
                }
            }
            return(result);
        }