public void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, ThingWithComps parentThing, string preLabel)
 {
     foreach (LootAffixModifier modifier in modifiers)
     {
         modifier.SpecialDisplayStatsInjectors(statDrawEntry, parentThing, preLabel);
     }
 }
Exemple #2
0
        //Thanks to XeoNovaDan
        public static void DisplayYieldInfo(PlantProperties __instance, ref IEnumerable <StatDrawEntry> __result)
        {
            ThingDef harvestedThingDef = Traverse.Create(__instance).Field("harvestedThingDef").GetValue <ThingDef>();
            float    harvestYield      = Traverse.Create(__instance).Field("harvestYield").GetValue <float>();

            if (harvestedThingDef == null)
            {
                return;
            }

            string harvestedThingDefLabel = harvestedThingDef.label;

            string extendedYieldInfo = string.Format("M4_HarvestYieldThingDetailInit".Translate(), harvestedThingDefLabel) + "\n\n";
            float  thingMarketValue  = harvestedThingDef.GetStatValueAbstract(StatDefOf.MarketValue, null);

            extendedYieldInfo += StatDefOf.MarketValue.label.CapitalizeFirst() + ": " + thingMarketValue.ToString();
            if (harvestedThingDef.IsNutritionGivingIngestible)
            {
                float         thingNutrition     = harvestedThingDef.GetStatValueAbstract(StatDefOf.Nutrition, null);
                FoodTypeFlags thingNutritionType = harvestedThingDef.ingestible.foodType;
                IDictionary <FoodTypeFlags, string> nutritionTypeToReportString = new Dictionary <FoodTypeFlags, string>()
                {
                    { FoodTypeFlags.VegetableOrFruit, "FoodTypeFlags_VegetableOrFruit" }, { FoodTypeFlags.Meat, "FoodTypeFlags_Meat" }, { FoodTypeFlags.Seed, "FoodTypeFlags_Seed" }
                };
                string nutritionTypeReportString = nutritionTypeToReportString.TryGetValue(thingNutritionType, out nutritionTypeReportString) ? nutritionTypeReportString : "StatsReport_OtherStats";
                extendedYieldInfo += "\n" + StatDefOf.Nutrition.label.CapitalizeFirst() + ": " + thingNutrition.ToString() +
                                     " (" + nutritionTypeReportString.Translate() + ")";
            }

            if (harvestYield > 0)
            {
                StatDrawEntry statDrawEntry = new StatDrawEntry(StatCategoryDefOf.Basics, "M4_HarvestYieldThing".Translate(), harvestedThingDef.label.CapitalizeFirst(), 0, extendedYieldInfo);
                __result = __result.Add(statDrawEntry);
            }
        }
        private string GetExplanationTextShip(StatDrawEntry sde, StatRequest optionalReq)
        {
            string reportText = (string)AccessTools.Field(typeof(StatDrawEntry), "overrideReportText").GetValue(sde);

            if (!reportText.NullOrEmpty())
            {
                return(reportText);
            }
            if (sde is null)
            {
                return(string.Empty);
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(sde.stat.LabelCap);
            sb.AppendLine();
            sb.AppendLine(sde.stat.description);
            sb.AppendLine();
            if (!optionalReq.Empty)
            {
                sb.AppendLine(sde.stat.Worker.GetExplanationFull(optionalReq, Traverse.Create(sde).Field("numberSense").GetValue <ToStringNumberSense>(), Traverse.Create(sde).Field("value").GetValue <float>()));
            }
            return(sb.ToString().TrimEndNewlines());
        }
Exemple #4
0
        public override IEnumerable <StatDrawEntry> SpecialDisplayStats(StatRequest req)
        {
            using (IEnumerator <StatDrawEntry> enumerator = base.SpecialDisplayStats(req).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    StatDrawEntry stat = enumerator.Current;
                    yield return(stat);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            string[] affordance = (from ta in affordances.Distinct()
                                   orderby ta.order
                                   select ta.label).ToArray();
            if (affordance.Length > 0)
            {
                yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "Supports".Translate(), affordance.ToCommaList().CapitalizeFirst(), 0, string.Empty));

                /*Error: Unable to find new state assignment for yield return*/;
            }
            yield break;
IL_0175:
            /*Error near IL_0176: Unexpected return in MoveNext()*/;
        }
