private void DrawOverallArmor(Rect rect, StatDef stat, string label, Texture image)
        {
            // Dark magic from vanilla code calculating armor value until the blank line.
            float num  = 0f;
            float num2 = Mathf.Clamp01(SelPawnForGear.GetStatValue(stat, true) / 2f);
            List <BodyPartRecord> allParts = SelPawnForGear.RaceProps.body.AllParts;
            List <Apparel>        list     = (SelPawnForGear.apparel == null) ? null : SelPawnForGear.apparel.WornApparel;

            for (int i = 0; i < allParts.Count; i++)
            {
                float num3 = 1f - num2;
                if (list != null)
                {
                    for (int j = 0; j < list.Count; j++)
                    {
                        if (list[j].def.apparel.CoversBodyPart(allParts[i]))
                        {
                            float num4 = Mathf.Clamp01(list[j].GetStatValue(stat, true) / 2f);
                            num3 *= 1f - num4;
                        }
                    }
                }
                num += allParts[i].coverageAbs * (1f - num3);
            }
            num = Mathf.Clamp(num * 2f, 0f, 2f);

            Rect iconRect = new Rect(rect.x, rect.y, SmallIconSize, SmallIconSize);

            GUI.DrawTexture(iconRect, image);
            TooltipHandler.TipRegion(iconRect, label);
            // the 36px can make the percentage number look like it is centered in the field. Brilliant Sandy.
            Rect valRect = new Rect(rect.x + SmallIconSize + 36f, rect.y + SmallIconMargin, statBoxWidth - SmallIconSize, SmallIconSize);

            Widgets.Label(valRect, num.ToStringPercent());
        }
        private void DrawComfyTemperatureRange(Vector2 topLeft)
        {
            if (SelPawnForGear.Dead)
            {
                return;
            }
            Rect iconRect = new Rect(topLeft.x, topLeft.y, SmallIconSize, SmallIconSize);

            GUI.DrawTexture(iconRect, ContentFinder <Texture2D> .Get("UI/Icons/Min_Temperature"));
            TooltipHandler.TipRegion(iconRect, "ComfyTemperatureRange".Translate());
            float statValue = SelPawnForGear.GetStatValue(StatDefOf.ComfyTemperatureMin);
            Rect  textRect  = new Rect(topLeft.x + SmallIconSize + MediumMargin, topLeft.y + SmallIconMargin, statBoxWidth - SmallIconSize, SmallIconSize);

            Widgets.Label(textRect, " " + statValue.ToStringTemperature("F0"));

            iconRect.Set(iconRect.x, iconRect.y + SmallIconSize + SmallIconMargin, SmallIconSize, SmallIconSize);
            GUI.DrawTexture(iconRect, ContentFinder <Texture2D> .Get("UI/Icons/Max_Temperature"));
            TooltipHandler.TipRegion(iconRect, "ComfyTemperatureRange".Translate());
            statValue = SelPawnForGear.GetStatValue(StatDefOf.ComfyTemperatureMax);
            textRect.Set(textRect.x, textRect.y + SmallIconSize + SmallIconMargin, statBoxWidth - SmallIconSize, SmallIconSize);
            Widgets.Label(textRect, " " + statValue.ToStringTemperature("F0"));
        }
Exemple #3
0
        // RimWorld.ITab_Pawn_Gear
        private void TryDrawOverallArmor(ref float curY, float width, StatDef stat, string label, string unit)
        {
            float          naturalArmor = SelPawnForGear.GetStatValue(stat);
            float          averageArmor = naturalArmor;
            List <Apparel> wornApparel  = SelPawnForGear.apparel?.WornApparel;

            foreach (Apparel apparel in wornApparel ?? Enumerable.Empty <Apparel>())
            {
                averageArmor += apparel.GetStatValue(stat, true) * apparel.def.apparel.HumanBodyCoverage;
            }
            if (averageArmor > 0.0001f)
            {
                Rect   rect = new Rect(0f, curY, width, _standardLineHeight);
                string text = "";
                foreach (BodyPartRecord bodyPart in SelPawnForGear.RaceProps.body.AllParts)
                {
                    BodyPartRecord part       = bodyPart;
                    float          armorValue = bodyPart.IsInGroup(CE_BodyPartGroupDefOf.CoveredByNaturalArmor) ? naturalArmor : 0f;
                    if (part.depth == BodyPartDepth.Outside && (part.coverage >= 0.1 || (part.def == BodyPartDefOf.Eye || part.def == BodyPartDefOf.Neck)))
                    {
                        text += part.LabelCap + ": ";
                        foreach (Apparel apparel in wornApparel ?? Enumerable.Empty <Apparel>())
                        {
                            if (apparel.def.apparel.CoversBodyPart(part))
                            {
                                armorValue += apparel.GetStatValue(stat, true);
                            }
                        }
                        text += formatArmorValue(armorValue, unit) + "\n";
                    }
                }
                TooltipHandler.TipRegion(rect, text);

                Widgets.Label(rect, label.Truncate(200f, null));
                rect.xMin += 200;
                Widgets.Label(rect, formatArmorValue(averageArmor, unit));
                curY += _standardLineHeight;
            }
        }