Exemple #5
0
        public override IEnumerable <StatDrawEntry> SpecialDisplayStats(StatRequest req)
        {
            using (IEnumerator <StatDrawEntry> enumerator = base.SpecialDisplayStats(req).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    StatDrawEntry stat = enumerator.Current;
                    yield return(stat);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            IEnumerable <TerrainAffordanceDef> affdefs = Enumerable.Empty <TerrainAffordanceDef>();

            if (PlaceWorkers != null)
            {
                affdefs = affdefs.Concat(PlaceWorkers.SelectMany((PlaceWorker pw) => pw.DisplayAffordances()));
            }
            if (terrainAffordanceNeeded != null)
            {
                affdefs = affdefs.Concat(terrainAffordanceNeeded);
            }
            string[] affordances = (from ta in affdefs.Distinct()
                                    orderby ta.order
                                    select ta.label).ToArray();
            if (affordances.Length > 0)
            {
                yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "TerrainRequirement".Translate(), affordances.ToCommaList().CapitalizeFirst(), 0, string.Empty));

                /*Error: Unable to find new state assignment for yield return*/;
            }
            yield break;
IL_01f5:
            /*Error near IL_01f6: Unexpected return in MoveNext()*/;
        }
Exemple #6
0
 public static void Postfix(ThingDef __instance, ref IEnumerable <StatDrawEntry> __result)
 {
     if (typeof(Building_Window).IsAssignableFrom(__instance.thingClass))
     {
         StatDrawEntry x = new StatDrawEntry(StatCategoryDefOf.Basics, "CoverEffectiveness".Translate(), WindowUtility.WindowBaseFillPercent.ToStringPercent(), "CoverEffectivenessExplanation".Translate(), 0);
         __result = new StatDrawEntry[] { x };
     }
 }
Exemple #7
0
 public override void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, ThingWithComps parentThing, string preLabel)
 {
     basicStatDesc.SpecialDisplayStatsInjectors(
         statDrawEntry:  statDrawEntry,
         preLabel:       preLabel,
         parentThing:    parentThing,
         parentModifier: this,
         curDef:         resolvedDef
         );
 }
Exemple #8
0
 public void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, string preLabel, ThingWithComps parentThing, LootAffixModifier parentModifier, bool curValue)
 {
     SpecialDisplayStatsInjectors(
         statDrawEntry:  statDrawEntry,
         preLabel:       preLabel,
         parentThing:    parentThing,
         parentModifier: parentModifier,
         finalString:    GetModifierChangeString(curValue)
         );
 }
 // FIXME
 public override void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, ThingWithComps parentThing, string preLabel)
 {
     basicStatDesc.SpecialDisplayStatsInjectors(
         statDrawEntry:  statDrawEntry,
         preLabel:       preLabel,
         parentThing:    parentThing,
         parentModifier: this,
         curDef:         extraDamage.def  // FIXME: placeholder
         );
 }
Exemple #10
0
        static void Postfix(ref StatDrawEntry __result, Thing thing)
        {
            if (!thing.PsiEquipmentTracker()?.IsPsychic ?? true)
            {
                return;
            }

            __result = new StatDrawEntry(StatCategoryDefOf.BasicsImportant, "Description".Translate(), "",
                                         thing.DescriptionFlavor + "PsiTech.PsychicWeaponDesc".Translate(), 99999, null,
                                         Dialog_InfoCard.DefsToHyperlinks(thing.def.descriptionHyperlinks));
        }
 //public static void Fillage_Prefix(ref ThingDef __instance) //This can intercept a method when it calls for a specific property!
 //{
 //    StackTrace stackTrace = new StackTrace();
 //    MethodBase target = AccessTools.Method(typeof(ThingDef), "SpecialDisplayStats") as MethodBase;
 //    //if (stackTrace.GetFrame(3).GetMethod() == target) Log.Message("eureka!"); //lighter load, but gotta know the method position on the stack
 //    foreach (StackFrame sf in stackTrace.GetFrames())
 //    {
 //        //Log.Message(sf.GetMethod().Name);
 //        if (sf.GetMethod().Equals(target)) Log.Message("eureka!");
 //        //{
 //        //    Log.Message(sf.GetMethod().Name);
 //        //}
 //    }
 //}
 public static void SpecialDisplayStats_Postfix(ThingDef __instance, ref IEnumerable <StatDrawEntry> __result)
 {
     if (typeof(Building_Window).IsAssignableFrom(__instance.thingClass))
     {
         StatDrawEntry x = new StatDrawEntry(StatCategoryDefOf.Basics, "CoverEffectiveness".Translate(), WindowBaseFillPercent.ToStringPercent(), 0, string.Empty)
         {
             overrideReportText = "CoverEffectivenessExplanation".Translate()
         };
         StatDrawEntry[] y = new StatDrawEntry[] { x };
         __result = y;
     }
 }
Exemple #12
0
        public static void Postfix(IEnumerator <StatDrawEntry> __instance, ref bool __result)
        {
            if (__result)
            {
                var entry = __instance.Current;
                if (entry.LabelCap.Contains(BurstShotStatName.Translate().CapitalizeFirst()))
                {
                    var def       = (ThingDef)AccessTools.Field(__instance.GetType(), "$this").GetValue(__instance);
                    var compProps = def.GetCompProperties <CompProperties_FireModes>();

                    if (compProps != null)
                    {
                        var aimedBurstCount = compProps.aimedBurstShotCount;
                        var burstShotCount  = ((VerbProperties)AccessTools.Field(__instance.GetType(), "<verb>__4").GetValue(__instance)).burstShotCount;

                        // Append aimed burst count
                        if (aimedBurstCount != burstShotCount)
                        {
                            var valueStringField = AccessTools.Field(typeof(StatDrawEntry), "valueStringInt");
                            valueStringField.SetValue(entry, $"{aimedBurstCount} / {burstShotCount}", BindingFlags.NonPublic | BindingFlags.Instance, null, CultureInfo.InvariantCulture);
                        }
                    }
                }
                // Override cover effectiveness with collision height
                else if (entry.LabelCap.Contains(CoverStatName.Translate().CapitalizeFirst()))
                {
                    // Determine collision height
                    var def = (ThingDef)AccessTools.Field(__instance.GetType(), "$this").GetValue(__instance);
                    if (def.plant?.IsTree ?? false)
                    {
                        return;
                    }

                    var height = def.Fillage == FillCategory.Full
                        ? CollisionVertical.WallCollisionHeight
                        : def.fillPercent;
                    height *= CollisionVertical.MeterPerCellHeight;

                    var newEntry = new StatDrawEntry(entry.category, "CE_CoverHeight".Translate(), height.ToStringByStyle(ToStringStyle.FloatMaxTwo) + " m", entry.DisplayPriorityWithinCategory)
                    {
                        overrideReportText = "CE_CoverHeightExplanation".Translate()
                    };

                    AccessTools.Field(__instance.GetType(), "$current").SetValue(__instance, newEntry);
                }
                // Remove obsolete vanilla stats
                else if (StatsToCull.Select(s => s.Translate().CapitalizeFirst()).Contains(entry.LabelCap))
                {
                    __result = __instance.MoveNext();
                }
            }
        }
Exemple #13
0
        public override IEnumerable <StatDrawEntry> SpecialDisplayStats()
        {
            if (!useSkillInCalc)
            {
                yield return(new StatDrawEntry(StatCategoryDefOf.Weapon, "Deflect chance", baseDeflectChance.ToStringPercent(), 0)
                {
                    overrideReportText = "Determines how often this weapon returns projectiles back at the attacker.",
                    //overrideReportText = "DeflectChanceEx".Translate(),
                });
            }
            else
            {
                float calc = Mathf.Clamp(baseDeflectChance + (deflectRatePerSkillPoint * 20), 0f, 1.0f);
                //yield return new StatDrawEntry(StatCategoryDefOf.Weapon, "MaxDeflectChance".Translate(), calc.ToStringPercent(), 0)
                //{
                //    overrideReportText = "MaxDeflectChanceEx".Translate(new object[]
                //    {
                //        deflectSkill.label,
                //        deflectRatePerSkillPoint.ToStringPercent(),
                //        calc.ToStringPercent()
                //    }),
                //};
                yield return(new StatDrawEntry(StatCategoryDefOf.Weapon, "Max deflect chance", calc.ToStringPercent(), 0)
                {
                    overrideReportText = "For each point in " + deflectSkill.label + ", the user gains a " + deflectRatePerSkillPoint.ToStringPercent() + " chance of deflecting the projectile back the target. " + calc.ToStringPercent() + " is the maximum possible deflection chance."
                });

                //yield return new StatDrawEntry(StatCategoryDefOf.Weapon, "DeflectChancePerLevel".Translate(new object[] { deflectSkill.label }), deflectRatePerSkillPoint.ToStringPercent(), 0)
                //{
                //    overrideReportText = "DeflectChancePerLevelEx".Translate(new object[] { deflectSkill.label })
                //};
                //yield return new StatDrawEntry(StatCategoryDefOf.Weapon, "DeflectChancePerLevel".Translate(new object[] { deflectSkill.label }), deflectRatePerSkillPoint.ToStringPercent(), 0)
                //{
                //    overrideReportText = "DeflectChancePerLevelEx".Translate(new object[] { deflectSkill.label })
                //};
                yield return(new StatDrawEntry(StatCategoryDefOf.Weapon, "Deflect % per " + deflectSkill.label + " skill", deflectRatePerSkillPoint.ToStringPercent(), 0)
                {
                    overrideReportText = "For each level in " + deflectSkill.label + ", the user gains this much % chance to deflect a projectile."
                });
            }

            IEnumerator <StatDrawEntry> enumerator2 = this.PostSpecialDisplayStats().GetEnumerator();

            while (enumerator2.MoveNext())
            {
                StatDrawEntry current2 = enumerator2.Current;
                yield return(current2);
            }

            yield break;
        }
        private IEnumerable <StatDrawEntry> StatsToDraw(Thing thing)
        {
            StatDrawEntry entry = new StatDrawEntry(StatCategoryDefOf_Ships.BasicsShip, "Description".Translate(), string.Empty, string.Empty, 99999);

            AccessTools.Field(typeof(StatDrawEntry), "overrideReportText").SetValue(entry, thing.DescriptionFlavor);
            yield return(entry);

            foreach (StatDef stat in from st in DefDatabase <StatDef> .AllDefs
                     where st.category == StatCategoryDefOf_Ships.BasicsShip
                     select st)
            {
                yield return(new StatDrawEntry(stat.category, stat));
            }
        }
Exemple #15
0
        public override void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, ThingWithComps parentThing, string preLabel)
        {
            var            comp      = parentThing.TryGetComp <CompLootAffixableThing>();
            VerbProperties baseVerb  = comp.PrimaryVerbPropsFromDef;  // since parentThing.def.verbs is already swapped
            VerbProperties finalVerb = comp.PrimaryVerbProps;

            FieldInfo field      = AccessTools.Field(typeof(VerbProperties), affectedField);
            float     baseValue  = ConvertHelper.Convert <float>(field.GetValue(baseVerb));
            float     finalValue = ConvertHelper.Convert <float>(field.GetValue(finalVerb));

            basicStatDesc.SpecialDisplayStatsInjectors(
                statDrawEntry:  statDrawEntry,
                preLabel:       preLabel,
                parentThing:    parentThing,
                parentModifier: this,
                baseValue:      baseValue,
                finalValue:     finalValue
                );
        }
Exemple #16
0
        public override IEnumerable <StatDrawEntry> SpecialDisplayStats(StatRequest req)
        {
            if (stages != null && stages.Count == 1)
            {
                using (IEnumerator <StatDrawEntry> enumerator = stages[0].SpecialDisplayStats().GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        StatDrawEntry de = enumerator.Current;
                        yield return(de);

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
            }
            yield break;
IL_00ea:
            /*Error near IL_00eb: Unexpected return in MoveNext()*/;
        }
        public override IEnumerable <StatDrawEntry> SpecialDisplayStats(ThingDef parentDef)
        {
            if (parentDef.IsDrug && base.chance >= 1f)
            {
                using (IEnumerator <StatDrawEntry> enumerator = this.hediffDef.SpecialDisplayStats(StatRequest.ForEmpty()).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        StatDrawEntry s = enumerator.Current;
                        yield return(s);

                        /*Error: Unable to find new state assignment for yield return*/
                        ;
                    }
                }
            }
            yield break;
            /*Error near IL_00e4: Unexpected return in MoveNext()*/
            ;
        }
Exemple #18
0
        static StatDrawEntry Postfix(StatDrawEntry entry, Thing thing)
        {
            ThingWithComps t = thing as ThingWithComps;

            if (t == null)
            {
                return(entry);
            }

            IEnumerable <IDefHyperlinkLister> listers = t.Comps().OfType <IDefHyperlinkLister>();

            if (listers.Count() == 0)
            {
                return(entry);
            }

            Traverse.Create(entry).Field <IEnumerable <Dialog_InfoCard.Hyperlink> >("hyperlinks").Value = Dialog_InfoCard.DefsToHyperlinks(listLinks(thing, listers));

            return(entry);
        }
        // NOTE: This also will get the SpecialDisplayStats entries above
        public void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry)
        {
            // Fix firefoam damage displays
            if (
                statDrawEntry.LabelCap == "Damage".Translate() && parent.def.IsWeaponUsingProjectiles &&
                PrimaryVerbProps?.defaultProjectile?.projectile.damageDef?.harmsHealth == false
                )
            {
                // [Reflection] statDrawEntry.value = 0f
                FieldInfo valueField = AccessTools.Field(typeof(StatDrawEntry), "value");
                valueField.SetValue(statDrawEntry, 0f);
            }

            var affixDict = AllAffixDefsByAffixes;

            foreach (string affixKey in AffixStrings)
            {
                LootAffixDef affix = affixDict[affixKey];
                affix.SpecialDisplayStatsInjectors(statDrawEntry, parent, affixKey);
            }
        }
Exemple #20
0
        public override IEnumerable <StatDrawEntry> SpecialDisplayStatsForThing(ThingWithComps parentThing, string preLabel)
        {
            // Add additional Equipped Stat Offsets modifiers
            var statDrawEntry = new StatDrawEntry(
                category:    StatCategoryDefOf.EquippedStatOffsets,
                label:       affectedStat.LabelCap,
                valueString: ModifierChangeString,  // much more flexible than value
                reportText:  affectedStat.description,
                displayPriorityWithinCategory: 10
                );

            StatRequest req = StatRequest.For(parentThing);

            // Extra properties, since we're overriding the typical stat value display
            statDrawEntry.stat           = affectedStat;
            statDrawEntry.hasOptionalReq = true;
            statDrawEntry.optionalReq    = req;

            // Calculate an example value
            StatWorker worker       = affectedStat.Worker;
            float      exampleValue =
                parentThing.ParentHolder != null && parentThing.ParentHolder is Pawn pawn?
                worker.GetValueUnfinalized(StatRequest.For(pawn)) :
                    affectedStat.defaultBaseValue
            ;

            // Use the Thing-tied StatRequest to hit our StatPart
            worker.FinalizeValue(req, ref exampleValue, true);

            // And finally, another private we need to dodge around to install both kinds of StatDrawEntry fields.

            // [Reflection] statDrawEntry.value = exampleValue;
            FieldInfo valueField = AccessTools.Field(typeof(StatDrawEntry), "value");

            valueField.SetValue(statDrawEntry, exampleValue);

            yield return(statDrawEntry);
        }
Exemple #21
0
        public override IEnumerable <StatDrawEntry> SpecialDisplayStats()
        {
            using (IEnumerator <StatDrawEntry> enumerator = base.SpecialDisplayStats().GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    StatDrawEntry s = enumerator.Current;
                    yield return(s);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            if (this.GetRotStage() == RotStage.Fresh)
            {
                StatDef meatAmount = StatDefOf.MeatAmount;
                yield return(new StatDrawEntry(meatAmount.category, meatAmount, InnerPawn.GetStatValue(meatAmount), StatRequest.For(InnerPawn)));

                /*Error: Unable to find new state assignment for yield return*/;
            }
            yield break;
IL_0197:
            /*Error near IL_0198: Unexpected return in MoveNext()*/;
        }
Exemple #22
0
        // Install our own affix stat data
        public void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, string preLabel, ThingWithComps parentThing, LootAffixModifier parentModifier, string finalString, string baseString = null)
        {
            if (statDrawEntry.LabelCap == GetModifierChangeStat())
            {
                // [Reflection] string reportText = statDrawEntry.overrideReportText
                string    reportText;
                FieldInfo reportTextField = AccessTools.Field(typeof(StatDrawEntry), "overrideReportText");
                reportText = (string)reportTextField.GetValue(statDrawEntry);

                int finalValuePos = reportText.IndexOf("StatsReport_FinalValue".Translate() + ": ");

                string affixValueStr = "RimLoot_AffixStatExplanationPart".Translate(preLabel) + ": " + parentModifier.ModifierChangeString + "\n";

                // Already has a stats report
                if (finalValuePos >= 0)
                {
                    reportText = reportText.Substring(0, finalValuePos) + affixValueStr + reportText.Substring(finalValuePos);
                }
                // No stats report; make our own
                else
                {
                    reportText += "\n\n";
                    if (baseString != null)
                    {
                        string baseValueStr  = "StatsReport_BaseValue".Translate() + ": " + baseString + "\n\n";
                        string finalValueStr = "StatsReport_FinalValue".Translate() + ": " + finalString + "\n";
                        reportText += baseValueStr + affixValueStr + finalValueStr;
                    }
                    else
                    {
                        reportText += affixValueStr;
                    }
                }

                reportTextField.SetValue(statDrawEntry, reportText);
            }
        }
Exemple #23
0
 public virtual void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, ThingWithComps parentThing, string preLabel)
 {
 }
        public static IEnumerable <StatDrawEntry> SpecialDisplayStats(RecipeDef surgery, StatRequest req)
        {
            category = DefDatabase <StatCategoryDef> .GetNamed("Surgery");

            yield return(SurgeryCategoryStat(surgery));

            StatDrawEntry workerModStat = WorkerModStat(surgery);

            if (workerModStat != null)
            {
                yield return(workerModStat);
            }

            yield return(new StatDrawEntry(
                             category:    category,
                             label:       "Stat_Recipe_Surgery_Anesthetize_Name".Translate(),
                             reportText:  "Stat_Recipe_Surgery_Anesthetize_Desc".Translate(),
                             valueString: surgery.anesthetize.ToStringYesNo(),
                             hyperlinks:  new[] { new Dialog_InfoCard.Hyperlink(HediffDefOf.Anesthetic) },
                             displayPriorityWithinCategory: 4950
                             ));

            if (!surgery.hideBodyPartNames)
            {
                yield return(AffectedBodyPartsStat(surgery));
            }
            if (!surgery.incompatibleWithHediffTags.NullOrEmpty())
            {
                yield return(IncompatibleWithHediffTagsStat(surgery));
            }

            if (surgery.addsHediff != null)
            {
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Recipe_Surgery_AddsHediff_Name".Translate(),
                                 reportText:  "Stat_Recipe_Surgery_AddsHediff_Desc".Translate(),
                                 valueString: surgery.addsHediff.LabelCap,
                                 hyperlinks:  new[] { new Dialog_InfoCard.Hyperlink(surgery.addsHediff) },
                                 displayPriorityWithinCategory: 4859
                                 ));
            }
            if (surgery.removesHediff != null)
            {
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Recipe_Surgery_RemovesHediff_Name".Translate(),
                                 reportText:  "Stat_Recipe_Surgery_RemovesHediff_Desc".Translate(),
                                 valueString: surgery.removesHediff.LabelCap,
                                 hyperlinks:  new[] { new Dialog_InfoCard.Hyperlink(surgery.removesHediff) },
                                 displayPriorityWithinCategory: 4858
                                 ));
            }
            if (surgery.changesHediffLevel != null)
            {
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Recipe_Surgery_ChangesHediffLevel_Name".Translate(),
                                 reportText:  "Stat_Recipe_Surgery_ChangesHediffLevel_Desc".Translate(),
                                 valueString: surgery.changesHediffLevel.LabelCap,
                                 hyperlinks:  new[] { new Dialog_InfoCard.Hyperlink(surgery.changesHediffLevel) },
                                 displayPriorityWithinCategory: 4857
                                 ));
            }
        }
        public static StatDrawEntry AffectedBodyPartsStat(RecipeDef surgery)
        {
            var bodyParts     = new List <BodyPartDef> {
            };
            string reportText = "";
            string title      = "";

            if (surgery.targetsBodyPart)
            {
                bodyParts  = surgery.appliedOnFixedBodyParts.ListFullCopy();
                reportText = "Stat_Recipe_Surgery_AffectedBodyParts_Desc".Translate();

                var sBPG = surgery.appliedOnFixedBodyPartGroups;
                if (!surgery.appliedOnFixedBodyPartGroups.NullOrEmpty())
                {
                    bodyParts.AddRange(
                        DefDatabase <BodyDef> .AllDefs.
                        SelectMany(bd => bd.AllParts).Distinct().
                        Where(bpr => sBPG.Any(bpgd => bpr.groups.Contains(bpgd))).
                        Select(bpr => bpr.def)
                        );
                }
            }

            // Remove duplicates. No, really...
            bodyParts.RemoveDuplicates();
            bodyParts = bodyParts.OrderBy(bpd => bpd.LabelShort).ToList();

            // Use SimplifyBodyPartLabel to remove dupes, but it's not really suitable for display text, because
            // of certain spelling errors.  So, we'll use the shortest string in each group for that.
            List <string> bodyPartLabels =
                bodyParts.
                Select(bpd => GenText.CapitalizeFirst(bpd.LabelShort)).
                // order first to make sure distinct picks the shortest one
                OrderBy(s => s.Length).
                ThenBy(s => s).
                Distinct(BodyPartMatcher.StringEqualityComparer).
                ToList()
            ;

            if (bodyPartLabels.Count == 0)
            {
                if (surgery.targetsBodyPart)
                {
                    title      = "Any".Translate();
                    reportText = "Stat_Recipe_Surgery_AffectedBodyParts_Desc_Any".Translate();
                }
                else
                {
                    title      = "None".Translate();
                    reportText = "Stat_Recipe_Surgery_AffectedBodyParts_Desc_None".Translate();
                }
            }
            else if (bodyPartLabels.Count <= 5)
            {
                title = string.Join("\n", bodyPartLabels);
            }
            else if (surgery.appliedOnFixedBodyPartGroups.Count > 0 && surgery.appliedOnFixedBodyPartGroups.Count <= 5)
            {
                title = string.Join("\n", surgery.appliedOnFixedBodyPartGroups.Select(bpd => bpd.LabelShortCap));
            }
            else if (surgery.appliedOnFixedBodyParts.Count > 0 && surgery.appliedOnFixedBodyParts.Count <= 5)
            {
                title = string.Join("\n", surgery.appliedOnFixedBodyParts.Select(bpd => bpd.LabelShortCap));
            }
            else
            {
                title = "VariousLabel".Translate();
            }

            var sde = new StatDrawEntry(
                category:    category,
                label:       "Stat_Recipe_Surgery_AffectedBodyParts_Name".Translate(),
                reportText:  reportText,
                valueString: title,
                hyperlinks:  bodyParts.Select(bpd => new Dialog_InfoCard.Hyperlink(bpd)),
                displayPriorityWithinCategory: 4875
                );

            return(sde);
        }
        private void DrawStatsWorker(Rect rect)
        {
            Rect rect2 = new Rect(rect);

            rect2.width *= 0.5f;
            Rect rect3 = new Rect(rect);

            rect3.x     = rect2.xMax;
            rect3.width = rect.xMax - rect3.x;
            Text.Font   = GameFont.Small;
            Rect viewRect = new Rect(0f, 0f, rect2.width - 16f, listHeight);

            Widgets.BeginScrollView(rect2, ref scrollPosition, viewRect, true);
            float  num = 0f;
            string b   = null;

            cachedDrawEntries = this.StatsToDraw(this.thing).ToList();
            this.FinalizeCachedDrawEntries();
            mousedOverEntry = null;
            foreach (StatDrawEntry stat in cachedDrawEntries)
            {
                if (stat.category.LabelCap != b)
                {
                    Widgets.ListSeparator(ref num, viewRect.width, stat.category.LabelCap);
                    b = stat.category.LabelCap;
                }
                num += stat.Draw(8f, num, viewRect.width - 8f, selectedEntry == stat, delegate
                {
                    selectedEntry = stat;
                    SoundDefOf.Tick_High.PlayOneShotOnCamera(null);
                }, delegate
                {
                    mousedOverEntry = stat;
                }, scrollPosition, rect2);
            }
            listHeight = num + 100f;
            Widgets.EndScrollView();
            Rect rect4 = rect3.ContractedBy(10f);

            GUI.BeginGroup(rect4);
            StatDrawEntry statDrawEntry;

            if ((statDrawEntry = selectedEntry) is null)
            {
                statDrawEntry = mousedOverEntry ?? cachedDrawEntries.FirstOrDefault <StatDrawEntry>();
            }
            StatDrawEntry statDrawEntry2 = statDrawEntry;

            if (statDrawEntry2 != null)
            {
                StatRequest optionalReq;
                if (statDrawEntry2.hasOptionalReq)
                {
                    optionalReq = statDrawEntry2.optionalReq;
                }
                else if (this.thing != null)
                {
                    optionalReq = StatRequest.For(this.thing);
                }
                else
                {
                    optionalReq = StatRequest.ForEmpty();
                }
                string explanation = statDrawEntry2.GetExplanationText(optionalReq);
                Rect   rect5       = rect4.AtZero();
                Widgets.Label(rect5, explanation);
            }
            GUI.EndGroup();
        }
Exemple #27
0
 public override void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, ThingWithComps parentThing, string preLabel)
 {
     // Nothing to inject
 }
        public override IEnumerable <StatDrawEntry> SpecialDisplayStats()
        {
            StatDrawEntry fuelEfficencyEntry = new StatDrawEntry(StatCategoryDefOf.EquippedStatOffsets, "AndroidFuelEfficencyStatPartLabel".Translate(), FuelUsageModifier().ToString("F2"), "AndroidFuelEfficencyStatPartReport".Translate(), 0);

            yield return(fuelEfficencyEntry);
        }
Exemple #29
0
 public abstract override void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, ThingWithComps parentThing, string preLabel);